[netinstall] Refactor variant-from-ItemData

This commit is contained in:
Adriaan de Groot 2020-02-18 11:40:43 +01:00
parent d5675508fa
commit 056b0d7548
3 changed files with 29 additions and 15 deletions

View File

@ -111,7 +111,6 @@ NetInstallViewStep::onActivate()
m_widget->onActivate();
}
void
NetInstallViewStep::onLeave()
{
@ -131,26 +130,15 @@ NetInstallViewStep::onLeave()
QVariantList installPackages;
QVariantList tryInstallPackages;
for ( auto package : packages )
for ( const auto& package : packages )
{
QVariant details( package.packageName );
// If it's a package with a pre- or post-script, replace
// with the more complicated datastructure.
if ( !package.preScript.isEmpty() || !package.postScript.isEmpty() )
{
QMap< QString, QVariant > sdetails;
sdetails.insert( "pre-script", package.preScript );
sdetails.insert( "package", package.packageName );
sdetails.insert( "post-script", package.postScript );
details = sdetails;
}
if ( package.isCritical )
{
installPackages.append( details );
installPackages.append( package.toOperation() );
}
else
{
tryInstallPackages.append( details );
tryInstallPackages.append( package.toOperation() );
}
}

View File

@ -21,6 +21,25 @@
#include "utils/Logger.h"
QVariant
PackageTreeItem::ItemData::toOperation() const
{
// If it's a package with a pre- or post-script, replace
// with the more complicated datastructure.
if ( !preScript.isEmpty() || !postScript.isEmpty() )
{
QMap< QString, QVariant > sdetails;
sdetails.insert( "pre-script", preScript );
sdetails.insert( "package", packageName );
sdetails.insert( "post-script", postScript );
return sdetails;
}
else
{
return packageName;
}
}
PackageTreeItem::PackageTreeItem( const ItemData& data, PackageTreeItem* parent )
: m_parentItem( parent )
, m_data( data )

View File

@ -37,6 +37,13 @@ public:
bool isCritical = false;
bool isHidden = false;
Qt::CheckState selected = Qt::Unchecked;
/** @brief Turns this item into a variant for PackageOperations use
*
* For "plain" items, this is just the package name; items with
* scripts return a map. See the package module for how it's interpreted.
*/
QVariant toOperation() const;
};
explicit PackageTreeItem( const ItemData& data, PackageTreeItem* parent = nullptr );
explicit PackageTreeItem( const QString packageName, PackageTreeItem* parent = nullptr );