[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.
This commit is contained in:
Adriaan de Groot 2021-09-03 17:29:21 +02:00
parent 47c504df5d
commit c367731c42
2 changed files with 35 additions and 14 deletions

View file

@ -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: <strong>%1</strong>" ).arg( m_pkgc );
return tr( "Install option: <strong>%1</strong>" ).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 )
{

View file

@ -17,6 +17,7 @@
#include "modulesystem/InstanceKey.h"
#include <memory>
#include <optional>
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;
};