From b5d800c87e7a12f9116069029d8e407eb4bea345 Mon Sep 17 00:00:00 2001 From: eelke Date: Wed, 13 Dec 2017 18:49:58 +0100 Subject: [PATCH] Added type of column on second line in column headers of QueryResultModel. --- pglab/MainWindow.cpp | 2 +- pglab/QueryResultModel.cpp | 10 ++++++++-- pglab/QueryResultModel.h | 5 ++++- pglab/QueryTab.cpp | 7 +++++-- pglab/QueryTab.h | 15 ++++++++------- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pglab/MainWindow.cpp b/pglab/MainWindow.cpp index 2b34610..da16f28 100644 --- a/pglab/MainWindow.cpp +++ b/pglab/MainWindow.cpp @@ -36,7 +36,7 @@ MainWindow::~MainWindow() QueryTab* MainWindow::newSqlPage() { QueryTab *qt = new QueryTab(this); - qt->setConfig(m_config); + qt->setConfig(m_config, m_database->catalogue()); ui->tabWidget->addTab(qt, "Tab"); ui->tabWidget->setCurrentWidget(qt); qt->newdoc(); diff --git a/pglab/QueryResultModel.cpp b/pglab/QueryResultModel.cpp index 2af82fd..45418b0 100644 --- a/pglab/QueryResultModel.cpp +++ b/pglab/QueryResultModel.cpp @@ -1,14 +1,17 @@ #include "QueryResultModel.h" #include "ResultTableModelUtil.h" #include "Pgsql_declare.h" +#include "PgDatabaseCatalog.h" #include #include using namespace Pgsql; -QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr r) +QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr r + , std::shared_ptr cat) : BaseTableModel(parent) , result(std::move(r)) + , catalog(cat) {} @@ -73,7 +76,10 @@ QVariant QueryResultModel::headerData(int section, Qt::Orientation orientation, QVariant r; if (role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) { - r = QString(result->getColName(section)); + QString s(result->getColName(section)); + s += "\n"; + s += getTypeDisplayString(*catalog, getType(section)); + r = s; } else { r = QString::number(section + 1); diff --git a/pglab/QueryResultModel.h b/pglab/QueryResultModel.h index 1481686..815d65d 100644 --- a/pglab/QueryResultModel.h +++ b/pglab/QueryResultModel.h @@ -5,11 +5,13 @@ #include "BaseTableModel.h" #include "Pgsql_Connection.h" +class PgDatabaseCatalog; + class QueryResultModel : public BaseTableModel { Q_OBJECT public: - QueryResultModel(QObject *parent, std::shared_ptr r); + QueryResultModel(QObject *parent, std::shared_ptr r, std::shared_ptr cat); int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; @@ -22,6 +24,7 @@ protected: virtual QVariant getData(const QModelIndex &index) const override; private: std::shared_ptr result; + std::shared_ptr catalog; }; #endif // QUERYRESULTMODEL_H diff --git a/pglab/QueryTab.cpp b/pglab/QueryTab.cpp index 05e7d0b..0a87a6c 100644 --- a/pglab/QueryTab.cpp +++ b/pglab/QueryTab.cpp @@ -63,9 +63,11 @@ QueryTab::~QueryTab() delete ui; } -void QueryTab::setConfig(const ConnectionConfig &config) +void QueryTab::setConfig(const ConnectionConfig &config, + std::shared_ptr cat) { m_config = config; + m_catalog = cat; m_win->QueueTask([this]() { startConnect(); }); } @@ -454,7 +456,8 @@ void QueryTab::query_ready(Expected> exp_res, qin //int n_rows = dbres->getRows(); //QString rowcount_str = QString("rows: %1").arg(dbres->getRows()); - auto result_model = std::make_shared(nullptr , dbres); + auto result_model = std::make_shared(nullptr , dbres, + m_catalog); TuplesResultWidget *trw = new TuplesResultWidget; trw->setResult(result_model, elapsedms); resultList.push_back(trw); diff --git a/pglab/QueryTab.h b/pglab/QueryTab.h index d8d18ce..73175d2 100644 --- a/pglab/QueryTab.h +++ b/pglab/QueryTab.h @@ -25,6 +25,7 @@ class QueryExplainModel; class PgTypeContainer; class OpenDatabase; class QueryParamListController; +class PgDatabaseCatalog; class QueryTab : public QWidget { Q_OBJECT @@ -32,7 +33,7 @@ public: QueryTab(MainWindow *win, QWidget *parent = nullptr); ~QueryTab(); - void setConfig(const ConnectionConfig &config); + void setConfig(const ConnectionConfig &config, std::shared_ptrcat); void newdoc(); // void open(); @@ -70,6 +71,12 @@ private: QString m_fileName; ///< use setFileName function to set bool m_queryTextChanged = false; + std::shared_ptr m_catalog; + ASyncDBConnection m_dbConnection; + + std::unique_ptr explainModel; + ResultTabContainer resultList; + void setFileName(const QString &filename); bool continueWithoutSavingWarning(); bool saveSqlTo(const QString &filename); @@ -77,12 +84,6 @@ private: - - ASyncDBConnection m_dbConnection; - - std::unique_ptr explainModel; - ResultTabContainer resultList; - void addLog(QString s); QString getCommand() const;