16 #ifndef QGSPROCESSINGTOOLBOXMODEL_H
17 #define QGSPROCESSINGTOOLBOXMODEL_H
21 #include <QAbstractItemModel>
22 #include <QSortFilterProxyModel>
29 class QgsProcessingToolboxModelGroupNode;
30 class QgsProcessingRecentAlgorithmLog;
40 class GUI_EXPORT QgsProcessingToolboxModelNode :
public QObject
46 if ( sipCpp->inherits(
"QgsProcessingToolboxModelNode" ) )
48 sipType = sipType_QgsProcessingToolboxModelNode;
49 QgsProcessingToolboxModelNode *node = qobject_cast<QgsProcessingToolboxModelNode *>( sipCpp );
50 if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeProvider )
51 sipType = sipType_QgsProcessingToolboxModelProviderNode;
52 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeGroup )
53 sipType = sipType_QgsProcessingToolboxModelGroupNode;
54 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeAlgorithm )
55 sipType = sipType_QgsProcessingToolboxModelAlgorithmNode;
56 else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeRecent )
57 sipType = sipType_QgsProcessingToolboxModelRecentNode;
75 ~QgsProcessingToolboxModelNode()
override;
80 virtual NodeType nodeType()
const = 0;
85 QgsProcessingToolboxModelNode *parent() {
return mParent; }
90 QList<QgsProcessingToolboxModelNode *> children() {
return mChildren; }
96 QList<QgsProcessingToolboxModelNode *> children()
const {
return mChildren; }
SIP_SKIP
102 QgsProcessingToolboxModelNode *takeChild( QgsProcessingToolboxModelNode *node );
109 QgsProcessingToolboxModelGroupNode *getChildGroupNode(
const QString &
id );
115 void addChildNode( QgsProcessingToolboxModelNode *node
SIP_TRANSFER );
120 void deleteChildren();
125 QgsProcessingToolboxModelNode *mParent =
nullptr;
126 QList<QgsProcessingToolboxModelNode *> mChildren;
136 class GUI_EXPORT QgsProcessingToolboxModelRecentNode :
public QgsProcessingToolboxModelNode
145 QgsProcessingToolboxModelRecentNode() =
default;
147 NodeType nodeType()
const override {
return NodeRecent; }
157 class GUI_EXPORT QgsProcessingToolboxModelProviderNode :
public QgsProcessingToolboxModelNode
169 NodeType nodeType()
const override {
return NodeProvider; }
179 QString providerId()
const {
return mProviderId; }
189 QPointer< QgsProcessingProvider > mProvider;
199 class GUI_EXPORT QgsProcessingToolboxModelGroupNode :
public QgsProcessingToolboxModelNode
212 QgsProcessingToolboxModelGroupNode(
const QString &
id,
const QString &name );
214 NodeType nodeType()
const override {
return NodeGroup; }
219 QString id()
const {
return mId; }
224 QString name()
const {
return mName; }
238 class GUI_EXPORT QgsProcessingToolboxModelAlgorithmNode :
public QgsProcessingToolboxModelNode
250 NodeType nodeType()
const override {
return NodeAlgorithm; }
283 RoleNodeType = Qt::UserRole,
304 QgsProcessingRecentAlgorithmLog *recentLog =
nullptr );
306 Qt::ItemFlags flags(
const QModelIndex &index )
const override;
307 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole )
const override;
308 int rowCount(
const QModelIndex &parent = QModelIndex() )
const override;
309 int columnCount(
const QModelIndex & = QModelIndex() )
const override;
310 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex() )
const override;
311 QModelIndex parent(
const QModelIndex &index )
const override;
312 QMimeData *mimeData(
const QModelIndexList &indexes )
const override;
318 QgsProcessingToolboxModelNode *index2node(
const QModelIndex &index )
const;
324 QModelIndex node2index( QgsProcessingToolboxModelNode *node )
const;
342 QString providerIdForIndex(
const QModelIndex &index )
const;
358 bool isAlgorithm(
const QModelIndex &index )
const;
364 QModelIndex indexForProvider(
const QString &providerId )
const;
369 QModelIndex indexOfParentTreeNode( QgsProcessingToolboxModelNode *parentNode )
const;
381 void repopulateRecentAlgorithms(
bool resetting =
false );
382 void providerAdded(
const QString &
id );
383 void providerRemoved(
const QString &
id );
387 QPointer< QgsProcessingRegistry > mRegistry;
388 QPointer< QgsProcessingRecentAlgorithmLog > mRecentLog;
390 std::unique_ptr< QgsProcessingToolboxModelGroupNode > mRootNode;
391 QgsProcessingToolboxModelRecentNode *mRecentNode =
nullptr;
399 static bool isTopLevelProvider(
const QString &providerId );
426 FilterToolbox = 1 << 1,
427 FilterModeler = 1 << 2,
428 FilterInPlace = 1 << 3,
429 FilterShowKnownIssues = 1 << 4,
431 Q_DECLARE_FLAGS( Filters, Filter )
447 QgsProcessingRecentAlgorithmLog *recentLog =
nullptr );
470 Filters filters()
const {
return mFilters; }
486 void setFilterString(
const QString &filter );
495 bool filterAcceptsRow(
int sourceRow,
const QModelIndex &sourceParent )
const override;
496 bool lessThan(
const QModelIndex &left,
const QModelIndex &right )
const override;
497 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole )
const override;
502 Filters mFilters = Filters();
503 QString mFilterString;
504 QPointer<QgsVectorLayer> mInPlaceLayer;
508 #endif // QGSPROCESSINGTOOLBOXMODEL_H