chore: add getOrRegisterSetting function

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2025-04-10 22:49:29 +03:00
parent 564f120c22
commit 5af06dec85
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
9 changed files with 23 additions and 28 deletions

View file

@ -124,3 +124,8 @@ void SettingsObject::connectSignals(const Setting& setting)
connect(&setting, &Setting::settingReset, this, &SettingsObject::resetSetting);
connect(&setting, SIGNAL(settingReset(Setting)), this, SIGNAL(settingReset(const Setting&)));
}
std::shared_ptr<Setting> SettingsObject::getOrRegisterSetting(const QString& id, QVariant defVal)
{
return contains(id) ? getSetting(id) : registerSetting(id, defVal);
}

View file

@ -103,6 +103,16 @@ class SettingsObject : public QObject {
*/
std::shared_ptr<Setting> getSetting(const QString& id) const;
/*!
* \brief Gets the setting with the given ID.
* \brief if is not registered yet it does that
* \param id The ID of the setting to get.
* \return A pointer to the setting with the given ID.
* Returns null if there is no setting with the given ID.
* \sa operator []()
*/
std::shared_ptr<Setting> getOrRegisterSetting(const QString& id, QVariant defVal = QVariant());
/*!
* \brief Gets the value of the setting with the given ID.
* \param id The ID of the setting to get.