Skip to content

Commit

Permalink
[processing] Fix crash when right clicking toolbox outside of an item
Browse files Browse the repository at this point in the history
Fixes #20264
  • Loading branch information
nyalldawson committed Oct 30, 2018
1 parent 2f1dec9 commit a873289
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gui/processing/qgsprocessingtoolboxtreeview.cpp
Expand Up @@ -31,7 +31,7 @@ QgsProcessingToolboxTreeView::QgsProcessingToolboxTreeView( QWidget *parent,
void QgsProcessingToolboxTreeView::setRegistry( QgsProcessingRegistry *registry, QgsProcessingRecentAlgorithmLog *recentLog )
{
QgsProcessingToolboxProxyModel *newModel = new QgsProcessingToolboxProxyModel( this, registry, recentLog );
mToolboxModel = mModel->toolboxModel();
mToolboxModel = newModel->toolboxModel();
setModel( newModel );
mModel->deleteLater();
mModel = newModel;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/processing/qgsprocessingtoolboxtreeview.h
Expand Up @@ -109,6 +109,8 @@ class GUI_EXPORT QgsProcessingToolboxTreeView : public QTreeView
*/
QModelIndex findFirstVisibleAlgorithm( const QModelIndex &parent );

friend class TestQgsProcessingModel;

};

///@endcond
Expand Down
16 changes: 16 additions & 0 deletions tests/src/gui/testqgsprocessingmodel.cpp
Expand Up @@ -154,6 +154,10 @@ void TestQgsProcessingModel::testModel()
QVERIFY( !model.providerForIndex( model.index( 0, 0, QModelIndex() ) ) );
QVERIFY( !model.providerForIndex( model.index( 1, 0, QModelIndex() ) ) );
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
QVERIFY( model.index2node( QModelIndex() ) ); // root node
QCOMPARE( model.index2node( QModelIndex() )->nodeType(), QgsProcessingToolboxModelNode::NodeGroup );
QVERIFY( model.index2node( model.index( -1, 0, QModelIndex() ) ) ); // root node
QCOMPARE( model.index2node( QModelIndex() ), model.index2node( model.index( -1, 0, QModelIndex() ) ) );

// add a provider
DummyProvider *p1 = new DummyProvider( "p1", "provider1" );
Expand Down Expand Up @@ -559,6 +563,11 @@ void TestQgsProcessingModel::testView()
QgsProcessingRecentAlgorithmLog recentLog;
QgsProcessingToolboxTreeView view( nullptr, &registry, &recentLog );

// Check view model consistency
QVERIFY( view.mModel );
QVERIFY( view.mToolboxModel );
QCOMPARE( view.mModel->toolboxModel(), view.mToolboxModel );

QVERIFY( !view.algorithmForIndex( QModelIndex() ) );

// add a provider
Expand Down Expand Up @@ -636,6 +645,13 @@ void TestQgsProcessingModel::testView()
// but if it doesn't remove the selected one, that algorithm should not be deselected
view.setFilterString( QStringLiteral( "a" ) );
QCOMPARE( view.selectedAlgorithm()->id(), QStringLiteral( "p2:a1" ) );

// Check view model consistency after resetting registry
view.setRegistry( &registry );
QVERIFY( view.mModel );
QVERIFY( view.mToolboxModel );
QCOMPARE( view.mModel->toolboxModel(), view.mToolboxModel );

}

QGSTEST_MAIN( TestQgsProcessingModel )
Expand Down

0 comments on commit a873289

Please sign in to comment.