Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE][processing] Add action to model designer to delete all sele…
…cted components
  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent 3c2d318 commit 1e67ee4
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 33 deletions.
Expand Up @@ -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

Expand Down Expand Up @@ -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

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

virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent *event );

virtual bool canDeleteComponent();


protected:

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

virtual bool canDeleteComponent();


protected:

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
62 changes: 57 additions & 5 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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() ) )
Expand Down Expand Up @@ -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();
Expand All @@ -737,7 +757,7 @@ QgsModelChildAlgorithmGraphicItem::QgsModelChildAlgorithmGraphicItem( QgsProcess
svg.render( &painter );
painter.end();
}
else
else if ( child->algorithm() )
{
mPixmap = child->algorithm()->icon().pixmap( 15, 15 );
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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() ) )
Expand Down Expand Up @@ -941,7 +976,6 @@ QgsModelOutputGraphicItem::QgsModelOutputGraphicItem( QgsProcessingModelOutput *
setLabel( output->name() );
}


QColor QgsModelOutputGraphicItem::fillColor( QgsModelComponentGraphicItem::State state ) const
{
QColor c( 172, 196, 114 );
Expand Down Expand Up @@ -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() ) )
Expand Down Expand Up @@ -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() )
Expand Down
24 changes: 17 additions & 7 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.h
Expand Up @@ -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!
Expand Down Expand Up @@ -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:

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

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

protected:

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1e67ee4

Please sign in to comment.