pgLab/queryresultmodel.cpp
Eelke Klein a36bf5f7f4 Query, Explain and Cancel are going throught the asyncdbconnection now.
Todo: Notice processing and error reporting.
2017-01-08 09:58:34 +01:00

58 lines
1.2 KiB
C++

#include "queryresultmodel.h"
QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r)
: QAbstractTableModel(parent)
, result(std::move(r))
{}
int QueryResultModel::rowCount(const QModelIndex &) const
{
int r = result->getRows();
return r;
}
int QueryResultModel::columnCount(const QModelIndex &) const
{
int r = result->getCols();
return r;
}
QVariant QueryResultModel::data(const QModelIndex &index, int role) const
{
QVariant r;
int rij = index.row();
int col = index.column();
if (role == Qt::DisplayRole) {
r = QString(result->getVal(col, rij));
}
else if (role == Qt::TextAlignmentRole) {
if (col == 0) {
r = Qt::AlignRight + Qt::AlignVCenter;
}
else {
r = Qt::AlignLeft + Qt::AlignVCenter;
}
}
return r;
}
QVariant QueryResultModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant r;
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
r = QString(result->getColName(section));
}
else {
r = QString::number(section + 1);
}
}
return r;
}
//Qt::ItemFlags QueryResultModel::flags(const QModelIndex &) const
//{
// return Qt::ItemIsUserCheckable;
//}