From c367731c42f5fd1cdeb9206c0010ff7ad98bf3c4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 3 Sep 2021 17:29:21 +0200 Subject: [PATCH] [packagechooser] Rename internals - pkgc -> packageChoice and similar for methods, variables - document that this is the convenience value for one-selection QML modules, not a full model - use std::optional to keep track of which one is being used. --- src/modules/packagechooser/Config.cpp | 23 +++++++++++++++-------- src/modules/packagechooser/Config.h | 26 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/modules/packagechooser/Config.cpp b/src/modules/packagechooser/Config.cpp index f66f16824..2c798ea03 100644 --- a/src/modules/packagechooser/Config.cpp +++ b/src/modules/packagechooser/Config.cpp @@ -100,10 +100,10 @@ Config::updateGlobalStorage( const QStringList& selected ) const { if ( m_method == PackageChooserMethod::Legacy ) { - //QString value = selected.join( ',' ); - QString value = ( m_pkgc ); + QString value = selected.join( ',' ); + // QString value = ( m_pkgc ); Calamares::JobQueue::instance()->globalStorage()->insert( m_id, value ); - cDebug() << m_id<< "selected" << value; + cDebug() << m_id << "selected" << value; } else if ( m_method == PackageChooserMethod::Packages ) { @@ -119,16 +119,23 @@ Config::updateGlobalStorage( const QStringList& selected ) const } void -Config::setPkgc( const QString& pkgc ) +Config::setPackageChoice( const QString& packageChoice ) { - m_pkgc = pkgc; - emit pkgcChanged( m_pkgc ); + if ( packageChoice.isEmpty() ) + { + m_packageChoice.reset(); + } + else + { + m_packageChoice = packageChoice; + } + emit packageChoiceChanged( m_packageChoice.value_or( QString() ) ); } QString Config::prettyStatus() const { - return tr( "Install option: %1" ).arg( m_pkgc ); + return tr( "Install option: %1" ).arg( m_packageChoice.value_or( tr( "None" ) ) ); } static void @@ -197,7 +204,7 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) PackageChooserMode::Required ); m_method = PackageChooserMethodNames().find( CalamaresUtils::getString( configurationMap, "method" ), PackageChooserMethod::Legacy ); - m_pkgc = CalamaresUtils::getString( configurationMap, "pkgc" ); + setPackageChoice( CalamaresUtils::getString( configurationMap, "pkgc" ) ); if ( m_method == PackageChooserMethod::Legacy ) { diff --git a/src/modules/packagechooser/Config.h b/src/modules/packagechooser/Config.h index b343a8cb2..75ff0d0c6 100644 --- a/src/modules/packagechooser/Config.h +++ b/src/modules/packagechooser/Config.h @@ -17,6 +17,7 @@ #include "modulesystem/InstanceKey.h" #include +#include enum class PackageChooserMode { @@ -40,7 +41,16 @@ class Config : public Calamares::ModuleSystem::Config { Q_OBJECT - Q_PROPERTY( QString pkgc READ pkgc WRITE setPkgc NOTIFY pkgcChanged ) + /** @brief This is the single-select package-choice + * + * For (QML) modules that support only a single selection and + * just want to do things in a straightforward pick-this-one + * way, the packageChoice property is a (the) way to go. + * + * Writing to this property means that any other form of package- + * choice or selection is ignored. + */ + Q_PROPERTY( QString packageChoice READ packageChoice WRITE setPackageChoice NOTIFY packageChoiceChanged ) Q_PROPERTY( QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL ) public: @@ -78,13 +88,13 @@ public: /// As updateGlobalStorage() with an empty selection list void fillGSSecondaryConfiguration() const { updateGlobalStorage( QStringList() ); } - QString pkgc() const { return m_pkgc; } - void setPkgc( const QString& pkgc ); + QString packageChoice() const { return m_packageChoice.value_or( QString() ); } + void setPackageChoice( const QString& packageChoice ); QString prettyStatus() const; signals: - void pkgcChanged( QString pkgc ); + void packageChoiceChanged( QString packageChoice ); void prettyStatusChanged(); private: @@ -99,8 +109,12 @@ private: QString m_id; /// Value to use for id if none is set in the config file Calamares::ModuleSystem::InstanceKey m_defaultId; - /// QML selection - QString m_pkgc; + /** @brief QML selection (for single-selection approaches) + * + * If there is no value, then there has been no selection. + * Reading the property will return an empty QString. + */ + std::optional< QString > m_packageChoice; };