59 lines
1.1 KiB
C++
59 lines
1.1 KiB
C++
|
|
#include "queryresultmodel.h"
|
|||
|
|
|
|||
|
|
QueryResultModel::QueryResultModel(QObject *parent, 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;
|
|||
|
|
//}
|