Skip to content
Permalink
Browse files

[processing] Start re-working model designer to use view tools

Based heavily on the layout designer approach, which is working well..
  • Loading branch information
nyalldawson committed Mar 10, 2020
1 parent 174e00a commit bb82c12791fd0a702bf55521f53c7c7784ae2343
Showing with 2,253 additions and 32 deletions.
  1. +5 −0 python/gui/auto_generated/processing/models/qgsmodelcomponentgraphicitem.sip.in
  2. +6 −0 python/gui/auto_generated/processing/models/qgsmodelgraphicitem.sip.in
  3. +1 −0 python/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in
  4. +54 −2 python/gui/auto_generated/processing/models/qgsmodelgraphicsview.sip.in
  5. +16 −0 src/gui/CMakeLists.txt
  6. +22 −8 src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
  7. +6 −0 src/gui/processing/models/qgsmodelcomponentgraphicitem.h
  8. +8 −0 src/gui/processing/models/qgsmodeldesignerdialog.cpp
  9. +2 −0 src/gui/processing/models/qgsmodeldesignerdialog.h
  10. +13 −2 src/gui/processing/models/qgsmodelgraphicitem.cpp
  11. +7 −0 src/gui/processing/models/qgsmodelgraphicitem.h
  12. +1 −0 src/gui/processing/models/qgsmodelgraphicsscene.h
  13. +267 −18 src/gui/processing/models/qgsmodelgraphicsview.cpp
  14. +68 −2 src/gui/processing/models/qgsmodelgraphicsview.h
  15. +29 −0 src/gui/processing/models/qgsmodelviewmouseevent.cpp
  16. +62 −0 src/gui/processing/models/qgsmodelviewmouseevent.h
  17. +188 −0 src/gui/processing/models/qgsmodelviewrubberband.cpp
  18. +180 −0 src/gui/processing/models/qgsmodelviewrubberband.h
  19. +135 −0 src/gui/processing/models/qgsmodelviewtool.cpp
  20. +221 −0 src/gui/processing/models/qgsmodelviewtool.h
  21. +298 −0 src/gui/processing/models/qgsmodelviewtoolselect.cpp
  22. +80 −0 src/gui/processing/models/qgsmodelviewtoolselect.h
  23. +47 −0 src/gui/processing/models/qgsmodelviewtooltemporarykeypan.cpp
  24. +52 −0 src/gui/processing/models/qgsmodelviewtooltemporarykeypan.h
  25. +113 −0 src/gui/processing/models/qgsmodelviewtooltemporarykeyzoom.cpp
  26. +58 −0 src/gui/processing/models/qgsmodelviewtooltemporarykeyzoom.h
  27. +47 −0 src/gui/processing/models/qgsmodelviewtooltemporarymousepan.cpp
  28. +53 −0 src/gui/processing/models/qgsmodelviewtooltemporarymousepan.h
  29. +144 −0 src/gui/processing/models/qgsmodelviewtoolzoom.cpp
  30. +70 −0 src/gui/processing/models/qgsmodelviewtoolzoom.h
@@ -69,6 +69,11 @@ Returns the model component associated with this item.
QgsProcessingModelAlgorithm *model();
%Docstring
Returns the model associated with this item.
%End

QgsModelGraphicsView *view();
%Docstring
Returns the associated view.
%End

QFont font() const;
@@ -10,6 +10,7 @@




