[netinstall] Chase removal of ItemData

- Simplify creation of PackageTreeItems by interpreting the
  YAML directly (instead of via ItemData),
- Simplify list types,
- Drop superfluous API.
This commit is contained in:
Adriaan de Groot 2020-03-20 23:03:47 +01:00
parent c66ef5a201
commit 4cb2ed9552
7 changed files with 53 additions and 49 deletions

View File

@ -167,7 +167,7 @@ NetInstallPage::dataIsHere()
emit checkReady( true ); emit checkReady( true );
} }
PackageModel::PackageItemDataList PackageTreeItem::List
NetInstallPage::selectedPackages() const NetInstallPage::selectedPackages() const
{ {
if ( m_groups ) if ( m_groups )
@ -177,7 +177,7 @@ NetInstallPage::selectedPackages() const
else else
{ {
cWarning() << "no netinstall groups are available."; cWarning() << "no netinstall groups are available.";
return PackageModel::PackageItemDataList(); return PackageTreeItem::List();
} }
} }

View File

@ -74,7 +74,7 @@ public:
// Returns the list of packages belonging to groups that are // Returns the list of packages belonging to groups that are
// selected in the view in this given moment. No data is cached here, so // selected in the view in this given moment. No data is cached here, so
// this function does not have constant time. // this function does not have constant time.
PackageModel::PackageItemDataList selectedPackages() const; PackageTreeItem::List selectedPackages() const;
public slots: public slots:
void dataIsHere(); void dataIsHere();

View File

