66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#include "resultmodel.h"
|
|
#include <boost/lexical_cast.hpp>
|
|
#include <iostream>
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
ResultModel::ResultModel(vector<vector<int>> inputData, vector<string> 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<int>(this->headers.size())) {
|
|
|
|
unsigned long index = static_cast<unsigned long>(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<int>(this->inputData.size());
|
|
}
|
|
|
|
int ResultModel::columnCount(const QModelIndex & parent) const {
|
|
Q_UNUSED(parent);
|
|
if (this->inputData.size() > 0) {
|
|
return static_cast<int>(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<unsigned long>(index.row());
|
|
unsigned long col = static_cast<unsigned long>(index.column());
|
|
int value = this->inputData.at(row).at(col);
|
|
|
|
return QString::fromStdString(boost::lexical_cast<string>(value));
|
|
}
|
|
} catch (std::exception & e) {
|
|
Q_UNUSED(e);
|
|
}
|
|
return QVariant();
|
|
}
|