pgLab/pglab/QueryTab.h
eelke 15bee33076 Made step to remove ASyncWindow in favour of usage of Future and FutureWatcher.
This should allow concurrency in the plugins to be independent from their container.

Contains also some work on the system for registering plugins.
2018-12-30 15:46:15 +01:00

124 lines
2.8 KiB
C++

#ifndef QUERYTAB_H
#define QUERYTAB_H
#include "ASyncDBConnection.h"
#include "QueryResultModel.h"
#include "QueryExplainModel.h"
#include "stopwatch.h"
#include "tuplesresultwidget.h"
#include <QWidget>
#include "plugin_support/PluginContentWidget.h"
#include <memory>
#include "plugin_support/PluginModule.h"
namespace Ui {
class QueryTab;
}
namespace Pgsql {
class ErrorDetails ;
}
class QTableView;
class QTabWidget;
class SqlSyntaxHighlighter;
class ExplainRoot;
class QueryResultModel;
class QueryExplainModel;
class PgTypeContainer;
class OpenDatabase;
class QueryParamListController;
class PgDatabaseCatalog;
class QueryTab : public PluginContentWidget {
Q_OBJECT
public:
QueryTab(IPluginContentWidgetContext *context, QWidget *parent = nullptr);
~QueryTab() override;
void newdoc();
bool load(const QString &filename);
bool save();
bool saveAs();
void saveCopyAs();
void execute();
void explain(bool analyze);
void cancel();
bool canClose() override;
void copyQueryAsCString();
void copyQueryAsRawCppString();
void generateCode();
void exportData(const QString &filename);
QString fileName() const { return m_fileName; }
bool isChanged() const { return m_queryTextChanged; }
bool isNew() const { return m_new; }
void focusEditor();
virtual std::vector<QAction*> getToolbarActions() override;
private:
using ResultTabContainer = std::vector<TuplesResultWidget*>;
Ui::QueryTab *ui;
SqlSyntaxHighlighter* highlighter;
ConnectionConfig m_config;
StopWatch m_stopwatch;
std::vector<QAction*> actions;
QueryParamListController *m_queryParamListController = nullptr;
bool m_new = true;
QString m_fileName; ///< use setFileName function to set
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);
bool continueWithoutSavingWarning();
bool saveSqlTo(const QString &filename);
QString promptUserForSaveSqlFilename();
void addLog(QString s);
QString getCommand() const;
std::string getCommandUtf8() const;
void explain_ready(ExplainRoot::SPtr explain);
void query_ready(Expected<std::shared_ptr<Pgsql::Result>> dbres, qint64 elapsedms);
//QTabWidget *getTabWidget();
//void setTabCaption(const QString &caption, const QString &tooltip);
void clearResult();
void markError(const Pgsql::ErrorDetails &details);
private slots:
void queryTextChanged();
void connectionStateChanged(ASyncDBConnection::State state);
void receiveNotice(Pgsql::ErrorDetails notice);
void startConnect();
};
class QueryToolModule: public PluginModule {
Q_OBJECT
public:
using PluginModule::PluginModule;
void init();
private slots:
void new_triggered();
};
#endif // QUERYTAB_H