pgLab/mainwindow.h
Eelke Klein 6c268bd774 Also added "Save copy as"
This prompts for a new filename but it keeps remembering the previous name.
2017-01-21 08:19:47 +01:00

109 lines
2.5 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "asyncdbconnection.h"
#include "connectionconfig.h"
#include "tsqueue.h"
#include <QLabel>
#include <QMainWindow>
#include <QSocketNotifier>
#include <memory>
#include <future>
#include "PgsqlConn.h"
#include <chrono>
#include <deque>
#include <mutex>
class ExplainRoot;
class QueryResultModel;
class QueryExplainModel;
class SqlHighlighter;
namespace Ui {
class MainWindow;
}
namespace Pgsql {
class Connection;
}
class QueryTab;
class QCloseEvent;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void setConfig(const ConnectionConfig &config);
/* Meant to be called from other threads to pass a code block
* that has to be executed in the context of the thread of the window.
*/
void QueueTask(TSQueue::t_Callable c);
private:
TSQueue m_taskQueue;
QLabel *m_timeElapsedLabel;
std::unique_ptr<QTimer> m_timer;
std::chrono::time_point<std::chrono::steady_clock> m_startTime;
ConnectionConfig m_config;
bool m_queryTextChanged = false;
QString m_fileName;
void startTimer();
void endTimer();
std::chrono::duration<float, std::milli> elapsedTime;
Ui::MainWindow *ui;
QueryTab *m_queryTab = nullptr;
std::unique_ptr<SqlHighlighter> highlighter;
ASyncDBConnection m_dbConnection;
void connectionStateChanged(ASyncDBConnection::State state);
std::unique_ptr<QueryResultModel> resultModel;
std::unique_ptr<QueryExplainModel> explainModel;
void query_ready(std::shared_ptr<Pgsql::Result> res);
void explain_ready(std::shared_ptr<ExplainRoot> explain);
std::string getCommand() const;
bool continueWithoutSaving();
void closeEvent(QCloseEvent *event);
void showEvent(QShowEvent *event);
QString promptUserForSaveSqlFilename();
void saveSqlTo(const QString &filename);
private slots:
void startConnect();
void performQuery();
void performExplain();
void cancel_query();
void queryTextChanged();
void receiveNotice(Pgsql::ErrorDetails notice);
void processCallableQueue();
void addLog(QString s);
void updateTimer();
void on_actionLoad_SQL_triggered();
void on_actionSave_SQL_triggered();
void on_actionExport_data_triggered();
void on_actionClose_triggered();
void on_actionAbout_triggered();
void on_actionExecute_SQL_triggered();
void on_actionExplain_Analyze_triggered();
void on_actionCancel_triggered();
void on_actionSave_SQL_as_triggered();
void on_actionSave_copy_of_SQL_as_triggered();
};
#endif // MAINWINDOW_H