QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
23#include <QGraphicsScene>
24
25class QgsProcessingModelAlgorithm;
26class QgsModelComponentGraphicItem;
27class QgsProcessingModelParameter;
28class QgsProcessingModelChildAlgorithm;
29class QgsProcessingModelOutput;
30class QgsProcessingModelComponent;
31class QgsProcessingModelComment;
32class QgsModelChildAlgorithmGraphicItem;
33class QgsProcessingModelGroupBox;
34class QgsMessageBar;
35
37
44class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
45{
46 Q_OBJECT
47
48 public:
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
127 QgsModelChildAlgorithmGraphicItem *childAlgorithmItem( const QString &childId );
128
134 QgsModelComponentGraphicItem *parameterItem( const QString &name );
135
139 void selectAll();
140
147 void deselectAll();
148
152 void setSelectedItem( QgsModelComponentGraphicItem *item );
153
157 void setLastRunResult( const QgsProcessingModelResult &result );
158
164 QgsMessageBar *messageBar() const;
165
171 void setMessageBar( QgsMessageBar *bar );
172
176 void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
177
183 void requestRebuildRequired();
184
192 void updateBounds();
193
194 signals:
195
199 void rebuildRequired();
200
207 void componentAboutToChange( const QString &text, int id = 0 );
208
212 void componentChanged();
213
218 void selectedItemChanged( QgsModelComponentGraphicItem *selected );
219
225 void runSelected();
226
232 void runFromChild( const QString &childId );
233
239 void showChildAlgorithmOutputs( const QString &childId );
240
246 void showChildAlgorithmLog( const QString &childId );
247
248 protected:
252 virtual QgsModelComponentGraphicItem *createParameterGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelParameter *param ) const SIP_FACTORY;
253
257 virtual QgsModelChildAlgorithmGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const SIP_FACTORY;
258
262 virtual QgsModelComponentGraphicItem *createOutputGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelOutput *output ) const SIP_FACTORY;
263
267 virtual QgsModelComponentGraphicItem *createCommentGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelComment *comment, QgsModelComponentGraphicItem *parentItem ) const SIP_FACTORY;
268
272 QgsModelComponentGraphicItem *createGroupBoxGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelGroupBox *box ) const SIP_FACTORY;
273
274 private:
275 struct LinkSource
276 {
277 QgsModelComponentGraphicItem *item = nullptr;
278 Qt::Edge edge = Qt::LeftEdge;
279 int linkIndex = -1;
280 };
281 QList<LinkSource> linkSourcesForParameterValue( QgsProcessingModelAlgorithm *model, const QVariant &value, const QString &childId, QgsProcessingContext &context ) const;
282
283 void addCommentItemForComponent( QgsProcessingModelAlgorithm *model, const QgsProcessingModelComponent &component, QgsModelComponentGraphicItem *parentItem );
284
285 Flags mFlags = Flags();
286
287 QgsProcessingModelAlgorithm *mModel = nullptr;
288
289 QMap<QString, QgsModelComponentGraphicItem *> mParameterItems;
290 QMap<QString, QgsModelChildAlgorithmGraphicItem *> mChildAlgorithmItems;
291 QMap<QString, QMap<QString, QgsModelComponentGraphicItem *>> mOutputItems;
292 QMap<QString, QgsModelComponentGraphicItem *> mGroupBoxItems;
293 QgsProcessingModelResult mLastResult;
294
295 static constexpr int SCENE_COMPONENT_MARGIN = 50;
296
297 QgsMessageBar *mMessageBar = nullptr;
298};
299
300Q_DECLARE_METATYPE( QgsModelGraphicsScene::Flags )
301
302
303
304#endif // QGSMODELCOMPONENTGRAPHICITEM_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:156
@ Warning
Warning message.
Definition qgis.h:158
A bar for displaying non-blocking messages to the user.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_FACTORY
Definition qgis_sip.h:84
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)