[packagechooser,netinstall] Proper implementation of source field
This commit is contained in:
parent
1db217931b
commit
22c9d888b4
@ -76,6 +76,6 @@ NetInstallPage::onActivate()
|
||||
const QVariantList groups = gs->value( "NetinstallAdd" ).toList();
|
||||
if ( !groups.isEmpty() )
|
||||
{
|
||||
m_config->model()->appendModelData( groups, "packageChooser" );
|
||||
m_config->model()->appendModelData( groups );
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,17 @@
|
||||
#include "utils/Variant.h"
|
||||
#include "utils/Yaml.h"
|
||||
|
||||
/** @brief Appends groups to the tree
|
||||
*
|
||||
* Uses the data from @p groupList to add elements to the
|
||||
* existing tree that m_rootItem points to. If m_rootItem
|
||||
* is not valid, it does nothing
|
||||
*
|
||||
* Before adding anything to the model, it ensures that there
|
||||
* is no existing data from the same source. If there is, that
|
||||
* data is pruned first
|
||||
*
|
||||
*/
|
||||
static void
|
||||
setSelections2( const QStringList& selectNames, PackageTreeItem* item )
|
||||
{
|
||||
@ -28,6 +39,28 @@ setSelections2( const QStringList& selectNames, PackageTreeItem* item )
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Collects all the "source" values from @p groupList
|
||||
*
|
||||
* Iterates over @p groupList and returns all nonempty "source"
|
||||
* values from the maps.
|
||||
*
|
||||
*/
|
||||
static QStringList
|
||||
collectSources( const QVariantList& groupList )
|
||||
{
|
||||
QStringList sources;
|
||||
for ( const QVariant& group : groupList )
|
||||
{
|
||||
QVariantMap groupMap = group.toMap();
|
||||
if ( !groupMap[ "source" ].toString().isEmpty() )
|
||||
{
|
||||
sources.append( groupMap[ "source" ].toString() );
|
||||
}
|
||||
}
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
PackageModel::PackageModel( QObject* parent )
|
||||
: QAbstractItemModel( parent )
|
||||
{
|
||||
@ -334,21 +367,26 @@ PackageModel::setupModelData( const QVariantList& l )
|
||||
}
|
||||
|
||||
void
|
||||
PackageModel::appendModelData( const QVariantList& groupList, const QString& source )
|
||||
PackageModel::appendModelData( const QVariantList& groupList )
|
||||
{
|
||||
if ( m_rootItem )
|
||||
{
|
||||
Q_EMIT beginResetModel();
|
||||
|
||||
const QStringList sources = collectSources( groupList );
|
||||
|
||||
if ( !sources.isEmpty() )
|
||||
{
|
||||
// Prune any existing data from the same source
|
||||
for ( int i = 0; i < m_rootItem->childCount(); i++ )
|
||||
{
|
||||
PackageTreeItem* child = m_rootItem->child( i );
|
||||
if ( child->source() == source )
|
||||
if ( sources.contains( child->source() ) )
|
||||
{
|
||||
m_rootItem->removeChild( i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the new data to the model
|
||||
setupModelData( groupList, m_rootItem );
|
||||
|
@ -68,18 +68,7 @@ public:
|
||||
PackageTreeItem::List getPackages() const;
|
||||
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
|
||||
|
||||
/** @brief Appends groups to the tree
|
||||
*
|
||||
* Uses the data from @p groupList to add elements to the
|
||||
* existing tree that m_rootItem points to. If m_rootItem
|
||||
* is not valid, it does nothing
|
||||
*
|
||||
* Before adding anything to the model, it ensures that there
|
||||
* is no existing data from the same source. If there is, that
|
||||
* data is pruned first
|
||||
*
|
||||
*/
|
||||
void appendModelData(const QVariantList& groupList, const QString &source );
|
||||
void appendModelData(const QVariantList& groupList);
|
||||
|
||||
private:
|
||||
friend class ItemTests;
|
||||
|
@ -140,14 +140,14 @@ QVariantList
|
||||
PackageListModel::getNetinstallDataForNames( const QStringList& ids ) const
|
||||
{
|
||||
QVariantList l;
|
||||
for ( auto &p : m_packages )
|
||||
for ( auto& p : m_packages )
|
||||
{
|
||||
if ( ids.contains( p.id ) )
|
||||
{
|
||||
if ( !p.netinstallData.isEmpty() )
|
||||
{
|
||||
QVariantMap newData = p.netinstallData;
|
||||
newData["source"] = "packageChooser";
|
||||
newData[ "source" ] = QStringLiteral( "packageChooser" );
|
||||
l.append( newData );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user