Skip to content
Permalink
Browse files

Fix some model issues

  • Loading branch information
nyalldawson committed Jul 8, 2018
1 parent 636c3fe commit 2efc08e960eaaac41528729254289d3603f36011
@@ -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();
}
@@ -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 ) )
@@ -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();
}
@@ -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
@@ -22,6 +22,12 @@

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

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


class DummyAlgorithm : public QgsProcessingAlgorithm
{
public:
@@ -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() );

0 comments on commit 2efc08e

Please sign in to comment.
You can’t perform that action at this time.