Skip to content
Permalink
Browse files

Auto add recent algs when run

  • Loading branch information
nyalldawson committed Jul 7, 2018
1 parent 670f408 commit 1793790f656394d0e7e6187a721e1f71f93a6a30
Showing with 48 additions and 11 deletions.
  1. +46 −11 src/gui/processing/qgsprocessingtoolboxmodel.cpp
  2. +2 −0 src/gui/processing/qgsprocessingtoolboxmodel.h
@@ -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 );
}
@@ -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();
@@ -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 );
@@ -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 );

@@ -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 );

0 comments on commit 1793790

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