#ifndef QUERYTAB_H #define QUERYTAB_H #include "ManagedPage.h" #include "ASyncDBConnection.h" #include "QueryExplainModel.h" #include "stopwatch.h" #include "tuplesresultwidget.h" #include "SqlDocument.h" #include #include class IDatabaseWindow; namespace Ui { class QueryTab; } namespace Pgsql { class ErrorDetails ; } class QTableView; class QTabWidget; class SqlSyntaxHighlighter; class SqlCompletionProvider; class ExplainRoot; class QueryExplainModel; class PgTypeContainer; class OpenDatabase; class QueryParamListController; class PgDatabaseCatalog; class QueryTool : public ManagedPage { Q_OBJECT public: QueryTool(IDatabaseWindow *context, std::shared_ptr document, QWidget *parent = nullptr); ~QueryTool() override; void explain(bool analyze); bool CanClose(bool prompt_user); void generateCode(); void exportDataToFilename(const QString &filename); QString fileName() const { return m_document->fileName(); } std::shared_ptr document() const { return m_document; } void focusEditor(); QString title() const; void updateTitle(); public slots: void execute(); /// Save the document under its current name, a file save dialog will be shown if this is a new document bool save(); /// Saves the document under a new name and continue editing the document under this new name. bool saveAs(); /// Save the document under a new name but continue editing the document under its old name. void saveCopyAs(); void copyQueryAsCString(); void copyQueryAsRawCppString(); void pasteLangString(); void cancel(); void exportData(); private: using ResultTabContainer = std::vector; IDatabaseWindow *m_context; Ui::QueryTab *ui; std::shared_ptr m_document; ConnectionConfig m_config; StopWatch m_stopwatch; QueryParamListController *m_queryParamListController = nullptr; std::shared_ptr m_catalog; std::shared_ptr m_completionProvider; ///< built on first use, reset when the catalog is refreshed void setupCompletion(); ASyncDBConnection m_dbConnection; std::unique_ptr explainModel; ResultTabContainer resultList; void addLog(QString s); QString getCommand() const; std::string getCommandUtf8() const; void clearResult(); void markError(const Pgsql::ErrorDetails &details); private slots: void explain_ready(ExplainRoot::SPtr explain); void query_ready(std::shared_ptr, qint64 elapsedms); void connectionStateChanged(); void receiveNotice(Pgsql::ErrorDetails notice); void startConnect(); }; #endif // QUERYTAB_H