Builds on windows again
This commit is contained in:
parent
33cf39b799
commit
bebb3391c3
160 changed files with 138 additions and 117 deletions
123
pglab/QueryResultModel.cpp
Normal file
123
pglab/QueryResultModel.cpp
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#include "QueryResultModel.h"
|
||||
#include "Pgsql_declare.h"
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
|
||||
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->rows();
|
||||
return r;
|
||||
}
|
||||
|
||||
int QueryResultModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
int r = result->cols();
|
||||
return r;
|
||||
}
|
||||
|
||||
QVariant QueryResultModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
using namespace Pgsql;
|
||||
|
||||
QVariant r;
|
||||
int rij = index.row();
|
||||
int col = index.column();
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (result->null(col, rij)) {
|
||||
r = "null";
|
||||
}
|
||||
else {
|
||||
Oid o = result->type(col);
|
||||
QString s(result->val(col, rij));
|
||||
switch (o) {
|
||||
case oid_bool:
|
||||
s = (s == "t") ? "TRUE" : "FALSE";
|
||||
// intentional fall through
|
||||
default:
|
||||
if (s.length() > 256) {
|
||||
s.truncate(256);
|
||||
}
|
||||
r = s;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else if (role == Qt::TextAlignmentRole) {
|
||||
Oid o = result->type(col);
|
||||
switch (o) {
|
||||
case oid_int2:
|
||||
case oid_int4:
|
||||
case oid_int8:
|
||||
case oid_float4:
|
||||
case oid_float8:
|
||||
case oid_numeric:
|
||||
case oid_oid:
|
||||
r = Qt::AlignRight + Qt::AlignVCenter;
|
||||
break;
|
||||
case oid_bool:
|
||||
r = Qt::AlignCenter;
|
||||
break;
|
||||
default:
|
||||
r = Qt::AlignLeft + Qt::AlignVCenter;
|
||||
}
|
||||
}
|
||||
else if (role == Qt::ForegroundRole) {
|
||||
if (result->null(col, rij)) {
|
||||
r = QBrush(Qt::gray);
|
||||
}
|
||||
else {
|
||||
Oid o = result->type(col);
|
||||
switch (o) {
|
||||
case oid_int2:
|
||||
case oid_int4:
|
||||
case oid_int8:
|
||||
r = QBrush(Qt::darkBlue);
|
||||
break;
|
||||
case oid_float4:
|
||||
case oid_float8:
|
||||
r = QBrush(Qt::darkCyan);
|
||||
break;
|
||||
case oid_numeric:
|
||||
r = QBrush(Qt::darkGreen);
|
||||
break;
|
||||
case oid_bool:
|
||||
if (strcmp(result->val(col, rij), "t") == 0) {
|
||||
r = QBrush(Qt::darkGreen);
|
||||
}
|
||||
else {
|
||||
r = QBrush(Qt::darkRed);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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