QGIS API Documentation 3.39.0-Master (67e056379ed)
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;
31class QgsProcessingFavoriteAlgorithmManager;
32
34
41class GUI_EXPORT QgsProcessingToolboxModelNode : public QObject
42{
43 Q_OBJECT
44
45#ifdef SIP_RUN
47 if ( sipCpp->inherits( "QgsProcessingToolboxModelNode" ) )
48 {
49 sipType = sipType_QgsProcessingToolboxModelNode;
50 QgsProcessingToolboxModelNode *node = qobject_cast<QgsProcessingToolboxModelNode *>( sipCpp );
51 if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Provider )
52 sipType = sipType_QgsProcessingToolboxModelProviderNode;
53 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Group )
54 sipType = sipType_QgsProcessingToolboxModelGroupNode;
55 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Algorithm )
56 sipType = sipType_QgsProcessingToolboxModelAlgorithmNode;
57 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Recent )
58 sipType = sipType_QgsProcessingToolboxModelRecentNode;
59 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeType::Favorite )
60 sipType = sipType_QgsProcessingToolboxModelFavoriteNode;
61 }
62 else
63 sipType = 0;
65#endif
66
67 public:
68
69 // *INDENT-OFF*
70
72 enum class NodeType SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsProcessingToolboxModelNode, NodeType ) : int
73 {
74 Provider SIP_MONKEYPATCH_COMPAT_NAME( NodeProvider ) = 0,
75 Group SIP_MONKEYPATCH_COMPAT_NAME( NodeGroup ),
76 Algorithm SIP_MONKEYPATCH_COMPAT_NAME( NodeAlgorithm ),
77 Recent SIP_MONKEYPATCH_COMPAT_NAME( NodeRecent ),
78 Favorite,
79 };
80 Q_ENUM( NodeType )
81 // *INDENT-ON*
82
83 ~QgsProcessingToolboxModelNode() override;
84
88 virtual NodeType nodeType() const = 0;
89
93 QgsProcessingToolboxModelNode *parent() { return mParent; }
94
98 QList<QgsProcessingToolboxModelNode *> children() { return mChildren; }
99
104 QList<QgsProcessingToolboxModelNode *> children() const { return mChildren; } SIP_SKIP
105
110 QgsProcessingToolboxModelNode *takeChild( QgsProcessingToolboxModelNode *node );
111
117 QgsProcessingToolboxModelGroupNode *getChildGroupNode( const QString &id );
118
123 void addChildNode( QgsProcessingToolboxModelNode *node SIP_TRANSFER );
124
128 void deleteChildren();
129
130 private:
131
132 NodeType mNodeType = NodeType::Provider;
133 QgsProcessingToolboxModelNode *mParent = nullptr;
134 QList<QgsProcessingToolboxModelNode *> mChildren;
135
136};
137
144class GUI_EXPORT QgsProcessingToolboxModelRecentNode : public QgsProcessingToolboxModelNode
145{
146 Q_OBJECT
147
148 public:
149
153 QgsProcessingToolboxModelRecentNode() = default;
154
155 NodeType nodeType() const override { return NodeType::Recent; }
156
157};
158
165class GUI_EXPORT QgsProcessingToolboxModelFavoriteNode : public QgsProcessingToolboxModelNode
166{
167 Q_OBJECT
168
169 public:
170
174 QgsProcessingToolboxModelFavoriteNode() = default;
175
176 NodeType nodeType() const override { return NodeType::Favorite; }
177
178};
179
186class GUI_EXPORT QgsProcessingToolboxModelProviderNode : public QgsProcessingToolboxModelNode
187{
188 Q_OBJECT
189
190 public:
191
196 QgsProcessingToolboxModelProviderNode( QgsProcessingProvider *provider );
197
198 NodeType nodeType() const override { return NodeType::Provider; }
199
203 QgsProcessingProvider *provider();
204
208 QString providerId() const { return mProviderId; }
209
210 private:
211
212 // NOTE: we store both the provider ID and a pointer to the provider here intentionally.
213 // We store the provider pointer to avoid having to lookup the provider from the registry
214 // every time the node is used (which kills performance in the filter proxy model), but
215 // we also store the provider id string in order to identify the provider that the node
216 // is linked to for cleanups after the provider is removed.
217 QString mProviderId;
218 QPointer< QgsProcessingProvider > mProvider;
219
220};
221
228class GUI_EXPORT QgsProcessingToolboxModelGroupNode : public QgsProcessingToolboxModelNode
229{
230 Q_OBJECT
231
232 public:
233
241 QgsProcessingToolboxModelGroupNode( const QString &id, const QString &name );
242
243 NodeType nodeType() const override { return NodeType::Group; }
244
248 QString id() const { return mId; }
249
253 QString name() const { return mName; }
254
255 private:
256 QString mId;
257 QString mName;
258
259};
260
267class GUI_EXPORT QgsProcessingToolboxModelAlgorithmNode : public QgsProcessingToolboxModelNode
268{
269 Q_OBJECT
270
271 public:
272
277 QgsProcessingToolboxModelAlgorithmNode( const QgsProcessingAlgorithm *algorithm );
278
279 NodeType nodeType() const override { return NodeType::Algorithm; }
280
284 const QgsProcessingAlgorithm *algorithm() const;
285
286 private:
287
288 const QgsProcessingAlgorithm *mAlgorithm = nullptr;
289
290};
291
293
303class GUI_EXPORT QgsProcessingToolboxModel : public QAbstractItemModel
304{
305 Q_OBJECT
306
307 public:
308
309 // *INDENT-OFF*
310
318 {
319 NodeType SIP_MONKEYPATCH_COMPAT_NAME(RoleNodeType) = Qt::UserRole,
320 AlgorithmFlags SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmFlags),
321 AlgorithmId SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmId),
322 AlgorithmName SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmName),
323 AlgorithmShortDescription SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmShortDescription),
324 AlgorithmTags SIP_MONKEYPATCH_COMPAT_NAME(RoleAlgorithmTags),
325 ProviderFlags SIP_MONKEYPATCH_COMPAT_NAME(RoleProviderFlags),
326 };
327 Q_ENUM( CustomRole )
328 // *INDENT-ON*
329
330
344 QgsProcessingToolboxModel( QObject *parent SIP_TRANSFERTHIS = nullptr, QgsProcessingRegistry *registry = nullptr,
345 QgsProcessingRecentAlgorithmLog *recentLog = nullptr,
346 QgsProcessingFavoriteAlgorithmManager *favoriteManager = nullptr );
347
348 Qt::ItemFlags flags( const QModelIndex &index ) const override;
349 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
350 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
351 int columnCount( const QModelIndex & = QModelIndex() ) const override;
352 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
353 QModelIndex parent( const QModelIndex &index ) const override;
354 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
355
360 QgsProcessingToolboxModelNode *index2node( const QModelIndex &index ) const;
361
366 QModelIndex node2index( QgsProcessingToolboxModelNode *node ) const;
367
375 QgsProcessingProvider *providerForIndex( const QModelIndex &index ) const;
376
384 QString providerIdForIndex( const QModelIndex &index ) const;
385
393 const QgsProcessingAlgorithm *algorithmForIndex( const QModelIndex &index ) const;
394
400 bool isAlgorithm( const QModelIndex &index ) const;
401
406 QModelIndex indexForProvider( const QString &providerId ) const;
407
411 QModelIndex indexOfParentTreeNode( QgsProcessingToolboxModelNode *parentNode ) const;
412
413 signals:
414
419
424
425 private slots:
426
427 void rebuild();
428 void repopulateRecentAlgorithms( bool resetting = false );
429 void repopulateFavoriteAlgorithms( bool resetting = false );
430 void providerAdded( const QString &id );
431 void providerRemoved( const QString &id );
432
433 private:
434
435 QPointer< QgsProcessingRegistry > mRegistry;
436 QPointer< QgsProcessingRecentAlgorithmLog > mRecentLog;
437 QPointer< QgsProcessingFavoriteAlgorithmManager > mFavoriteManager;
438
439 std::unique_ptr< QgsProcessingToolboxModelGroupNode > mRootNode;
440 QgsProcessingToolboxModelRecentNode *mRecentNode = nullptr;
441 QgsProcessingToolboxModelFavoriteNode *mFavoriteNode = nullptr;
442
443 void addProvider( QgsProcessingProvider *provider );
444
449 static bool isTopLevelProvider( const QString &providerId );
450
454 static QString toolTipForAlgorithm( const QgsProcessingAlgorithm *algorithm );
455
456};
457
458
467class GUI_EXPORT QgsProcessingToolboxProxyModel: public QSortFilterProxyModel
468{
469 Q_OBJECT
470
471 public:
472
473 // *INDENT-OFF*
474
477 {
478 Toolbox SIP_MONKEYPATCH_COMPAT_NAME( FilterToolbox ) = 1 << 1,
479 Modeler SIP_MONKEYPATCH_COMPAT_NAME( FilterModeler ) = 1 << 2,
480 InPlace SIP_MONKEYPATCH_COMPAT_NAME( FilterInPlace ) = 1 << 3,
481 ShowKnownIssues SIP_MONKEYPATCH_COMPAT_NAME( FilterShowKnownIssues ) = 1 << 4,
482 };
483 Q_ENUM( Filter )
484 Q_DECLARE_FLAGS( Filters, Filter )
485 Q_FLAG( Filters )
486 // *INDENT-ON*
487
502 explicit QgsProcessingToolboxProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr,
503 QgsProcessingRegistry *registry = nullptr,
504 QgsProcessingRecentAlgorithmLog *recentLog = nullptr,
505 QgsProcessingFavoriteAlgorithmManager *favoriteManager = nullptr );
506
510 QgsProcessingToolboxModel *toolboxModel();
511
516 const QgsProcessingToolboxModel *toolboxModel() const SIP_SKIP;
517
522 void setFilters( QgsProcessingToolboxProxyModel::Filters filters );
523
528 Filters filters() const { return mFilters; }
529
533 void setInPlaceLayer( QgsVectorLayer *layer );
534
544 void setFilterString( const QString &filter );
545
551 QString filterString() const { return mFilterString; }
552
553 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
554 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
555 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
556
557 private:
558
559 QgsProcessingToolboxModel *mModel = nullptr;
560 Filters mFilters = Filters();
561 QString mFilterString;
562 QPointer<QgsVectorLayer> mInPlaceLayer;
563};
565
566#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.
void favoriteAlgorithmAdded()
Emitted whenever favorite 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)