[netinstall] Add explicit isGroup()
- Previously you would either need to know where in the tree a PackageTreeItem was, or guess that an empty packageName() means that it's a group.
This commit is contained in:
parent
bca316299e
commit
52d3f4417f
@ -40,6 +40,7 @@ PackageTreeItem::PackageTreeItem( const QString& packageName, PackageTreeItem* p
|
||||
: m_parentItem( parent )
|
||||
, m_packageName( packageName )
|
||||
, m_selected( parentCheckState( parent ) )
|
||||
, m_isGroup( false )
|
||||
{
|
||||
}
|
||||
|
||||
@ -50,6 +51,7 @@ PackageTreeItem::PackageTreeItem( const QVariantMap& groupData, PackageTreeItem*
|
||||
, m_description( CalamaresUtils::getString( groupData, "description" ) )
|
||||
, m_preScript( CalamaresUtils::getString( groupData, "pre-install" ) )
|
||||
, m_postScript( CalamaresUtils::getString( groupData, "post-install" ) )
|
||||
, m_isGroup( true )
|
||||
, m_isCritical( CalamaresUtils::getBool( groupData, "critical", false ) )
|
||||
, m_isHidden( CalamaresUtils::getBool( groupData, "hidden", false ) )
|
||||
, m_showReadOnly( CalamaresUtils::getBool( groupData, "immutable", false ) )
|
||||
@ -57,12 +59,12 @@ PackageTreeItem::PackageTreeItem( const QVariantMap& groupData, PackageTreeItem*
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PackageTreeItem::PackageTreeItem::PackageTreeItem()
|
||||
: PackageTreeItem( QString(), nullptr )
|
||||
: m_parentItem( nullptr )
|
||||
, m_name( QStringLiteral( "<root>" ) )
|
||||
, m_selected( Qt::Checked )
|
||||
, m_isGroup( true )
|
||||
{
|
||||
m_selected = Qt::Checked;
|
||||
m_name = QLatin1String( "<root>" );
|
||||
}
|
||||
|
||||
PackageTreeItem::~PackageTreeItem()
|
||||
|
@ -53,6 +53,20 @@ public:
|
||||
QString preScript() const { return m_preScript; }
|
||||
QString postScript() const { return m_postScript; }
|
||||
|
||||
/** @brief Is this item a group-item?
|
||||
*
|
||||
* Groups have a (possibly empty) list of packages, and a
|
||||
* (possibly empty) list of sub-groups, and can be marked
|
||||
* critical, hidden, etc. Packages, on the other hand, only
|
||||
* have a meaningful packageName() and selection status.
|
||||
*
|
||||
* Root is a group.
|
||||
*/
|
||||
bool isGroup() const { return m_isGroup; }
|
||||
|
||||
/// @brief Is this item a single package?
|
||||
bool isPackage() const { return !isGroup(); }
|
||||
|
||||
/** @brief Is this item hidden?
|
||||
*
|
||||
* Hidden items (generally only groups) are maintained separately,
|
||||
@ -106,7 +120,7 @@ private:
|
||||
PackageTreeItem* m_parentItem;
|
||||
List m_childItems;
|
||||
|
||||
// An entry can be a packkage, or a group.
|
||||
// An entry can be a package, or a group.
|
||||
QString m_name;
|
||||
QString m_packageName;
|
||||
Qt::CheckState m_selected = Qt::Unchecked;
|
||||
@ -115,6 +129,7 @@ private:
|
||||
QString m_description;
|
||||
QString m_preScript;
|
||||
QString m_postScript;
|
||||
bool m_isGroup = false;
|
||||
bool m_isCritical = false;
|
||||
bool m_isHidden = false;
|
||||
bool m_showReadOnly = false;
|
||||
|
@ -55,6 +55,7 @@ ItemTests::testRoot()
|
||||
QCOMPARE( r.isSelected(), Qt::Checked );
|
||||
QCOMPARE( r.name(), QStringLiteral( "<root>" ) );
|
||||
QCOMPARE( r.parentItem(), nullptr );
|
||||
QVERIFY( r.isGroup() );
|
||||
}
|
||||
|
||||
void
|
||||
@ -69,6 +70,8 @@ ItemTests::testPackage()
|
||||
QCOMPARE( p.childCount(), 0 );
|
||||
QVERIFY( !p.isHidden() );
|
||||
QVERIFY( !p.isCritical() );
|
||||
QVERIFY( !p.isGroup() );
|
||||
QVERIFY( p.isPackage() );
|
||||
|
||||
// This doesn't happen in normal constructions,
|
||||
// because a package can't have children.
|
||||
@ -77,6 +80,8 @@ ItemTests::testPackage()
|
||||
QCOMPARE( c.packageName(), QStringLiteral( "zsh" ) );
|
||||
QVERIFY( c.name().isEmpty() ); // not a group
|
||||
QCOMPARE( c.parentItem(), &p );
|
||||
QVERIFY( !c.isGroup() );
|
||||
QVERIFY( c.isPackage() );
|
||||
|
||||
QCOMPARE( p.childCount(), 0 ); // not noticed it has a child
|
||||
}
|
||||
@ -109,6 +114,8 @@ ItemTests::testGroup()
|
||||
QVERIFY( !p.isCritical() );
|
||||
// The item-constructor doesn't consider the packages: list
|
||||
QCOMPARE( p.childCount(), 0 );
|
||||
QVERIFY( p.isGroup() );
|
||||
QVERIFY( !p.isPackage() );
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN( ItemTests )
|
||||
|
Loading…
Reference in New Issue
Block a user