Skip to content
Permalink
Browse files

[FEATURE][processing] Add action to model designer to delete all sele…

…cted components
  • Loading branch information
nyalldawson committed Mar 11, 2020
1 parent 3c2d318 commit 1e67ee42fa95d7ea3078f346f28a5d29b77c2177
@@ -191,6 +191,18 @@ Returns the best link point to use for a link originating at a specified ``other
%Docstring
Called when the comment attached to the item should be edited.

The default implementation does nothing.
%End

virtual bool canDeleteComponent();
%Docstring
Returns ``True`` if the component can be deleted.
%End

virtual void deleteComponent();
%Docstring
Called when the component should be deleted.

The default implementation does nothing.
%End

@@ -233,13 +245,6 @@ Emitted when item requires that all connected arrow paths are recalculated.
%Docstring
Called when the component should be edited.

The default implementation does nothing.
%End

virtual void deleteComponent();
%Docstring
Called when the component should be deleted.

The default implementation does nothing.
%End

@@ -326,6 +331,8 @@ Ownership of ``parameter`` is transferred to the item.

virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent *event );

virtual bool canDeleteComponent();


protected:

@@ -377,6 +384,8 @@ Ownership of ``child`` is transferred to the item.
%End
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent *event );

virtual bool canDeleteComponent();


protected:

@@ -435,6 +444,9 @@ it must exist for the lifetime of this object.
Ownership of ``output`` is transferred to the item.
%End

virtual bool canDeleteComponent();


protected:

virtual QColor fillColor( State state ) const;
@@ -489,6 +501,8 @@ Ownership of ``output`` is transferred to the item.
~QgsModelCommentGraphicItem();
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent *event );

virtual bool canDeleteComponent();

protected:

virtual QColor fillColor( State state ) const;
@@ -405,8 +405,8 @@ QPixmap QgsModelComponentGraphicItem::iconPixmap() const
void QgsModelComponentGraphicItem::updateButtonPositions()
{
mEditButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - 2,
itemSize().height() / 2.0 - mButtonSize.height() / 2.0 - 2 ) );
mDeleteButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - 2,
itemSize().height() / 2.0 - mButtonSize.height() / 2.0 - 2 ) );
mDeleteButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - 2,
mButtonSize.height() / 2.0 - itemSize().height() / 2.0 + 2 ) );

if ( mExpandTopButton )
@@ -697,6 +697,26 @@ void QgsModelParameterGraphicItem::updateStoredComponentPosition( const QPointF
}
}

bool QgsModelParameterGraphicItem::canDeleteComponent()
{
if ( const QgsProcessingModelParameter *param = dynamic_cast< const QgsProcessingModelParameter * >( component() ) )
{
if ( model()->childAlgorithmsDependOnParameter( param->parameterName() ) )
{
return false;
}
else if ( model()->otherParametersDependOnParameter( param->parameterName() ) )
{
return false;
}
else
{
return true;
}
}
return false;
}

