Switching to linux for development of pglab.

Switched from qmake to cmake. Code changes to make it compile.
This commit is contained in:
Eelke Klein 2017-08-23 08:10:01 +02:00
parent dd9906dbd8
commit 04723a289b
142 changed files with 124 additions and 83 deletions

123
pglab/QueryResultModel.cpp Normal file
View 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;
//}