Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start on recent item proxy handling
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 2efc08e commit 9de2cc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/gui/processing/qgsprocessingtoolboxmodel.cpp
Expand Up @@ -720,7 +720,11 @@ bool QgsProcessingToolboxProxyModel::lessThan( const QModelIndex &left, const QM
QgsProcessingToolboxModelNode::NodeType leftType = static_cast< QgsProcessingToolboxModelNode::NodeType >( sourceModel()->data( left, QgsProcessingToolboxModel::RoleNodeType ).toInt() );
QgsProcessingToolboxModelNode::NodeType rightType = static_cast< QgsProcessingToolboxModelNode::NodeType >( sourceModel()->data( right, QgsProcessingToolboxModel::RoleNodeType ).toInt() );

if ( leftType != rightType )
if ( leftType == QgsProcessingToolboxModelNode::NodeRecent )
return true;
else if ( rightType == QgsProcessingToolboxModelNode::NodeRecent )
return false;
else if ( leftType != rightType )
{
if ( leftType == QgsProcessingToolboxModelNode::NodeProvider )
return false;
Expand Down
15 changes: 14 additions & 1 deletion tests/src/gui/testqgsprocessingmodel.cpp
Expand Up @@ -382,8 +382,14 @@ void TestQgsProcessingModel::testModel()

void TestQgsProcessingModel::testProxyModel()
{
QgsSettings().clear();
QgsProcessingRegistry registry;
QgsProcessingToolboxProxyModel model( nullptr, &registry );
QgsProcessingRecentAlgorithmLog recentLog;
QgsProcessingToolboxProxyModel model( nullptr, &registry, &recentLog );

#ifdef ENABLE_MODELTEST
new ModelTest( &model, this ); // for model validity checking
#endif

// add a provider
DummyAlgorithm *a1 = new DummyAlgorithm( "a1", "group2", QgsProcessingAlgorithm::FlagHideFromModeler );
Expand Down Expand Up @@ -510,6 +516,13 @@ void TestQgsProcessingModel::testProxyModel()
QCOMPARE( model.data( model.index( 0, 0, group2Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString(), QStringLiteral( "p2:a1" ) );

model.setFilterString( QString() );
QCOMPARE( model.rowCount(), 4 );

// check sort order of recent algorithms
recentLog.push( QStringLiteral( "qgis:a1" ) );
QCOMPARE( model.rowCount(), 5 );
QModelIndex recentIndex = model.index( 0, 0, QModelIndex() );
QCOMPARE( model.data( recentIndex, Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );

// inactive provider - should not be visible
QCOMPARE( model.rowCount(), 4 );
Expand Down

0 comments on commit 9de2cc3

Please sign in to comment.