Skip to content

Commit 9de2cc3

Browse files
committedJul 16, 2018
Start on recent item proxy handling
1 parent 2efc08e commit 9de2cc3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

‎src/gui/processing/qgsprocessingtoolboxmodel.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,11 @@ bool QgsProcessingToolboxProxyModel::lessThan( const QModelIndex &left, const QM
720720
QgsProcessingToolboxModelNode::NodeType leftType = static_cast< QgsProcessingToolboxModelNode::NodeType >( sourceModel()->data( left, QgsProcessingToolboxModel::RoleNodeType ).toInt() );
721721
QgsProcessingToolboxModelNode::NodeType rightType = static_cast< QgsProcessingToolboxModelNode::NodeType >( sourceModel()->data( right, QgsProcessingToolboxModel::RoleNodeType ).toInt() );
722722

723-
if ( leftType != rightType )
723+
if ( leftType == QgsProcessingToolboxModelNode::NodeRecent )
724+
return true;
725+
else if ( rightType == QgsProcessingToolboxModelNode::NodeRecent )
726+
return false;
727+
else if ( leftType != rightType )
724728
{
725729
if ( leftType == QgsProcessingToolboxModelNode::NodeProvider )
726730
return false;

‎tests/src/gui/testqgsprocessingmodel.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,14 @@ void TestQgsProcessingModel::testModel()
382382

383383
void TestQgsProcessingModel::testProxyModel()
384384
{
385+
QgsSettings().clear();
385386
QgsProcessingRegistry registry;
386-
QgsProcessingToolboxProxyModel model( nullptr, &registry );
387+
QgsProcessingRecentAlgorithmLog recentLog;
388+
QgsProcessingToolboxProxyModel model( nullptr, &registry, &recentLog );
389+
390+
#ifdef ENABLE_MODELTEST
391+
new ModelTest( &model, this ); // for model validity checking
392+
#endif
387393

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

512518
model.setFilterString( QString() );
519+
QCOMPARE( model.rowCount(), 4 );
520+
521+
// check sort order of recent algorithms
522+
recentLog.push( QStringLiteral( "qgis:a1" ) );
523+
QCOMPARE( model.rowCount(), 5 );
524+
QModelIndex recentIndex = model.index( 0, 0, QModelIndex() );
525+
QCOMPARE( model.data( recentIndex, Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );
513526

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

0 commit comments

Comments
 (0)
Please sign in to comment.