pgLab/pglab/QueryTab.h

126 lines
2.7 KiB
C
Raw Normal View History

#ifndef QUERYTAB_H
#define QUERYTAB_H
#include "ASyncDBConnection.h"
#include "ParamListModel.h"
#include "ParamTypeDelegate.h"
#include "QueryResultModel.h"
#include "QueryExplainModel.h"
#include "stopwatch.h"
#include "tuplesresultwidget.h"
#include <QWidget>
#include <memory>
namespace Ui {
class QueryTab;
}
class QTableView;
class QTabWidget;
class MainWindow;
class SqlSyntaxHighlighter;
class ExplainRoot;
class QueryResultModel;
class QueryExplainModel;
class PgTypeContainer;
class OpenDatabase;
class QueryParamListController : public QObject {
Q_OBJECT
public:
QueryParamListController(QTableView *tv, OpenDatabase *opendb, QWidget *parent);
Pgsql::Params params() const;
bool empty() const;
public slots:
void on_addParam();
void on_removeParam();
private:
QTableView *paramTableView;
OpenDatabase *m_openDatabase;
ParamListModel m_paramList;
ParamTypeDelegate m_typeDelegate;
};
class QueryTab : public QWidget {
Q_OBJECT
public:
QueryTab(MainWindow *win, QWidget *parent = nullptr);
~QueryTab();
void setConfig(const ConnectionConfig &config);
void newdoc();
// void open();
bool load(const QString &filename);
bool save();
bool saveAs();
void saveCopyAs();
void execute();
void explain(bool analyze);
void cancel();
bool canClose();
2017-02-05 08:23:06 +01:00
void copyQueryAsCString();
void copyQueryAsRawCppString();
2017-02-05 13:35:41 +01:00
void exportData(const QString &filename);
QString fileName() const { return m_fileName; }
bool isChanged() const { return m_queryTextChanged; }
bool isNew() const { return m_new; }
private:
using ResultTabContainer = std::vector<TuplesResultWidget*>;
Ui::QueryTab *ui;
MainWindow *m_win;
SqlSyntaxHighlighter* highlighter;
ConnectionConfig m_config;
StopWatch m_stopwatch;
QueryParamListController *m_queryParamListController = nullptr;
bool m_new = true;
QString m_fileName; ///< use setFileName function to set
bool m_queryTextChanged = false;
void setFileName(const QString &filename);
bool continueWithoutSavingWarning();
bool saveSqlTo(const QString &filename);
QString promptUserForSaveSqlFilename();
ASyncDBConnection m_dbConnection;
std::unique_ptr<QueryExplainModel> explainModel;
ResultTabContainer resultList;
void addLog(QString s);
QString getCommand() const;
std::string getCommandUtf8() const;
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);
QTabWidget *getTabWidget();
void setTabCaption(const QString &caption, const QString &tooltip);
void clearResult();
private slots:
void queryTextChanged();
void connectionStateChanged(ASyncDBConnection::State state);
void receiveNotice(Pgsql::ErrorDetails notice);
void startConnect();
};
#endif // QUERYTAB_H