Skip to content

Commit 99cdccf

Browse files
committed
MSUSettings refactoring
1 parent f9d2929 commit 99cdccf

File tree

6 files changed

+89
-92
lines changed

6 files changed

+89
-92
lines changed

src/qt/helpwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ HelpWindow::HelpWindow(QWidget *parent) :
1111
mActionGoMainPage(new QAction(tr("Home"), this)),
1212
mActionBackward(new QAction(tr("Backward"), this)),
1313
mActionForward(new QAction(tr("Forward"), this)),
14-
mHelpEngine(new QHelpEngine(settingsObj.getResourcesPath(MSUSettings::HELP) + "msuproj-qt.qhc", this)),
14+
mHelpEngine(new QHelpEngine(settingsObj.getPath(MSUSettings::PATH_SHARE_HELP) + "msuproj-qt.qhc", this)),
1515
mPageWidget(new HelpBrowser(mHelpEngine, this))
1616
{
1717
QByteArray geom(settingsObj.getGeometry(MSUSettings::HELPWINDOW));

src/qt/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char *argv[])
1616
msuProjQt.setOrganizationDomain("www.ntsomz.ru");
1717

1818
QTranslator appTranslation;
19-
if (appTranslation.load("msuproj-qt_" + settingsObj.getLocale(), settingsObj.getResourcesPath(MSUSettings::I18N)))
19+
if (appTranslation.load("msuproj-qt_" + settingsObj.getLocale(), settingsObj.getPath(MSUSettings::PATH_SHARE_I18N)))
2020
msuProjQt.installTranslator(&appTranslation);
2121

2222
MainWindow msuProjMainWindow;

src/qt/mainwindow.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ MainWindow::MainWindow(QWidget *parent) :
3232
ui->imageView->setScene(mGraphicsScene);
3333
mOpenImageDialog->setFileMode(QFileDialog::ExistingFile);
3434
QString curPath;
35-
if (settingsObj.usePreferedInputPath())
36-
curPath = settingsObj.getPath(MSUSettings::INPUT_PREFERED);
35+
if (settingsObj.getBool(MSUSettings::BOOL_USE_PREFERED_INPUT))
36+
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREFERED);
3737
else
38-
curPath = settingsObj.getPath(MSUSettings::INPUT_PREVIOUS);
38+
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREVIOUS);
3939
mOpenImageDialog->setDirectory(curPath);
4040

4141
connect(ui->statusbar, &QStatusBar::messageChanged, this, &MainWindow::showStdStatus);
@@ -55,7 +55,7 @@ MainWindow::MainWindow(QWidget *parent) :
5555

