#include "resultmodel.h" #include #include using std::cout; using std::endl; using std::string; using std::vector; ResultModel::ResultModel(vector> inputData, vector header, QObject * parent) : QAbstractTableModel(parent) { this->inputData = inputData; this->headers = header; } QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) { if (section < static_cast(this->headers.size())) { unsigned long index = static_cast(section); string strToReturn = this->headers.at(index); QString qStrToReturn = QString::fromStdString(strToReturn); return qStrToReturn; } else { return QVariant(); } } } return QVariant(); } int ResultModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); return static_cast(this->inputData.size()); } int ResultModel::columnCount(const QModelIndex & parent) const { Q_UNUSED(parent); if (this->inputData.size() > 0) { return static_cast(this->inputData.at(0).size()); } else { return 0; } } QVariant ResultModel::data(const QModelIndex & index, int role) const { try { if (role == Qt::EditRole || role == Qt::DisplayRole) { unsigned long row = static_cast(index.row()); unsigned long col = static_cast(index.column()); int value = this->inputData.at(row).at(col); return QString::fromStdString(boost::lexical_cast(value)); } } catch (std::exception & e) { Q_UNUSED(e); } return QVariant(); }