Skip to content
Permalink
Browse files

Move some modeler scene code to c++, avoid hard link between scene

and dialog
  • Loading branch information
nyalldawson committed Mar 3, 2020
1 parent c178276 commit 5c44441cd392689230473364f9a8d0bac71e8ce0
@@ -71,6 +71,21 @@ Returns the current combination of flags set for the scene.
.. seealso:: :py:func:`setFlags`

.. seealso:: :py:func:`setFlag`
%End

virtual void mousePressEvent( QGraphicsSceneMouseEvent *event );


signals:

void rebuildRequired();
%Docstring
Emitted when a change in the model requires a full rebuild of the scene.
%End

void componentChanged();
%Docstring
Emitted whenever a component of the model is changed.
%End

};
@@ -329,8 +329,10 @@ def __init__(self, model=None):
self.restoreState(settings.value("/Processing/stateModeler", QByteArray()))
self.restoreGeometry(settings.value("/Processing/geometryModeler", QByteArray()))

self.scene = ModelerScene(self, dialog=self)
self.scene = ModelerScene(self)
self.scene.setSceneRect(QRectF(0, 0, self.CANVAS_SIZE, self.CANVAS_SIZE))
self.scene.rebuildRequired.connect(self.repaintModel)
self.scene.componentChanged.connect(self.componentChanged)

self.view.setScene(self.scene)
self.view.setAcceptDrops(True)
@@ -781,7 +783,7 @@ def loadModel(self, filename):
'See the log for more information.'))

def repaintModel(self, controls=True):
self.scene = ModelerScene(self, dialog=self)
self.scene = ModelerScene(self)
self.scene.setSceneRect(QRectF(0, 0, self.CANVAS_SIZE,
self.CANVAS_SIZE))

@@ -790,6 +792,12 @@ def repaintModel(self, controls=True):
self.scene.paintModel(self.model)
self.view.setScene(self.scene)

self.scene.rebuildRequired.connect(self.repaintModel)
self.scene.componentChanged.connect(self.componentChanged)

def componentChanged(self):
self.hasChanged = True

def addInput(self):
item = self.inputsTree.currentItem()
param = item.data(0, Qt.UserRole)
@@ -22,7 +22,6 @@
__copyright__ = '(C) 2012, Victor Olaya'

from qgis.PyQt.QtCore import QPointF, Qt
from qgis.PyQt.QtWidgets import QGraphicsScene
from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingModelChildParameterSource,
QgsExpression)
@@ -40,31 +39,11 @@

class ModelerScene(QgsModelGraphicsScene):

def __init__(self, parent=None, dialog=None):
def __init__(self, parent=None):
super().__init__(parent)
self.paramItems = {}
self.algItems = {}
self.outputItems = {}
self.setItemIndexMethod(QGraphicsScene.NoIndex)
self.dialog = dialog

def getParameterPositions(self):
return {key: item.pos() for key, item in self.paramItems.items()}

def getAlgorithmPositions(self):
return {key: item.pos() for key, item in self.algItems.items()}

def getOutputPositions(self):
pos = {}
for algName, outputs in self.outputItems.items():
outputPos = {}
for key, value in outputs.items():
if value is not None:
outputPos[key] = value.pos()
else:
outputPos[key] = None
pos[algName] = outputPos
return pos

def getItemsFromParamValue(self, value, child_id, context):
items = []
@@ -89,12 +68,6 @@ def getItemsFromParamValue(self, value, child_id, context):
items.extend(self.getItemsFromParamValue(variables[v].source, child_id, context))
return items

def requestModelRepaint(self):
self.dialog.repaintModel()

def componentChanged(self):
self.dialog.haschanged = True

def paintModel(self, model):
self.model = model
context = createContext()
@@ -105,7 +78,7 @@ def paintModel(self, model):
item.setPos(inp.position().x(), inp.position().y())
self.paramItems[inp.parameterName()] = item

item.requestModelRepaint.connect(self.requestModelRepaint)
item.requestModelRepaint.connect(self.rebuildRequired)
item.changed.connect(self.componentChanged)

# Input dependency arrows
@@ -138,7 +111,7 @@ def paintModel(self, model):
item.setPos(alg.position().x(), alg.position().y())
self.algItems[alg.childId()] = item

item.requestModelRepaint.connect(self.requestModelRepaint)
item.requestModelRepaint.connect(self.rebuildRequired)
item.changed.connect(self.componentChanged)

# And then the arrows
@@ -172,7 +145,7 @@ def paintModel(self, model):
for key, out in outputs.items():
if out is not None:
item = ModelerOutputGraphicItem(out.clone(), model)
item.requestModelRepaint.connect(self.requestModelRepaint)
item.requestModelRepaint.connect(self.rebuildRequired)
item.changed.connect(self.componentChanged)

self.addItem(item)
@@ -197,8 +170,3 @@ def paintModel(self, model):
else:
outputItems[key] = None
self.outputItems[alg.childId()] = outputItems

def mousePressEvent(self, mouseEvent):
if mouseEvent.button() != Qt.LeftButton:
return
super(ModelerScene, self).mousePressEvent(mouseEvent)
@@ -14,13 +14,14 @@
***************************************************************************/

#include "qgsmodelgraphicsscene.h"
#include <QGraphicsSceneMouseEvent>

///@cond NOT_STABLE

QgsModelGraphicsScene::QgsModelGraphicsScene( QObject *parent )
: QGraphicsScene( parent )
{

setItemIndexMethod( QGraphicsScene::NoIndex );
}

void QgsModelGraphicsScene::setFlag( QgsModelGraphicsScene::Flag flag, bool on )
@@ -31,5 +32,12 @@ void QgsModelGraphicsScene::setFlag( QgsModelGraphicsScene::Flag flag, bool on )
mFlags &= ~flag;
}

void QgsModelGraphicsScene::mousePressEvent( QGraphicsSceneMouseEvent *event )
{
if ( event->button() != Qt::LeftButton )
return;
QGraphicsScene::mousePressEvent( event );
}

///@endcond

@@ -76,6 +76,20 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
*/
QgsModelGraphicsScene::Flags flags() const { return mFlags; }

void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;

signals:

/**
* Emitted when a change in the model requires a full rebuild of the scene.
*/
void rebuildRequired();

/**
* Emitted whenever a component of the model is changed.
*/
void componentChanged();

private:

Flags mFlags = nullptr;

0 comments on commit 5c44441

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