Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some model issues
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 636c3fe commit 2efc08e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/gui/processing/qgsprocessingtoolboxmodel.cpp
Expand Up @@ -152,9 +152,11 @@ void QgsProcessingToolboxModel::repopulateRecentAlgorithms( bool resetting )
if ( !mRecentNode )
return;

if ( !resetting && rowCount( index( 0, 0 ) ) > 0 )
QModelIndex recentIndex = index( 0, 0 );
const int prevCount = rowCount( recentIndex );
if ( !resetting && prevCount > 0 )
{
beginRemoveRows( index( 0, 0 ), 0, rowCount( index( 0, 0 ) ) );
beginRemoveRows( recentIndex, 0, prevCount - 1 );
mRecentNode->deleteChildren();
endRemoveRows();
}
Expand All @@ -174,7 +176,7 @@ void QgsProcessingToolboxModel::repopulateRecentAlgorithms( bool resetting )

if ( !resetting )
{
beginInsertRows( index( 0, 0 ), 0, recentAlgorithms.count() - 1 );
beginInsertRows( recentIndex, 0, recentAlgorithms.count() - 1 );
}

for ( const QgsProcessingAlgorithm *algorithm : qgis::as_const( recentAlgorithms ) )
Expand All @@ -199,7 +201,7 @@ void QgsProcessingToolboxModel::providerAdded( const QString &id )
if ( !isTopLevelProvider( id ) )
{
int previousRowCount = rowCount();
beginInsertRows( QModelIndex(), previousRowCount + 1, previousRowCount + 1 );
beginInsertRows( QModelIndex(), previousRowCount, previousRowCount );
addProvider( provider );
endInsertRows();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/src/gui/CMakeLists.txt
Expand Up @@ -44,6 +44,10 @@ INCLUDE_DIRECTORIES(SYSTEM
${QSCINTILLA_INCLUDE_DIR}
)

IF(ENABLE_MODELTEST)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/tests/qt_modeltest)
ENDIF(ENABLE_MODELTEST)

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
Expand Down
10 changes: 10 additions & 0 deletions tests/src/gui/testqgsprocessingmodel.cpp
Expand Up @@ -22,6 +22,12 @@

#include <QtTest/QSignalSpy>
#include "qgstest.h"

#ifdef ENABLE_MODELTEST
#include "modeltest.h"
#endif


class DummyAlgorithm : public QgsProcessingAlgorithm
{
public:
Expand Down Expand Up @@ -134,6 +140,10 @@ void TestQgsProcessingModel::testModel()
QgsProcessingRecentAlgorithmLog recentLog;
QgsProcessingToolboxModel model( nullptr, &registry, &recentLog );

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

QCOMPARE( model.columnCount(), 1 );
QCOMPARE( model.rowCount(), 1 );
QVERIFY( model.hasChildren() );
Expand Down

0 comments on commit 2efc08e

Please sign in to comment.