mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Tweak model component clipboard logic -- only copy comments and outputs
connected to algorithms when they have been explicitly selected by the user
This commit is contained in:
parent
47f96e2466
commit
d24ae53e0f
@ -520,6 +520,12 @@ Ownership of ``output`` is transferred to the item.
|
|||||||
|
|
||||||
virtual bool canDeleteComponent();
|
virtual bool canDeleteComponent();
|
||||||
|
|
||||||
|
|
||||||
|
QgsModelComponentGraphicItem *parentComponentItem() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the parent model component item.
|
||||||
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual QColor fillColor( State state ) const;
|
virtual QColor fillColor( State state ) const;
|
||||||
|
|||||||
@ -1421,5 +1421,10 @@ QgsProcessingModelComment *QgsModelCommentGraphicItem::modelComponent()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsModelComponentGraphicItem *QgsModelCommentGraphicItem::parentComponentItem() const
|
||||||
|
{
|
||||||
|
return mParentItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///@endcond
|
///@endcond
|
||||||
|
|||||||
@ -568,6 +568,12 @@ class GUI_EXPORT QgsModelCommentGraphicItem : public QgsModelComponentGraphicIte
|
|||||||
~QgsModelCommentGraphicItem() override;
|
~QgsModelCommentGraphicItem() override;
|
||||||
void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
|
void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
|
||||||
bool canDeleteComponent() override;
|
bool canDeleteComponent() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the parent model component item.
|
||||||
|
*/
|
||||||
|
QgsModelComponentGraphicItem *parentComponentItem() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
QColor fillColor( State state ) const override;
|
QColor fillColor( State state ) const override;
|
||||||
|
|||||||
@ -486,13 +486,42 @@ void QgsModelGraphicsView::copyItems( const QList<QgsModelComponentGraphicItem *
|
|||||||
QList< QVariant > paramComponents;
|
QList< QVariant > paramComponents;
|
||||||
QList< QVariant > groupBoxComponents;
|
QList< QVariant > groupBoxComponents;
|
||||||
QList< QVariant > algComponents;
|
QList< QVariant > algComponents;
|
||||||
|
|
||||||
|
QList< QgsModelComponentGraphicItem * > selectedCommentParents;
|
||||||
|
QList< QgsProcessingModelOutput > selectedOutputs;
|
||||||
|
QList< QgsProcessingModelOutput > selectedOutputsComments;
|
||||||
for ( QgsModelComponentGraphicItem *item : items )
|
for ( QgsModelComponentGraphicItem *item : items )
|
||||||
{
|
{
|
||||||
if ( QgsProcessingModelParameter *param = dynamic_cast< QgsProcessingModelParameter * >( item->component() ) )
|
if ( const QgsModelCommentGraphicItem *commentItem = dynamic_cast< QgsModelCommentGraphicItem * >( item ) )
|
||||||
{
|
{
|
||||||
|
selectedCommentParents << commentItem->parentComponentItem();
|
||||||
|
if ( const QgsModelOutputGraphicItem *outputItem = dynamic_cast< QgsModelOutputGraphicItem * >( commentItem->parentComponentItem() ) )
|
||||||
|
{
|
||||||
|
selectedOutputsComments << *( static_cast< const QgsProcessingModelOutput *>( outputItem->component() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( const QgsModelOutputGraphicItem *outputItem = dynamic_cast< QgsModelOutputGraphicItem * >( item ) )
|
||||||
|
{
|
||||||
|
selectedOutputs << *( static_cast< const QgsProcessingModelOutput *>( outputItem->component() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( QgsModelComponentGraphicItem *item : items )
|
||||||
|
{
|
||||||
|
if ( const QgsProcessingModelParameter *param = dynamic_cast< QgsProcessingModelParameter * >( item->component() ) )
|
||||||
|
{
|
||||||
|
QgsProcessingModelParameter component = *param;
|
||||||
|
|
||||||
|
// was comment selected?
|
||||||
|
if ( !selectedCommentParents.contains( item ) )
|
||||||
|
{
|
||||||
|
// no, so drop comment
|
||||||
|
component.comment()->setDescription( QString() );
|
||||||
|
}
|
||||||
|
|
||||||
QVariantMap paramDef;
|
QVariantMap paramDef;
|
||||||
paramDef.insert( QStringLiteral( "component" ), param->toVariant() );
|
paramDef.insert( QStringLiteral( "component" ), component.toVariant() );
|
||||||
const QgsProcessingParameterDefinition *def = modelScene()->model()->parameterDefinition( param->parameterName() );
|
const QgsProcessingParameterDefinition *def = modelScene()->model()->parameterDefinition( component.parameterName() );
|
||||||
paramDef.insert( QStringLiteral( "definition" ), def->toVariantMap() );
|
paramDef.insert( QStringLiteral( "definition" ), def->toVariantMap() );
|
||||||
|
|
||||||
paramComponents << paramDef;
|
paramComponents << paramDef;
|
||||||
@ -501,9 +530,54 @@ void QgsModelGraphicsView::copyItems( const QList<QgsModelComponentGraphicItem *
|
|||||||
{
|
{
|
||||||
groupBoxComponents << groupBox->toVariant();
|
groupBoxComponents << groupBox->toVariant();
|
||||||
}
|
}
|
||||||
else if ( QgsProcessingModelChildAlgorithm *alg = dynamic_cast< QgsProcessingModelChildAlgorithm * >( item->component() ) )
|
else if ( const QgsProcessingModelChildAlgorithm *alg = dynamic_cast< QgsProcessingModelChildAlgorithm * >( item->component() ) )
|
||||||
{
|
{
|
||||||
algComponents << alg->toVariant();
|
QgsProcessingModelChildAlgorithm childAlg = *alg;
|
||||||
|
|
||||||
|
// was comment selected?
|
||||||
|
if ( !selectedCommentParents.contains( item ) )
|
||||||
|
{
|
||||||
|
// no, so drop comment
|
||||||
|
childAlg.comment()->setDescription( QString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't copy outputs which weren't selected either
|
||||||
|
QMap<QString, QgsProcessingModelOutput> clipboardOutputs;
|
||||||
|
const QMap<QString, QgsProcessingModelOutput> existingOutputs = childAlg.modelOutputs();
|
||||||
|
for ( auto it = existingOutputs.constBegin(); it != existingOutputs.constEnd(); ++ it )
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
for ( const QgsProcessingModelOutput &candidate : selectedOutputs )
|
||||||
|
{
|
||||||
|
if ( candidate.childId() == childAlg.childId() && candidate.name() == it.value().name() && candidate.childOutputName() == it.value().childOutputName() )
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( found )
|
||||||
|
{
|
||||||
|
// should we also copy the comment?
|
||||||
|
bool commentFound = false;
|
||||||
|
for ( const QgsProcessingModelOutput &candidate : selectedOutputsComments )
|
||||||
|
{
|
||||||
|
if ( candidate.childId() == childAlg.childId() && candidate.name() == it.value().name() && candidate.childOutputName() == it.value().childOutputName() )
|
||||||
|
{
|
||||||
|
commentFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsProcessingModelOutput output = it.value();
|
||||||
|
if ( !commentFound )
|
||||||
|
output.comment()->setDescription( QString() );
|
||||||
|
|
||||||
|
clipboardOutputs.insert( it.key(), output );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
childAlg.setModelOutputs( clipboardOutputs );
|
||||||
|
|
||||||
|
algComponents << childAlg.toVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QVariantMap components;
|
QVariantMap components;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user