Skip to content

Commit c07a654

Browse files
committed
Make project settings nullable
And allow resetting them instead of always having to remove them For #168
1 parent edbc805 commit c07a654

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

src/db/tables/settings_table.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SettingsTable::SettingsTable() :
3535
// name uiName type nullable primaryKey foreignKey table
3636
primaryKeyColumn (new Column("projectSettingID", QString(), ID, false, true, nullptr, this)),
3737
settingKeyColumn (new Column("settingKey", QString(), String, false, false, nullptr, this)),
38-
settingValueColumn (new Column("settingValue", QString(), String, false, false, nullptr, this))
38+
settingValueColumn (new Column("settingValue", QString(), String, true, false, nullptr, this))
3939
{
4040
addColumn(primaryKeyColumn);
4141
addColumn(settingKeyColumn);
@@ -45,15 +45,18 @@ SettingsTable::SettingsTable() :
4545

4646

4747
/**
48-
* Indicates whether the given setting is present in the project settings table.
48+
* Indicates whether the given setting is present and has a value in the project settings table.
4949
*
5050
* @param setting The setting to check.
5151
* @param parent The parent window. Can be nullptr, in which case no cleanup is performed for duplicate settings.
52-
* @return True if the setting is present, false otherwise.
52+
* @return True if the setting is present and not null, false otherwise.
5353
*/
5454
bool SettingsTable::settingIsPresent(const GenericProjectSetting* setting, QWidget* parent)
5555
{
56-
return findSettingID(setting, parent).isValid();
56+
ItemID settingID = findSettingID(setting, parent);
57+
if (settingID.isInvalid()) return false;
58+
QVariant value = settingValueColumn->getValueFor(FORCE_VALID(settingID));
59+
return value.isValid();
5760
}
5861

5962
/**
@@ -108,11 +111,24 @@ void SettingsTable::setSetting(QWidget* parent, const GenericProjectSetting* set
108111
}
109112

110113
/**
111-
* Removes the setting from the project settings table entirely.
114+
* Removes the value from the setting in the project settings table.
112115
*
113116
* @param parent The parent window. Cannot be nullptr.
114117
* @param setting The setting to remove.
115118
*/
119+
void SettingsTable::clearSetting(QWidget* parent, const GenericProjectSetting* setting)
120+
{
121+
ItemID id = findSettingID(setting, parent);
122+
if (id.isInvalid()) return;
123+
updateCellInNormalTable(parent, FORCE_VALID(id), settingValueColumn, QVariant());
124+
}
125+
126+
/**
127+
* Removes the setting from the project settings table entirely.
128+
*
129+
* @param parent The parent window. Cannot be nullptr.
130+
* @param setting The setting to remove.
131+
*/
116132
void SettingsTable::removeSetting(QWidget* parent, const GenericProjectSetting* setting)
117133
{
118134
ItemID id = findSettingID(setting, parent);

src/db/tables/settings_table.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SettingsTable : public Table {
5151
QVariant getSetting(const GenericProjectSetting* setting, QWidget* parent = nullptr);
5252

5353
void setSetting(QWidget* parent, const GenericProjectSetting* setting, QVariant value);
54+
void clearSetting(QWidget* parent, const GenericProjectSetting* setting);
5455
void removeSetting(QWidget* parent, const GenericProjectSetting* setting);
5556

5657
private:

src/settings/project_settings.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,21 @@ void GenericProjectSetting::set(QWidget* parent, QVariant value)
8888
}
8989

9090
/**
91-
* Removes the setting from the project settings storage.
92-
*
91+
* Clears the setting in the project settings storage.
92+
*
9393
* @param parent The parent window. Cannot be nullptr.
9494
*/
9595
void GenericProjectSetting::clear(QWidget* parent)
96+
{
97+
table->clearSetting(parent, this);
98+
}
99+
100+
/**
101+
* Removes the setting from the project settings storage completely.
102+
*
103+
* @param parent The parent window. Cannot be nullptr.
104+
*/
105+
void GenericProjectSetting::remove(QWidget* parent)
96106
{
97107
table->removeSetting(parent, this);
98108
}

src/settings/project_settings.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class GenericProjectSetting {
5757

5858
void set(QWidget* parent, QVariant value);
5959
void clear(QWidget* parent);
60+
void remove(QWidget* parent);
6061
};
6162

6263

@@ -114,8 +115,8 @@ class ProjectSettings {
114115
/** The hiker filter setting. */
115116
ProjectSetting<int> ascentFilterHiker;
116117

117-
118-
118+
119+
119120
/**
120121
* Creates a new ProjectSettings object.
121122
*

0 commit comments

Comments
 (0)