5656
MainWindow::~MainWindow()
5757
{
58-
settingsObj.setPath(MSUSettings::INPUT_PREVIOUS, mOpenImageDialog->directory().path());
58+
settingsObj.setPath(MSUSettings::PATH_INPUT_PREVIOUS, mOpenImageDialog->directory().path());
5959
settingsObj.setGeometry(MSUSettings::MAINWINDOW, this->saveGeometry());
6060
QThread *wThread = mWarper->thread();
6161
if (wThread != qApp->thread())
@@ -139,10 +139,10 @@ void MainWindow::on_gcpPathButton_clicked()
139139
QString curPath = ui->gcpPathEdit->text();
140140
if (curPath.isEmpty())
141141
{
142-
if (settingsObj.usePreferedInputPath())
143-
curPath = settingsObj.getPath(MSUSettings::INPUT_PREFERED);
142+
if (settingsObj.getBool(MSUSettings::BOOL_USE_PREFERED_INPUT))
143+
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREFERED);
144144
else
145-
curPath = settingsObj.getPath(MSUSettings::INPUT_PREVIOUS);
145+
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREVIOUS);
146146
}
147147
QFileDialog openGCPs(this, tr("Select input GCP file"),
148148
curPath,
@@ -200,10 +200,10 @@ void MainWindow::on_outPathButton_clicked()
200200
QString curPath = ui->outPathEdit->text();
201201
if (curPath.isEmpty())
202202
{
203-
if (settingsObj.usePreferedInputPath())
204-
curPath = settingsObj.getPath(MSUSettings::INPUT_PREFERED);
203+
if (settingsObj.getBool(MSUSettings::BOOL_USE_PREFERED_INPUT))
204+
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREFERED);
205205
else
206-
curPath = settingsObj.getPath(MSUSettings::INPUT_PREVIOUS);
206+
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREVIOUS);
207207
}
208208
QFileDialog outFile(this, tr("Specify output file"),
209209
QFileInfo(curPath).path(),

src/qt/settings.cpp

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
MSUSettings::MSUSettings() :
99
mSettings(QSettings::IniFormat, QSettings::UserScope,
1010
"NTsOMZ", "MSUProj-Qt"),
11-
mResourcesPath(""),
12-
mPathsKeys({
13-
"History/InputPath",
14-
"InputPath"
15-
})
11+
mResourcesPath("")
1612
{
1713
QStringList resourcesPaths;
1814
resourcesPaths << "./"
@@ -56,104 +52,100 @@ QString MSUSettings::getLocale(bool *ok) const
5652
return mSettings.value("locale", QLocale().system().name()).toString();
5753
}
5854

59-
QString MSUSettings::getResourcesPath(const RES_PATHS type) const
55+
void MSUSettings::setLocale(const QString &locale)
56+
{
57+
mSettings.setValue("locale", locale);
58+
}
59+
60+
void MSUSettings::unsetLocale()
6061
{
61-
switch (type) {
62-
case I18N:
62+
mSettings.remove("locale");
63+
}
64+
65+
QString MSUSettings::getPath(const MSUSettings::PATHS type) const
66+
{
67+
switch (type)
68+
{
69+
case PATH_SHARE:
70+
return mResourcesPath;
71+
case PATH_SHARE_I18N:
6372
return mResourcesPath + "i18n/";
64-
case HELP:
73+
case PATH_SHARE_HELP:
6574
return mResourcesPath + "help/";
6675
default:
67-
return mResourcesPath;
76+
return mSettings.value(option(type)).toString();
6877
}
6978
}
7079

71-
void MSUSettings::setLocale(const QString &locale)
80+
void MSUSettings::setPath(const MSUSettings::PATHS type, const QString &value)
7281
{
73-
mSettings.setValue("locale", locale);
82+
if (type > PATH_SHARE)
83+
mSettings.setValue(option(type), value);
7484
}
7585

76-
void MSUSettings::unsetLocale()
86+
bool MSUSettings::getBool(MSUSettings::BOOL_OPTIONS type) const
7787
{
78-
mSettings.remove("locale");
88+
return mSettings.value(option(type)).toBool();
7989
}
8090

81-
QString MSUSettings::getPath(const PATHS_TYPES type) const
91+
void MSUSettings::setBool(MSUSettings::BOOL_OPTIONS type, const bool &value)
8292
{
83-
if (type < PATHS_TYPES_SIZE)
84-
return mSettings.value(mPathsKeys[type]).toString();
85-
else
86-
return QString();
93+
mSettings.setValue(option(type), value);
8794
}
8895

89-
void MSUSettings::setPath(const PATHS_TYPES type, const QString &value)
96+
QByteArray MSUSettings::getGeometry(MSUSettings::WIDGETS type) const
9097
{
91-
if (type < PATHS_TYPES_SIZE)
92-
mSettings.setValue(mPathsKeys[type], value);
98+
return mSettings.value(option(type) + "/geom").toByteArray();
9399
}
94100

95-
bool MSUSettings::usePreferedInputPath() const
101+
void MSUSettings::setGeometry(MSUSettings::WIDGETS type, const QByteArray &value)
96102
{
97-
return mSettings.value("UsePreferedPath").toBool();
103+
mSettings.setValue(option(type) + "/geom", value);
98104
}
99105

100-
void MSUSettings::setUsePreferedInputPath(const bool value)
106+
QByteArray MSUSettings::getState(MSUSettings::WIDGETS type) const
101107
{
102-
mSettings.setValue("UsePreferedPath", value);
108+
return mSettings.value(option(type) + "/state").toByteArray();
103109
}
104110

105-
QByteArray MSUSettings::getGeometry(MSUSettings::WIDGETS widget) const
111+
void MSUSettings::setState(MSUSettings::WIDGETS type, const QByteArray &value)
106112
{
107-
switch (widget)
108-
{
109-
case MAINWINDOW:
110-
return mSettings.value("MainWindow/geom").toByteArray();
111-
case HELPWINDOW:
112-
return mSettings.value("HelpWindow/geom").toByteArray();
113-
default:
114-
return 0;
115-
}
113+
mSettings.setValue(option(type) + "/state", value);
116114
}
117115

118-
void MSUSettings::setGeometry(MSUSettings::WIDGETS widget, const QByteArray &value)
116+
QString MSUSettings::option(MSUSettings::PATHS type) const
119117
{
120-
switch (widget)
118+
switch (type)
121119
{
122-
case MAINWINDOW:
123-
mSettings.setValue("MainWindow/geom", value);
124-
break;
125-
case HELPWINDOW:
126-
mSettings.setValue("HelpWindow/geom", value);
127-
break;
120+
case PATH_INPUT_PREVIOUS:
121+
return "History/InputPath";
122+
case PATH_INPUT_PREFERED:
123+
return "InputPath";
128124
default:
129-
break;
125+
return 0;
130126
}
131127
}
132128

133-
QByteArray MSUSettings::getState(MSUSettings::WIDGETS widget) const
129+
QString MSUSettings::option(MSUSettings::BOOL_OPTIONS type) const
134130
{
135-
switch (widget)
131+
switch (type)
136132
{
137-
case MAINWINDOW:
138-
return mSettings.value("MainWindow/state").toByteArray();
139-
case HELPWINDOW:
140-
return mSettings.value("HelpWindow/state").toByteArray();
133+
case BOOL_USE_PREFERED_INPUT:
134+
return "UsePreferedPath";
141135
default:
142136
return 0;
143137
}
144138
}
145139

146-
void MSUSettings::setState(MSUSettings::WIDGETS widget, const QByteArray &value)
140+
QString MSUSettings::option(MSUSettings::WIDGETS type) const
147141
{
148-
switch (widget)
142+
switch (type)
149143
{
150144
case MAINWINDOW:
151-
mSettings.setValue("MainWindow/state", value);
152-
break;
145+
return "MainWindow";
153146
case HELPWINDOW:
154-
mSettings.setValue("HelpWindow/state", value);
155-
break;
147+
return "HelpWindow";
156148
default:
157-
break;
149+
return 0;
158150
}
159151
}

src/qt/settings.h

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ class MSUSettings
99

1010
public:
1111

12-
enum PATHS_TYPES
12+
enum PATHS
1313
{
14-
INPUT_PREVIOUS,
15-
INPUT_PREFERED,
16-
PATHS_TYPES_SIZE,
14+
PATH_SHARE_I18N,
15+
PATH_SHARE_HELP,
16+
PATH_SHARE,
17+
PATH_INPUT_PREVIOUS,
18+
PATH_INPUT_PREFERED,
19+
PATH_TOTAL
1720
};
1821

19-
enum RES_PATHS
22+
enum BOOL_OPTIONS
2023
{
21-
RES_ROOT,
22-
I18N,
23-
HELP
24+
BOOL_USE_PREFERED_INPUT
2425
};
2526

2627
enum WIDGETS
@@ -37,27 +38,31 @@ class MSUSettings
3738

3839
QStringList getLocalesList() const;
3940
QString getLocale(bool *ok = 0) const;
40-
QString getResourcesPath(const RES_PATHS type) const;
4141
void setLocale(const QString &locale);
4242
void unsetLocale();
4343

44-
QString getPath(const PATHS_TYPES type) const;
45-
void setPath(const PATHS_TYPES type, const QString &value);
44+
QString getPath(const PATHS type) const;
45+
void setPath(const PATHS type, const QString &value);
4646

47-
bool usePreferedInputPath() const;
48-
void setUsePreferedInputPath(const bool value);
47+
bool getBool(BOOL_OPTIONS type) const;
48+
void setBool(BOOL_OPTIONS type, const bool &value);
4949

50-
QByteArray getGeometry(WIDGETS widget) const;
51-
void setGeometry(WIDGETS widget, const QByteArray &value);
50+
QByteArray getGeometry(WIDGETS type) const;
51+
void setGeometry(WIDGETS type, const QByteArray &value);
5252

53-
QByteArray getState(WIDGETS widget) const;
54-
void setState(WIDGETS widget, const QByteArray &value);
53+
QByteArray getState(WIDGETS type) const;
54+
void setState(WIDGETS type, const QByteArray &value);
5555

5656
private:
5757

5858
QSettings mSettings;
5959
QString mResourcesPath;
60-
QStringList mPathsKeys;
60+
61+
private:
62+
63+
QString option(PATHS type) const;
64+
QString option(BOOL_OPTIONS type) const;
65+
QString option(WIDGETS type) const;
6166

6267
};
6368

src/qt/settingswindow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ SettingsWindow::SettingsWindow(QWidget *parent) :
3131
ui->langBox->setCurrentIndex(1);
3232
}
3333

