Use QtConcurrent::run.then chain in DatabaseWindow too.
This commit is contained in:
parent
521e5d7370
commit
badd46ea8f
2 changed files with 13 additions and 34 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
#include "TaskExecutor.h"
|
#include "TaskExecutor.h"
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QtConcurrent>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
|
@ -30,9 +31,6 @@ DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, m_masterController(master)
|
, m_masterController(master)
|
||||||
{
|
{
|
||||||
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
|
||||||
this, &DatabaseWindow::catalogLoaded);
|
|
||||||
|
|
||||||
m_tabWidget = new QTabWidget(this);
|
m_tabWidget = new QTabWidget(this);
|
||||||
m_tabWidget->setObjectName("m_tabWidget");
|
m_tabWidget->setObjectName("m_tabWidget");
|
||||||
setCentralWidget(m_tabWidget);
|
setCentralWidget(m_tabWidget);
|
||||||
|
|
@ -107,8 +105,15 @@ void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
||||||
title += m_config.name();
|
title += m_config.name();
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
|
|
||||||
auto f = TaskExecutor::run(new LoadCatalog(m_config));
|
auto cfg = m_config;
|
||||||
loadWatcher.setFuture(f);
|
auto qthis = QPointer(this);
|
||||||
|
QtConcurrent::run([cfg] {
|
||||||
|
return OpenDatabase::createOpenDatabase(cfg);
|
||||||
|
}).then(qApp, [qthis](OpenDatabase::OpenDatabaseSPtr db) {
|
||||||
|
if (qthis) {
|
||||||
|
qthis.data()->catalogLoaded(db);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} catch (std::runtime_error &ex) {
|
} catch (std::runtime_error &ex) {
|
||||||
QMessageBox::critical(this, "Error reading database",
|
QMessageBox::critical(this, "Error reading database",
|
||||||
|
|
@ -316,15 +321,10 @@ void DatabaseWindow::openSqlFile(QString file_name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::catalogLoaded()
|
void DatabaseWindow::catalogLoaded(OpenDatabase::OpenDatabaseSPtr db)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
m_database = loadWatcher.future().result();
|
m_database = db;
|
||||||
|
|
||||||
// for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
|
||||||
// // TODO open inspector windows
|
|
||||||
// }
|
|
||||||
// newCreateTablePage();
|
|
||||||
actionNewSql_triggered();
|
actionNewSql_triggered();
|
||||||
} catch (const OpenDatabaseException &ex) {
|
} catch (const OpenDatabaseException &ex) {
|
||||||
QMessageBox::critical(this, "Error reading database", ex.text());
|
QMessageBox::critical(this, "Error reading database", ex.text());
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
#include "Pgsql_Connection.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "ControllableTask.h"
|
#include "ControllableTask.h"
|
||||||
#include "IDatabaseWindow.h"
|
#include "IDatabaseWindow.h"
|
||||||
#include <QFutureWatcher>
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
@ -100,24 +99,6 @@ private:
|
||||||
QMenu *menuCrud = nullptr;
|
QMenu *menuCrud = nullptr;
|
||||||
QMenu *menuWindow = nullptr;
|
QMenu *menuWindow = nullptr;
|
||||||
|
|
||||||
|
|
||||||
class LoadCatalog: public ControllableTask<OpenDatabase::OpenDatabaseSPtr> {
|
|
||||||
public:
|
|
||||||
LoadCatalog(ConnectionConfig config)
|
|
||||||
: m_config(config)
|
|
||||||
{}
|
|
||||||
|
|
||||||
OpenDatabase::OpenDatabaseSPtr run(TaskControl& ) override
|
|
||||||
{
|
|
||||||
return OpenDatabase::createOpenDatabase(m_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ConnectionConfig m_config;
|
|
||||||
};
|
|
||||||
|
|
||||||
QFutureWatcher<LoadCatalog::Result> loadWatcher;
|
|
||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
void initMenus();
|
void initMenus();
|
||||||
|
|
||||||
|
|
@ -139,10 +120,8 @@ private:
|
||||||
QAction* createAction(QString caption, void (DatabaseWindow::*func)());
|
QAction* createAction(QString caption, void (DatabaseWindow::*func)());
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void catalogLoaded();
|
void catalogLoaded(OpenDatabase::OpenDatabaseSPtr db);
|
||||||
void tableSelected(Oid tableoid);
|
void tableSelected(Oid tableoid);
|
||||||
// void tabWidget_tabCloseRequested(int index);
|
|
||||||
// void tabWidget_currentChanged(int index);
|
|
||||||
|
|
||||||
void actionAbout_triggered();
|
void actionAbout_triggered();
|
||||||
void actionCancelQuery_triggered();
|
void actionCancelQuery_triggered();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue