QueryResultModel inherits from QAbstractTableModel now instead of BaseTableModel and the tableview now gets a custom delegate.
This commit is contained in:
parent
3ac1d21728
commit
208883462c
3 changed files with 51 additions and 41 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "QueryResultModel.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "Pgsql_declare.h"
|
||||
#include "Pgsql_oids.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
|
|
@ -9,7 +10,7 @@ using namespace Pgsql;
|
|||
|
||||
QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r
|
||||
, std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
: BaseTableModel(parent)
|
||||
: QAbstractTableModel(parent)
|
||||
, result(std::move(r))
|
||||
, catalog(cat)
|
||||
{}
|
||||
|
|
@ -27,48 +28,51 @@ int QueryResultModel::columnCount(const QModelIndex &) const
|
|||
return r;
|
||||
}
|
||||
|
||||
Oid QueryResultModel::getType(int column) const
|
||||
{
|
||||
return result->type(column);
|
||||
}
|
||||
//Oid QueryResultModel::getType(int column) const
|
||||
//{
|
||||
// return result->type(column);
|
||||
//}
|
||||
|
||||
QVariant QueryResultModel::getData(const QModelIndex &index) const
|
||||
{
|
||||
QVariant r;
|
||||
int rij = index.row();
|
||||
int col = index.column();
|
||||
if (result->null(col, rij)) {
|
||||
r = "null";
|
||||
}
|
||||
else {
|
||||
Oid o = result->type(col);
|
||||
auto value = result->get(col, rij);
|
||||
switch (o) {
|
||||
case BOOLOID:
|
||||
r = bool(value); //s = (s == "t") ? "TRUE" : "FALSE";
|
||||
break;
|
||||
default: {
|
||||
QString s = value;
|
||||
if (s.length() > 256) {
|
||||
s.truncate(256);
|
||||
}
|
||||
r = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
//QVariant QueryResultModel::getData(const QModelIndex &index) const
|
||||
//{
|
||||
// QVariant r;
|
||||
// int rij = index.row();
|
||||
// int col = index.column();
|
||||
// return r;
|
||||
//}
|
||||
|
||||
QVariant QueryResultModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::ForegroundRole) {
|
||||
int rij = index.row();
|
||||
int col = index.column();
|
||||
// static const QString null_str("null");
|
||||
QVariant v;
|
||||
|
||||
const int col = index.column();
|
||||
const int rij = index.row();
|
||||
const Oid oid = result->type(col);
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (result->null(col, rij)) {
|
||||
return QBrush(Qt::gray);
|
||||
//v = nullptr;
|
||||
}
|
||||
else {
|
||||
auto value = result->val(col, rij);
|
||||
if (oid == bool_oid) {
|
||||
bool b = value;
|
||||
v = b;
|
||||
}
|
||||
else {
|
||||
QString s = value;
|
||||
if (s.length() > 256) {
|
||||
s.truncate(256);
|
||||
}
|
||||
v = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return BaseTableModel::data(index, role);
|
||||
else if (role == Qt::UserRole) {
|
||||
v = oid;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
QVariant QueryResultModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
|
@ -78,7 +82,7 @@ QVariant QueryResultModel::headerData(int section, Qt::Orientation orientation,
|
|||
if (orientation == Qt::Horizontal) {
|
||||
QString s(result->getColName(section));
|
||||
s += "\n";
|
||||
s += getTypeDisplayString(*catalog, getType(section));
|
||||
s += getTypeDisplayString(*catalog, result->type(section));
|
||||
r = s;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue