[packagechooser,netinstall] Fix issues where going back and forth between pkgchooser and netinstall produced unexpected behavior

This commit is contained in:
dalto 2022-01-23 13:58:10 -06:00
parent 2aa8c2f0e0
commit f4c2db7f21
7 changed files with 54 additions and 14 deletions

View file

@ -78,6 +78,6 @@ NetInstallPage::onActivate()
{
const QVariantList groups = gs->value( "NetinstallAdd" ).toList();
static_cast< PackageModel* >( ui->groupswidget->model() )->appendModelData( groups );
static_cast< PackageModel* >( ui->groupswidget->model() )->appendModelData( groups, "packageChooser" );
}
}

View file

@ -342,20 +342,26 @@ PackageModel::setupModelData( const QVariantList& l )
emit endResetModel();
}
/** @brief Appends groups to the tree
*
* Uses the data from @p groupList to add elements to the
* existing tree that m_rootItem points to. If m_rootItem
* is not valid, it does nothing
*
*/
void
PackageModel::appendModelData( const QVariantList& groupList )
PackageModel::appendModelData( const QVariantList& groupList, const QString source )
{
if ( m_rootItem )
{
emit beginResetModel();
// Prune any existing data from the same source
for ( int i = 0; i < m_rootItem->childCount(); i++ )
{
PackageTreeItem* child = m_rootItem->child( i );
if ( child->source() == source )
{
m_rootItem->removeChild( i );
}
}
// Add the new data to the model
setupModelData( groupList, m_rootItem );
emit endResetModel();
}
}

View file

@ -55,12 +55,23 @@ public:
int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
void setSelections( QStringList selectNames );
void setSelections(QStringList selectNames, PackageTreeItem *item );
void setSelections( QStringList selectNames, PackageTreeItem* item );
PackageTreeItem::List getPackages() const;
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
void appendModelData( const QVariantList& groupList );
/** @brief Appends groups to the tree
*
* Uses the data from @p groupList to add elements to the
* existing tree that m_rootItem points to. If m_rootItem
* is not valid, it does nothing
*
* Before adding anything to the model, it ensures that there
* is no existing data from the same source. If there is, that
* data is pruned first
*
*/
void appendModelData( const QVariantList& groupList, const QString source );
private:
friend class ItemTests;

View file

@ -70,6 +70,7 @@ PackageTreeItem::PackageTreeItem( const QVariantMap& groupData, GroupTag&& paren
, m_description( CalamaresUtils::getString( groupData, "description" ) )
, m_preScript( CalamaresUtils::getString( groupData, "pre-install" ) )
, m_postScript( CalamaresUtils::getString( groupData, "post-install" ) )
, m_source( CalamaresUtils::getString( groupData, "source" ) )
, m_isGroup( true )
, m_isCritical( parentCriticality( groupData, parent.parent ) )
, m_isHidden( CalamaresUtils::getBool( groupData, "hidden", false ) )
@ -248,6 +249,19 @@ PackageTreeItem::setChildrenSelected( Qt::CheckState isSelected )
}
}
void
PackageTreeItem::removeChild( int row )
{
if ( row < m_childItems.count() )
{
m_childItems.removeAt( row );
}
else
{
cWarning() << "Attempt to remove invalid child in removeChild() at row " + QString::number( row );
}
}
int
PackageTreeItem::type() const
{

View file

@ -56,6 +56,7 @@ public:
QString description() const { return m_description; }
QString preScript() const { return m_preScript; }
QString postScript() const { return m_postScript; }
QString source() const { return m_source; }
/** @brief Is this item a group-item?
*
@ -124,6 +125,8 @@ public:
void setSelected( Qt::CheckState isSelected );
void setChildrenSelected( Qt::CheckState isSelected );
void removeChild( int row );
/** @brief Update selectedness based on the children's states
*
* This only makes sense for groups, which might have packages
@ -157,6 +160,7 @@ private:
QString m_description;
QString m_preScript;
QString m_postScript;
QString m_source;
bool m_isGroup = false;
bool m_isCritical = false;
bool m_isHidden = false;

View file

@ -140,7 +140,7 @@ Config::updateGlobalStorage( const QStringList& selected ) const
auto netinstallAddOrig = gs->value( "NetinstallAdd" );
if ( netinstallAddOrig.canConvert( QVariant::List ) )
{
netinstallDataList += netinstallAddOrig.toList();
//netinstallDataList += netinstallAddOrig.toList();
}
else
{

View file

@ -140,11 +140,16 @@ QVariantList
PackageListModel::getNetinstallDataForNames( const QStringList& ids ) const
{
QVariantList l;
for ( const auto& p : qAsConst( m_packages ) )
for ( auto &p : m_packages )
{
if ( ids.contains( p.id ) )
{
l.append( p.netinstallData );
if ( !p.netinstallData.isEmpty() )
{
QVariantMap newData = p.netinstallData;
newData["source"] = "packageChooser";
l.append( newData );
}
}
}
return l;