2017-01-21 18:16:57 +01:00
|
|
|
|
#ifndef QUERYTAB_H
|
2017-01-21 08:09:12 +01:00
|
|
|
|
#define QUERYTAB_H
|
|
|
|
|
|
|
2017-01-21 18:16:57 +01:00
|
|
|
|
#include "asyncdbconnection.h"
|
2017-02-04 11:55:49 +01:00
|
|
|
|
#include "ParamListModel.h"
|
|
|
|
|
|
#include "ParamTypeDelegate.h"
|
2017-01-22 08:50:41 +01:00
|
|
|
|
#include "queryresultmodel.h"
|
|
|
|
|
|
#include "queryexplainmodel.h"
|
|
|
|
|
|
#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>
|
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
|
|
|
|
}
|
|
|
|
|
|
|
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-01-21 18:16:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-01-21 08:09:12 +01:00
|
|
|
|
class QueryTab : public QWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QueryTab(MainWindow *win, QWidget *parent = 0);
|
2017-01-21 08:09:12 +01:00
|
|
|
|
~QueryTab();
|
|
|
|
|
|
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void setConfig(const ConnectionConfig &config);
|
|
|
|
|
|
|
2017-01-22 08:50:41 +01:00
|
|
|
|
void newdoc();
|
|
|
|
|
|
// void open();
|
|
|
|
|
|
bool load(const QString &filename);
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void save();
|
|
|
|
|
|
void saveAs();
|
|
|
|
|
|
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-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-01-21 08:09:12 +01:00
|
|
|
|
private:
|
2017-01-25 06:54:21 +01:00
|
|
|
|
|
|
|
|
|
|
// struct ResultTab {
|
|
|
|
|
|
// public:
|
|
|
|
|
|
// std::shared_ptr<QueryResultModel> resultModel;
|
|
|
|
|
|
// std::shared_ptr<TuplesResultWidget> tuplesResult;
|
|
|
|
|
|
//// ResultTab(std::shared_ptr<QueryResultModel> rm, Ui::TuplesResult *tr)
|
|
|
|
|
|
//// : resultModel(rm), tuplesResult(tr)
|
|
|
|
|
|
//// {}
|
|
|
|
|
|
// };
|
|
|
|
|
|
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;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
ParamListModel m_paramList;
|
|
|
|
|
|
ParamTypeDelegate m_typeDelegate;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
|
|
|
|
|
QString m_fileName; ///< use setFileName function to set
|
|
|
|
|
|
bool m_queryTextChanged = false;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
ASyncDBConnection m_dbConnection;
|
2017-01-25 06:54:21 +01:00
|
|
|
|
|
2017-01-21 18:16:57 +01:00
|
|
|
|
std::unique_ptr<QueryExplainModel> explainModel;
|
2017-01-25 06:54:21 +01:00
|
|
|
|
ResultTabContainer resultList;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
|
|
|
|
|
void addLog(QString s);
|
|
|
|
|
|
|
|
|
|
|
|
std::string getCommand() const;
|
|
|
|
|
|
void explain_ready(ExplainRoot::SPtr explain);
|
2017-01-25 06:54:21 +01:00
|
|
|
|
void query_ready(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();
|
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
|