Skip to content

Commit

Permalink
Start on recent item proxy handling
Browse files Browse the repository at this point in the history
  • 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.