pre-select default item in packagechooser

This commit is contained in:
bill-auger 2019-11-11 01:47:10 -05:00
parent 17dcc38f3c
commit 7510e883b8
5 changed files with 44 additions and 0 deletions

View File

@ -140,6 +140,16 @@ PackageChooserPage::setModel( QAbstractItemModel* model )
&PackageChooserPage::updateLabels ); &PackageChooserPage::updateLabels );
} }
void
PackageChooserPage::setSelection( const QModelIndex& index )
{
if ( index.isValid() )
{
ui->products->selectionModel()->select( index, QItemSelectionModel::Select );
currentChanged( index );
}
}
bool bool
PackageChooserPage::hasSelection() const PackageChooserPage::hasSelection() const
{ {

View File

@ -35,10 +35,13 @@ class PackageChooserPage : public QWidget
public: public:
explicit PackageChooserPage( PackageChooserMode mode, QWidget* parent = nullptr ); explicit PackageChooserPage( PackageChooserMode mode, QWidget* parent = nullptr );
/// @brief Sets the data model for the listview
void setModel( QAbstractItemModel* model ); void setModel( QAbstractItemModel* model );
/// @brief Sets the introductory (no-package-selected) texts /// @brief Sets the introductory (no-package-selected) texts
void setIntroduction( const PackageItem& item ); void setIntroduction( const PackageItem& item );
/// @brief Selects a listview item
void setSelection( const QModelIndex& index );
/// @brief Is anything selected? /// @brief Is anything selected?
bool hasSelection() const; bool hasSelection() const;
/** @brief Get the list of selected ids /** @brief Get the list of selected ids

View File

@ -144,6 +144,12 @@ PackageChooserViewStep::isAtEnd() const
return true; return true;
} }
void
PackageChooserViewStep::onActivate()
{
if ( !m_widget->hasSelection() )
m_widget->setSelection( m_defaultIdx );
}
void void
PackageChooserViewStep::onLeave() PackageChooserViewStep::onLeave()
@ -198,6 +204,9 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap
} }
} }
QString default_item_id = CalamaresUtils::getString( configurationMap, "default" );
m_defaultIdx = QModelIndex();
bool first_time = !m_model; bool first_time = !m_model;
if ( configurationMap.contains( "items" ) ) if ( configurationMap.contains( "items" ) )
{ {
@ -208,6 +217,22 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap
{ {
hookupModel(); hookupModel();
} }
// find default item
if ( first_time && m_model && !default_item_id.isEmpty() )
{
for (int item_n = 0; item_n < m_model->packageCount(); ++item_n)
{
QModelIndex item_idx = m_model->index( item_n, 0 );
QVariant item_id = m_model->data( item_idx, PackageListModel::IdRole );
if ( item_id.toString() == default_item_id )
{
m_defaultIdx = item_idx;
break;
}
}
}
} }
void void

View File

@ -50,6 +50,7 @@ public:
bool isAtBeginning() const override; bool isAtBeginning() const override;
bool isAtEnd() const override; bool isAtEnd() const override;
void onActivate() override;
void onLeave() override; void onLeave() override;
Calamares::JobList jobs() const override; Calamares::JobList jobs() const override;
@ -67,6 +68,7 @@ private:
PackageChooserMode m_mode; PackageChooserMode m_mode;
QString m_id; QString m_id;
CalamaresUtils::Locale::TranslatedString* m_stepName; // As it appears in the sidebar CalamaresUtils::Locale::TranslatedString* m_stepName; // As it appears in the sidebar
QModelIndex m_defaultIdx;
}; };
CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory ) CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory )

View File

@ -33,6 +33,10 @@ labels:
step: "Packages" step: "Packages"
step[nl]: "Pakketten" step[nl]: "Pakketten"
# (Optional) 'id' of pre-selected list-view item.
# Pre-selects one of the items below.
# default: kde
# Items to display in the chooser. In general, this should be a # Items to display in the chooser. In general, this should be a
# pretty short list to avoid overwhelming the UI. This is a list # pretty short list to avoid overwhelming the UI. This is a list
# of objects, and the items are displayed in list order. # of objects, and the items are displayed in list order.