Initial commit. Contains a simple query tool.
This commit is contained in:
commit
edc6df25da
19 changed files with 1245 additions and 0 deletions
58
queryresultmodel.cpp
Normal file
58
queryresultmodel.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#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;
|
||||
//}
|
||||
Loading…
Add table
Add a link
Reference in a new issue