From 2f127e8902dcad65293013a0092ddcc08571478b Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Tue, 24 Nov 2015 16:14:36 +0100 Subject: [PATCH] Path to database is now saved via QSettings object. --- application/mainwindow.cpp | 1 + core/context.cpp | 29 +++++++++++++++++++++++++++++ core/context.h | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index 8b4c6fc..05adcbd 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -37,6 +37,7 @@ MainWindow::~MainWindow() void MainWindow::on_actionExit_triggered() { this->close(); + Context::instance().destroy(); } void MainWindow::openPlugin() diff --git a/core/context.cpp b/core/context.cpp index b03cdd0..2660622 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -55,21 +55,50 @@ void Context::loadPlugins() } } } + + QString dbPath = m_settings->value("db/path", "").toString(); + if (!dbPath.isEmpty()) + { + openDb(dbPath); + } } void Context::openDb(const QString &path) { if (m_db != NULL) { delete m_db; + m_dbOpened = false; } checkDb(path); m_db = new odb::sqlite::database(path.toStdString()); + m_settings->setValue("db/path", path); + m_dbOpened = true; +} + +void Context::destroy() +{ + if (m_db != NULL) + { + delete m_db; + m_db = NULL; + m_dbOpened = false; + } + + delete m_settings; + + foreach (IPlugin *plugin, m_plugins) + { + delete plugin; + } + m_plugins.clear(); } Context::Context() { m_db = NULL; + m_settings = new QSettings("itsolved.cz", "prodejna"); + m_dbOpened = false; } void Context::checkDb(const QString &path) diff --git a/core/context.h b/core/context.h index 2840708..993af5f 100644 --- a/core/context.h +++ b/core/context.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "define.h" #include "core_global.h" @@ -24,11 +25,16 @@ public: void loadPlugins(); void openDb(const QString &path); odb::database *db() { return m_db; } + QSettings *settings() { return m_settings; } + bool dbOpened() { return m_dbOpened; } + void destroy(); private: Context(); QList m_plugins; odb::database *m_db; + QSettings *m_settings; + bool m_dbOpened; QStringList m_solved;