Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hide inactive providers from model
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 0bbf126 commit dab3f51
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
Expand Up @@ -304,6 +304,8 @@ registry attached to QgsApplication.processingRegistry() will be used
by the model.
%End

virtual bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;

virtual bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;


Expand Down
5 changes: 5 additions & 0 deletions src/3d/processing/qgsalgorithmtessellate.cpp
Expand Up @@ -41,6 +41,11 @@ QString QgsTessellateAlgorithm::group() const
return QObject::tr( "Vector geometry" );
}

QString QgsTessellateAlgorithm::groupId() const
{
return QStringLiteral( "vectorgeometry" );
}

QString QgsTessellateAlgorithm::outputName() const
{
return QObject::tr( "Tessellated" );
Expand Down
1 change: 1 addition & 0 deletions src/3d/processing/qgsalgorithmtessellate.h
Expand Up @@ -38,6 +38,7 @@ class QgsTessellateAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString displayName() const override;
QStringList tags() const override;
QString group() const override;
QString groupId() const override;
QString shortHelpString() const override;
QList<int> inputLayerTypes() const override;
QgsTessellateAlgorithm *createInstance() const override SIP_FACTORY;
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -851,6 +851,7 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )

mModelName = map.value( QStringLiteral( "model_name" ) ).toString();
mModelGroup = map.value( QStringLiteral( "model_group" ) ).toString();
mModelGroupId = map.value( QStringLiteral( "model_group" ) ).toString();
mHelpContent = map.value( QStringLiteral( "help" ) ).toMap();

mChildAlgorithms.clear();
Expand Down
15 changes: 15 additions & 0 deletions src/gui/processing/qgsprocessingtoolboxmodel.cpp
Expand Up @@ -420,6 +420,21 @@ QgsProcessingToolboxProxyModel::QgsProcessingToolboxProxyModel( QObject *parent,
sort( 0 );
}

bool QgsProcessingToolboxProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
{
QModelIndex sourceIndex = mModel->index( sourceRow, 0, sourceParent );
if ( QgsProcessingProvider *provider = mModel->providerForIndex( sourceIndex ) )
{
return provider->isActive(); // and has visible children!!
}

// TODO
// check flags - hide from toolbox/modeler
// check search string
// check group has visible children
return true;
}

bool QgsProcessingToolboxProxyModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
{
QgsProcessingToolboxModelNode::NodeType leftType = static_cast< QgsProcessingToolboxModelNode::NodeType >( sourceModel()->data( left, QgsProcessingToolboxModel::RoleNodeType ).toInt() );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/processing/qgsprocessingtoolboxmodel.h
Expand Up @@ -336,7 +336,7 @@ class GUI_EXPORT QgsProcessingToolboxProxyModel: public QSortFilterProxyModel
*/
explicit QgsProcessingToolboxProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr, QgsProcessingRegistry *registry = nullptr );

// bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;

private:
Expand Down
12 changes: 11 additions & 1 deletion tests/src/gui/testqgsprocessingmodel.cpp
Expand Up @@ -56,10 +56,11 @@ class DummyProvider : public QgsProcessingProvider
}

QString id() const override { return mId; }
bool isActive() const override { return mActive; }

QString name() const override { return mName; }
QString longName() const override { return QStringLiteral( "long name %1" ).arg( mName );}

bool mActive = true;
protected:
void loadAlgorithms() override
{
Expand All @@ -68,6 +69,7 @@ class DummyProvider : public QgsProcessingProvider
}
QString mId;
QString mName;

QList< QgsProcessingAlgorithm *> mAlgs;

};
Expand Down Expand Up @@ -338,6 +340,14 @@ void TestQgsProcessingModel::testProxyModel()
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "group2" ) );
QCOMPARE( model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( model.data( model.index( 3, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
QCOMPARE( model.rowCount(), 4 );

// inactive provider - should not be visible
DummyAlgorithm *qgisA31 = new DummyAlgorithm( "a3", "group1" );
DummyProvider *p3 = new DummyProvider( "p3", "provider3", QList< QgsProcessingAlgorithm * >() << qgisA31 );
p3->mActive = false;
registry.addProvider( p3 );
QCOMPARE( model.rowCount(), 4 );
}

QGSTEST_MAIN( TestQgsProcessingModel )
Expand Down

0 comments on commit dab3f51

Please sign in to comment.