Commit 464561b4 authored by Adriaan de Groot's avatar Adriaan de Groot

[netinstall] Update subgroup-checkedness based on children

- An unselected group with (some) selected subgroups was not
  displayed as (semi)checked -- it was unchecked, because
  its checked-ness was not updated based on the children.
parent 63b940a6
......@@ -249,6 +249,10 @@ PackageModel::setupModelData( const QVariantList& groupList, PackageTreeItem* pa
if ( !subgroups.isEmpty() )
{
setupModelData( subgroups, item );
// The children might be checked while the parent isn't (yet).
// Children are added to their parent (below) without affecting
// the checked-state -- do it manually.
item->updateSelected();
}
}
if ( item->isHidden() )
......
......@@ -194,34 +194,41 @@ PackageTreeItem::setSelected( Qt::CheckState isSelected )
return;
}
currentItem->updateSelected();
}
void
PackageTreeItem::updateSelected()
{
// Figure out checked-state based on the children
int childrenSelected = 0;
int childrenPartiallySelected = 0;
for ( int i = 0; i < currentItem->childCount(); i++ )
for ( int i = 0; i < childCount(); i++ )
{
if ( currentItem->child( i )->isSelected() == Qt::Checked )
if ( child( i )->isSelected() == Qt::Checked )
{
childrenSelected++;
}
if ( currentItem->child( i )->isSelected() == Qt::PartiallyChecked )
if ( child( i )->isSelected() == Qt::PartiallyChecked )
{
childrenPartiallySelected++;
}
}
if ( !childrenSelected && !childrenPartiallySelected )
{
currentItem->setSelected( Qt::Unchecked );
setSelected( Qt::Unchecked );
}
else if ( childrenSelected == currentItem->childCount() )
else if ( childrenSelected == childCount() )
{
currentItem->setSelected( Qt::Checked );
setSelected( Qt::Checked );
}
else
{
currentItem->setSelected( Qt::PartiallyChecked );
setSelected( Qt::PartiallyChecked );
}
}
void
PackageTreeItem::setChildrenSelected( Qt::CheckState isSelected )
{
......
......@@ -120,6 +120,13 @@ public:
void setSelected( Qt::CheckState isSelected );
void setChildrenSelected( Qt::CheckState isSelected );
/** @brief Update selectedness based on the children's states
*
* This only makes sense for groups, which might have packages
* or subgroups; it checks only direct children.
*/
void updateSelected();
// QStandardItem methods
int type() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment