[packagechooser] Use all translations for no-package-selected

- If there is an item with id "" (empty), it is used as the
   "no-package-selected" placeholder text.
 - Existing code iterated over the abstract model and used the
   name and description at the time the model was set -- but
   by getting the name and description from the model, only
   a single string was obtained instead of the full range
   of translations.
 - Therefore, when arriving on the page, the "no-package-selected"
   information was displayed from the translation that was active
   when the model was set.

Instead, extend the non-abstract model so we can find the no-package-
selected item and pass that explicitly to the page.

FIXES #1241
This commit is contained in:
Adriaan de Groot 2019-09-04 19:33:24 +02:00
parent c2f1070f2a
commit 996714dd06
5 changed files with 39 additions and 23 deletions

View File

@ -129,26 +129,7 @@ void
PackageChooserPage::setModel( QAbstractItemModel* model ) PackageChooserPage::setModel( QAbstractItemModel* model )
{ {
ui->products->setModel( model ); ui->products->setModel( model );
// Check if any of the items in the model is the "none" option.
// If so, copy its values into the introduction / none item.
for ( int r = 0; r < model->rowCount(); ++r )
{
auto index = model->index( r, 0 );
if ( index.isValid() )
{
QVariant v = model->data( index, PackageListModel::IdRole );
if ( v.isValid() && v.toString().isEmpty() )
{
m_introduction.name = model->data( index, PackageListModel::NameRole ).toString();
m_introduction.description = model->data( index, PackageListModel::DescriptionRole ).toString();
m_introduction.screenshot = model->data( index, PackageListModel::ScreenshotRole ).value< QPixmap >();
currentChanged( QModelIndex() ); currentChanged( QModelIndex() );
break;
}
}
}
connect( ui->products->selectionModel(), connect( ui->products->selectionModel(),
&QItemSelectionModel::selectionChanged, &QItemSelectionModel::selectionChanged,
this, this,
@ -181,3 +162,11 @@ PackageChooserPage::selectedPackageIds() const
} }
return ids; return ids;
} }
void
PackageChooserPage::setIntroduction( const CalamaresUtils::Locale::TranslatedString& name,
const CalamaresUtils::Locale::TranslatedString& description )
{
m_introduction.name = name;
m_introduction.description = description;
}

View File

@ -21,6 +21,8 @@
#include "PackageModel.h" #include "PackageModel.h"
#include "locale/TranslatableConfiguration.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QWidget> #include <QWidget>
@ -37,6 +39,9 @@ public:
void setModel( QAbstractItemModel* model ); void setModel( QAbstractItemModel* model );
/// @brief Sets the introductory (no-package-selected) texts
void setIntroduction( const CalamaresUtils::Locale::TranslatedString& name,
const CalamaresUtils::Locale::TranslatedString& description );
/// @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

@ -283,4 +283,13 @@ PackageChooserViewStep::hookupModel()
} }
m_widget->setModel( m_model ); m_widget->setModel( m_model );
for ( int i = 0; i < m_model->packageCount(); ++i )
{
const auto& package = m_model->packageData( i );
if ( package.id.isEmpty() )
{
m_widget->setIntroduction( package.name, package.description );
break;
}
}
} }

View File

@ -80,6 +80,14 @@ struct PackageItem
* A valid item has an untranslated name available. * A valid item has an untranslated name available.
*/ */
bool isValid() const { return !name.isEmpty(); } bool isValid() const { return !name.isEmpty(); }
/** @brief Is this a (the) No-Package package?
*
* There should be at most one No-Package item in a collection
* of PackageItems. That one will be used to describe a
* "no package" situation.
*/
bool isNonePackage() const { return id.isEmpty(); }
}; };
using PackageList = QVector< PackageItem >; using PackageList = QVector< PackageItem >;
@ -100,6 +108,11 @@ public:
int rowCount( const QModelIndex& index ) const override; int rowCount( const QModelIndex& index ) const override;
QVariant data( const QModelIndex& index, int role ) const override; QVariant data( const QModelIndex& index, int role ) const override;
/// @brief Direct (non-abstract) access to package data
const PackageItem& packageData( int r ) const { return m_packages[ r ]; }
/// @brief Direct (non-abstract) count of package data
int packageCount() const { return m_packages.count(); }
enum Roles : int enum Roles : int
{ {
NameRole = Qt::DisplayRole, NameRole = Qt::DisplayRole,