QueryTool now uses the same DataGrid as the CRUD tool.
This commit is contained in:
parent
bbe52c9db8
commit
5e7fb68c55
15 changed files with 135 additions and 203 deletions
|
|
@ -1,85 +0,0 @@
|
|||
#include "QueryResultModel.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "Pgsql_declare.h"
|
||||
#include "Pgsql_oids.h"
|
||||
#include "catalog/PgDatabaseCatalog.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
|
||||
using namespace Pgsql;
|
||||
|
||||
QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r
|
||||
, std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
: QAbstractTableModel(parent)
|
||||
, result(std::move(r))
|
||||
, catalog(cat)
|
||||
{}
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
// 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 || role == Qt::EditRole) {
|
||||
if (result->null(col, rij)) {
|
||||
//v = nullptr;
|
||||
}
|
||||
else {
|
||||
Value value = result->get(col, rij);
|
||||
if (oid == bool_oid) {
|
||||
bool b = value;
|
||||
v = b;
|
||||
}
|
||||
else {
|
||||
QString s = value;
|
||||
v = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (role == CustomDataTypeRole) {
|
||||
v = oid;
|
||||
}
|
||||
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
QVariant QueryResultModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
QVariant r;
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (orientation == Qt::Horizontal) {
|
||||
QString s(result->getColName(section));
|
||||
s += "\n";
|
||||
s += getTypeDisplayString(*catalog, result->type(section));
|
||||
r = s;
|
||||
}
|
||||
else {
|
||||
r = QString::number(section + 1);
|
||||
}
|
||||
}
|
||||
Qt::ItemFlags f;
|
||||
return r;
|
||||
}
|
||||
|
||||
Qt::ItemFlags QueryResultModel::flags(const QModelIndex &) const
|
||||
{
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef QUERYRESULTMODEL_H
|
||||
#define QUERYRESULTMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include "catalog/models/BaseTableModel.h"
|
||||
#include "Pgsql_Connection.h"
|
||||
|
||||
class PgDatabaseCatalog;
|
||||
|
||||
class QueryResultModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r, std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
std::shared_ptr<const Pgsql::Result> GetPgsqlResult() const { return result; }
|
||||
protected:
|
||||
// virtual Oid getType(int column) const override;
|
||||
// virtual QVariant getData(const QModelIndex &index) const override;
|
||||
private:
|
||||
std::shared_ptr<Pgsql::Result> result;
|
||||
std::shared_ptr<PgDatabaseCatalog> catalog;
|
||||
};
|
||||
|
||||
#endif // QUERYRESULTMODEL_H
|
||||
|
|
@ -476,10 +476,8 @@ void QueryTool::query_ready(std::shared_ptr<Pgsql::Result> dbres, qint64 elapsed
|
|||
//int n_rows = dbres->getRows();
|
||||
//QString rowcount_str = QString("rows: %1").arg(dbres->getRows());
|
||||
|
||||
auto result_model = std::make_shared<QueryResultModel>(nullptr , dbres,
|
||||
m_catalog);
|
||||
TuplesResultWidget *trw = new TuplesResultWidget;
|
||||
trw->setResult(result_model, elapsedms);
|
||||
trw->setResult(m_context->openDatabase(), dbres, elapsedms);
|
||||
resultList.push_back(trw);
|
||||
ui->tabWidget->addTab(trw, "Data");
|
||||
if (resultList.size() == 1)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "ManagedPage.h"
|
||||
#include "ASyncDBConnection.h"
|
||||
#include "QueryResultModel.h"
|
||||
#include "QueryExplainModel.h"
|
||||
#include "stopwatch.h"
|
||||
#include "tuplesresultwidget.h"
|
||||
|
|
@ -26,7 +25,6 @@ class QTableView;
|
|||
class QTabWidget;
|
||||
class SqlSyntaxHighlighter;
|
||||
class ExplainRoot;
|
||||
class QueryResultModel;
|
||||
class QueryExplainModel;
|
||||
class PgTypeContainer;
|
||||
class OpenDatabase;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue