[netinstall] Build model from QVariantList
- As an alternative to the YAML-wranging, build the model from a QVariantList instead. - Expose this as a constructor, too.
This commit is contained in:
parent
4143ad67af
commit
dc403237f2
@ -19,6 +19,7 @@
|
||||
|
||||
#include "PackageModel.h"
|
||||
|
||||
#include "utils/Variant.h"
|
||||
#include "utils/Yaml.h"
|
||||
|
||||
PackageModel::PackageModel( const YAML::Node& data, QObject* parent )
|
||||
@ -28,6 +29,13 @@ PackageModel::PackageModel( const YAML::Node& data, QObject* parent )
|
||||
setupModelData( data, m_rootItem );
|
||||
}
|
||||
|
||||
PackageModel::PackageModel( const QVariantList& data, QObject* parent )
|
||||
: QAbstractItemModel( parent )
|
||||
{
|
||||
m_rootItem = new PackageTreeItem();
|
||||
setupModelData( data, m_rootItem );
|
||||
}
|
||||
|
||||
PackageModel::~PackageModel()
|
||||
{
|
||||
delete m_rootItem;
|
||||
@ -206,18 +214,55 @@ PackageModel::getItemPackages( PackageTreeItem* item ) const
|
||||
return selectedPackages;
|
||||
}
|
||||
|
||||
static QString
|
||||
getString( const YAML::Node& itemDefinition, const char* key )
|
||||
{
|
||||
return itemDefinition[ key ] ? CalamaresUtils::yamlToVariant( itemDefinition[ key ] ).toString() : QString();
|
||||
}
|
||||
|
||||
static bool
|
||||
getBool( const YAML::Node& itemDefinition, const char* key )
|
||||
{
|
||||
return itemDefinition[ key ] ? CalamaresUtils::yamlToVariant( itemDefinition[ key ] ).toBool() : false;
|
||||
}
|
||||
|
||||
void
|
||||
PackageModel::setupModelData( const QVariantList& groupList, PackageTreeItem* parent )
|
||||
{
|
||||
for ( const auto& group : groupList )
|
||||
{
|
||||
QVariantMap groupMap = group.toMap();
|
||||
if ( groupMap.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
PackageTreeItem* item = new PackageTreeItem( groupMap, parent );
|
||||
if ( groupMap.contains( "selected" ) )
|
||||
{
|
||||
item->setSelected( CalamaresUtils::getBool( groupMap, "selected", false ) ? Qt::Checked : Qt::Unchecked );
|
||||
}
|
||||
if ( groupMap.contains( "packages" ) )
|
||||
{
|
||||
for ( const auto& packageName : groupMap.value( "packages" ).toStringList() )
|
||||
{
|
||||
item->appendChild( new PackageTreeItem( packageName, item ) );
|
||||
}
|
||||
}
|
||||
if ( groupMap.contains( "subgroups" ) )
|
||||
{
|
||||
QVariantList subgroups = groupMap.value( "subgroups" ).toList();
|
||||
if ( !subgroups.isEmpty() )
|
||||
{
|
||||
setupModelData( subgroups, item );
|
||||
}
|
||||
}
|
||||
if ( item->isHidden() )
|
||||
{
|
||||
m_hiddenItems.append( item );
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setCheckable( true );
|
||||
parent->appendChild( item );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PackageModel::setupModelData( const YAML::Node& data, PackageTreeItem* parent )
|
||||
{
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
static constexpr const int MetaExpandRole = Qt::UserRole + 1;
|
||||
|
||||
explicit PackageModel( const YAML::Node& data, QObject* parent = nullptr );
|
||||
explicit PackageModel( const QVariantList& data, QObject* parent = nullptr );
|
||||
~PackageModel() override;
|
||||
|
||||
QVariant data( const QModelIndex& index, int role ) const override;
|
||||
@ -66,6 +67,7 @@ public:
|
||||
|
||||
private:
|
||||
void setupModelData( const YAML::Node& data, PackageTreeItem* parent );
|
||||
void setupModelData( const QVariantList& l, PackageTreeItem* parent );
|
||||
|
||||
PackageTreeItem* m_rootItem;
|
||||
PackageTreeItem::List m_hiddenItems;
|
||||
|
Loading…
Reference in New Issue
Block a user