Skip to content

Commit

Permalink
Start on history item
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 6275960 commit 69ab3c9
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@
<file>themes/default/mActionIdentifyByRadius.svg</file>
<file>themes/default/mActionIdentifyByRectangle.svg</file>
<file>themes/default/mIndicatorEmbedded.svg</file>
<file>themes/default/mIconHistory.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
File renamed without changes
3 changes: 3 additions & 0 deletions python/gui/auto_additions/qgsprocessingtoolboxmodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/gui/processing/qgsprocessingtoolboxmodel.h
QgsProcessingToolboxProxyModel.Filters.baseClass = QgsProcessingToolboxProxyModel
Filters = QgsProcessingToolboxProxyModel # dirty hack since SIP seems to introduce the flags in module
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Abstract base class for nodes contained within a QgsProcessingToolboxModel.
sipType = sipType_QgsProcessingToolboxModelGroupNode;
else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeAlgorithm )
sipType = sipType_QgsProcessingToolboxModelAlgorithmNode;
else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeRecent )
sipType = sipType_QgsProcessingToolboxModelRecentNode;
}
else
sipType = 0;
Expand All @@ -47,6 +49,7 @@ Abstract base class for nodes contained within a QgsProcessingToolboxModel.
NodeProvider,
NodeGroup,
NodeAlgorithm,
NodeRecent,
};

~QgsProcessingToolboxModelNode();
Expand Down Expand Up @@ -93,6 +96,32 @@ Deletes all child nodes from this node.

};

class QgsProcessingToolboxModelRecentNode : QgsProcessingToolboxModelNode
{
%Docstring
Processing toolbox model node corresponding to the recent algorithms group

.. versionadded:: 3.2

.. warning::

Not part of stable API and may change in future QGIS releases.
%End

%TypeHeaderCode
#include "qgsprocessingtoolboxmodel.h"
%End
public:

QgsProcessingToolboxModelRecentNode();
%Docstring
Constructor for QgsProcessingToolboxModelRecentNode.
%End

virtual NodeType nodeType() const;

};

class QgsProcessingToolboxModelProviderNode : QgsProcessingToolboxModelNode
{
%Docstring
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/ProcessingPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def initGui(self):
self.menu.addAction(self.modelerAction)

self.historyAction = QAction(
QIcon(os.path.join(pluginPath, 'images', 'history.svg')),
QgsApplication.getThemeIcon("/mIconHistory.svg"),
QCoreApplication.translate('ProcessingPlugin', '&History…'), self.iface.mainWindow())
self.historyAction.setObjectName('historyAction')
self.historyAction.triggered.connect(self.openHistory)
Expand Down
14 changes: 13 additions & 1 deletion src/gui/processing/qgsprocessingtoolboxmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ void QgsProcessingToolboxModel::rebuild()

mRootNode->deleteChildren();

mRootNode->addChildNode( new QgsProcessingToolboxModelRecentNode() );

const QList< QgsProcessingProvider * > providers = mRegistry->providers();
for ( QgsProcessingProvider *provider : providers )
{
Expand Down Expand Up @@ -276,6 +278,10 @@ QVariant QgsProcessingToolboxModel::data( const QModelIndex &index, int role ) c
return QVariant();
}

bool isRecentNode = false;
if ( QgsProcessingToolboxModelNode *node = index2node( index ) )
isRecentNode = node->nodeType() == QgsProcessingToolboxModelNode::NodeRecent;

QgsProcessingProvider *provider = providerForIndex( index );
QgsProcessingToolboxModelGroupNode *groupNode = qobject_cast< QgsProcessingToolboxModelGroupNode * >( index2node( index ) );
const QgsProcessingAlgorithm *algorithm = algorithmForIndex( index );
Expand All @@ -293,6 +299,8 @@ QVariant QgsProcessingToolboxModel::data( const QModelIndex &index, int role ) c
return algorithm->displayName();
else if ( groupNode )
return groupNode->name();
else if ( isRecentNode )
return tr( "Recently used" );
else
return QVariant();

Expand Down Expand Up @@ -323,6 +331,8 @@ QVariant QgsProcessingToolboxModel::data( const QModelIndex &index, int role ) c
return provider->icon();
else if ( algorithm )
return algorithm->icon();
else if ( isRecentNode )
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconHistory.svg" ) );
else if ( !index.parent().isValid() )
// top level groups get the QGIS icon
return QgsApplication::getThemeIcon( QStringLiteral( "/providerQgis.svg" ) );
Expand Down Expand Up @@ -630,14 +640,16 @@ bool QgsProcessingToolboxProxyModel::filterAcceptsRow( int sourceRow, const QMod
}
}

bool isRecentNode = mModel->data( sourceIndex, QgsProcessingToolboxModel::RoleNodeType ).toInt() == QgsProcessingToolboxModelNode::NodeRecent;

if ( QgsProcessingProvider *provider = mModel->providerForIndex( sourceIndex ) )
{
return hasChildren && provider->isActive();
}
else
{
// group
return hasChildren;
return hasChildren || isRecentNode;
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/gui/processing/qgsprocessingtoolboxmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class GUI_EXPORT QgsProcessingToolboxModelNode : public QObject
sipType = sipType_QgsProcessingToolboxModelGroupNode;
else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeAlgorithm )
sipType = sipType_QgsProcessingToolboxModelAlgorithmNode;
else if ( node->nodeType() == QgsProcessingToolboxModelNode::NodeRecent )
sipType = sipType_QgsProcessingToolboxModelRecentNode;
}
else
sipType = 0;
Expand All @@ -64,6 +66,7 @@ class GUI_EXPORT QgsProcessingToolboxModelNode : public QObject
NodeProvider = 0, //!< Provider node
NodeGroup, //!< Group node
NodeAlgorithm, //!< Algorithm node
NodeRecent, //!< Recent algorithms node
};

~QgsProcessingToolboxModelNode() override;
Expand Down Expand Up @@ -121,6 +124,27 @@ class GUI_EXPORT QgsProcessingToolboxModelNode : public QObject

};

/**
* Processing toolbox model node corresponding to the recent algorithms group
* \ingroup gui
* \since QGIS 3.2
* \warning Not part of stable API and may change in future QGIS releases.
*/
class GUI_EXPORT QgsProcessingToolboxModelRecentNode : public QgsProcessingToolboxModelNode
{
Q_OBJECT

public:

/**
* Constructor for QgsProcessingToolboxModelRecentNode.
*/
QgsProcessingToolboxModelRecentNode() = default;

NodeType nodeType() const override { return NodeRecent; }

};

/**
* Processing toolbox model node corresponding to a Processing provider.
* \ingroup gui
Expand Down

0 comments on commit 69ab3c9

Please sign in to comment.