QueryResultModel relies on BaseTableModel for most formatting now.
This commit is contained in:
parent
dec52a3829
commit
5a199c9138
4 changed files with 40 additions and 63 deletions
|
|
@ -5,7 +5,7 @@
|
|||
#include <QColor>
|
||||
|
||||
QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r)
|
||||
: QAbstractTableModel(parent)
|
||||
: BaseTableModel(parent)
|
||||
, result(std::move(r))
|
||||
{}
|
||||
|
||||
|
|
@ -22,72 +22,48 @@ int QueryResultModel::columnCount(const QModelIndex &) const
|
|||
return r;
|
||||
}
|
||||
|
||||
QVariant QueryResultModel::data(const QModelIndex &index, int role) const
|
||||
Oid QueryResultModel::getType(int column) const
|
||||
{
|
||||
using namespace Pgsql;
|
||||
return result->type(column);
|
||||
}
|
||||
|
||||
QVariant QueryResultModel::getData(const QModelIndex &index) const
|
||||
{
|
||||
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 BOOLOID:
|
||||
s = (s == "t") ? "TRUE" : "FALSE";
|
||||
// intentional fall through
|
||||
default:
|
||||
if (s.length() > 256) {
|
||||
s.truncate(256);
|
||||
}
|
||||
r = s;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (result->null(col, rij)) {
|
||||
r = "null";
|
||||
}
|
||||
else if (role == Qt::TextAlignmentRole) {
|
||||
r = GetDefaultAlignmentForType(result->type(col));
|
||||
}
|
||||
else if (role == Qt::ForegroundRole) {
|
||||
if (result->null(col, rij)) {
|
||||
r = QBrush(Qt::gray);
|
||||
}
|
||||
else {
|
||||
Oid o = result->type(col);
|
||||
switch (o) {
|
||||
case INT2OID:
|
||||
case INT4OID:
|
||||
case INT8OID:
|
||||
r = QBrush(Qt::darkBlue);
|
||||
break;
|
||||
case FLOAT4OID:
|
||||
case FLOAT8OID:
|
||||
r = QBrush(Qt::darkCyan);
|
||||
break;
|
||||
case NUMERICOID:
|
||||
r = QBrush(Qt::darkGreen);
|
||||
break;
|
||||
case BOOLOID:
|
||||
if (strcmp(result->val(col, rij), "t") == 0) {
|
||||
r = QBrush(Qt::darkGreen);
|
||||
}
|
||||
else {
|
||||
r = QBrush(Qt::darkRed);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
else {
|
||||
// Oid o = result->type(col);
|
||||
QString s(result->val(col, rij));
|
||||
// switch (o) {
|
||||
// case BOOLOID:
|
||||
// s = (s == "t") ? "TRUE" : "FALSE";
|
||||
// // intentional fall through
|
||||
// default:
|
||||
if (s.length() > 256) {
|
||||
s.truncate(256);
|
||||
}
|
||||
}
|
||||
r = s;
|
||||
// }
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
QVariant QueryResultModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::ForegroundRole) {
|
||||
int rij = index.row();
|
||||
int col = index.column();
|
||||
if (result->null(col, rij)) {
|
||||
return QBrush(Qt::gray);
|
||||
}
|
||||
}
|
||||
return BaseTableModel::data(index, role);
|
||||
}
|
||||
|
||||
QVariant QueryResultModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
QVariant r;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue