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 "util.h"
|
||||
#include "MasterController.h"
|
||||
#include "OpenDatabase.h"
|
||||
#include "WorkManager.h"
|
||||
|
||||
namespace pg = Pgsql;
|
||||
|
||||
|
|
@ -56,13 +56,31 @@ void MainWindow::setConfig(const ConnectionConfig &config)
|
|||
{
|
||||
m_config = config;
|
||||
try {
|
||||
auto res = OpenDatabase::createOpenDatabase(config);
|
||||
//if (res.valid()) {
|
||||
m_database = res.get();
|
||||
QString title = "pglab - ";
|
||||
title += m_config.name().c_str();
|
||||
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);
|
||||
tt->setCatalog(m_database->catalogue());
|
||||
ui->tabWidget->addTab(tt, "Tables");
|
||||
|
|
@ -70,10 +88,6 @@ void MainWindow::setConfig(const ConnectionConfig &config)
|
|||
|
||||
newSqlPage();
|
||||
} catch (std::runtime_error &ex) {
|
||||
// QMessageBox msgBox;
|
||||
// msgBox.setText(QString::fromUtf8(ex.what()));
|
||||
// msgBox.exec();
|
||||
|
||||
QMessageBox::critical(this, "Error reading database",
|
||||
QString::fromUtf8(ex.what()));
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "ASyncDBConnection.h"
|
||||
#include "ConnectionConfig.h"
|
||||
#include "tsqueue.h"
|
||||
#include "OpenDatabase.h"
|
||||
#include <QLabel>
|
||||
#include "ASyncWindow.h"
|
||||
#include <QSocketNotifier>
|
||||
|
|
@ -64,6 +64,8 @@ private:
|
|||
void showEvent(QShowEvent *event);
|
||||
QueryTab *newSqlPage();
|
||||
|
||||
void catalogLoaded(Expected<OpenDatabase::OpenDatabaseSPtr> result);
|
||||
|
||||
private slots:
|
||||
|
||||
void on_actionLoad_SQL_triggered();
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ public:
|
|||
using OpenDatabaseSPtr = std::shared_ptr<OpenDatabase>;
|
||||
static Expected<OpenDatabaseSPtr> createOpenDatabase(const ConnectionConfig &cfg);
|
||||
|
||||
// using on_createResult_callback = std::function<void(Expected<std::shared_ptr<Pgsql::Result>>, qint64)>;
|
||||
// void asyncCreateOpenDatabase(const ConnectionConfig &cfg, );
|
||||
// using on_createResult_callback = std::function<void(Expected<std::shared_ptr<Pgsql::Result>>)>;
|
||||
// void asyncCreateOpenDatabase(const ConnectionConfig &cfg, on_createResult_callback);
|
||||
|
||||
OpenDatabase(const OpenDatabase &) = delete;
|
||||
OpenDatabase& operator=(const OpenDatabase &) = delete;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue