QGIS API Documentation 3.41.0-Master (cea29feecf2)
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:
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
124 void selectAll();
125
132 void deselectAll();
133
137 void setSelectedItem( QgsModelComponentGraphicItem *item );
138
142 void setLastRunResult( const QgsProcessingModelResult &result );
143
149 QgsMessageBar *messageBar() const;
150
156 void setMessageBar( QgsMessageBar *bar );
157
161 void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
162
163 signals:
164
168 void rebuildRequired();
169
176 void componentAboutToChange( const QString &text, int id = 0 );
177
181 void componentChanged();
182
187 void selectedItemChanged( QgsModelComponentGraphicItem *selected );
188
194 void runSelected();
195
201 void runFromChild( const QString &childId );
202
208 void showChildAlgorithmOutputs( const QString &childId );
209
215 void showChildAlgorithmLog( const QString &childId );
216
217 protected:
221 virtual QgsModelComponentGraphicItem *createParameterGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelParameter *param ) const SIP_FACTORY;
222
226 virtual QgsModelChildAlgorithmGraphicItem *createChildAlgGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelChildAlgorithm *child ) const SIP_FACTORY;
227
231 virtual QgsModelComponentGraphicItem *createOutputGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelOutput *output ) const SIP_FACTORY;
232
236 virtual QgsModelComponentGraphicItem *createCommentGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelComment *comment, QgsModelComponentGraphicItem *parentItem ) const SIP_FACTORY;
237
241 QgsModelComponentGraphicItem *createGroupBoxGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelGroupBox *box ) const SIP_FACTORY;
242
243 private:
244 struct LinkSource
245 {
246 QgsModelComponentGraphicItem *item = nullptr;
247 Qt::Edge edge = Qt::LeftEdge;
248 int linkIndex = -1;
249 };
250 QList<LinkSource> linkSourcesForParameterValue( QgsProcessingModelAlgorithm *model, const QVariant &value, const QString &childId, QgsProcessingContext &context ) const;
251
252 void addCommentItemForComponent( QgsProcessingModelAlgorithm *model, const QgsProcessingModelComponent &component, QgsModelComponentGraphicItem *parentItem );
253
254 Flags mFlags = Flags();
255
256 QgsProcessingModelAlgorithm *mModel = nullptr;
257
258 QMap<QString, QgsModelComponentGraphicItem *> mParameterItems;
259 QMap<QString, QgsModelChildAlgorithmGraphicItem *> mChildAlgorithmItems;
260 QMap<QString, QMap<QString, QgsModelComponentGraphicItem *>> mOutputItems;
261 QMap<QString, QgsModelComponentGraphicItem *> mGroupBoxItems;
262 QgsProcessingModelResult mLastResult;
263
264 QgsMessageBar *mMessageBar = nullptr;
265};
266
267Q_DECLARE_METATYPE( QgsModelGraphicsScene::Flags )
268
269
270
271#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)