class QgsModelDesignerFlatButtonGraphicItem : QGraphicsObject
{
%Docstring
@@ -47,6 +48,11 @@ for the button. The button will be rendered at the specified ``position`` and ``
virtual void mousePressEvent( QGraphicsSceneMouseEvent *event );


QgsModelGraphicsView *view();
%Docstring
Returns the associated model view.
%End

signals:

void clicked();
@@ -31,6 +31,7 @@ QGraphicsScene subclass representing the model designer.
{
ArrowLink,
ModelComponent,
RubberBand,
};

enum Flag
@@ -9,6 +9,7 @@




class QgsModelGraphicsView : QGraphicsView
{
%Docstring
@@ -30,6 +31,7 @@ QGraphicsView subclass representing the model designer.
%Docstring
Constructor for QgsModelGraphicsView, with the specified ``parent`` widget.
%End
~QgsModelGraphicsView();

virtual void dragEnterEvent( QDragEnterEvent *event );

@@ -39,12 +41,43 @@ Constructor for QgsModelGraphicsView, with the specified ``parent`` widget.

virtual void wheelEvent( QWheelEvent *event );

virtual void enterEvent( QEvent *event );

virtual void mousePressEvent( QMouseEvent *event );

virtual void mouseReleaseEvent( QMouseEvent *event );

virtual void mouseMoveEvent( QMouseEvent *event );

virtual void mouseDoubleClickEvent( QMouseEvent *event );

virtual void keyPressEvent( QKeyEvent *event );

virtual void keyReleaseEvent( QKeyEvent *event );


QgsModelViewTool *tool();
%Docstring
Returns the currently active tool for the view.

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

void setTool( QgsModelViewTool *tool );
%Docstring
Sets the ``tool`` currently being used in the view.

.. seealso:: :py:func:`unsetTool`

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

void unsetTool( QgsModelViewTool *tool );
%Docstring
Unsets the current view tool, if it matches the specified ``tool``.

This is called from destructor of view tools to make sure
that the tool won't be used any more.
You don't have to call it manually, QgsModelViewTool takes care of it.
%End

signals:

@@ -56,6 +89,25 @@ Emitted when an algorithm is dropped onto the view.
void inputDropped( const QString &inputId, const QPointF &pos );
%Docstring
Emitted when an input parameter is dropped onto the view.
%End

void toolSet( QgsModelViewTool *tool );
%Docstring
Emitted when the current ``tool`` is changed.

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

void itemFocused( QgsModelComponentGraphicItem *item );
%Docstring
Emitted when an ``item`` is "focused" in the view, i.e. it becomes the active
item and should have its properties displayed in any designer windows.
%End

void willBeDeleted();
%Docstring
Emitted in the destructor when the view is about to be deleted,
but is still in a perfectly valid state.
%End

};
@@ -283,6 +283,14 @@ SET(QGIS_GUI_SRCS
processing/models/qgsmodelgraphicsscene.cpp
processing/models/qgsmodelgraphicsview.cpp
processing/models/qgsmodelundocommand.cpp
processing/models/qgsmodelviewmouseevent.cpp
processing/models/qgsmodelviewrubberband.cpp
processing/models/qgsmodelviewtool.cpp
processing/models/qgsmodelviewtoolselect.cpp
processing/models/qgsmodelviewtooltemporarykeypan.cpp
processing/models/qgsmodelviewtooltemporarykeyzoom.cpp
processing/models/qgsmodelviewtooltemporarymousepan.cpp
processing/models/qgsmodelviewtoolzoom.cpp

providers/gdal/qgsgdalsourceselect.cpp
providers/gdal/qgsgdalguiprovider.cpp
@@ -944,6 +952,14 @@ SET(QGIS_GUI_HDRS
processing/models/qgsmodelgraphicsscene.h
processing/models/qgsmodelgraphicsview.h
processing/models/qgsmodelundocommand.h
processing/models/qgsmodelviewmouseevent.h
processing/models/qgsmodelviewrubberband.h
processing/models/qgsmodelviewtool.h
processing/models/qgsmodelviewtoolselect.h
processing/models/qgsmodelviewtooltemporarykeypan.h
processing/models/qgsmodelviewtooltemporarykeyzoom.h
processing/models/qgsmodelviewtooltemporarymousepan.h
processing/models/qgsmodelviewtoolzoom.h

providers/gdal/qgsgdalguiprovider.h
providers/gdal/qgsgdalsourceselect.h
@@ -22,6 +22,9 @@
#include "qgsapplication.h"
#include "qgsmodelgraphicitem.h"
#include "qgsprocessingmodelalgorithm.h"
#include "qgsmodelgraphicsview.h"
#include "qgsmodelviewtool.h"

#include <QSvgRenderer>
#include <QPicture>
#include <QPainter>
@@ -89,6 +92,11 @@ QgsProcessingModelAlgorithm *QgsModelComponentGraphicItem::model()
return mModel;
}

QgsModelGraphicsView *QgsModelComponentGraphicItem::view()
{
return qobject_cast< QgsModelGraphicsView * >( scene()->views().first() );
}

QFont QgsModelComponentGraphicItem::font() const
{
return mFont;
@@ -102,7 +110,8 @@ void QgsModelComponentGraphicItem::setFont( const QFont &font )

void QgsModelComponentGraphicItem::mouseDoubleClickEvent( QGraphicsSceneMouseEvent * )
{
editComponent();
if ( view()->tool() && view()->tool()->allowItemInteraction() )
editComponent();
}

void QgsModelComponentGraphicItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
@@ -117,22 +126,27 @@ void QgsModelComponentGraphicItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *

void QgsModelComponentGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent *event )
{
updateToolTip( event->pos() );
if ( view()->tool() && view()->tool()->allowItemInteraction() )
updateToolTip( event->pos() );
}

void QgsModelComponentGraphicItem::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
{
updateToolTip( event->pos() );
if ( view()->tool() && view()->tool()->allowItemInteraction() )
updateToolTip( event->pos() );
}

void QgsModelComponentGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
{
setToolTip( QString() );
if ( mIsHovering )
if ( view()->tool() && view()->tool()->allowItemInteraction() )
{
mIsHovering = false;
update();
emit repaintArrows();
setToolTip( QString() );
if ( mIsHovering )
{
mIsHovering = false;
update();
emit repaintArrows();
}
}
}

@@ -31,6 +31,7 @@ class QgsProcessingModelComment;
class QgsProcessingModelAlgorithm;
class QgsModelDesignerFlatButtonGraphicItem;
class QgsModelDesignerFoldButtonGraphicItem;
class QgsModelGraphicsView;

///@cond NOT_STABLE

@@ -95,6 +96,11 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
*/
QgsProcessingModelAlgorithm *model();

/**
* Returns the associated view.
*/
QgsModelGraphicsView *view();

/**
* Returns the font used to render text in the item.
* \see setFont()
@@ -24,6 +24,7 @@
#include "qgsgui.h"
#include "qgsprocessingparametertype.h"
#include "qgsmodelundocommand.h"
#include "qgsmodelviewtoolselect.h"

#include <QShortcut>
#include <QDesktopWidget>
@@ -229,6 +230,13 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
mActionShowComments->setChecked( settings.value( QStringLiteral( "/Processing/Modeler/ShowComments" ), true ).toBool() );
connect( mActionShowComments, &QAction::toggled, this, &QgsModelDesignerDialog::toggleComments );

mSelectTool = new QgsModelViewToolSelect( mView );
#if 0
mSelectTool->setAction( mActionSelectMoveItem );
#endif
mView->setTool( mSelectTool );
mView->setFocus();

updateWindowTitle();
}

@@ -26,6 +26,7 @@ class QgsMessageBar;
class QgsProcessingModelAlgorithm;
class QgsModelUndoCommand;
class QUndoView;
class QgsModelViewToolSelect;

///@cond NOT_STABLE

@@ -137,6 +138,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode

QgsMessageBar *mMessageBar = nullptr;
QgsModelerToolboxModel *mAlgorithmsModel = nullptr;
QgsModelViewToolSelect *mSelectTool = nullptr;

bool mHasChanged = false;
QUndoStack *mUndoStack = nullptr;
@@ -16,6 +16,8 @@
#include "qgsmodelgraphicitem.h"
#include "qgsapplication.h"
#include "qgsmodelgraphicsscene.h"
#include "qgsmodelgraphicsview.h"
#include "qgsmodelviewtool.h"
#include <QPainter>
#include <QSvgRenderer>

@@ -68,7 +70,10 @@ QRectF QgsModelDesignerFlatButtonGraphicItem::boundingRect() const

void QgsModelDesignerFlatButtonGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent * )
{
mHoverState = true;
if ( view()->tool() && !view()->tool()->allowItemInteraction() )
mHoverState = false;
else
mHoverState = true;
update();
}

@@ -80,7 +85,13 @@ void QgsModelDesignerFlatButtonGraphicItem::hoverLeaveEvent( QGraphicsSceneHover

void QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent * )
{
emit clicked();
if ( view()->tool() && view()->tool()->allowItemInteraction() )
emit clicked();
}

QgsModelGraphicsView *QgsModelDesignerFlatButtonGraphicItem::view()
{
return qobject_cast< QgsModelGraphicsView * >( scene()->views().first() );
}

void QgsModelDesignerFlatButtonGraphicItem::setPicture( const QPicture &picture )
@@ -21,6 +21,8 @@
#include <QGraphicsObject>
#include <QPicture>

class QgsModelGraphicsView;

///@cond NOT_STABLE


@@ -50,6 +52,11 @@ class GUI_EXPORT QgsModelDesignerFlatButtonGraphicItem : public QGraphicsObject
void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;

/**
* Returns the associated model view.
*/
QgsModelGraphicsView *view();

signals:

/**
@@ -48,6 +48,7 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
{
ArrowLink = 0, //!< An arrow linking model items
ModelComponent = 1, //!< Model components (e.g. algorithms, inputs and outputs)
RubberBand = 100, //!< Rubber band item
};

//! Flags for controlling how the scene is rendered and scene behavior

0 comments on commit bb82c12

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