QGIS API Documentation 3.35.0-Master (f6e073f0eed)
Loading...
Searching...
No Matches
qgsprocessingtoolboxmodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingtoolboxmodel.h
3 ---------------------------
4 begin : May 2018
5 copyright : (C) 2018 by 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 QGSPROCESSINGTOOLBOXMODEL_H
17#define QGSPROCESSINGTOOLBOXMODEL_H
18
19#include "qgis.h"
20#include "qgis_gui.h"
21#include <QAbstractItemModel>
22#include <QSortFilterProxyModel>
23#include <QPointer>
24
25class QgsVectorLayer;
29class QgsProcessingToolboxModelGroupNode;
30class QgsProcessingRecentAlgorithmLog;
31
33
40class GUI_EXPORT QgsProcessingToolboxModelNode : public QObject
41{
42 Q_OBJECT
43
44#ifdef SIP_RUN
46 if ( sipCpp->inherits( "QgsProcessingToolboxModelNode" ) )
47 {
48 sipType = sipType_QgsProcessingToolboxModelNode;
49 QgsProcessingToolboxModelNode *node = qobject_cast<QgsProcessingToolboxModelNode *>( sipCpp );
50 if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Provider )
51 sipType = sipType_QgsProcessingToolboxModelProviderNode;
52 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Group )
53 sipType = sipType_QgsProcessingToolboxModelGroupNode;
54 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Algorithm )
55 sipType = sipType_QgsProcessingToolboxModelAlgorithmNode;
56 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Recent )
57 sipType = sipType_QgsProcessingToolboxModelRecentNode;
58 }
59 else
60 sipType = 0;
62#endif
63
64 public:
65
66 // *INDENT-OFF*
67
69 enum class NodeType SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsProcessingToolboxModelNode, NodeType ) : int
70 {
71 Provider SIP_MONKEYPATCH_COMPAT_NAME( NodeProvider ) = 0,
72 Group SIP_MONKEYPATCH_COMPAT_NAME( NodeGroup ),
73 Algorithm SIP_MONKEYPATCH_COMPAT_NAME( NodeAlgorithm ),
74 Recent SIP_MONKEYPATCH_COMPAT_NAME( NodeRecent ),
75 };
76 Q_ENUM( NodeType )
77 // *INDENT-ON*
78
79 ~QgsProcessingToolboxModelNode() override;
80
84 virtual NodeType nodeType() const = 0;
85
89 QgsProcessingToolboxModelNode *parent() { return mParent; }
90
94 QList<QgsProcessingToolboxModelNode *> children() { return mChildren; }
95
100 QList<QgsProcessingToolboxModelNode *> children() const { return mChildren; } SIP_SKIP
101
106 QgsProcessingToolboxModelNode *takeChild( QgsProcessingToolboxModelNode *node );
107
113 QgsProcessingToolboxModelGroupNode *getChildGroupNode( const QString &id );
114
119 void addChildNode( QgsProcessingToolboxModelNode *node SIP_TRANSFER );
120
124 void deleteChildren();
125
126 private:
127
128 NodeType mNodeType = NodeType::Provider;
129 QgsProcessingToolboxModelNode *mParent = nullptr;
130 QList<QgsProcessingToolboxModelNode *> mChildren;
131
132};
133
140class GUI_EXPORT QgsProcessingToolboxModelRecentNode : public QgsProcessingToolboxModelNode
141{
142 Q_OBJECT
143
144 public:
145
149 QgsProcessingToolboxModelRecentNode() = default;
150
151 NodeType nodeType() const override { return NodeType::Recent; }
152
153};
154
161class GUI_EXPORT QgsProcessingToolboxModelProviderNode : public QgsProcessingToolboxModelNode
162{
163 Q_OBJECT
164
165 public:
166
171 QgsProcessingToolboxModelProviderNode( QgsProcessingProvider *provider );
172
173 NodeType nodeType() const override { return NodeType::Provider; }
174
178 QgsProcessingProvider *provider();
179
183 QString providerId() const { return mProviderId; }
184
185 private:
186
187 // NOTE: we store both the provider ID and a pointer to the provider here intentionally.
188 // We store the provider pointer to avoid having to lookup the provider from the registry
189 // every time the node is used (which kills performance in the filter proxy model), but
190 // we also store the provider id string in order to identify the provider that the node
191 // is linked to for cleanups after the provider is removed.
192 QString mProviderId;
193 QPointer< QgsProcessingProvider > mProvider;
194
195};
196
203class GUI_EXPORT QgsProcessingToolboxModelGroupNode : public QgsProcessingToolboxModelNode
204{
205 Q_OBJECT
206
207 public:
208
216 QgsProcessingToolboxModelGroupNode( const QString &id, const QString &name );
217
218 NodeType nodeType() const override { return NodeType::Group; }
219
223 QString id() const { return mId; }
224
228 QString name() const { return mName; }
229
230 private:
231 QString mId;
232 QString mName;
233
234};
235
242class GUI_EXPORT QgsProcessingToolboxModelAlgorithmNode : public QgsProcessingToolboxModelNode
243{
244 Q_OBJECT
245
246 public:
247
252 QgsProcessingToolboxModelAlgorithmNode( const QgsProcessingAlgorithm *algorithm );
253
254 NodeType nodeType() const override { return NodeType::Algorithm; }
255
259 const QgsProcessingAlgorithm *algorithm() const;
260
261 private:
262
263 const QgsProcessingAlgorithm *mAlgorithm = nullptr;
264
265};
266
268
278class GUI_EXPORT QgsProcessingToolboxModel : public QAbstractItemModel
279{
280 Q_OBJECT
281
282 public:
283
284 // *INDENT-OFF*
285
293 {
294 NodeType SIP_MONKEYPATCH_COMPAT_NAME(RoleNodeType) = Qt::UserRole,
295 AlgorithmFlags SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmFlags),
296 AlgorithmId SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmId),
297 AlgorithmName SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmName),
298 AlgorithmShortDescription SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmShortDescription),
299 AlgorithmTags SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmTags),
300 ProviderFlags SIP_MONKEYPATCH_COMPAT_NAME(RoleProviderFlags),
301 };
302 Q_ENUM( CustomRole )
303 // *INDENT-ON*
304
305
316 QgsProcessingToolboxModel( QObject *parent SIP_TRANSFERTHIS = nullptr, QgsProcessingRegistry *registry = nullptr,
317 QgsProcessingRecentAlgorithmLog *recentLog = nullptr );
318
319 Qt::ItemFlags flags( const QModelIndex &index ) const override;
320 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
321 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
322 int columnCount( const QModelIndex & = QModelIndex() ) const override;
323 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
324 QModelIndex parent( const QModelIndex &index ) const override;
325 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
326
331 QgsProcessingToolboxModelNode *index2node( const QModelIndex &index ) const;
332
337 QModelIndex node2index( QgsProcessingToolboxModelNode *node ) const;
338
346 QgsProcessingProvider *providerForIndex( const QModelIndex &index ) const;
347
355 QString providerIdForIndex( const QModelIndex &index ) const;
356
364 const QgsProcessingAlgorithm *algorithmForIndex( const QModelIndex &index ) const;
365
371 bool isAlgorithm( const QModelIndex &index ) const;
372
377 QModelIndex indexForProvider( const QString &providerId ) const;
378
382 QModelIndex indexOfParentTreeNode( QgsProcessingToolboxModelNode *parentNode ) const;
383
384 signals:
385
390
391 private slots:
392
393 void rebuild();
394 void repopulateRecentAlgorithms( bool resetting = false );
395 void providerAdded( const QString &id );
396 void providerRemoved( const QString &id );
397
398 private:
399
400 QPointer< QgsProcessingRegistry > mRegistry;
401 QPointer< QgsProcessingRecentAlgorithmLog > mRecentLog;
402
403 std::unique_ptr< QgsProcessingToolboxModelGroupNode > mRootNode;
404 QgsProcessingToolboxModelRecentNode *mRecentNode = nullptr;
405
406 void addProvider( QgsProcessingProvider *provider );
407
412 static bool isTopLevelProvider( const QString &providerId );
413
417 static QString toolTipForAlgorithm( const QgsProcessingAlgorithm *algorithm );
418
419};
420
421
430class GUI_EXPORT QgsProcessingToolboxProxyModel: public QSortFilterProxyModel
431{
432 Q_OBJECT
433
434 public:
435
436 // *INDENT-OFF*
437
440 {
441 Toolbox SIP_MONKEYPATCH_COMPAT_NAME( FilterToolbox ) = 1 << 1,
442 Modeler SIP_MONKEYPATCH_COMPAT_NAME( FilterModeler ) = 1 << 2,
443 InPlace SIP_MONKEYPATCH_COMPAT_NAME( FilterInPlace ) = 1 << 3,
444 ShowKnownIssues SIP_MONKEYPATCH_COMPAT_NAME( FilterShowKnownIssues ) = 1 << 4,
445 };
446 Q_ENUM( Filter )
447 Q_DECLARE_FLAGS( Filters, Filter )
448 Q_FLAG( Filters )
449 // *INDENT-ON*
450
451
462 explicit QgsProcessingToolboxProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr,
463 QgsProcessingRegistry *registry = nullptr,
464 QgsProcessingRecentAlgorithmLog *recentLog = nullptr );
465
469 QgsProcessingToolboxModel *toolboxModel();
470
475 const QgsProcessingToolboxModel *toolboxModel() const SIP_SKIP;
476
481 void setFilters( QgsProcessingToolboxProxyModel::Filters filters );
482
487 Filters filters() const { return mFilters; }
488
492 void setInPlaceLayer( QgsVectorLayer *layer );
493
503 void setFilterString( const QString &filter );
504
510 QString filterString() const { return mFilterString; }
511
512 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
513 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
514 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
515
516 private:
517
518 QgsProcessingToolboxModel *mModel = nullptr;
519 Filters mFilters = Filters();
520 QString mFilterString;
521 QPointer<QgsVectorLayer> mInPlaceLayer;
522};
523Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingToolboxProxyModel::Filters )
524
525#endif // QGSPROCESSINGTOOLBOXMODEL_H
Abstract base class for processing algorithms.
Abstract base class for processing providers.
Registry for various processing components, including providers, algorithms and various parameters an...
A model for providers and algorithms shown within the Processing toolbox.
void recentAlgorithmAdded()
Emitted whenever recent algorithms are added to the model.
A sort/filter proxy model for providers and algorithms shown within the Processing toolbox,...
QString filterString() const
Returns the current filter string, if set.
Filter
Available filter flags for filtering the model.
Represents a vector layer which manages a vector based data sets.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_END
Definition qgis_sip.h:208
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)