Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Auto add recent algs when run
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 670f408 commit 1793790
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
57 changes: 46 additions & 11 deletions src/gui/processing/qgsprocessingtoolboxmodel.cpp
Expand Up @@ -117,6 +117,9 @@ QgsProcessingToolboxModel::QgsProcessingToolboxModel( QObject *parent, QgsProces
{
rebuild();

if ( mRecentLog )
connect( mRecentLog, &QgsProcessingRecentAlgorithmLog::changed, this, [ = ] { repopulateRecentAlgorithms(); } );

connect( mRegistry, &QgsProcessingRegistry::providerAdded, this, &QgsProcessingToolboxModel::providerAdded );
connect( mRegistry, &QgsProcessingRegistry::providerRemoved, this, &QgsProcessingToolboxModel::providerRemoved );
}
Expand All @@ -126,22 +129,14 @@ void QgsProcessingToolboxModel::rebuild()
beginResetModel();

mRootNode->deleteChildren();
mRecentNode = nullptr;

if ( mRecentLog )
{
std::unique_ptr< QgsProcessingToolboxModelRecentNode > recentNode = qgis::make_unique< QgsProcessingToolboxModelRecentNode >();
QgsProcessingToolboxModelRecentNode *parentNode = recentNode.get();
mRecentNode = recentNode.get();
mRootNode->addChildNode( recentNode.release() );
const QStringList recentAlgIds = mRecentLog->recentAlgorithmIds();
for ( const QString &id : recentAlgIds )
{
const QgsProcessingAlgorithm *algorithm = mRegistry->algorithmById( id );
if ( algorithm )
{
std::unique_ptr< QgsProcessingToolboxModelAlgorithmNode > algorithmNode = qgis::make_unique< QgsProcessingToolboxModelAlgorithmNode >( algorithm, mRegistry );
parentNode->addChildNode( algorithmNode.release() );
}
}
repopulateRecentAlgorithms();
}

const QList< QgsProcessingProvider * > providers = mRegistry->providers();
Expand All @@ -152,6 +147,46 @@ void QgsProcessingToolboxModel::rebuild()
endResetModel();
}

void QgsProcessingToolboxModel::repopulateRecentAlgorithms( bool resetting )
{
if ( !mRecentNode )
return;

if ( !resetting && rowCount( index( 0, 0 ) ) > 0 )
{
beginRemoveRows( index( 0, 0 ), 0, rowCount( index( 0, 0 ) ) );
mRecentNode->deleteChildren();
endRemoveRows();
}

const QStringList recentAlgIds = mRecentLog->recentAlgorithmIds();
QList< const QgsProcessingAlgorithm * > recentAlgorithms;
recentAlgorithms.reserve( recentAlgIds.count() );
for ( const QString &id : recentAlgIds )
{
const QgsProcessingAlgorithm *algorithm = mRegistry->algorithmById( id );
if ( algorithm )
recentAlgorithms << algorithm;
}

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

for ( const QgsProcessingAlgorithm *algorithm : recentAlgorithms )
{
std::unique_ptr< QgsProcessingToolboxModelAlgorithmNode > algorithmNode = qgis::make_unique< QgsProcessingToolboxModelAlgorithmNode >( algorithm, mRegistry );
mRecentNode->addChildNode( algorithmNode.release() );
}

if ( !resetting )
{
endInsertRows();
}

}

void QgsProcessingToolboxModel::providerAdded( const QString &id )
{
QgsProcessingProvider *provider = mRegistry->providerById( id );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/processing/qgsprocessingtoolboxmodel.h
Expand Up @@ -362,6 +362,7 @@ class GUI_EXPORT QgsProcessingToolboxModel : public QAbstractItemModel
private slots:

void rebuild();
void repopulateRecentAlgorithms( bool resetting = false );
void providerAdded( const QString &id );
void providerRemoved( const QString &id );

Expand All @@ -371,6 +372,7 @@ class GUI_EXPORT QgsProcessingToolboxModel : public QAbstractItemModel
QgsProcessingRecentAlgorithmLog *mRecentLog = nullptr;

std::unique_ptr< QgsProcessingToolboxModelGroupNode > mRootNode;
QgsProcessingToolboxModelRecentNode *mRecentNode = nullptr;

void addProvider( QgsProcessingProvider *provider );

Expand Down

0 comments on commit 1793790

Please sign in to comment.