Skip to content
Permalink
Browse files

Move designer edit buttons to c++

  • Loading branch information
nyalldawson committed Mar 2, 2020
1 parent 8f6a611 commit 0dbb082dfdf9b49e2ec51599eeeac853f2186321
@@ -817,6 +817,8 @@
<file>themes/default/mActionAddManualTable.svg</file>
<file>themes/default/mIconModelerCollapse.svg</file>
<file>themes/default/mIconModelerExpand.svg</file>
<file>themes/default/mActionDeleteModelComponent.svg</file>
<file>themes/default/mActionEditModelComponent.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M11.023 2.707L8 5.73 4.974 2.708 2.707 4.975 5.732 8l-3.025 3.023 2.268 2.27L8 10.266l3.023 3.025 2.27-2.27L10.265 8l3.024-3.025z" fill-opacity=".059" stroke="#000" stroke-opacity=".435"/></svg>
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><circle cx="4" cy="12" r="1.5" fill-opacity=".059" stroke="#000" stroke-linecap="round" stroke-opacity=".435"/><circle cx="8" cy="12" r="1.5" fill-opacity=".059" stroke="#000" stroke-linecap="round" stroke-opacity=".435"/><circle cx="12" cy="12" r="1.5" fill-opacity=".059" stroke="#000" stroke-linecap="round" stroke-opacity=".435"/></svg>
@@ -10,7 +10,6 @@




class QgsModelComponentGraphicItem : QGraphicsObject
{
%Docstring
@@ -63,6 +62,22 @@ Emitted by the item to request a repaint of the parent model scene.
%Docstring
Emitted when the definition of the associated component is changed
by the item.
%End

protected slots:

virtual void editComponent();
%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

};
@@ -35,7 +35,6 @@
from qgis.gui import (
QgsProcessingParameterDefinitionDialog,
QgsProcessingParameterWidgetContext,
QgsModelDesignerFlatButtonGraphicItem,
QgsModelDesignerFoldButtonGraphicItem,
QgsModelComponentGraphicItem
)
@@ -50,7 +49,6 @@
class ModelerGraphicItem(QgsModelComponentGraphicItem):

BUTTON_WIDTH = 16
BUTTON_HEIGHT = 16

repaintArrows = pyqtSignal()
updateArrowPaths = pyqtSignal()
@@ -63,29 +61,6 @@ def __init__(self, element, model):
self.picture = None
self.hover_over_item = False

svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'edit.svg'))
picture = QPicture()
painter = QPainter(picture)
svg.render(painter)
painter.end()
pt = QPointF(self.component().size().width() / 2 -
ModelerGraphicItem.BUTTON_WIDTH / 2,
self.component().size().height() / 2 -
ModelerGraphicItem.BUTTON_HEIGHT / 2)
self.editButton = QgsModelDesignerFlatButtonGraphicItem(self, picture, pt)
self.editButton.clicked.connect(self.editComponent)
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'delete.svg'))
picture = QPicture()
painter = QPainter(picture)
svg.render(painter)
painter.end()
pt = QPointF(self.component().size().width() / 2 -
ModelerGraphicItem.BUTTON_WIDTH / 2,
ModelerGraphicItem.BUTTON_HEIGHT / 2 -
self.component().size().height() / 2)
self.deleteButton = QgsModelDesignerFlatButtonGraphicItem(self, picture, pt)
self.deleteButton.clicked.connect(self.removeComponent)

def boundingRect(self):
fm = QFontMetricsF(self.item_font)
unfolded = isinstance(self.component(),
@@ -326,7 +301,7 @@ def editComponent(self):
self.text = new_param.description()
self.requestModelRepaint.emit()

def removeComponent(self):
def deleteComponent(self):
if self.model().childAlgorithmsDependOnParameter(self.component().parameterName()):
QMessageBox.warning(None, 'Could not remove input',
'Algorithms depend on the selected input.\n'
@@ -343,7 +318,7 @@ def removeComponent(self):
def contextMenuEvent(self, event):
popupmenu = QMenu()
removeAction = popupmenu.addAction('Remove')
removeAction.triggered.connect(self.removeComponent)
removeAction.triggered.connect(self.deleteComponent)
editAction = popupmenu.addAction('Edit')
editAction.triggered.connect(self.editComponent)
popupmenu.exec_(event.screenPos())
@@ -422,7 +397,7 @@ def updateAlgorithm(self, alg):
(i + 1.5) * self.component().size().height()))
self.model().setChildAlgorithm(alg)

