2017-01-21 18:16:57 +01:00
|
|
|
|
#ifndef QUERYTAB_H
|
2017-01-21 08:09:12 +01:00
|
|
|
|
#define QUERYTAB_H
|
|
|
|
|
|
|
2017-08-23 13:27:23 +02:00
|
|
|
|
#include "ASyncDBConnection.h"
|
|
|
|
|
|
#include "QueryResultModel.h"
|
|
|
|
|
|
#include "QueryExplainModel.h"
|
2017-01-22 08:50:41 +01:00
|
|
|
|
#include "stopwatch.h"
|
2017-01-25 06:54:21 +01:00
|
|
|
|
#include "tuplesresultwidget.h"
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
2017-01-21 08:09:12 +01:00
|
|
|
|
#include <QWidget>
|
2018-05-14 20:24:41 +02:00
|
|
|
|
#include "PlgPage.h"
|
2017-01-21 18:16:57 +01:00
|
|
|
|
#include <memory>
|
2017-01-21 08:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Ui {
|
2017-01-25 06:54:21 +01:00
|
|
|
|
class QueryTab;
|
2017-01-21 08:09:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-09 21:44:00 +02:00
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
class ErrorDetails ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-19 11:12:43 +01:00
|
|
|
|
class QTableView;
|
|
|
|
|
|
|
2017-02-01 18:01:02 +01:00
|
|
|
|
class QTabWidget;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
class MainWindow;
|
2017-02-07 21:39:45 +01:00
|
|
|
|
class SqlSyntaxHighlighter;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
class ExplainRoot;
|
|
|
|
|
|
class QueryResultModel;
|
|
|
|
|
|
class QueryExplainModel;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
class PgTypeContainer;
|
2017-02-19 11:12:43 +01:00
|
|
|
|
class OpenDatabase;
|
2017-12-09 14:16:47 +01:00
|
|
|
|
class QueryParamListController;
|
2017-12-13 18:49:58 +01:00
|
|
|
|
class PgDatabaseCatalog;
|
2017-02-19 11:12:43 +01:00
|
|
|
|
|
2018-05-14 20:24:41 +02:00
|
|
|
|
class QueryTab : public PlgPage {
|
2017-02-19 11:12:43 +01:00
|
|
|
|
Q_OBJECT
|
2017-01-21 08:09:12 +01:00
|
|
|
|
public:
|
2017-02-19 11:12:43 +01:00
|
|
|
|
QueryTab(MainWindow *win, QWidget *parent = nullptr);
|
2017-01-21 08:09:12 +01:00
|
|
|
|
~QueryTab();
|
|
|
|
|
|
|
2017-12-13 18:49:58 +01:00
|
|
|
|
void setConfig(const ConnectionConfig &config, std::shared_ptr<PgDatabaseCatalog>cat);
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
2017-01-22 08:50:41 +01:00
|
|
|
|
void newdoc();
|
|
|
|
|
|
// void open();
|
|
|
|
|
|
bool load(const QString &filename);
|
2017-02-19 14:46:01 +01:00
|
|
|
|
bool save();
|
|
|
|
|
|
bool saveAs();
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void saveCopyAs();
|
|
|
|
|
|
|
|
|
|
|
|
void execute();
|
2017-01-25 06:54:21 +01:00
|
|
|
|
void explain(bool analyze);
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void cancel();
|
2017-01-22 08:50:41 +01:00
|
|
|
|
|
|
|
|
|
|
bool canClose();
|
2017-02-05 08:23:06 +01:00
|
|
|
|
|
|
|
|
|
|
void copyQueryAsCString();
|
2017-10-05 16:02:06 +02:00
|
|
|
|
void copyQueryAsRawCppString();
|
2018-09-18 11:53:19 +02:00
|
|
|
|
void generateCode();
|
2017-02-05 13:35:41 +01:00
|
|
|
|
void exportData(const QString &filename);
|
2017-02-12 08:13:38 +01:00
|
|
|
|
|
|
|
|
|
|
QString fileName() const { return m_fileName; }
|
|
|
|
|
|
bool isChanged() const { return m_queryTextChanged; }
|
2017-02-19 17:40:43 +01:00
|
|
|
|
bool isNew() const { return m_new; }
|
2018-04-21 14:36:33 +02:00
|
|
|
|
void focusEditor();
|
2018-05-14 20:24:41 +02:00
|
|
|
|
|
|
|
|
|
|
virtual std::vector<QAction*> getToolbarActions() override;
|
2017-01-21 08:09:12 +01:00
|
|
|
|
private:
|
2017-01-25 06:54:21 +01:00
|
|
|
|
|
|
|
|
|
|
using ResultTabContainer = std::vector<TuplesResultWidget*>;
|
|
|
|
|
|
|
2017-01-21 08:09:12 +01:00
|
|
|
|
Ui::QueryTab *ui;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
MainWindow *m_win;
|
2017-02-07 21:39:45 +01:00
|
|
|
|
SqlSyntaxHighlighter* highlighter;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
ConnectionConfig m_config;
|
2017-01-22 08:50:41 +01:00
|
|
|
|
StopWatch m_stopwatch;
|
2018-05-14 20:24:41 +02:00
|
|
|
|
std::vector<QAction*> actions;
|
2017-02-19 11:12:43 +01:00
|
|
|
|
|
|
|
|
|
|
QueryParamListController *m_queryParamListController = nullptr;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
2017-02-19 17:40:43 +01:00
|
|
|
|
bool m_new = true;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QString m_fileName; ///< use setFileName function to set
|
|
|
|
|
|
bool m_queryTextChanged = false;
|
|
|
|
|
|
|
2017-12-13 18:49:58 +01:00
|
|
|
|
std::shared_ptr<PgDatabaseCatalog> m_catalog;
|
|
|
|
|
|
ASyncDBConnection m_dbConnection;
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<QueryExplainModel> explainModel;
|
|
|
|
|
|
ResultTabContainer resultList;
|
|
|
|
|
|
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void setFileName(const QString &filename);
|
|
|
|
|
|
bool continueWithoutSavingWarning();
|
2017-01-22 08:50:41 +01:00
|
|
|
|
bool saveSqlTo(const QString &filename);
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QString promptUserForSaveSqlFilename();
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-25 06:54:21 +01:00
|
|
|
|
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void addLog(QString s);
|
|
|
|
|
|
|
2017-10-05 16:02:06 +02:00
|
|
|
|
QString getCommand() const;
|
|
|
|
|
|
std::string getCommandUtf8() const;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void explain_ready(ExplainRoot::SPtr explain);
|
2017-09-10 10:11:58 +02:00
|
|
|
|
void query_ready(Expected<std::shared_ptr<Pgsql::Result>> dbres, qint64 elapsedms);
|
2017-01-22 08:50:41 +01:00
|
|
|
|
|
2017-02-01 18:01:02 +01:00
|
|
|
|
QTabWidget *getTabWidget();
|
2017-01-25 06:54:21 +01:00
|
|
|
|
void setTabCaption(const QString &caption, const QString &tooltip);
|
2017-01-22 08:50:41 +01:00
|
|
|
|
void clearResult();
|
2018-04-09 21:44:00 +02:00
|
|
|
|
void markError(const Pgsql::ErrorDetails &details);
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2017-01-21 18:16:57 +01:00
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
|
|
|
|
void queryTextChanged();
|
|
|
|
|
|
void connectionStateChanged(ASyncDBConnection::State state);
|
|
|
|
|
|
void receiveNotice(Pgsql::ErrorDetails notice);
|
|
|
|
|
|
|
|
|
|
|
|
void startConnect();
|
2017-01-21 08:09:12 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // QUERYTAB_H
|