Made slow part of MainWindow initialization asynchronous.
This commit is contained in:
parent
6d4662aa98
commit
554f138d6d
3 changed files with 27 additions and 11 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
#include "QueryTab.h"
|
#include "QueryTab.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "MasterController.h"
|
#include "MasterController.h"
|
||||||
#include "OpenDatabase.h"
|
#include "WorkManager.h"
|
||||||
|
|
||||||
namespace pg = Pgsql;
|
namespace pg = Pgsql;
|
||||||
|
|
||||||
|
|
@ -56,13 +56,31 @@ void MainWindow::setConfig(const ConnectionConfig &config)
|
||||||
{
|
{
|
||||||
m_config = config;
|
m_config = config;
|
||||||
try {
|
try {
|
||||||
auto res = OpenDatabase::createOpenDatabase(config);
|
|
||||||
//if (res.valid()) {
|
|
||||||
m_database = res.get();
|
|
||||||
QString title = "pglab - ";
|
QString title = "pglab - ";
|
||||||
title += m_config.name().c_str();
|
title += m_config.name().c_str();
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
|
|
||||||
|
WorkManager::getWorkManager()->addWork(
|
||||||
|
[config, this]() {
|
||||||
|
auto res = OpenDatabase::createOpenDatabase(config);
|
||||||
|
QueueTask([this, res] () {
|
||||||
|
catalogLoaded(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (std::runtime_error &ex) {
|
||||||
|
QMessageBox::critical(this, "Error reading database",
|
||||||
|
QString::fromUtf8(ex.what()));
|
||||||
|
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::catalogLoaded(Expected<OpenDatabase::OpenDatabaseSPtr> res)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
m_database = res.get();
|
||||||
|
|
||||||
auto tt = new TablesPage(this);
|
auto tt = new TablesPage(this);
|
||||||
tt->setCatalog(m_database->catalogue());
|
tt->setCatalog(m_database->catalogue());
|
||||||
ui->tabWidget->addTab(tt, "Tables");
|
ui->tabWidget->addTab(tt, "Tables");
|
||||||
|
|
@ -70,10 +88,6 @@ void MainWindow::setConfig(const ConnectionConfig &config)
|
||||||
|
|
||||||
newSqlPage();
|
newSqlPage();
|
||||||
} catch (std::runtime_error &ex) {
|
} catch (std::runtime_error &ex) {
|
||||||
// QMessageBox msgBox;
|
|
||||||
// msgBox.setText(QString::fromUtf8(ex.what()));
|
|
||||||
// msgBox.exec();
|
|
||||||
|
|
||||||
QMessageBox::critical(this, "Error reading database",
|
QMessageBox::critical(this, "Error reading database",
|
||||||
QString::fromUtf8(ex.what()));
|
QString::fromUtf8(ex.what()));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "ASyncDBConnection.h"
|
#include "ASyncDBConnection.h"
|
||||||
#include "ConnectionConfig.h"
|
#include "ConnectionConfig.h"
|
||||||
#include "tsqueue.h"
|
#include "OpenDatabase.h"
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include "ASyncWindow.h"
|
#include "ASyncWindow.h"
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
|
|
@ -64,6 +64,8 @@ private:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
QueryTab *newSqlPage();
|
QueryTab *newSqlPage();
|
||||||
|
|
||||||
|
void catalogLoaded(Expected<OpenDatabase::OpenDatabaseSPtr> result);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void on_actionLoad_SQL_triggered();
|
void on_actionLoad_SQL_triggered();
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ public:
|
||||||
using OpenDatabaseSPtr = std::shared_ptr<OpenDatabase>;
|
using OpenDatabaseSPtr = std::shared_ptr<OpenDatabase>;
|
||||||
static Expected<OpenDatabaseSPtr> createOpenDatabase(const ConnectionConfig &cfg);
|
static Expected<OpenDatabaseSPtr> createOpenDatabase(const ConnectionConfig &cfg);
|
||||||
|
|
||||||
// using on_createResult_callback = std::function<void(Expected<std::shared_ptr<Pgsql::Result>>, qint64)>;
|
// using on_createResult_callback = std::function<void(Expected<std::shared_ptr<Pgsql::Result>>)>;
|
||||||
// void asyncCreateOpenDatabase(const ConnectionConfig &cfg, );
|
// void asyncCreateOpenDatabase(const ConnectionConfig &cfg, on_createResult_callback);
|
||||||
|
|
||||||
OpenDatabase(const OpenDatabase &) = delete;
|
OpenDatabase(const OpenDatabase &) = delete;
|
||||||
OpenDatabase& operator=(const OpenDatabase &) = delete;
|
OpenDatabase& operator=(const OpenDatabase &) = delete;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue