Make currently used settings be printed out at application start
Due to the SettingsController being a static object it will be initialized before the main method has been run. This will cause easylogging to log using the default logging style instead of the defined application style. Because of this the settings are propogated up through a function into the main method.
This commit is contained in:
+5
-2
@@ -7,6 +7,11 @@ int main( int argc, char* argv[] )
|
|||||||
{
|
{
|
||||||
setUpLogging();
|
setUpLogging();
|
||||||
|
|
||||||
|
LOG( INFO ) << "Settings File: "
|
||||||
|
<< settings::initializeAndGetSettingsPath();
|
||||||
|
|
||||||
|
LOG( INFO ) << settings::getSettingsAndValues();
|
||||||
|
|
||||||
MyQApplication mainEventLoop( argc, argv );
|
MyQApplication mainEventLoop( argc, argv );
|
||||||
mainEventLoop.setOrganizationName(
|
mainEventLoop.setOrganizationName(
|
||||||
application_strings::applicationOrganizationName );
|
application_strings::applicationOrganizationName );
|
||||||
@@ -40,8 +45,6 @@ int main( int argc, char* argv[] )
|
|||||||
mainEventLoop.organizationName(),
|
mainEventLoop.organizationName(),
|
||||||
mainEventLoop.applicationName() );
|
mainEventLoop.applicationName() );
|
||||||
advsettings::OverlayController::setAppSettings( &appSettings );
|
advsettings::OverlayController::setAppSettings( &appSettings );
|
||||||
LOG( INFO ) << "Settings File: "
|
|
||||||
<< settings::initializeAndGetSettingsPath();
|
|
||||||
|
|
||||||
QQmlEngine qmlEngine;
|
QQmlEngine qmlEngine;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,38 @@
|
|||||||
|
|
||||||
namespace settings
|
namespace settings
|
||||||
{
|
{
|
||||||
|
template <typename Value> std::string valueToString( Value value )
|
||||||
|
{
|
||||||
|
using std::is_same;
|
||||||
|
if constexpr ( is_same<bool, Value>::value )
|
||||||
|
{
|
||||||
|
return value ? "true" : "false";
|
||||||
|
}
|
||||||
|
else if constexpr ( is_same<double, Value>::value
|
||||||
|
|| is_same<int, Value>::value )
|
||||||
|
{
|
||||||
|
return std::to_string( value );
|
||||||
|
}
|
||||||
|
if constexpr ( is_same<std::string, Value>::value )
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <int ArraySize, typename Value>
|
||||||
|
[[nodiscard]] std::string
|
||||||
|
returnSettingsAndValues( std::array<Value, ArraySize> v )
|
||||||
|
{
|
||||||
|
std::string s = "default";
|
||||||
|
|
||||||
|
for ( const auto& setting : v )
|
||||||
|
{
|
||||||
|
s += setting.qtInfo().settingName + ": '"
|
||||||
|
+ valueToString( setting.value() ) + "' | ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
template <typename Enum, int ArraySize, typename Value>
|
template <typename Enum, int ArraySize, typename Value>
|
||||||
void verifySettings( std::array<Value, ArraySize> v ) noexcept
|
void verifySettings( std::array<Value, ArraySize> v ) noexcept
|
||||||
{
|
{
|
||||||
@@ -40,8 +72,6 @@ void verifySettings( std::array<Value, ArraySize> v ) noexcept
|
|||||||
exit( ReturnErrorCode::SETTING_INCORRECT_INDEX );
|
exit( ReturnErrorCode::SETTING_INCORRECT_INDEX );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG( DEBUG ) << "Settings for '" << typeid( Enum ).name() << "' verified.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsController
|
class SettingsController
|
||||||
@@ -58,6 +88,20 @@ public:
|
|||||||
verifySettings<IntSetting, intSettingsSize>( m_intSettings );
|
verifySettings<IntSetting, intSettingsSize>( m_intSettings );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getSettingsAndValues() const noexcept
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
s += returnSettingsAndValues<boolSettingSize>( m_boolSettings );
|
||||||
|
|
||||||
|
s += returnSettingsAndValues<doubleSettingSize>( m_doubleSettings );
|
||||||
|
|
||||||
|
s += returnSettingsAndValues<stringSettingsSize>( m_stringSettings );
|
||||||
|
|
||||||
|
s += returnSettingsAndValues<intSettingsSize>( m_intSettings );
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
std::string getSettingsFileName() const noexcept
|
std::string getSettingsFileName() const noexcept
|
||||||
{
|
{
|
||||||
return getQSettings().fileName().toStdString();
|
return getQSettings().fileName().toStdString();
|
||||||
|
|||||||
@@ -68,4 +68,9 @@ std::string initializeAndGetSettingsPath()
|
|||||||
return settingController.getSettingsFileName();
|
return settingController.getSettingsFileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getSettingsAndValues()
|
||||||
|
{
|
||||||
|
return settingController.getSettingsAndValues();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace settings
|
} // namespace settings
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ enum class IntSetting
|
|||||||
|
|
||||||
std::string initializeAndGetSettingsPath();
|
std::string initializeAndGetSettingsPath();
|
||||||
|
|
||||||
|
std::string getSettingsAndValues();
|
||||||
|
|
||||||
void saveChangedSettings();
|
void saveChangedSettings();
|
||||||
|
|
||||||
void saveAllSettings();
|
void saveAllSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user