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()
{
this->close();
Context::instance().destroy();
}
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)
{
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)

@ -6,6 +6,7 @@
#include <QString>
#include <QSqlDatabase>
#include <QStringList>
#include <QSettings>
#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<IPlugin*> m_plugins;
odb::database *m_db;
QSettings *m_settings;
bool m_dbOpened;
QStringList m_solved;

Loading…
Cancel
Save