[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();
|
const QVariantList groups = gs->value( "NetinstallAdd" ).toList();
|
||||||
if ( !groups.isEmpty() )
|
if ( !groups.isEmpty() )
|
||||||
{
|
{
|
||||||
m_config->model()->appendModelData( groups, "packageChooser" );
|
m_config->model()->appendModelData( groups );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,17 @@
|
|||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
#include "utils/Yaml.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
|
static void
|
||||||
setSelections2( const QStringList& selectNames, PackageTreeItem* item )
|
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 )
|
PackageModel::PackageModel( QObject* parent )
|
||||||
: QAbstractItemModel( parent )
|
: QAbstractItemModel( parent )
|
||||||
{
|
{
|
||||||
@ -334,19 +367,24 @@ PackageModel::setupModelData( const QVariantList& l )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageModel::appendModelData( const QVariantList& groupList, const QString& source )
|
PackageModel::appendModelData( const QVariantList& groupList )
|
||||||
{
|
{
|
||||||
if ( m_rootItem )
|
if ( m_rootItem )
|
||||||
{
|
{
|
||||||
Q_EMIT beginResetModel();
|
Q_EMIT beginResetModel();
|
||||||
|
|
||||||
// Prune any existing data from the same source
|
const QStringList sources = collectSources( groupList );
|
||||||
for ( int i = 0; i < m_rootItem->childCount(); i++ )
|
|
||||||
|
if ( !sources.isEmpty() )
|
||||||
{
|
{
|
||||||
PackageTreeItem* child = m_rootItem->child( i );
|
// Prune any existing data from the same source
|
||||||
if ( child->source() == source )
|
for ( int i = 0; i < m_rootItem->childCount(); i++ )
|
||||||
{
|
{
|
||||||
m_rootItem->removeChild( i );
|
PackageTreeItem* child = m_rootItem->child( i );
|
||||||
|
if ( sources.contains( child->source() ) )
|
||||||
|
{
|
||||||
|
m_rootItem->removeChild( i );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,18 +68,7 @@ public:
|
|||||||
PackageTreeItem::List getPackages() const;
|
PackageTreeItem::List getPackages() const;
|
||||||
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
|
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
|
||||||
|
|
||||||
/** @brief Appends groups to the tree
|
void appendModelData(const QVariantList& groupList);
|
||||||
*
|
|
||||||
* 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 );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ItemTests;
|
friend class ItemTests;
|
||||||
|
@ -140,14 +140,14 @@ QVariantList
|
|||||||
PackageListModel::getNetinstallDataForNames( const QStringList& ids ) const
|
PackageListModel::getNetinstallDataForNames( const QStringList& ids ) const
|
||||||
{
|
{
|
||||||
QVariantList l;
|
QVariantList l;
|
||||||
for ( auto &p : m_packages )
|
for ( auto& p : m_packages )
|
||||||
{
|
{
|
||||||
if ( ids.contains( p.id ) )
|
if ( ids.contains( p.id ) )
|
||||||
{
|
{
|
||||||
if ( !p.netinstallData.isEmpty() )
|
if ( !p.netinstallData.isEmpty() )
|
||||||
{
|
{
|
||||||
QVariantMap newData = p.netinstallData;
|
QVariantMap newData = p.netinstallData;
|
||||||
newData["source"] = "packageChooser";
|
newData[ "source" ] = QStringLiteral( "packageChooser" );
|
||||||
l.append( newData );
|
l.append( newData );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user