@ -127,7 +127,7 @@ NetInstallViewStep::onActivate()
void void
NetInstallViewStep::onLeave() NetInstallViewStep::onLeave()
{ {
PackageModel::PackageItemDataList packages = m_widget->selectedPackages(); auto packages = m_widget->selectedPackages();
cDebug() << "Netinstall: Processing" << packages.length() << "packages."; cDebug() << "Netinstall: Processing" << packages.length() << "packages.";
static const char PACKAGEOP[] = "packageOperations"; static const char PACKAGEOP[] = "packageOperations";
@ -158,13 +158,13 @@ NetInstallViewStep::onLeave()
for ( const auto& package : packages ) for ( const auto& package : packages )
{ {
if ( package.isCritical ) if ( package->isCritical() )
{ {
installPackages.append( package.toOperation() ); installPackages.append( package->toOperation() );
} }
else else
{ {
tryInstallPackages.append( package.toOperation() ); tryInstallPackages.append( package->toOperation() );
} }
} }

View File

@ -169,29 +169,21 @@ PackageModel::headerData( int section, Qt::Orientation orientation, int role ) c
return QVariant(); return QVariant();
} }
QList< PackageTreeItem::ItemData > PackageTreeItem::List
PackageModel::getPackages() const PackageModel::getPackages() const
{ {
QList< PackageTreeItem* > items = getItemPackages( m_rootItem ); auto items = getItemPackages( m_rootItem );
for ( auto package : m_hiddenItems ) for ( auto package : m_hiddenItems )
{
if ( package->hiddenSelected() ) if ( package->hiddenSelected() )
{ {
items.append( getItemPackages( package ) ); items.append( getItemPackages( package ) );
} }
QList< PackageTreeItem::ItemData > packages;
for ( auto item : items )
{
PackageTreeItem::ItemData itemData;
itemData.preScript = item->parentItem()->preScript(); // Only groups have hooks
itemData.packageName = item->packageName(); // this seg faults
itemData.postScript = item->parentItem()->postScript(); // Only groups have hooks
itemData.isCritical = item->parentItem()->isCritical(); // Only groups are critical
packages.append( itemData );
} }
return packages; return items;
} }
QList< PackageTreeItem* > PackageTreeItem::List
PackageModel::getItemPackages( PackageTreeItem* item ) const PackageModel::getItemPackages( PackageTreeItem* item ) const
{ {
QList< PackageTreeItem* > selectedPackages; QList< PackageTreeItem* > selectedPackages;
@ -232,21 +224,7 @@ PackageModel::setupModelData( const YAML::Node& data, PackageTreeItem* parent )
for ( YAML::const_iterator it = data.begin(); it != data.end(); ++it ) for ( YAML::const_iterator it = data.begin(); it != data.end(); ++it )
{ {
const YAML::Node itemDefinition = *it; const YAML::Node itemDefinition = *it;
PackageTreeItem* item = new PackageTreeItem( CalamaresUtils::yamlMapToVariant( itemDefinition ), parent );
QString name( tr( CalamaresUtils::yamlToVariant( itemDefinition[ "name" ] ).toByteArray() ) );
QString description( tr( CalamaresUtils::yamlToVariant( itemDefinition[ "description" ] ).toByteArray() ) );
PackageTreeItem::ItemData itemData;
itemData.name = name;
itemData.description = description;
itemData.preScript = getString( itemDefinition, "pre-install" );
itemData.postScript = getString( itemDefinition, "post-install" );
itemData.isCritical = getBool( itemDefinition, "critical" );
itemData.isHidden = getBool( itemDefinition, "hidden" );
itemData.startExpanded = getBool( itemDefinition, "expanded" );
PackageTreeItem* item = new PackageTreeItem( itemData, parent );
if ( itemDefinition[ "selected" ] ) if ( itemDefinition[ "selected" ] )
{ {

View File

@ -37,8 +37,6 @@ class PackageModel : public QAbstractItemModel
Q_OBJECT Q_OBJECT
public: public:
using PackageItemDataList = QList< PackageTreeItem::ItemData >;
// Names for columns (unused in the code) // Names for columns (unused in the code)
static constexpr const int NameColumn = 0; static constexpr const int NameColumn = 0;
static constexpr const int DescriptionColumn = 1; static constexpr const int DescriptionColumn = 1;
@ -63,14 +61,14 @@ 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;
PackageItemDataList getPackages() const; PackageTreeItem::List getPackages() const;
QList< PackageTreeItem* > getItemPackages( PackageTreeItem* item ) const; PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
private: private:
void setupModelData( const YAML::Node& data, PackageTreeItem* parent ); void setupModelData( const YAML::Node& data, PackageTreeItem* parent );
PackageTreeItem* m_rootItem; PackageTreeItem* m_rootItem;
QList< PackageTreeItem* > m_hiddenItems; PackageTreeItem::List m_hiddenItems;
}; };
#endif // PACKAGEMODEL_H #endif // PACKAGEMODEL_H

View File

@ -20,22 +20,43 @@
#include "PackageTreeItem.h" #include "PackageTreeItem.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h"
PackageTreeItem::PackageTreeItem( const QString& packageName, PackageTreeItem* parent ) static Qt::CheckState
: m_parentItem( parent ) parentCheckState( PackageTreeItem* parent )
{ {
m_packageName = packageName; if ( parent )
if ( parent != nullptr )
{ {
// Avoid partially-checked .. a package can't be partial // Avoid partially-checked .. a package can't be partial
m_selected = parent->isSelected() == Qt::Unchecked ? Qt::Unchecked : Qt::Checked; return parent->isSelected() == Qt::Unchecked ? Qt::Unchecked : Qt::Checked;
} }
else else
{ {
m_selected = Qt::Unchecked; return Qt::Unchecked;
} }
} }
PackageTreeItem::PackageTreeItem( const QString& packageName, PackageTreeItem* parent )
: m_parentItem( parent )
, m_packageName( packageName )
, m_selected( parentCheckState( parent ) )
{
}
PackageTreeItem::PackageTreeItem( const QVariantMap& groupData, PackageTreeItem* parent )
: m_parentItem( parent )
, m_name( CalamaresUtils::getString( groupData, "name" ) )
, m_selected( parentCheckState( parent ) )
, m_description( CalamaresUtils::getString( groupData, "description" ) )
, m_preScript( CalamaresUtils::getString( groupData, "pre-install" ) )
, m_postScript( CalamaresUtils::getString( groupData, "post-install" ) )
, m_isCritical( CalamaresUtils::getBool( groupData, "critical", false ) )
, m_isHidden( CalamaresUtils::getBool( groupData, "hidden", false ) )
, m_startExpanded( CalamaresUtils::getBool( groupData, "expanded", false ) )
{
}
PackageTreeItem::PackageTreeItem::PackageTreeItem() PackageTreeItem::PackageTreeItem::PackageTreeItem()
: PackageTreeItem( QString(), nullptr ) : PackageTreeItem( QString(), nullptr )
{ {

View File

@ -27,10 +27,12 @@
class PackageTreeItem : public QStandardItem class PackageTreeItem : public QStandardItem
{ {
public: public:
using PackageList = QList< PackageTreeItem* >; using List = QList< PackageTreeItem* >;
///@brief A package (individual package) ///@brief A package (individual package)
explicit PackageTreeItem( const QString& packageName, PackageTreeItem* parent = nullptr ); explicit PackageTreeItem( const QString& packageName, PackageTreeItem* parent = nullptr );
///@brief A group (sub-items and sub-groups are ignored)
explicit PackageTreeItem( const QVariantMap& groupData, PackageTreeItem* parent = nullptr );
///@brief A root item, always selected, named "<root>" ///@brief A root item, always selected, named "<root>"
explicit PackageTreeItem(); explicit PackageTreeItem();
~PackageTreeItem() override; ~PackageTreeItem() override;
@ -81,6 +83,12 @@ public:
*/ */
bool expandOnStart() const { return m_startExpanded; } bool expandOnStart() const { return m_startExpanded; }
/** @brief is this item selected?
*
* Groups may be partially selected; packages are only on or off.
*/
Qt::CheckState isSelected() const { return m_selected; }
/** @brief Turns this item into a variant for PackageOperations use /** @brief Turns this item into a variant for PackageOperations use
* *
* For "plain" items, this is just the package name; items with * For "plain" items, this is just the package name; items with
@ -88,7 +96,6 @@ public:
*/ */
QVariant toOperation() const; QVariant toOperation() const;
Qt::CheckState isSelected() const;
void setSelected( Qt::CheckState isSelected ); void setSelected( Qt::CheckState isSelected );
void setChildrenSelected( Qt::CheckState isSelected ); void setChildrenSelected( Qt::CheckState isSelected );
@ -97,7 +104,7 @@ public:
private: private:
PackageTreeItem* m_parentItem; PackageTreeItem* m_parentItem;
PackageList m_childItems; List m_childItems;
// An entry can be a packkage, or a group. // An entry can be a packkage, or a group.
QString m_name; QString m_name;