QGIS API Documentation  3.21.0-Master (909859188c)
qgsmodelgraphicsscene.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmodelgraphicsscene.h
3  -----------------------
4  Date : March 2020
5  Copyright : (C) 2020 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMODELGRAPHICSCENE_H
17 #define QGSMODELGRAPHICSCENE_H
18 
19 #include "qgis.h"
20 #include "qgis_gui.h"
21 #include "qgsprocessingcontext.h"
22 #include <QGraphicsScene>
23 
24 class QgsProcessingModelAlgorithm;
25 class QgsModelComponentGraphicItem;
26 class QgsProcessingModelParameter;
27 class QgsProcessingModelChildAlgorithm;
28 class QgsProcessingModelOutput;
29 class QgsProcessingModelComponent;
30 class QgsProcessingModelComment;
31 class QgsModelChildAlgorithmGraphicItem;
32 class QgsProcessingModelGroupBox;
33 class QgsMessageBar;
34 
36 
43 class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
44 {
45  Q_OBJECT
46 
47  public:
48 
50  enum ZValues
51  {
52  GroupBox = 0,
53  ArrowLink = 1,
54  ModelComponent = 2,
55  MouseHandles = 99,
56  RubberBand = 100,
57  ZSnapIndicator = 101,
58 
59  };
60 
62  enum Flag
63  {
64  FlagHideControls = 1 << 1,
65  FlagHideComments = 1 << 2,
66  };
67  Q_DECLARE_FLAGS( Flags, Flag )
68 
69 
72  QgsModelGraphicsScene( QObject *parent SIP_TRANSFERTHIS = nullptr );
73 
74  QgsProcessingModelAlgorithm *model();
75 
76  void setModel( QgsProcessingModelAlgorithm *model );
77 
83  void setFlags( QgsModelGraphicsScene::Flags flags ) { mFlags = flags; }
84 
91  void setFlag( QgsModelGraphicsScene::Flag flag, bool on = true );
92 
98  QgsModelGraphicsScene::Flags flags() const { return mFlags; }
99 
100  void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
101 
105  void createItems( QgsProcessingModelAlgorithm *model, QgsProcessingContext &context );
106 
110  QList<QgsModelComponentGraphicItem *> selectedComponentItems();
111 
115  QgsModelComponentGraphicItem *componentItemAt( QPointF position ) const;
116 
120  QgsModelComponentGraphicItem *groupBoxItem( const QString &uuid );
121 
125  void selectAll();
126 
133  void deselectAll();
134 
138  void setSelectedItem( QgsModelComponentGraphicItem *item );
139 
143  void setChildAlgorithmResults( const QVariantMap &results );
144 
148  void setChildAlgorithmInputs( const QVariantMap &inputs );
149 
155  QgsMessageBar *messageBar() const;
156 
162  void setMessageBar( QgsMessageBar *bar );
163 
167  void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
168 
169  signals:
170 
174  void rebuildRequired();
175 
182  void componentAboutToChange( const QString &text, int id = 0 );
183 
187  void componentChanged();
188 
193  void selectedItemChanged( QgsModelComponentGraphicItem *selected );
194 
195  protected:
196 
200  virtual QgsModelComponentGraphicItem *createParameterGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelParameter *param ) const SIP_FACTORY;
201 
205  virtual QgsModelChildAlgorithmGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const SIP_FACTORY;
206 
210  virtual QgsModelComponentGraphicItem *createOutputGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelOutput *output ) const SIP_FACTORY;
211 
215  virtual QgsModelComponentGraphicItem *createCommentGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelComment *comment,
216  QgsModelComponentGraphicItem *parentItem ) const SIP_FACTORY;
217 
221  QgsModelComponentGraphicItem *createGroupBoxGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelGroupBox *box ) const SIP_FACTORY;
222 
223  private:
224 
225  struct LinkSource
226  {
227  QgsModelComponentGraphicItem *item = nullptr;
228  Qt::Edge edge = Qt::LeftEdge;
229  int linkIndex = -1;
230  };
231  QList< LinkSource > linkSourcesForParameterValue( QgsProcessingModelAlgorithm *model, const QVariant &value, const QString &childId, QgsProcessingContext &context ) const;
232 
233  void addCommentItemForComponent( QgsProcessingModelAlgorithm *model, const QgsProcessingModelComponent &component, QgsModelComponentGraphicItem *parentItem );
234 
235  Flags mFlags = Flags();
236 
237  QgsProcessingModelAlgorithm *mModel = nullptr;
238 
239  QMap< QString, QgsModelComponentGraphicItem * > mParameterItems;
240  QMap< QString, QgsModelChildAlgorithmGraphicItem * > mChildAlgorithmItems;
241  QMap< QString, QMap< QString, QgsModelComponentGraphicItem * > > mOutputItems;
242  QMap< QString, QgsModelComponentGraphicItem * > mGroupBoxItems;
243  QVariantMap mChildResults;
244  QVariantMap mChildInputs;
245 
246  QgsMessageBar *mMessageBar = nullptr;
247 
248 };
249 
250 Q_DECLARE_METATYPE( QgsModelGraphicsScene::Flags )
251 
252 
254 #endif // QGSMODELCOMPONENTGRAPHICITEM_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:106
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Contains information about the context in which a processing algorithm is executed.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76
Q_DECLARE_METATYPE(QgsMeshTimeSettings)