[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
main
Adriaan de Groot 5 years ago
parent c2f1070f2a
commit 996714dd06

@ -53,10 +53,10 @@ PackageChooserPage::PackageChooserPage( PackageChooserMode mode, QWidget* parent
}
/** @brief size the given @p pixmap to @p size
*
*
* This is "smart" in the sense that it tries to keep the image un-scaled
* (if it's just a little too big) and otherwise scales as needed.
*
*
* Returns a copy if any modifications are done.
*/
static QPixmap
@ -129,26 +129,7 @@ void
PackageChooserPage::setModel( QAbstractItemModel* 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() );
break;
}
}
}
currentChanged( QModelIndex() );
connect( ui->products->selectionModel(),
&QItemSelectionModel::selectionChanged,
this,
@ -181,3 +162,11 @@ PackageChooserPage::selectedPackageIds() const
}
return ids;
}
void
PackageChooserPage::setIntroduction( const CalamaresUtils::Locale::TranslatedString& name,
const CalamaresUtils::Locale::TranslatedString& description )
{
m_introduction.name = name;
m_introduction.description = description;
}

@ -21,6 +21,8 @@
#include "PackageModel.h"
#include "locale/TranslatableConfiguration.h"
#include <QAbstractItemModel>
#include <QWidget>
@ -37,6 +39,9 @@ public:
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?
bool hasSelection() const;
/** @brief Get the list of selected ids

@ -283,4 +283,13 @@ PackageChooserViewStep::hookupModel()
}
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;
}
}
}

@ -66,7 +66,7 @@ private:
// Configuration
PackageChooserMode m_mode;
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
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory )

@ -80,6 +80,14 @@ struct PackageItem
* A valid item has an untranslated name available.
*/
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 >;
@ -100,6 +108,11 @@ public:
int rowCount( const QModelIndex& index ) 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
{
NameRole = Qt::DisplayRole,

Loading…
Cancel
Save