From 52d3f4417f5940b5b1bd42f305fcc0bda3a0985d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 23 Mar 2020 09:59:03 +0100 Subject: [PATCH] [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. --- src/modules/netinstall/PackageTreeItem.cpp | 10 ++++++---- src/modules/netinstall/PackageTreeItem.h | 17 ++++++++++++++++- src/modules/netinstall/Tests.cpp | 7 +++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/modules/netinstall/PackageTreeItem.cpp b/src/modules/netinstall/PackageTreeItem.cpp index 51fa2b13e..eca62141f 100644 --- a/src/modules/netinstall/PackageTreeItem.cpp +++ b/src/modules/netinstall/PackageTreeItem.cpp @@ -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( "" ) ) + , m_selected( Qt::Checked ) + , m_isGroup( true ) { - m_selected = Qt::Checked; - m_name = QLatin1String( "" ); } PackageTreeItem::~PackageTreeItem() diff --git a/src/modules/netinstall/PackageTreeItem.h b/src/modules/netinstall/PackageTreeItem.h index 89a07aadc..c35b98eea 100644 --- a/src/modules/netinstall/PackageTreeItem.h +++ b/src/modules/netinstall/PackageTreeItem.h @@ -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; diff --git a/src/modules/netinstall/Tests.cpp b/src/modules/netinstall/Tests.cpp index d1d73d7fe..420b690aa 100644 --- a/src/modules/netinstall/Tests.cpp +++ b/src/modules/netinstall/Tests.cpp @@ -55,6 +55,7 @@ ItemTests::testRoot() QCOMPARE( r.isSelected(), Qt::Checked ); QCOMPARE( r.name(), QStringLiteral( "" ) ); 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 )