fix qaservice (autoInstance method)

This commit is contained in:
Andrei Yankovich 2023-08-16 13:34:40 +02:00
parent 53a67709ff
commit d4a3e7dff2
4 changed files with 28 additions and 2 deletions

View File

@ -104,7 +104,22 @@ public:
*/
void setMode(const SettingsSaveMode &mode);
/**
* @brief instance This method returns pointer to current settings object.
* @return pointer to current settings object.
* @see Service::instance
*/
static ISettings* instance();
/**
* @brief initService This method initialize the global settings object.
* @param obj This is prepared settings object. You should create a your object monyaly, and add to initialization
* @code{cpp}
* bool result = initService(std::make_unique<MySettings>());
* @endcode
* @return true if initialization finished successful else false.
* @see Service::initService
*/
static bool initService(std::unique_ptr<ISettings> obj);
public slots:

View File

@ -78,12 +78,12 @@ public:
* @see deinitService
* @see autoInstance
*/
static Base* initService() {
static inline std::unique_ptr<Base>& initService() {
auto& val = instancePrivat();
if(!val) {
val.reset(new Base());
}
return val._data;
return val;
}
/**

View File

@ -65,4 +65,8 @@ void Settings::setBoolOptions(const QSet<QString> &newBoolOptions)
_boolOptions = newBoolOptions;
}
bool Settings::initService() {
return ISettings::initService(std::make_unique<Settings>());
}
}

View File

@ -61,6 +61,13 @@ public:
*/
void setBoolOptions(const QSet<QString> &newBoolOptions);
/**
* @brief initService This method initialize default object of the QuasarAppUtils::Settings type.
* @return true if initialization finished successfull else false.
* @see ISettings::initService
*/
static bool initService();
protected:
void syncImplementation() override;