Skip to content

Commit

Permalink
MSUSettings refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mentaljam committed Aug 30, 2015
1 parent f9d2929 commit 99cdccf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/qt/helpwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HelpWindow::HelpWindow(QWidget *parent) :
mActionGoMainPage(new QAction(tr("Home"), this)),
mActionBackward(new QAction(tr("Backward"), this)),
mActionForward(new QAction(tr("Forward"), this)),
mHelpEngine(new QHelpEngine(settingsObj.getResourcesPath(MSUSettings::HELP) + "msuproj-qt.qhc", this)),
mHelpEngine(new QHelpEngine(settingsObj.getPath(MSUSettings::PATH_SHARE_HELP) + "msuproj-qt.qhc", this)),
mPageWidget(new HelpBrowser(mHelpEngine, this))
{
QByteArray geom(settingsObj.getGeometry(MSUSettings::HELPWINDOW));
Expand Down
2 changes: 1 addition & 1 deletion src/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main(int argc, char *argv[])
msuProjQt.setOrganizationDomain("www.ntsomz.ru");

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

MainWindow msuProjMainWindow;
Expand Down
20 changes: 10 additions & 10 deletions src/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ MainWindow::MainWindow(QWidget *parent) :
ui->imageView->setScene(mGraphicsScene);
mOpenImageDialog->setFileMode(QFileDialog::ExistingFile);
QString curPath;
if (settingsObj.usePreferedInputPath())
curPath = settingsObj.getPath(MSUSettings::INPUT_PREFERED);
if (settingsObj.getBool(MSUSettings::BOOL_USE_PREFERED_INPUT))
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREFERED);
else
curPath = settingsObj.getPath(MSUSettings::INPUT_PREVIOUS);
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREVIOUS);
mOpenImageDialog->setDirectory(curPath);

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

