Merge branch 'development' into 3.2.x-stable

This commit is contained in:
Philip Müller 2019-09-04 13:46:42 -04:00
commit fd327aedc5
5 changed files with 35 additions and 23 deletions

View File

@ -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,10 @@ PackageChooserPage::selectedPackageIds() const
}
return ids;
}
void
PackageChooserPage::setIntroduction( const PackageItem& item )
{
m_introduction.name = item.name;
m_introduction.description = item.description;
}

View File

@ -37,6 +37,8 @@ public:
void setModel( QAbstractItemModel* model );
/// @brief Sets the introductory (no-package-selected) texts
void setIntroduction( const PackageItem& item );
/// @brief Is anything selected?
bool hasSelection() const;
/** @brief Get the list of selected ids

View File

@ -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 );
break;
}
}
}

View File

@ -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 )

View File

@ -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,