Skip to content

Commit 0e4dc9a

Browse files
committed
Refactor: Make app version function global
For #168
1 parent a16ed57 commit 0e4dc9a

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

src/main/about_window.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ AboutWindow::AboutWindow(QWidget* parent) :
4040
{
4141
setupUi(this);
4242

43-
QString appVersion = Settings::getAppVersion();
43+
QString appVersion = getAppVersion();
4444
QString qtVersion = QString("%1.%2.%3").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH);
4545

4646
appNameLabel ->setText(appNameLabel ->text().replace("$APP_VERSION$", appVersion));

src/settings/settings.cpp

+40-36
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,6 @@ QString getDefaultLanguageCode()
7272

7373

7474

75-
/**
76-
* Returns a string containing the application's version number.
77-
*
78-
* @return The application's version number in string form.
79-
*/
80-
QString Settings::getAppVersion()
81-
{
82-
return QString("%1.%2.%3")
83-
.arg(APP_VERSION_MAJOR)
84-
.arg(APP_VERSION_MINOR)
85-
.arg(APP_VERSION_PATCH);
86-
}
87-
88-
/**
89-
* Compares two version strings and determines whether the first one is older than the second one.
90-
*
91-
* @param settingsVersion The version of the application that saved the settings file.
92-
* @param minimalVersion The version of the application with which to compare the settings file version.
93-
* @return True if the settings file is older than the given version, false otherwise.
94-
*/
95-
bool Settings::isBelowVersion(QString settingsVersion, QString minimalVersion)
96-
{
97-
QStringList settingsSplit = settingsVersion.split('.');
98-
QStringList minimalSplit = minimalVersion.split('.');
99-
assert(settingsSplit.size() == 3 && minimalSplit.size() == 3);
100-
for (int i = 0; i < 3; i++) {
101-
bool conversionOk = false;
102-
int settingsNumber = settingsSplit.at(i).toInt(&conversionOk);
103-
assert(conversionOk);
104-
int minimalNumber = minimalSplit.at(i).toInt(&conversionOk);
105-
assert(conversionOk);
106-
if (settingsNumber < minimalNumber) return true;
107-
}
108-
return false;
109-
}
110-
11175
/**
11276
* Determines whether the settings file was last saved by a version of the application that is
11377
* older than the current version.
@@ -162,6 +126,46 @@ void Settings::checkForVersionChange()
162126

163127

164128

129+
/**
130+
* Returns a string containing the application's version number.
131+
*
132+
* @return The application's version number in string form.
133+
*/
134+
QString getAppVersion()
135+
{
136+
return QString("%1.%2.%3")
137+
.arg(APP_VERSION_MAJOR)
138+
.arg(APP_VERSION_MINOR)
139+
.arg(APP_VERSION_PATCH);
140+
}
141+
142+
/**
143+
* Compares two version strings and determines whether the first one is older than the second one.
144+
*
145+
* @param settingsVersion The version of the application that saved the settings file.
146+
* @param minimalVersion The version of the application with which to compare the settings file version.
147+
* @return True if the settings file is older than the given version, false otherwise.
148+
*/
149+
bool isBelowVersion(QString versionToCheck, QString minimalVersion)
150+
{
151+
QStringList checkSplit = versionToCheck.split('.');
152+
QStringList minimalSplit = minimalVersion.split('.');
153+
assert(checkSplit.size() == 3 && minimalSplit.size() == 3);
154+
for (int i = 0; i < 3; i++) {
155+
bool conversionOk = false;
156+
int settingsNumber = checkSplit.at(i).toInt(&conversionOk);
157+
assert(conversionOk);
158+
int minimalNumber = minimalSplit.at(i).toInt(&conversionOk);
159+
assert(conversionOk);
160+
if (settingsNumber < minimalNumber) return true;
161+
}
162+
return false;
163+
}
164+
165+
166+
167+
168+
165169
/**
166170
* Stores implicit settings about position and geometry for the given dialog.
167171
*

src/settings/settings.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,18 @@ class Settings {
460460
}
461461

462462
private:
463-
static bool isBelowVersion(QString settingsVersion, QString minimalVersion);
464463
static bool settingsOlderThan(QString version);
465464
public:
466-
static QString getAppVersion();
467465
static void checkForVersionChange();
468466
};
469467

470468

471469

470+
QString getAppVersion();
471+
bool isBelowVersion(QString versionToCheck, QString minimalVersion);
472+
473+
474+
472475
void saveDialogGeometry (QWidget* dialog, QWidget* parent, const Setting<QRect>* geometrySetting);
473476
void restoreDialogGeometry(QWidget* dialog, QWidget* parent, const Setting<QRect>* geometrySetting);
474477

0 commit comments

Comments
 (0)