2016-12-26 16:06:55 +01:00
|
|
|
|
#ifndef MAINWINDOW_H
|
|
|
|
|
|
#define MAINWINDOW_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
2016-12-27 15:41:11 +01:00
|
|
|
|
#include <QSocketNotifier>
|
2016-12-26 16:06:55 +01:00
|
|
|
|
#include <memory>
|
2016-12-27 21:22:49 +01:00
|
|
|
|
#include <future>
|
2016-12-27 15:41:11 +01:00
|
|
|
|
#include "PgsqlConn.h"
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2016-12-29 13:48:35 +01:00
|
|
|
|
class ExplainRoot;
|
2016-12-26 16:06:55 +01:00
|
|
|
|
class QueryResultModel;
|
2016-12-29 13:48:35 +01:00
|
|
|
|
class QueryExplainModel;
|
2016-12-26 16:06:55 +01:00
|
|
|
|
class SqlHighlighter;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
class MainWindow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-27 15:41:11 +01:00
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
|
|
|
|
|
|
class Connection;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-30 10:14:26 +01:00
|
|
|
|
#include <deque>
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
|
|
class TaskQueue {
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
class MainWindow : public QMainWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2016-12-30 10:14:26 +01:00
|
|
|
|
using callable = std::function<void()>;
|
|
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
explicit MainWindow(QWidget *parent = 0);
|
|
|
|
|
|
~MainWindow();
|
|
|
|
|
|
|
2016-12-30 10:14:26 +01:00
|
|
|
|
/* 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(callable c);
|
|
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
private:
|
2016-12-30 10:14:26 +01:00
|
|
|
|
using t_CallableQueue = std::deque<callable>;
|
|
|
|
|
|
std::mutex m_mutexCallableQueue;
|
|
|
|
|
|
t_CallableQueue m_callableQueue;
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
std::unique_ptr<Ui::MainWindow> ui;
|
|
|
|
|
|
std::unique_ptr<SqlHighlighter> highlighter;
|
|
|
|
|
|
|
2016-12-27 15:41:11 +01:00
|
|
|
|
std::unique_ptr<Pgsql::Connection> connection;
|
2016-12-26 16:06:55 +01:00
|
|
|
|
std::unique_ptr<QueryResultModel> resultModel;
|
2016-12-29 13:48:35 +01:00
|
|
|
|
std::unique_ptr<QueryExplainModel> explainModel;
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2016-12-29 13:48:35 +01:00
|
|
|
|
Pgsql::Canceller queryCancel;
|
2016-12-27 21:22:49 +01:00
|
|
|
|
std::future<Pgsql::Result> queryFuture;
|
2016-12-29 13:48:35 +01:00
|
|
|
|
std::future<std::unique_ptr<ExplainRoot>> explainFuture;
|
2016-12-27 21:22:49 +01:00
|
|
|
|
|
2016-12-27 15:41:11 +01:00
|
|
|
|
struct {
|
|
|
|
|
|
std::unique_ptr<QSocketNotifier> notifier;
|
|
|
|
|
|
PostgresPollingStatusType poll_state;
|
|
|
|
|
|
} connectingState;
|
|
|
|
|
|
|
2016-12-27 21:22:49 +01:00
|
|
|
|
// struct {
|
|
|
|
|
|
// std::unique_ptr<QSocketNotifier> notifierRead;
|
|
|
|
|
|
// std::unique_ptr<QSocketNotifier> notifierWrite;
|
|
|
|
|
|
// } queryState;
|
|
|
|
|
|
|
2016-12-29 13:48:35 +01:00
|
|
|
|
void processNotice(const PGresult *result);
|
2016-12-26 16:06:55 +01:00
|
|
|
|
private slots:
|
2016-12-27 15:41:11 +01:00
|
|
|
|
|
|
|
|
|
|
void startConnect();
|
|
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
void performQuery();
|
2016-12-29 13:48:35 +01:00
|
|
|
|
void performExplain();
|
2016-12-27 15:41:11 +01:00
|
|
|
|
void socket_activate_connect(int socket);
|
2016-12-27 21:22:49 +01:00
|
|
|
|
void query_ready();
|
2016-12-29 13:48:35 +01:00
|
|
|
|
void explain_ready();
|
|
|
|
|
|
void cancel_query();
|
|
|
|
|
|
void receiveNotice(Pgsql::ErrorDetails notice);
|
|
|
|
|
|
|
2016-12-30 10:14:26 +01:00
|
|
|
|
void processCallableQueue();
|
2016-12-26 16:06:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // MAINWINDOW_H
|