def removeComponent(self):
def deleteComponent(self):
if not self.model().removeChildAlgorithm(self.component().childId()):
QMessageBox.warning(None, 'Could not remove element',
'Other elements depend on the selected one.\n'
@@ -434,7 +409,7 @@ def removeComponent(self):
def contextMenuEvent(self, event):
popupmenu = QMenu()
removeAction = popupmenu.addAction('Remove')
removeAction.triggered.connect(self.removeComponent)
removeAction.triggered.connect(self.deleteComponent)
editAction = popupmenu.addAction('Edit')
editAction.triggered.connect(self.editComponent)

@@ -485,7 +460,7 @@ def editComponent(self):
model_output.setMandatory(not (dlg.param.flags() & QgsProcessingParameterDefinition.FlagOptional))
self.model().updateDestinationParameters()

def removeComponent(self):
def deleteComponent(self):
self.model().childAlgorithm(self.component().childId()).removeModelOutput(self.component().name())
self.model().updateDestinationParameters()
self.changed.emit()
@@ -19,6 +19,11 @@
#include "qgsprocessingmodelchildalgorithm.h"
#include "qgsprocessingmodeloutput.h"
#include "qgsmodelgraphicsscene.h"
#include "qgsapplication.h"
#include "qgsmodelgraphicitem.h"
#include <QSvgRenderer>
#include <QPicture>
#include <QPainter>

///@cond NOT_STABLE

@@ -32,6 +37,26 @@ QgsModelComponentGraphicItem::QgsModelComponentGraphicItem( QgsProcessingModelCo
setFlag( QGraphicsItem::ItemIsSelectable, true );
setFlag( QGraphicsItem::ItemSendsGeometryChanges, true );
setZValue( QgsModelGraphicsScene::ZValues::ModelComponent );

QSvgRenderer svg( QgsApplication::iconPath( QStringLiteral( "mActionEditModelComponent.svg" ) ) );
QPicture editPicture;
QPainter painter( &editPicture );
svg.render( &painter );
painter.end();
mEditButton = new QgsModelDesignerFlatButtonGraphicItem( this, editPicture,
QPointF( component->size().width() / 2.0 - mButtonSize.width() / 2.0,
component->size().height() / 2.0 - mButtonSize.height() / 2.0 ) );
connect( mEditButton, &QgsModelDesignerFlatButtonGraphicItem::clicked, this, &QgsModelComponentGraphicItem::editComponent );

QSvgRenderer svg2( QgsApplication::iconPath( QStringLiteral( "mActionDeleteModelComponent.svg" ) ) );
QPicture deletePicture;
painter.begin( &deletePicture );
svg2.render( &painter );
painter.end();
mDeleteButton = new QgsModelDesignerFlatButtonGraphicItem( this, deletePicture,
QPointF( component->size().width() / 2.0 - mButtonSize.width() / 2.0,
mButtonSize.height() / 2.0 - component->size().height() / 2.0 ) );
connect( mDeleteButton, &QgsModelDesignerFlatButtonGraphicItem::clicked, this, &QgsModelComponentGraphicItem::deleteComponent );
}

QgsProcessingModelComponent *QgsModelComponentGraphicItem::component()
@@ -25,7 +25,7 @@ class QgsProcessingModelParameter;
class QgsProcessingModelChildAlgorithm;
class QgsProcessingModelOutput;
class QgsProcessingModelAlgorithm;

class QgsModelDesignerFlatButtonGraphicItem;

///@cond NOT_STABLE

@@ -80,11 +80,33 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
*/
void changed();

protected slots:

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

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

private:

std::unique_ptr< QgsProcessingModelComponent > mComponent;
QgsProcessingModelAlgorithm *mModel = nullptr;

QgsModelDesignerFlatButtonGraphicItem *mEditButton = nullptr;
QgsModelDesignerFlatButtonGraphicItem *mDeleteButton = nullptr;

static constexpr double DEFAULT_BUTTON_WIDTH = 16;
static constexpr double DEFAULT_BUTTON_HEIGHT = 16;
QSizeF mButtonSize { DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT };

};

0 comments on commit 0dbb082

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