Path to database is now saved via QSettings object.

print
Josef Rokos 9 years ago
parent 989c8fdac3
commit 2f127e8902

@ -37,6 +37,7 @@ MainWindow::~MainWindow()
void MainWindow::on_actionExit_triggered() void MainWindow::on_actionExit_triggered()
{ {
this->close(); this->close();
Context::instance().destroy();
} }
void MainWindow::openPlugin() void MainWindow::openPlugin()

@ -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) void Context::openDb(const QString &path)
{ {
if (m_db != NULL) { if (m_db != NULL) {
delete m_db; delete m_db;
m_dbOpened = false;
} }
checkDb(path); checkDb(path);
m_db = new odb::sqlite::database(path.toStdString()); 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() Context::Context()
{ {
m_db = NULL; m_db = NULL;
m_settings = new QSettings("itsolved.cz", "prodejna");
m_dbOpened = false;
} }
void Context::checkDb(const QString &path) void Context::checkDb(const QString &path)

@ -6,6 +6,7 @@
#include <QString> #include <QString>
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QStringList> #include <QStringList>
#include <QSettings>
#include "define.h" #include "define.h"
#include "core_global.h" #include "core_global.h"
@ -24,11 +25,16 @@ public:
void loadPlugins(); void loadPlugins();
void openDb(const QString &path); void openDb(const QString &path);
odb::database *db() { return m_db; } odb::database *db() { return m_db; }
QSettings *settings() { return m_settings; }
bool dbOpened() { return m_dbOpened; }
void destroy();
private: private:
Context(); Context();
QList<IPlugin*> m_plugins; QList<IPlugin*> m_plugins;
odb::database *m_db; odb::database *m_db;
QSettings *m_settings;
bool m_dbOpened;
QStringList m_solved; QStringList m_solved;

Loading…
Cancel
Save