34-
ui->inputPathEdit->setText(settingsObj.getPath(MSUSettings::INPUT_PREFERED));
35-
ui->inputPathPreferedButton->setChecked(settingsObj.usePreferedInputPath());
34+
ui->inputPathEdit->setText(settingsObj.getPath(MSUSettings::PATH_INPUT_PREFERED));
35+
ui->inputPathPreferedButton->setChecked(settingsObj.getBool(MSUSettings::BOOL_USE_PREFERED_INPUT));
3636
}
3737

3838
SettingsWindow::~SettingsWindow()
@@ -58,8 +58,8 @@ void SettingsWindow::on_buttonBox_clicked(QAbstractButton *button)
5858
settingsObj.setLocale(mLocales[curIndex - 2]);
5959
break;
6060
}
61-
settingsObj.setUsePreferedInputPath(ui->inputPathPreferedButton->isChecked());
62-
settingsObj.setPath(MSUSettings::INPUT_PREFERED, ui->inputPathEdit->text());
61+
settingsObj.setBool(MSUSettings::BOOL_USE_PREFERED_INPUT, ui->inputPathPreferedButton->isChecked());
62+
settingsObj.setPath(MSUSettings::PATH_INPUT_PREFERED, ui->inputPathEdit->text());
6363
break;
6464
default:
6565
break;

0 commit comments

Comments
 (0)