void QgsModelParameterGraphicItem::deleteComponent()
{
if ( const QgsProcessingModelParameter *param = dynamic_cast< const QgsProcessingModelParameter * >( component() ) )
@@ -728,7 +748,7 @@ void QgsModelParameterGraphicItem::deleteComponent()
QgsModelChildAlgorithmGraphicItem::QgsModelChildAlgorithmGraphicItem( QgsProcessingModelChildAlgorithm *child, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent )
: QgsModelComponentGraphicItem( child, model, parent )
{
if ( !child->algorithm()->svgIconPath().isEmpty() )
if ( child->algorithm() && !child->algorithm()->svgIconPath().isEmpty() )
{
QSvgRenderer svg( child->algorithm()->svgIconPath() );
const QSizeF size = svg.defaultSize();
@@ -737,7 +757,7 @@ QgsModelChildAlgorithmGraphicItem::QgsModelChildAlgorithmGraphicItem( QgsProcess
svg.render( &painter );
painter.end();
}
else
else if ( child->algorithm() )
{
mPixmap = child->algorithm()->icon().pixmap( 15, 15 );
}
@@ -823,6 +843,9 @@ int QgsModelChildAlgorithmGraphicItem::linkPointCount( Qt::Edge edge ) const
{
if ( const QgsProcessingModelChildAlgorithm *child = dynamic_cast< const QgsProcessingModelChildAlgorithm * >( component() ) )
{
if ( !child->algorithm() )
return 0;

switch ( edge )
{
case Qt::BottomEdge:
@@ -852,6 +875,9 @@ QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int ind

if ( const QgsProcessingModelChildAlgorithm *child = dynamic_cast< const QgsProcessingModelChildAlgorithm * >( component() ) )
{
if ( !child->algorithm() )
return 0;

switch ( edge )
{
case Qt::BottomEdge:
@@ -885,6 +911,15 @@ void QgsModelChildAlgorithmGraphicItem::updateStoredComponentPosition( const QPo
}
}

bool QgsModelChildAlgorithmGraphicItem::canDeleteComponent()
{
if ( const QgsProcessingModelChildAlgorithm *child = dynamic_cast< const QgsProcessingModelChildAlgorithm * >( component() ) )
{
return model()->dependentChildAlgorithms( child->childId() ).empty();
}
return false;
}

void QgsModelChildAlgorithmGraphicItem::deleteComponent()
{
if ( const QgsProcessingModelChildAlgorithm *child = dynamic_cast< const QgsProcessingModelChildAlgorithm * >( component() ) )
@@ -941,7 +976,6 @@ QgsModelOutputGraphicItem::QgsModelOutputGraphicItem( QgsProcessingModelOutput *
setLabel( output->name() );
}


QColor QgsModelOutputGraphicItem::fillColor( QgsModelComponentGraphicItem::State state ) const
{
QColor c( 172, 196, 114 );
@@ -992,6 +1026,15 @@ void QgsModelOutputGraphicItem::updateStoredComponentPosition( const QPointF &po
}
}

bool QgsModelOutputGraphicItem::canDeleteComponent()
{
if ( dynamic_cast< const QgsProcessingModelOutput * >( component() ) )
{
return true;
}
return false;
}

void QgsModelOutputGraphicItem::deleteComponent()
{
if ( const QgsProcessingModelOutput *output = dynamic_cast< const QgsProcessingModelOutput * >( component() ) )
@@ -1081,6 +1124,15 @@ void QgsModelCommentGraphicItem::updateStoredComponentPosition( const QPointF &p
}
}

bool QgsModelCommentGraphicItem::canDeleteComponent()
{
if ( modelComponent() )
{
return true;
}
return false;
}

void QgsModelCommentGraphicItem::deleteComponent()
{
if ( QgsProcessingModelComment *comment = modelComponent() )
@@ -229,6 +229,18 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
*/
virtual void editComment() {}

/**
* Returns TRUE if the component can be deleted.
*/
virtual bool canDeleteComponent() { return false; }

/**
* Called when the component should be deleted.
*
* The default implementation does nothing.
*/
virtual void deleteComponent() {}

signals:

// TODO - rework this, should be triggered externally when the model actually changes!
@@ -272,13 +284,6 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
*/
virtual void editComponent() {}

/**
* Called when the component should be deleted.
*
* The default implementation does nothing.
*/
virtual void deleteComponent() {}

protected:

/**
@@ -385,6 +390,7 @@ class GUI_EXPORT QgsModelParameterGraphicItem : public QgsModelComponentGraphicI
QGraphicsItem *parent SIP_TRANSFERTHIS );

void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
bool canDeleteComponent() override;

protected:

@@ -427,6 +433,7 @@ class GUI_EXPORT QgsModelChildAlgorithmGraphicItem : public QgsModelComponentGra
QgsProcessingModelAlgorithm *model,
QGraphicsItem *parent SIP_TRANSFERTHIS );
void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
bool canDeleteComponent() override;

protected:

@@ -478,6 +485,8 @@ class GUI_EXPORT QgsModelOutputGraphicItem : public QgsModelComponentGraphicItem
QgsProcessingModelAlgorithm *model,
QGraphicsItem *parent SIP_TRANSFERTHIS );

bool canDeleteComponent() override;

protected:

QColor fillColor( State state ) const override;
@@ -523,6 +532,7 @@ class GUI_EXPORT QgsModelCommentGraphicItem : public QgsModelComponentGraphicIte
QGraphicsItem *parent SIP_TRANSFERTHIS );
~QgsModelCommentGraphicItem() override;
void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
bool canDeleteComponent() override;
protected:

QColor fillColor( State state ) const override;

0 comments on commit 1e67ee4

Please sign in to comment.
You can’t perform that action at this time.