From 2930ea6d4ff04d98a4cc07f725541938863aef01 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 24 Jan 2020 13:51:48 +0100 Subject: [PATCH] Add VideoProfiles to new object settings API --- src/tabcontrollers/VideoTabController.cpp | 68 +---------------------- src/tabcontrollers/VideoTabController.h | 55 +++++++++++++++++- 2 files changed, 56 insertions(+), 67 deletions(-) diff --git a/src/tabcontrollers/VideoTabController.cpp b/src/tabcontrollers/VideoTabController.cpp index b4f4135..d506031 100644 --- a/src/tabcontrollers/VideoTabController.cpp +++ b/src/tabcontrollers/VideoTabController.cpp @@ -932,7 +932,6 @@ void VideoTabController::addVideoProfile( const QString name ) profile->overlayMethodState = isOverlayMethodActive(); saveVideoProfiles(); - OverlayController::appSettings()->sync(); emit videoProfilesUpdated(); emit videoProfileAdded(); } @@ -964,81 +963,18 @@ void VideoTabController::deleteVideoProfile( const unsigned index ) auto pos = videoProfiles.begin() + index; videoProfiles.erase( pos ); saveVideoProfiles(); - OverlayController::appSettings()->sync(); emit videoProfilesUpdated(); } } void VideoTabController::reloadVideoProfiles() { - videoProfiles.clear(); - auto settings = OverlayController::appSettings(); - settings->beginGroup( "VideoSettings" ); - auto profileCount = settings->beginReadArray( "videoProfiles" ); - for ( int i = 0; i < profileCount; i++ ) - { - settings->setArrayIndex( i ); - videoProfiles.emplace_back(); - auto& entry = videoProfiles[static_cast( i )]; - entry.profileName - = settings->value( "profileName" ).toString().toStdString(); - - entry.supersampleOverride - = settings->value( "supersamplingOverride", false ).toBool(); - entry.supersampling - = settings->value( "supersampling", 1.0f ).toFloat(); - entry.anisotropicFiltering - = settings->value( "anisotropicFiltering", true ).toBool(); - entry.motionSmooth = settings->value( "motionSmooth", true ).toBool(); - - entry.colorRed = settings->value( "colorRedNew", 1.0f ).toFloat(); - entry.colorBlue = settings->value( "colorBlueNew", 1.0f ).toFloat(); - entry.colorGreen = settings->value( "colorGreenNew", 1.0f ).toFloat(); - - entry.brightnessToggle - = settings->value( "brightnessToggle", false ).toBool(); - entry.brightnessOpacityValue - = settings->value( "brightnessOpacityValue", 1.0f ).toFloat(); - entry.opacity = settings->value( "opacity", 0.0f ).toFloat(); - entry.overlayMethodState - = settings->value( "overlayMethodState", false ).toBool(); - } - settings->endArray(); - settings->endGroup(); + settings::loadAllObjects( videoProfiles ); } void VideoTabController::saveVideoProfiles() { - auto settings = OverlayController::appSettings(); - settings->beginGroup( "VideoSettings" ); - settings->beginWriteArray( "videoProfiles" ); - unsigned i = 0; - for ( auto& p : videoProfiles ) - { - settings->setArrayIndex( static_cast( i ) ); - settings->setValue( "profileName", - QString::fromStdString( p.profileName ) ); - - settings->setValue( "supersamplingOverride", p.supersampleOverride ); - settings->setValue( "supersampling", p.supersampling ); - settings->setValue( "anisotropicFiltering", p.anisotropicFiltering ); - settings->setValue( "motionSmooth", p.motionSmooth ); - - settings->setValue( "colorRedNew", p.colorRed ); - settings->setValue( "colorBlueNew", p.colorBlue ); - settings->setValue( "colorGreenNew", p.colorGreen ); - - settings->setValue( "brightnessToggle", p.brightnessToggle ); - settings->setValue( "brightnessOpacityValue", - p.brightnessOpacityValue ); - - settings->setValue( "opacity", p.opacity ); - settings->setValue( "overlayMethodState", p.overlayMethodState ); - - i++; - } - settings->endArray(); - settings->endGroup(); + settings::saveAllObjects( videoProfiles ); } int VideoTabController::getVideoProfileCount() diff --git a/src/tabcontrollers/VideoTabController.h b/src/tabcontrollers/VideoTabController.h index f2fec49..6de2c10 100644 --- a/src/tabcontrollers/VideoTabController.h +++ b/src/tabcontrollers/VideoTabController.h @@ -5,6 +5,7 @@ #include #include #include "../utils/FrameRateUtils.h" +#include "../settings/settings_object.h" class QQuickWindow; @@ -20,7 +21,7 @@ namespace advsettings // forward declaration class OverlayController; -struct VideoProfile +struct VideoProfile : settings::ISettingsObject { std::string profileName; @@ -35,6 +36,58 @@ struct VideoProfile float brightnessOpacityValue = 1.0f; bool overlayMethodState = false; float opacity = 0.0f; // TODO check + + virtual settings::SettingsObjectData saveSettings() const override + { + settings::SettingsObjectData o; + + o.addValue( static_cast( supersampling ) ); + + o.addValue( anisotropicFiltering ); + o.addValue( motionSmooth ); + o.addValue( supersampleOverride ); + + o.addValue( static_cast( colorRed ) ); + o.addValue( static_cast( colorGreen ) ); + o.addValue( static_cast( colorBlue ) ); + + o.addValue( brightnessToggle ); + + o.addValue( static_cast( brightnessOpacityValue ) ); + + o.addValue( overlayMethodState ); + + o.addValue( static_cast( opacity ) ); + + return o; + } + + virtual void loadSettings( settings::SettingsObjectData& obj ) override + { + supersampling = static_cast( obj.getNextValueOrDefault( 1.0 ) ); + + anisotropicFiltering = obj.getNextValueOrDefault( false ); + motionSmooth = obj.getNextValueOrDefault( false ); + supersampleOverride = obj.getNextValueOrDefault( false ); + + colorRed = static_cast( obj.getNextValueOrDefault( 1.0 ) ); + colorGreen = static_cast( obj.getNextValueOrDefault( 1.0 ) ); + colorBlue = static_cast( obj.getNextValueOrDefault( 1.0 ) ); + + brightnessToggle = obj.getNextValueOrDefault( false ); + + brightnessOpacityValue + = static_cast( obj.getNextValueOrDefault( 1.0 ) ); + + overlayMethodState = obj.getNextValueOrDefault( false ); + + opacity = static_cast( obj.getNextValueOrDefault( 1.0 ) ); + } + + virtual std::string settingsName() const override + { + return "VideoTabController::VideoProfile"; + } }; class VideoTabController : public QObject