MainWindow::~MainWindow()
{
settingsObj.setPath(MSUSettings::INPUT_PREVIOUS, mOpenImageDialog->directory().path());
settingsObj.setPath(MSUSettings::PATH_INPUT_PREVIOUS, mOpenImageDialog->directory().path());
settingsObj.setGeometry(MSUSettings::MAINWINDOW, this->saveGeometry());
QThread *wThread = mWarper->thread();
if (wThread != qApp->thread())
Expand Down Expand Up @@ -139,10 +139,10 @@ void MainWindow::on_gcpPathButton_clicked()
QString curPath = ui->gcpPathEdit->text();
if (curPath.isEmpty())
{
if (settingsObj.usePreferedInputPath())
curPath = settingsObj.getPath(MSUSettings::INPUT_PREFERED);
if (settingsObj.getBool(MSUSettings::BOOL_USE_PREFERED_INPUT))
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREFERED);
else
curPath = settingsObj.getPath(MSUSettings::INPUT_PREVIOUS);
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREVIOUS);
}
QFileDialog openGCPs(this, tr("Select input GCP file"),
curPath,
Expand Down Expand Up @@ -200,10 +200,10 @@ void MainWindow::on_outPathButton_clicked()
QString curPath = ui->outPathEdit->text();
if (curPath.isEmpty())
{
if (settingsObj.usePreferedInputPath())
curPath = settingsObj.getPath(MSUSettings::INPUT_PREFERED);
if (settingsObj.getBool(MSUSettings::BOOL_USE_PREFERED_INPUT))
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREFERED);
else
curPath = settingsObj.getPath(MSUSettings::INPUT_PREVIOUS);
curPath = settingsObj.getPath(MSUSettings::PATH_INPUT_PREVIOUS);
}
QFileDialog outFile(this, tr("Specify output file"),
QFileInfo(curPath).path(),
Expand Down
108 changes: 50 additions & 58 deletions src/qt/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
MSUSettings::MSUSettings() :
mSettings(QSettings::IniFormat, QSettings::UserScope,
"NTsOMZ", "MSUProj-Qt"),
mResourcesPath(""),
mPathsKeys({
"History/InputPath",
"InputPath"
})
mResourcesPath("")
{
QStringList resourcesPaths;
resourcesPaths << "./"
Expand Down Expand Up @@ -56,104 +52,100 @@ QString MSUSettings::getLocale(bool *ok) const
return mSettings.value("locale", QLocale().system().name()).toString();
}

QString MSUSettings::getResourcesPath(const RES_PATHS type) const
void MSUSettings::setLocale(const QString &locale)
{
mSettings.setValue("locale", locale);
}

void MSUSettings::unsetLocale()
{
switch (type) {
case I18N:
mSettings.remove("locale");
}

QString MSUSettings::getPath(const MSUSettings::PATHS type) const
{
switch (type)
{
case PATH_SHARE:
return mResourcesPath;
case PATH_SHARE_I18N:
return mResourcesPath + "i18n/";
case HELP:
case PATH_SHARE_HELP:
return mResourcesPath + "help/";
default:
return mResourcesPath;
return mSettings.value(option(type)).toString();
}
}

void MSUSettings::setLocale(const QString &locale)
void MSUSettings::setPath(const MSUSettings::PATHS type, const QString &value)
{
mSettings.setValue("locale", locale);
if (type > PATH_SHARE)
mSettings.setValue(option(type), value);
}

void MSUSettings::unsetLocale()
bool MSUSettings::getBool(MSUSettings::BOOL_OPTIONS type) const
{
mSettings.remove("locale");
return mSettings.value(option(type)).toBool();
}

QString MSUSettings::getPath(const PATHS_TYPES type) const
void MSUSettings::setBool(MSUSettings::BOOL_OPTIONS type, const bool &value)
{
if (type < PATHS_TYPES_SIZE)
return mSettings.value(mPathsKeys[type]).toString();
else
return QString();
mSettings.setValue(option(type), value);
}

void MSUSettings::setPath(const PATHS_TYPES type, const QString &value)
QByteArray MSUSettings::getGeometry(MSUSettings::WIDGETS type) const
{
if (type < PATHS_TYPES_SIZE)
mSettings.setValue(mPathsKeys[type], value);
return mSettings.value(option(type) + "/geom").toByteArray();
}

bool MSUSettings::usePreferedInputPath() const
void MSUSettings::setGeometry(MSUSettings::WIDGETS type, const QByteArray &value)
{
return mSettings.value("UsePreferedPath").toBool();
mSettings.setValue(option(type) + "/geom", value);
}

void MSUSettings::setUsePreferedInputPath(const bool value)
QByteArray MSUSettings::getState(MSUSettings::WIDGETS type) const
{
mSettings.setValue("UsePreferedPath", value);
return mSettings.value(option(type) + "/state").toByteArray();
}

QByteArray MSUSettings::getGeometry(MSUSettings::WIDGETS widget) const
void MSUSettings::setState(MSUSettings::WIDGETS type, const QByteArray &value)
{
switch (widget)
{
case MAINWINDOW:
return mSettings.value("MainWindow/geom").toByteArray();
case HELPWINDOW:
return mSettings.value("HelpWindow/geom").toByteArray();
default:
return 0;
}
mSettings.setValue(option(type) + "/state", value);
}

void MSUSettings::setGeometry(MSUSettings::WIDGETS widget, const QByteArray &value)
QString MSUSettings::option(MSUSettings::PATHS type) const
{
switch (widget)
switch (type)
{
case MAINWINDOW:
mSettings.setValue("MainWindow/geom", value);
break;
case HELPWINDOW:
mSettings.setValue("HelpWindow/geom", value);
break;
case PATH_INPUT_PREVIOUS:
return "History/InputPath";
case PATH_INPUT_PREFERED:
return "InputPath";
default:
break;
return 0;
}
}

QByteArray MSUSettings::getState(MSUSettings::WIDGETS widget) const
QString MSUSettings::option(MSUSettings::BOOL_OPTIONS type) const
{
switch (widget)
switch (type)
{
case MAINWINDOW:
return mSettings.value("MainWindow/state").toByteArray();
case HELPWINDOW:
return mSettings.value("HelpWindow/state").toByteArray();
case BOOL_USE_PREFERED_INPUT:
return "UsePreferedPath";
default:
return 0;
}
}

void MSUSettings::setState(MSUSettings::WIDGETS widget, const QByteArray &value)
QString MSUSettings::option(MSUSettings::WIDGETS type) const
{
switch (widget)
switch (type)
{
case MAINWINDOW:
mSettings.setValue("MainWindow/state", value);
break;
return "MainWindow";
case HELPWINDOW:
mSettings.setValue("HelpWindow/state", value);
break;
return "HelpWindow";
default:
break;
return 0;
}
}
41 changes: 23 additions & 18 deletions src/qt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ class MSUSettings

public:

enum PATHS_TYPES
enum PATHS
{
INPUT_PREVIOUS,
INPUT_PREFERED,
PATHS_TYPES_SIZE,
PATH_SHARE_I18N,
PATH_SHARE_HELP,
PATH_SHARE,
PATH_INPUT_PREVIOUS,
PATH_INPUT_PREFERED,
PATH_TOTAL
};

enum RES_PATHS
enum BOOL_OPTIONS
{
RES_ROOT,
I18N,
HELP
BOOL_USE_PREFERED_INPUT
};

enum WIDGETS
Expand All @@ -37,27 +38,31 @@ class MSUSettings

QStringList getLocalesList() const;
QString getLocale(bool *ok = 0) const;
QString getResourcesPath(const RES_PATHS type) const;
void setLocale(const QString &locale);
void unsetLocale();

QString getPath(const PATHS_TYPES type) const;
void setPath(const PATHS_TYPES type, const QString &value);
QString getPath(const PATHS type) const;
void setPath(const PATHS type, const QString &value);

bool usePreferedInputPath() const;
void setUsePreferedInputPath(const bool value);
bool getBool(BOOL_OPTIONS type) const;
void setBool(BOOL_OPTIONS type, const bool &value);

QByteArray getGeometry(WIDGETS widget) const;
void setGeometry(WIDGETS widget, const QByteArray &value);
QByteArray getGeometry(WIDGETS type) const;
void setGeometry(WIDGETS type, const QByteArray &value);

QByteArray getState(WIDGETS widget) const;
void setState(WIDGETS widget, const QByteArray &value);
QByteArray getState(WIDGETS type) const;
void setState(WIDGETS type, const QByteArray &value);

private:

QSettings mSettings;
QString mResourcesPath;
QStringList mPathsKeys;

private:

QString option(PATHS type) const;
QString option(BOOL_OPTIONS type) const;
QString option(WIDGETS type) const;

};

Expand Down
8 changes: 4 additions & 4 deletions src/qt/settingswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ SettingsWindow::SettingsWindow(QWidget *parent) :
ui->langBox->setCurrentIndex(1);
}

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

SettingsWindow::~SettingsWindow()
Expand All @@ -58,8 +58,8 @@ void SettingsWindow::on_buttonBox_clicked(QAbstractButton *button)
settingsObj.setLocale(mLocales[curIndex - 2]);
break;
}
settingsObj.setUsePreferedInputPath(ui->inputPathPreferedButton->isChecked());
settingsObj.setPath(MSUSettings::INPUT_PREFERED, ui->inputPathEdit->text());
settingsObj.setBool(MSUSettings::BOOL_USE_PREFERED_INPUT, ui->inputPathPreferedButton->isChecked());
settingsObj.setPath(MSUSettings::PATH_INPUT_PREFERED, ui->inputPathEdit->text());
break;
default:
break;
Expand Down

0 comments on commit 99cdccf

Please sign in to comment.