Skip to content
Permalink
Browse files

Hide inactive providers from model

  • Loading branch information
nyalldawson committed Jul 2, 2018
1 parent 0bbf126 commit dab3f5137f0fb5147d8c71a465ce78e3ffcfe21b
@@ -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;


@@ -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" );
@@ -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;
@@ -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();
@@ -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() );
@@ -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:
@@ -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
{
@@ -68,6 +69,7 @@ class DummyProvider : public QgsProcessingProvider
}
QString mId;
QString mName;

QList< QgsProcessingAlgorithm *> mAlgs;

};
@@ -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 )

0 comments on commit dab3f51

Please sign in to comment.
You can’t perform that action at this time.