[netinstall] Refactor model-data setting
- Introduce convenience methods getString(), getBool() to pick out an entry from item definitions in YAML format. - Apply coding style. - Pick up the "expanded" property as well.
This commit is contained in:
parent
0f7f5216ee
commit
4f216b0394
@ -117,7 +117,7 @@ PackageModel::data( const QModelIndex& index, int role ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
PackageTreeItem* item = static_cast< PackageTreeItem* >( index.internalPointer() );
|
PackageTreeItem* item = static_cast< PackageTreeItem* >( index.internalPointer() );
|
||||||
switch( role )
|
switch ( role )
|
||||||
{
|
{
|
||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
return index.column() == NameColumn ? item->isSelected() : QVariant();
|
return index.column() == NameColumn ? item->isSelected() : QVariant();
|
||||||
@ -212,6 +212,18 @@ PackageModel::getItemPackages( PackageTreeItem* item ) const
|
|||||||
return selectedPackages;
|
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
|
void
|
||||||
PackageModel::setupModelData( const YAML::Node& data, PackageTreeItem* parent )
|
PackageModel::setupModelData( const YAML::Node& data, PackageTreeItem* parent )
|
||||||
{
|
{
|
||||||
@ -226,22 +238,11 @@ PackageModel::setupModelData( const YAML::Node& data, PackageTreeItem* parent )
|
|||||||
itemData.name = name;
|
itemData.name = name;
|
||||||
itemData.description = description;
|
itemData.description = description;
|
||||||
|
|
||||||
if ( itemDefinition[ "pre-install" ] )
|
itemData.preScript = getString( itemDefinition, "pre-install" );
|
||||||
{
|
itemData.postScript = getString( itemDefinition, "post-install" );
|
||||||
itemData.preScript = CalamaresUtils::yamlToVariant( itemDefinition[ "pre-install" ] ).toString();
|
itemData.isCritical = getBool( itemDefinition, "critical" );
|
||||||
}
|
itemData.isHidden = getBool( itemDefinition, "hidden" );
|
||||||
if ( itemDefinition[ "post-install" ] )
|
itemData.startExpanded = getBool( itemDefinition, "expanded" );
|
||||||
{
|
|
||||||
itemData.postScript = CalamaresUtils::yamlToVariant( itemDefinition[ "post-install" ] ).toString();
|
|
||||||
}
|
|
||||||
if ( itemDefinition[ "critical" ] )
|
|
||||||
{
|
|
||||||
itemData.isCritical = CalamaresUtils::yamlToVariant( itemDefinition[ "critical" ] ).toBool();
|
|
||||||
}
|
|
||||||
if ( itemDefinition[ "hidden" ] )
|
|
||||||
{
|
|
||||||
itemData.isHidden = CalamaresUtils::yamlToVariant( itemDefinition[ "hidden" ] ).toBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
PackageTreeItem* item = new PackageTreeItem( itemData, parent );
|
PackageTreeItem* item = new PackageTreeItem( itemData, parent );
|
||||||
|
|
||||||
@ -253,8 +254,6 @@ PackageModel::setupModelData( const YAML::Node& data, PackageTreeItem* parent )
|
|||||||
item->setSelected( parent->isSelected() ); // Inherit from it's parent
|
item->setSelected( parent->isSelected() ); // Inherit from it's parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( itemDefinition[ "packages" ] )
|
if ( itemDefinition[ "packages" ] )
|
||||||
for ( YAML::const_iterator packageIt = itemDefinition[ "packages" ].begin();
|
for ( YAML::const_iterator packageIt = itemDefinition[ "packages" ].begin();
|
||||||
packageIt != itemDefinition[ "packages" ].end();
|
packageIt != itemDefinition[ "packages" ].end();
|
||||||
|
Loading…
Reference in New Issue
Block a user