[netinstall] Minor changes from code review
This commit is contained in:
parent
a657d7388c
commit
1db217931b
@ -64,20 +64,18 @@ NetInstallPage::onActivate()
|
|||||||
{
|
{
|
||||||
ui->groupswidget->setFocus();
|
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();
|
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();
|
m_config->model()->setSelections( selectNames );
|
||||||
|
|
||||||
static_cast< PackageModel* >( ui->groupswidget->model() )->setSelections( selectNames );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If NetInstallAdd is found in global storage, add those items to the tree
|
// 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();
|
m_config->model()->appendModelData( groups, "packageChooser" );
|
||||||
|
|
||||||
static_cast< PackageModel* >( ui->groupswidget->model() )->appendModelData( groups, "packageChooser" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,20 @@
|
|||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
#include "utils/Yaml.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 )
|
PackageModel::PackageModel( QObject* parent )
|
||||||
: QAbstractItemModel( parent )
|
: QAbstractItemModel( parent )
|
||||||
{
|
{
|
||||||
@ -170,35 +184,12 @@ PackageModel::headerData( int section, Qt::Orientation orientation, int role ) c
|
|||||||
return QVariant();
|
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
|
void
|
||||||
PackageModel::setSelections( QStringList selectNames )
|
PackageModel::setSelections( const QStringList& selectNames )
|
||||||
{
|
{
|
||||||
if ( m_rootItem )
|
if ( m_rootItem )
|
||||||
{
|
{
|
||||||
setSelections( selectNames, m_rootItem );
|
setSelections2( 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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,19 +326,19 @@ PackageModel::setupModelData( const QVariantList& groupList, PackageTreeItem* pa
|
|||||||
void
|
void
|
||||||
PackageModel::setupModelData( const QVariantList& l )
|
PackageModel::setupModelData( const QVariantList& l )
|
||||||
{
|
{
|
||||||
emit beginResetModel();
|
Q_EMIT beginResetModel();
|
||||||
delete m_rootItem;
|
delete m_rootItem;
|
||||||
m_rootItem = new PackageTreeItem();
|
m_rootItem = new PackageTreeItem();
|
||||||
setupModelData( l, m_rootItem );
|
setupModelData( l, m_rootItem );
|
||||||
emit endResetModel();
|
Q_EMIT endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageModel::appendModelData( const QVariantList& groupList, const QString source )
|
PackageModel::appendModelData( const QVariantList& groupList, const QString& source )
|
||||||
{
|
{
|
||||||
if ( m_rootItem )
|
if ( m_rootItem )
|
||||||
{
|
{
|
||||||
emit beginResetModel();
|
Q_EMIT beginResetModel();
|
||||||
|
|
||||||
// Prune any existing data from the same source
|
// Prune any existing data from the same source
|
||||||
for ( int i = 0; i < m_rootItem->childCount(); i++ )
|
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
|
// Add the new data to the model
|
||||||
setupModelData( groupList, m_rootItem );
|
setupModelData( groupList, m_rootItem );
|
||||||
|
|
||||||
emit endResetModel();
|
Q_EMIT endResetModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,16 @@ public:
|
|||||||
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
||||||
int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
|
int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
|
||||||
|
|
||||||
void setSelections( QStringList selectNames );
|
/** @brief Sets the checked flag on matching groups in the tree
|
||||||
void setSelections( QStringList selectNames, PackageTreeItem* item );
|
*
|
||||||
|
* 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 getPackages() const;
|
||||||
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
|
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
|
||||||
@ -71,7 +79,7 @@ public:
|
|||||||
* data is pruned first
|
* data is pruned first
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void appendModelData( const QVariantList& groupList, const QString source );
|
void appendModelData(const QVariantList& groupList, const QString &source );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ItemTests;
|
friend class ItemTests;
|
||||||
|
@ -258,7 +258,7 @@ PackageTreeItem::removeChild( int row )
|
|||||||
}
|
}
|
||||||
else
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user