-
Notifications
You must be signed in to change notification settings - Fork 39
/
DatabaseSettingsPage.cpp
115 lines (97 loc) · 3.88 KB
/
DatabaseSettingsPage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (C) 2020 Adrian Carpenter
*
* This file is part of a regex101.com offline application.
*
* https://github.com/fizzyade/regex101
*
* =====================================================================
* The regex101 web content is owned and used with permission from
* Firas Dib at regex101.com. This application is an unofficial
* tool to provide an offline application version of the website.
* =====================================================================
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DatabaseSettingsPage.h"
#include "RegExDatabase.h"
#include "ui_DatabaseSettingsPage.h"
#include <QDebug>
#include <QMap>
#include <QSqlDatabase>
Nedrysoft::DatabaseSettingsPage::DatabaseSettingsPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::DatabaseSettingsPage)
{
ui->setupUi(this);
QMap<QString, QString> databaseDriverMap(std::map<QString, QString> {
{"QDB2", "IBM DB2 (Version 7.1 and above)"},
{"QIBASE", "Borland InterBase" },
{"QMYSQL", "MySQL or MariaDB (Version 5.0 and above)"},
{"QOCI", "Oracle Call Interface Driver"},
{"QODBC", "ODBC"},
{"QODBC3", "ODBC (Version 3 and above)"},
{"QPSQL", "PostgreSQL (Version 7.3 and above)"},
{"QPSQL7", "PostgreSQL (Version 6.x and 7.x)"},
{"QSQLITE2", "SQLite (Version 2)"},
{"QSQLITE", "SQLite (Version 3)"},
{"QTDS", "Sybase Adaptive Server"}
});
auto ignoredDriverList = QStringList() << "QODBC" << "QPSQL7" << "QSQLITE2";
#if defined(Q_OS_MACOS)
m_size = QSize(qMax(minimumSizeHint().width(), size().width()), qMax(minimumSizeHint().height(), size().height()));
#else
m_size = minimumSizeHint();
#endif
auto driverList = QSqlDatabase::drivers();
for(auto driver : driverList) {
if ((ignoredDriverList.contains(driver))) {
continue;
}
if (databaseDriverMap.contains(driver)) {
ui->databaseTypeComboBox->addItem(databaseDriverMap[driver]+" ", driver);;
} else {
ui->databaseTypeComboBox->addItem(driver, driver);
}
}
QVariantMap settingsMap;
settingsMap = RegExDatabase::getInstance()->getSettings();
ui->databaseTypeComboBox->setCurrentText(settingsMap["databaseDriver"].toString());
ui->databaseNameLineEdit->setText(settingsMap["databaseName"].toString());
ui->hostNameLineEdit->setText(settingsMap["databaseHost"].toString());
ui->usernameLineEdit->setText(settingsMap["databaseUser"].toString());
ui->passwordLineEdit->setText(settingsMap["databasePassword"].toString());
}
Nedrysoft::DatabaseSettingsPage::~DatabaseSettingsPage()
{
delete ui;
}
bool Nedrysoft::DatabaseSettingsPage::canAcceptSettings()
{
return true;
}
void Nedrysoft::DatabaseSettingsPage::acceptSettings()
{
QVariantMap settingsMap;
settingsMap["databaseDriver"] = ui->databaseTypeComboBox->currentData();
settingsMap["databaseName"] = ui->databaseNameLineEdit->text();
settingsMap["databaseHost"] = ui->hostNameLineEdit->text();
settingsMap["databaseUser"] = ui->usernameLineEdit->text();
settingsMap["databasePassword"]= ui->passwordLineEdit->text();
RegExDatabase::getInstance()->storeSettings(settingsMap);
}
QSize Nedrysoft::DatabaseSettingsPage::sizeHint() const
{
return m_size;
}