QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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:
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 SIP_ENUM_BASETYPE( IntFlag )
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 setLastRunResult( const QgsProcessingModelResult &result );
144
150 QgsMessageBar *messageBar() const;
151
157 void setMessageBar( QgsMessageBar *bar );
158
162 void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
163
164 signals:
165
169 void rebuildRequired();
170
177 void componentAboutToChange( const QString &text, int id = 0 );
178
182 void componentChanged();
183
188 void selectedItemChanged( QgsModelComponentGraphicItem *selected );
189
195 void runSelected();
196
202 void runFromChild( const QString &childId );
203
209 void showChildAlgorithmOutputs( const QString &childId );
210
216 void showChildAlgorithmLog( const QString &childId );
217
218 protected:
219
223 virtual QgsModelComponentGraphicItem *createParameterGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelParameter *param ) const SIP_FACTORY;
224
228 virtual QgsModelChildAlgorithmGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const SIP_FACTORY;
229
233 virtual QgsModelComponentGraphicItem *createOutputGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelOutput *output ) const SIP_FACTORY;
234
238 virtual QgsModelComponentGraphicItem *createCommentGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelComment *comment,
239 QgsModelComponentGraphicItem *parentItem ) const SIP_FACTORY;
240
244 QgsModelComponentGraphicItem *createGroupBoxGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelGroupBox *box ) const SIP_FACTORY;
245
246 private:
247
248 struct LinkSource
249 {
250 QgsModelComponentGraphicItem *item = nullptr;
251 Qt::Edge edge = Qt::LeftEdge;
252 int linkIndex = -1;
253 };
254 QList< LinkSource > linkSourcesForParameterValue( QgsProcessingModelAlgorithm *model, const QVariant &value, const QString &childId, QgsProcessingContext &context ) const;
255
256 void addCommentItemForComponent( QgsProcessingModelAlgorithm *model, const QgsProcessingModelComponent &component, QgsModelComponentGraphicItem *parentItem );
257
258 Flags mFlags = Flags();
259
260 QgsProcessingModelAlgorithm *mModel = nullptr;
261
262 QMap< QString, QgsModelComponentGraphicItem * > mParameterItems;
263 QMap< QString, QgsModelChildAlgorithmGraphicItem * > mChildAlgorithmItems;
264 QMap< QString, QMap< QString, QgsModelComponentGraphicItem * > > mOutputItems;
265 QMap< QString, QgsModelComponentGraphicItem * > mGroupBoxItems;
266 QgsProcessingModelResult mLastResult;
267
268 QgsMessageBar *mMessageBar = nullptr;
269
270};
271
272Q_DECLARE_METATYPE( QgsModelGraphicsScene::Flags )
273
274
275
276#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)