[netinstall] Minor changes from code review

This commit is contained in:
dalto 2022-01-24 15:39:14 -06:00
parent a657d7388c
commit 1db217931b
4 changed files with 40 additions and 43 deletions

View File

@ -64,20 +64,18 @@ NetInstallPage::onActivate()
{
ui->groupswidget->setFocus();
// The NetInstallSelect global sotrage value can be used to make additional items selected by default
// The NetInstallSelect global storage value can be used to make additional items selected by default
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if ( gs->contains( "NetinstallSelect" ) && gs->value( "NetinstallSelect" ).canConvert( QVariant::StringList ) )
const QStringList selectNames = gs->value( "NetinstallSelect" ).toStringList();
if ( !selectNames.isEmpty() )
{
const QStringList selectNames = gs->value( "NetinstallSelect" ).toStringList();
static_cast< PackageModel* >( ui->groupswidget->model() )->setSelections( selectNames );
m_config->model()->setSelections( selectNames );
}
// If NetInstallAdd is found in global storage, add those items to the tree
if ( gs->contains( "NetinstallAdd" ) && gs->value( "NetinstallAdd" ).canConvert( QVariant::List ) )
const QVariantList groups = gs->value( "NetinstallAdd" ).toList();
if ( !groups.isEmpty() )
{
const QVariantList groups = gs->value( "NetinstallAdd" ).toList();
static_cast< PackageModel* >( ui->groupswidget->model() )->appendModelData( groups, "packageChooser" );
m_config->model()->appendModelData( groups, "packageChooser" );
}
}

View File

@ -14,6 +14,20 @@
#include "utils/Variant.h"
#include "utils/Yaml.h"
static void
setSelections2( const QStringList& selectNames, PackageTreeItem* item )
{
for ( int i = 0; i < item->childCount(); i++ )
{
auto* child = item->child( i );
setSelections2( selectNames, child );
}
if ( item->isGroup() && selectNames.contains( item->name() ) )
{
item->setSelected( Qt::CheckState::Checked );
}
}
PackageModel::PackageModel( QObject* parent )
: QAbstractItemModel( parent )
{
@ -170,35 +184,12 @@ PackageModel::headerData( int section, Qt::Orientation orientation, int role ) c
return QVariant();
}
/** @brief Sets the checked flag on matching groups in the tree
*
* Recursively traverses the tree pointed to by m_rootItem and
* checks if a group name matches any of the items in @p selectNames.
* If a match is found, set check the box for that group and it's children.
*
* Individual packages will not be matched.
*
*/
void
PackageModel::setSelections( QStringList selectNames )
PackageModel::setSelections( const QStringList& selectNames )
{
if ( m_rootItem )
{
setSelections( selectNames, m_rootItem );
}
}
void
PackageModel::setSelections( QStringList selectNames, PackageTreeItem* item )
{
for ( int i = 0; i < item->childCount(); i++ )
{
auto* child = item->child( i );
setSelections( selectNames, child );
}
if ( item->isGroup() && selectNames.contains( item->name() ) )
{
item->setSelected( Qt::CheckState::Checked );
setSelections2( selectNames, m_rootItem );
}
}
@ -335,19 +326,19 @@ PackageModel::setupModelData( const QVariantList& groupList, PackageTreeItem* pa
void
PackageModel::setupModelData( const QVariantList& l )
{
emit beginResetModel();
Q_EMIT beginResetModel();
delete m_rootItem;
m_rootItem = new PackageTreeItem();
setupModelData( l, m_rootItem );
emit endResetModel();
Q_EMIT endResetModel();
}
void
PackageModel::appendModelData( const QVariantList& groupList, const QString source )
PackageModel::appendModelData( const QVariantList& groupList, const QString& source )
{
if ( m_rootItem )
{
emit beginResetModel();
Q_EMIT beginResetModel();
// Prune any existing data from the same source
for ( int i = 0; i < m_rootItem->childCount(); i++ )
@ -362,6 +353,6 @@ PackageModel::appendModelData( const QVariantList& groupList, const QString sour
// Add the new data to the model
setupModelData( groupList, m_rootItem );
emit endResetModel();
Q_EMIT endResetModel();
}
}

View File

@ -54,8 +54,16 @@ public:
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
void setSelections( QStringList selectNames );
void setSelections( QStringList selectNames, PackageTreeItem* item );
/** @brief Sets the checked flag on matching groups in the tree
*
* Recursively traverses the tree pointed to by m_rootItem and
* checks if a group name matches any of the items in @p selectNames.
* If a match is found, set check the box for that group and it's children.
*
* Individual packages will not be matched.
*
*/
void setSelections(const QStringList &selectNames );
PackageTreeItem::List getPackages() const;
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
@ -71,7 +79,7 @@ public:
* data is pruned first
*
*/
void appendModelData( const QVariantList& groupList, const QString source );
void appendModelData(const QVariantList& groupList, const QString &source );
private:
friend class ItemTests;

View File

@ -258,7 +258,7 @@ PackageTreeItem::removeChild( int row )
}
else
{
cWarning() << "Attempt to remove invalid child in removeChild() at row " + QString::number( row );
cWarning() << "Attempt to remove invalid child in removeChild() at row " << row;
}
}