Skip to content
Permalink
Browse files

Less Python, more c++

  • Loading branch information
nyalldawson committed Mar 2, 2020
1 parent 72d7305 commit 167a8d3846cfa575bb5bfef7342f898ebb3dde33
@@ -27,6 +27,12 @@ QGraphicsScene subclass representing the model designer.
%End
public:

enum ZValues
{
ArrowLink,
ModelComponent,
};

QgsModelGraphicsScene( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsModelGraphicsScene with the specified ``parent`` object.
@@ -46,9 +46,9 @@
***************************************************************************
"""

from qgis.core import (QgsProcessingModelAlgorithm,
QgsProcessingModelChildAlgorithm,
from qgis.core import (QgsProcessingModelChildAlgorithm,
QgsProcessingModelParameter)
from qgis.gui import QgsModelGraphicsScene
from qgis.PyQt.QtCore import Qt, QPointF
from qgis.PyQt.QtWidgets import QApplication, QGraphicsPathItem, QGraphicsItem
from qgis.PyQt.QtGui import QPen, QPainterPath, QPolygonF, QPainter, QPalette
@@ -71,7 +71,7 @@ def __init__(self, startItem, startIndex, endItem, endIndex,
self.myColor.setAlpha(150)
self.setPen(QPen(self.myColor, 1, Qt.SolidLine,
Qt.RoundCap, Qt.RoundJoin))
self.setZValue(0)
self.setZValue(QgsModelGraphicsScene.ArrowLink)

def setPenStyle(self, style):
pen = self.pen()
@@ -23,17 +23,15 @@
__copyright__ = '(C) 2012, Victor Olaya'

import os
import math

from qgis.PyQt.QtCore import Qt, QPointF, QRectF
from qgis.PyQt.QtGui import QFont, QFontMetricsF, QPen, QBrush, QColor, QPolygonF, QPicture, QPainter, QPalette
from qgis.PyQt.QtGui import QFont, QFontMetricsF, QPen, QBrush, QColor, QPicture, QPainter, QPalette
from qgis.PyQt.QtWidgets import QApplication, QGraphicsItem, QMessageBox, QMenu
from qgis.PyQt.QtSvg import QSvgRenderer
from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingModelParameter,
QgsProcessingModelOutput,
QgsProcessingModelChildAlgorithm,
QgsProcessingModelAlgorithm,
QgsProject)
from qgis.gui import (
QgsProcessingParameterDefinitionDialog,
@@ -60,7 +58,6 @@ class ModelerGraphicItem(QgsModelComponentGraphicItem):

def __init__(self, element, model, controls, scene=None):
super().__init__(element, None)
self.setAcceptHoverEvents(True)
self.controls = controls
self.model = model
self.scene = scene
@@ -104,32 +101,28 @@ def __init__(self, element, model, controls, scene=None):
self.pixmap = element.algorithm().icon().pixmap(15, 15)
self.text = element.description()
self.arrows = []
self.setFlag(QGraphicsItem.ItemIsMovable, True)
self.setFlag(QGraphicsItem.ItemIsSelectable, True)
self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
self.setZValue(1000)

if controls:
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'edit.svg'))
picture = QPicture()
painter = QPainter(picture)
svg.render(painter)
painter.end()
pt = QPointF(self.box_width / 2
- ModelerGraphicItem.BUTTON_WIDTH / 2,
self.box_height / 2
- ModelerGraphicItem.BUTTON_HEIGHT / 2)
pt = QPointF(self.box_width / 2 -
ModelerGraphicItem.BUTTON_WIDTH / 2,
self.box_height / 2 -
ModelerGraphicItem.BUTTON_HEIGHT / 2)
self.editButton = QgsModelDesignerFlatButtonGraphicItem(self, picture, pt)
self.editButton.clicked.connect(self.editElement)
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'delete.svg'))
picture = QPicture()
painter = QPainter(picture)
svg.render(painter)
painter.end()
pt = QPointF(self.box_width / 2
- ModelerGraphicItem.BUTTON_WIDTH / 2,
ModelerGraphicItem.BUTTON_HEIGHT / 2
- self.box_height / 2)
pt = QPointF(self.box_width / 2 -
ModelerGraphicItem.BUTTON_WIDTH / 2,
ModelerGraphicItem.BUTTON_HEIGHT / 2 -
self.box_height / 2)
self.deleteButton = QgsModelDesignerFlatButtonGraphicItem(self, picture, pt)
self.deleteButton.clicked.connect(self.removeElement)

@@ -312,8 +305,8 @@ def updateAlgorithm(self, alg):
alg.setParametersCollapsed(existing_child.parametersCollapsed())
alg.setOutputsCollapsed(existing_child.outputsCollapsed())
for i, out in enumerate(alg.modelOutputs().keys()):
alg.modelOutput(out).setPosition(alg.modelOutput(out).position()
or alg.position() + QPointF(
alg.modelOutput(out).setPosition(alg.modelOutput(out).position() or
alg.position() + QPointF(
self.box_width,
(i + 1.5) * self.box_height))
self.model.setChildAlgorithm(alg)
@@ -485,21 +478,3 @@ def itemChange(self, change, value):
self.repaintArrows()

return super().itemChange(change, value)

def polygon(self):
fm = QFontMetricsF(self.item_font)
hUp = fm.height() * 1.2 * (len(self.component().parameters) + 2)
hDown = fm.height() * 1.2 * (len(self.component().outputs) + 2)
pol = QPolygonF([
QPointF(-(self.box_width + 2) / 2,
-(self.box_height + 2) / 2 - hUp),
QPointF(-(self.box_width + 2) / 2,
(self.box_height + 2) / 2 + hDown),
QPointF((self.box_width + 2) / 2,
(self.box_height + 2) / 2 + hDown),
QPointF((self.box_width + 2) / 2,
-(self.box_height + 2) / 2 - hUp),
QPointF(-(self.box_width + 2) / 2,
-(self.box_height + 2) / 2 - hUp)
])
return pol
@@ -15,14 +15,19 @@

#include "qgsmodelcomponentgraphicitem.h"
#include "qgsprocessingmodelcomponent.h"
#include "qgsmodelgraphicsscene.h"

///@cond NOT_STABLE

QgsModelComponentGraphicItem::QgsModelComponentGraphicItem( QgsProcessingModelComponent *component, QGraphicsItem *parent )
: QGraphicsObject( parent )
, mComponent( component )
{

setAcceptHoverEvents( true );
setFlag( QGraphicsItem::ItemIsMovable, true );
setFlag( QGraphicsItem::ItemIsSelectable, true );
setFlag( QGraphicsItem::ItemSendsGeometryChanges, true );
setZValue( QgsModelGraphicsScene::ZValues::ModelComponent );
}

QgsProcessingModelComponent *QgsModelComponentGraphicItem::component()
@@ -35,6 +35,13 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene

public:

//! Z values for scene items
enum ZValues
{
ArrowLink = 0, //!< An arrow linking model items
ModelComponent = 1, //!< Model components (e.g. algorithms, inputs and outputs)
};

/**
* Constructor for QgsModelGraphicsScene with the specified \a parent object.
*/

0 comments on commit 167a8d3

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