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 <QAction>
|
||||
#include <QApplication>
|
||||
#include <QtConcurrent>
|
||||
#include <QCloseEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QMenuBar>
|
||||
|
|
@ -30,9 +31,6 @@ DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
|||
: QMainWindow(parent)
|
||||
, m_masterController(master)
|
||||
{
|
||||
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
||||
this, &DatabaseWindow::catalogLoaded);
|
||||
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
m_tabWidget->setObjectName("m_tabWidget");
|
||||
setCentralWidget(m_tabWidget);
|
||||
|
|
@ -107,8 +105,15 @@ void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
|||
title += m_config.name();
|
||||
setWindowTitle(title);
|
||||
|
||||
auto f = TaskExecutor::run(new LoadCatalog(m_config));
|
||||
loadWatcher.setFuture(f);
|
||||
auto cfg = m_config;
|
||||
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) {
|
||||
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 {
|
||||
m_database = loadWatcher.future().result();
|
||||
|
||||
// for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
||||
// // TODO open inspector windows
|
||||
// }
|
||||
// newCreateTablePage();
|
||||
m_database = db;
|
||||
actionNewSql_triggered();
|
||||
} catch (const OpenDatabaseException &ex) {
|
||||
QMessageBox::critical(this, "Error reading database", ex.text());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue