Skip to content

Commit

Permalink
Work on recent item - todo sort by use, test filter, update on change
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 3e9648f commit 670f408
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ A sort/filter proxy model for providers and algorithms shown within the Processi
which automatically sorts the toolbox in a logical fashion and supports filtering
the results.

If \recentLog is specified then it will be used to create a "Recently used" top
level group containing recently used algorithms.

.. versionadded:: 3.2
%End

Expand All @@ -374,7 +377,9 @@ the results.
typedef QFlags<QgsProcessingToolboxProxyModel::Filter> Filters;


explicit QgsProcessingToolboxProxyModel( QObject *parent /TransferThis/ = 0, QgsProcessingRegistry *registry = 0 );
explicit QgsProcessingToolboxProxyModel( QObject *parent /TransferThis/ = 0,
QgsProcessingRegistry *registry = 0,
QgsProcessingRecentAlgorithmLog *recentLog = 0 );
%Docstring
Constructor for QgsProcessingToolboxProxyModel, with the given ``parent`` object.

Expand Down
20 changes: 17 additions & 3 deletions src/gui/processing/qgsprocessingtoolboxmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "qgsprocessingtoolboxmodel.h"
#include "qgsapplication.h"
#include "qgsprocessingregistry.h"
#include "qgsprocessingrecentalgorithmlog.h"
#include <functional>

#ifdef ENABLE_MODELTEST
Expand Down Expand Up @@ -128,7 +129,19 @@ void QgsProcessingToolboxModel::rebuild()

if ( mRecentLog )
{
mRootNode->addChildNode( new QgsProcessingToolboxModelRecentNode() );
std::unique_ptr< QgsProcessingToolboxModelRecentNode > recentNode = qgis::make_unique< QgsProcessingToolboxModelRecentNode >();
QgsProcessingToolboxModelRecentNode *parentNode = 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() );
}
}
}

const QList< QgsProcessingProvider * > providers = mRegistry->providers();
Expand Down Expand Up @@ -551,9 +564,10 @@ QModelIndex QgsProcessingToolboxModel::indexOfParentTreeNode( QgsProcessingToolb
// QgsProcessingToolboxProxyModel
//

QgsProcessingToolboxProxyModel::QgsProcessingToolboxProxyModel( QObject *parent, QgsProcessingRegistry *registry )
QgsProcessingToolboxProxyModel::QgsProcessingToolboxProxyModel( QObject *parent, QgsProcessingRegistry *registry,
QgsProcessingRecentAlgorithmLog *recentLog )
: QSortFilterProxyModel( parent )
, mModel( new QgsProcessingToolboxModel( parent, registry ) )
, mModel( new QgsProcessingToolboxModel( parent, registry, recentLog ) )
{
setSourceModel( mModel );
setDynamicSortFilter( true );
Expand Down
7 changes: 6 additions & 1 deletion src/gui/processing/qgsprocessingtoolboxmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ class GUI_EXPORT QgsProcessingToolboxModel : public QAbstractItemModel
* which automatically sorts the toolbox in a logical fashion and supports filtering
* the results.
*
* If \recentLog is specified then it will be used to create a "Recently used" top
* level group containing recently used algorithms.
*
* \ingroup gui
* \since QGIS 3.2
*/
Expand All @@ -418,7 +421,9 @@ class GUI_EXPORT QgsProcessingToolboxProxyModel: public QSortFilterProxyModel
* registry attached to QgsApplication::processingRegistry() will be used
* by the model.
*/
explicit QgsProcessingToolboxProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr, QgsProcessingRegistry *registry = nullptr );
explicit QgsProcessingToolboxProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr,
QgsProcessingRegistry *registry = nullptr,
QgsProcessingRecentAlgorithmLog *recentLog = nullptr );

/**
* Set \a filters that affect how toolbox content is filtered.
Expand Down

0 comments on commit 670f408

Please sign in to comment.