The MainWindow now uses a background task to load the catalog.
As the background task can't be cancelled yet only closing of the window can block if the task is still running.
This commit is contained in:
parent
057e745ebe
commit
2705a3417b
4 changed files with 173 additions and 64 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include "util.h"
|
||||
#include "MasterController.h"
|
||||
#include "WorkManager.h"
|
||||
#include "ScopeGuard.h"
|
||||
|
||||
namespace pg = Pgsql;
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ MainWindow::MainWindow(MasterController *master, QWidget *parent)
|
|||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
loader.reset();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
|
@ -60,13 +62,10 @@ void MainWindow::setConfig(const ConnectionConfig &config)
|
|||
title += m_config.name().c_str();
|
||||
setWindowTitle(title);
|
||||
|
||||
WorkManager::getWorkManager()->addWork(
|
||||
[config, this]() {
|
||||
auto res = OpenDatabase::createOpenDatabase(config);
|
||||
QueueTask([this, res] () {
|
||||
catalogLoaded(res);
|
||||
});
|
||||
});
|
||||
loader = std::make_shared<QLoad>(m_config, [this](QRunnable *) {
|
||||
QueueTask([this] () { catalogLoaded(); });
|
||||
} );
|
||||
WorkManager::getWorkManager()->addRunnable(loader.get());
|
||||
} catch (std::runtime_error &ex) {
|
||||
QMessageBox::critical(this, "Error reading database",
|
||||
QString::fromUtf8(ex.what()));
|
||||
|
|
@ -75,11 +74,11 @@ void MainWindow::setConfig(const ConnectionConfig &config)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::catalogLoaded(Expected<OpenDatabase::OpenDatabaseSPtr> res)
|
||||
void MainWindow::catalogLoaded()
|
||||
{
|
||||
try {
|
||||
|
||||
m_database = res.get();
|
||||
SCOPE_EXIT { loader.reset(); };
|
||||
m_database = loader->GetResult();
|
||||
|
||||
auto tt = new TablesPage(this);
|
||||
tt->setCatalog(m_database->catalogue());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue