QGIS API Documentation 3.43.0-Master (69d1901085b)
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"
22#include <QGraphicsScene>
23
24class QgsProcessingModelAlgorithm;
25class QgsModelComponentGraphicItem;
26class QgsProcessingModelParameter;
27class QgsProcessingModelChildAlgorithm;
28class QgsProcessingModelOutput;
29class QgsProcessingModelComponent;
30class QgsProcessingModelComment;
31class QgsModelChildAlgorithmGraphicItem;
32class QgsProcessingModelGroupBox;
33class QgsMessageBar;
34
36
43class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
44{
45 Q_OBJECT
46
47 public:
49 enum ZValues
50 {
51 GroupBox = 0,
52 ArrowLink = 1,
53 ModelComponent = 2,
54 MouseHandles = 99,
55 RubberBand = 100,
56 ZSnapIndicator = 101,
57
58 };
59
61 enum Flag SIP_ENUM_BASETYPE( IntFlag )
62 {
63 FlagHideControls = 1 << 1,
64 FlagHideComments = 1 << 2,
65 };
66 Q_DECLARE_FLAGS( Flags, Flag )
67
68
71 QgsModelGraphicsScene( QObject *parent SIP_TRANSFERTHIS = nullptr );
72
73 QgsProcessingModelAlgorithm *model();
74
75 void setModel( QgsProcessingModelAlgorithm *model );
76
82 void setFlags( QgsModelGraphicsScene::Flags flags ) { mFlags = flags; }
83
90 void setFlag( QgsModelGraphicsScene::Flag flag, bool on = true );
91
97 QgsModelGraphicsScene::Flags flags() const { return mFlags; }
98
99 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
100
104 void createItems( QgsProcessingModelAlgorithm *model, QgsProcessingContext &context );
105
109 QList<QgsModelComponentGraphicItem *> selectedComponentItems();
110
114 QgsModelComponentGraphicItem *componentItemAt( QPointF position ) const;
115
119 QgsModelComponentGraphicItem *groupBoxItem( const QString &uuid );
120
126 QgsModelChildAlgorithmGraphicItem *childAlgorithmItem( const QString &childId );
127
133 QgsModelComponentGraphicItem *parameterItem( const QString &name );
134
138 void selectAll();
139
146 void deselectAll();
147
151 void setSelectedItem( QgsModelComponentGraphicItem *item );
152
156 void setLastRunResult( const QgsProcessingModelResult &result );
157
163 QgsMessageBar *messageBar() const;
164
170 void setMessageBar( QgsMessageBar *bar );
171
175 void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
176
182 void requestRebuildRequired();
183
184 signals:
185
189 void rebuildRequired();
190
197 void componentAboutToChange( const QString &text, int id = 0 );
198
202 void componentChanged();
203
208 void selectedItemChanged( QgsModelComponentGraphicItem *selected );
209
215 void runSelected();
216
222 void runFromChild( const QString &childId );
223
229 void showChildAlgorithmOutputs( const QString &childId );
230
236 void showChildAlgorithmLog( const QString &childId );
237
238 protected:
242 virtual QgsModelComponentGraphicItem *createParameterGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelParameter *param ) const SIP_FACTORY;
243
247 virtual QgsModelChildAlgorithmGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const SIP_FACTORY;
248
252 virtual QgsModelComponentGraphicItem *createOutputGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelOutput *output ) const SIP_FACTORY;
253
257 virtual QgsModelComponentGraphicItem *createCommentGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelComment *comment, QgsModelComponentGraphicItem *parentItem ) const SIP_FACTORY;
258
262 QgsModelComponentGraphicItem *createGroupBoxGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelGroupBox *box ) const SIP_FACTORY;
263
264 private:
265 struct LinkSource
266 {
267 QgsModelComponentGraphicItem *item = nullptr;
268 Qt::Edge edge = Qt::LeftEdge;
269 int linkIndex = -1;
270 };
271 QList<LinkSource> linkSourcesForParameterValue( QgsProcessingModelAlgorithm *model, const QVariant &value, const QString &childId, QgsProcessingContext &context ) const;
272
273 void addCommentItemForComponent( QgsProcessingModelAlgorithm *model, const QgsProcessingModelComponent &component, QgsModelComponentGraphicItem *parentItem );
274
275 Flags mFlags = Flags();
276
277 QgsProcessingModelAlgorithm *mModel = nullptr;
278
279 QMap<QString, QgsModelComponentGraphicItem *> mParameterItems;
280 QMap<QString, QgsModelChildAlgorithmGraphicItem *> mChildAlgorithmItems;
281 QMap<QString, QMap<QString, QgsModelComponentGraphicItem *>> mOutputItems;
282 QMap<QString, QgsModelComponentGraphicItem *> mGroupBoxItems;
283 QgsProcessingModelResult mLastResult;
284
285 QgsMessageBar *mMessageBar = nullptr;
286};
287
288Q_DECLARE_METATYPE( QgsModelGraphicsScene::Flags )
289
290
291
292#endif // QGSMODELCOMPONENTGRAPHICITEM_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
@ Warning
Warning message.
Definition qgis.h:156
A bar for displaying non-blocking messages to the user.
Contains information about the context in which a processing algorithm is executed.
Encapsulates the results of running a Processing model.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_FACTORY
Definition qgis_sip.h:76
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)