Added type of column on second line in column headers of QueryResultModel.

This commit is contained in:
eelke 2017-12-13 18:49:58 +01:00
parent c6dbe72170
commit b5d800c87e
5 changed files with 26 additions and 13 deletions

View file

@ -36,7 +36,7 @@ MainWindow::~MainWindow()
QueryTab* MainWindow::newSqlPage() QueryTab* MainWindow::newSqlPage()
{ {
QueryTab *qt = new QueryTab(this); QueryTab *qt = new QueryTab(this);
qt->setConfig(m_config); qt->setConfig(m_config, m_database->catalogue());
ui->tabWidget->addTab(qt, "Tab"); ui->tabWidget->addTab(qt, "Tab");
ui->tabWidget->setCurrentWidget(qt); ui->tabWidget->setCurrentWidget(qt);
qt->newdoc(); qt->newdoc();

View file

@ -1,14 +1,17 @@
#include "QueryResultModel.h" #include "QueryResultModel.h"
#include "ResultTableModelUtil.h" #include "ResultTableModelUtil.h"
#include "Pgsql_declare.h" #include "Pgsql_declare.h"
#include "PgDatabaseCatalog.h"
#include <QBrush> #include <QBrush>
#include <QColor> #include <QColor>
using namespace Pgsql; using namespace Pgsql;
QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r) QueryResultModel::QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r
, std::shared_ptr<PgDatabaseCatalog> cat)
: BaseTableModel(parent) : BaseTableModel(parent)
, result(std::move(r)) , result(std::move(r))
, catalog(cat)
{} {}
@ -73,7 +76,10 @@ QVariant QueryResultModel::headerData(int section, Qt::Orientation orientation,
QVariant r; QVariant r;
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) { if (orientation == Qt::Horizontal) {
r = QString(result->getColName(section)); QString s(result->getColName(section));
s += "\n";
s += getTypeDisplayString(*catalog, getType(section));
r = s;
} }
else { else {
r = QString::number(section + 1); r = QString::number(section + 1);

View file

@ -5,11 +5,13 @@
#include "BaseTableModel.h" #include "BaseTableModel.h"
#include "Pgsql_Connection.h" #include "Pgsql_Connection.h"
class PgDatabaseCatalog;
class QueryResultModel : public BaseTableModel class QueryResultModel : public BaseTableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r); QueryResultModel(QObject *parent, std::shared_ptr<Pgsql::Result> r, std::shared_ptr<PgDatabaseCatalog> cat);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(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; virtual QVariant getData(const QModelIndex &index) const override;
private: private:
std::shared_ptr<Pgsql::Result> result; std::shared_ptr<Pgsql::Result> result;
std::shared_ptr<PgDatabaseCatalog> catalog;
}; };
#endif // QUERYRESULTMODEL_H #endif // QUERYRESULTMODEL_H

View file

@ -63,9 +63,11 @@ QueryTab::~QueryTab()
delete ui; delete ui;
} }
void QueryTab::setConfig(const ConnectionConfig &config) void QueryTab::setConfig(const ConnectionConfig &config,
std::shared_ptr<PgDatabaseCatalog> cat)
{ {
m_config = config; m_config = config;
m_catalog = cat;
m_win->QueueTask([this]() { startConnect(); }); m_win->QueueTask([this]() { startConnect(); });
} }
@ -454,7 +456,8 @@ void QueryTab::query_ready(Expected<std::shared_ptr<Pgsql::Result>> exp_res, qin
//int n_rows = dbres->getRows(); //int n_rows = dbres->getRows();
//QString rowcount_str = QString("rows: %1").arg(dbres->getRows()); //QString rowcount_str = QString("rows: %1").arg(dbres->getRows());
auto result_model = std::make_shared<QueryResultModel>(nullptr , dbres); auto result_model = std::make_shared<QueryResultModel>(nullptr , dbres,
m_catalog);
TuplesResultWidget *trw = new TuplesResultWidget; TuplesResultWidget *trw = new TuplesResultWidget;
trw->setResult(result_model, elapsedms); trw->setResult(result_model, elapsedms);
resultList.push_back(trw); resultList.push_back(trw);

View file

@ -25,6 +25,7 @@ class QueryExplainModel;
class PgTypeContainer; class PgTypeContainer;
class OpenDatabase; class OpenDatabase;
class QueryParamListController; class QueryParamListController;
class PgDatabaseCatalog;
class QueryTab : public QWidget { class QueryTab : public QWidget {
Q_OBJECT Q_OBJECT
@ -32,7 +33,7 @@ public:
QueryTab(MainWindow *win, QWidget *parent = nullptr); QueryTab(MainWindow *win, QWidget *parent = nullptr);
~QueryTab(); ~QueryTab();
void setConfig(const ConnectionConfig &config); void setConfig(const ConnectionConfig &config, std::shared_ptr<PgDatabaseCatalog>cat);
void newdoc(); void newdoc();
// void open(); // void open();
@ -70,6 +71,12 @@ private:
QString m_fileName; ///< use setFileName function to set QString m_fileName; ///< use setFileName function to set
bool m_queryTextChanged = false; bool m_queryTextChanged = false;
std::shared_ptr<PgDatabaseCatalog> m_catalog;
ASyncDBConnection m_dbConnection;
std::unique_ptr<QueryExplainModel> explainModel;
ResultTabContainer resultList;
void setFileName(const QString &filename); void setFileName(const QString &filename);
bool continueWithoutSavingWarning(); bool continueWithoutSavingWarning();
bool saveSqlTo(const QString &filename); bool saveSqlTo(const QString &filename);
@ -77,12 +84,6 @@ private:
ASyncDBConnection m_dbConnection;
std::unique_ptr<QueryExplainModel> explainModel;
ResultTabContainer resultList;
void addLog(QString s); void addLog(QString s);
QString getCommand() const; QString getCommand() const;