Larger improvements

This commit is contained in:
feedc0de committed 2019-04-07 18:20:01 +02:00
1 parent b1ce4ecf64
commit 0704012542
22 files changed
+553 -185

No files matched your search

+64 -6
View File
@@ -4,6 +4,7 @@
#include <QMessageBox>
#include <QStringBuilder>
#include <QSqlError>
#include <QSqlQuery>
OpenDialog::OpenDialog(QWidget *parent) :
QDialog(parent),
@@ -16,21 +17,78 @@ OpenDialog::OpenDialog(QWidget *parent) :
OpenDialog::~OpenDialog() = default;
QSqlDatabase OpenDialog::database()
std::unique_ptr<Project> &OpenDialog::project()
{
return m_database;
return m_project;
}
void OpenDialog::submit()
{
m_database = m_ui->databaseWidget->createConnection();
auto project = std::make_unique<Project>();
project->database = m_ui->databaseWidget->createConnection();
if (!m_database.open())
if (!project->database.open())
{
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % m_database.lastError().text());
m_database = {};
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % project->database.lastError().text());
return;
}
{
QSqlQuery query("SELECT `ID`, `Name` FROM `Hosts`;", project->database);
if (query.lastError().isValid())
{
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
return;
}
while(query.next())
project->hosts.insert(query.value(0).toInt(), query.value(1).toString());
}
{
QSqlQuery query("SELECT `ID`, `Name` FROM `Processes`;", project->database);
if (query.lastError().isValid())
{
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
return;
}
while(query.next())
project->processes.insert(query.value(0).toInt(), query.value(1).toString());
}
{
QSqlQuery query("SELECT `ID`, `Name` FROM `Filenames`;", project->database);
if (query.lastError().isValid())
{
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
return;
}
while(query.next())
project->filenames.insert(query.value(0).toInt(), query.value(1).toString());
}
{
QSqlQuery query("SELECT `ID`, `Name` FROM `Threads`;", project->database);
if (query.lastError().isValid())
{
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
return;
}
while(query.next())
project->threads.insert(query.value(0).toInt(), query.value(1).toString());
}
{
QSqlQuery query("SELECT `ID`, `Name` FROM `Types`;", project->database);
if (query.lastError().isValid())
{
QMessageBox::warning(this, tr("Could not open database!"), tr("Could not open database!") % "\n\n" % query.lastError().text());
return;
}
while(query.next())
project->types.insert(query.value(0).toInt(), query.value(1).toString());
}
m_project = std::move(project);
accept();
}
+4 -2
View File
@@ -5,6 +5,8 @@
#include <memory>
#include "common.h"
namespace Ui { class OpenDialog; }
class OpenDialog : public QDialog
@@ -15,7 +17,7 @@ public:
explicit OpenDialog(QWidget *parent = nullptr);
~OpenDialog() override;
QSqlDatabase database();
std::unique_ptr<Project> &project();
private slots:
void submit();
@@ -23,5 +25,5 @@ private slots:
private:
const std::unique_ptr<Ui::OpenDialog> m_ui;
QSqlDatabase m_database;
std::unique_ptr<Project> m_project;
};