Skip to content
Permalink
Browse files
Convert action ids to uuid
  • Loading branch information
m-kuhn committed Nov 16, 2016
1 parent 08d350c commit a6eb7b62811cb80dc2ccf3810dc168086d5d3380
@@ -33,6 +33,32 @@ class QgsAction
OpenUrl,
};

/**
* Default constructor
*/
QgsAction();

/**
* Create a new QgsAction
*
* @param type The type of this action
* @param description A human readable description string
* @param command The action text. Its interpretation depends on the type
* @param capture If this is set to true, the output will be captured when an action is run
*/
QgsAction( ActionType type, const QString& description, const QString& command, bool capture = false );

/**
* Create a new QgsAction
*
* @param type The type of this action
* @param description A human readable description string
* @param action The action text. Its interpretation depends on the type
* @param icon Path to an icon for this action
* @param capture If this is set to true, the output will be captured when an action is run
* @param shortTitle A short string used to label user interface elements like buttons
* @param actionScopes A set of scopes in which this action will be available
*/
QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, const QString& shortTitle = QString(), const QSet<QString>& actionScopes = QSet<QString>() );

//! The name of the action. This may be a longer description.
@@ -46,14 +72,14 @@ class QgsAction
*
* @note Added in QGIS 3.0
*/
QString id() const { return mShortTitle; }
QUuid id() const;

/**
* Returns true if this action was a default constructed one.
*
* @note Added in QGIS 3.0
*/
bool isValid() const { return !mShortTitle.isNull(); }
bool isValid() const;

//! The path to the icon
QString iconPath() const;
@@ -105,4 +131,20 @@ class QgsAction
* @note Added in QGIS 3.0
*/
void setActionScopes( const QSet<QString>& actionScopes );

/**
* Reads an XML definition from actionNode
* into this object.
*
* @note Added in QGIS 3.0
*/
void readXml( const QDomNode& actionNode );

/**
* Appends an XML definition for this action as a new
* child node to actionsNode.
*
* @note Added in QGIS 3.0
*/
void writeXml(QDomNode& actionsNode ) const;
};
@@ -44,15 +44,15 @@ class QgsActionManager
* any stdout from the process will be captured and displayed in a
* dialog box.
*/
void addAction( QgsAction::ActionType type, const QString& name, const QString& action, bool capture = false );
QUuid addAction(QgsAction::ActionType type, const QString& name, const QString& command, bool capture = false );

/** Add an action with the given name and action details.
* Will happily have duplicate names and actions. If
* capture is true, when running the action using doAction(),
* any stdout from the process will be captured and displayed in a
* dialog box.
*/
void addAction( QgsAction::ActionType type, const QString& name, const QString& action, const QString& icon, bool capture = false );
QUuid addAction(QgsAction::ActionType type, const QString& name, const QString& command, const QString& icon, bool capture = false );

/**
* Add a new action to this list.
@@ -63,31 +63,30 @@ class QgsActionManager
* field to be used if the action has a $currfield placeholder.
* @note available in python bindings as doActionFeature
*/
void doAction( const QString& actionId,
const QgsFeature &feat,
int defaultValueIndex = 0 ) /PyName=doActionFeature/;
void doAction(const QUuid& actionId, const QgsFeature& feature, int defaultValueIndex = 0 ) /PyName=doActionFeature/;

/** Does the action using the expression engine to replace any embedded expressions
* in the action definition.
* @param actionId action id
* @param feature feature to run action for
* @param context expression context to evalute expressions under
*/
void doAction( const QString& actionId,
const QgsFeature& feature,
const QgsExpressionContext& context );
void doAction( const QUuid& actionId, const QgsFeature& feature, const QgsExpressionContext& context );

//! Removes all actions
void clearActions();

//! List all actions
/**
* Return a list of actions that are available in the given action scope.
* If no action scope is provided, all actions will be returned.
*/
QList<QgsAction> listActions( const QString& actionScope = QString() ) const;

//! Return the layer
QgsVectorLayer* layer() const;

//! Writes the actions out in XML format
bool writeXml( QDomNode& layer_node, QDomDocument& doc ) const;
bool writeXml( QDomNode& layer_node ) const;

//! Reads the actions in in XML format
bool readXml( const QDomNode& layer_node );
@@ -97,15 +96,15 @@ class QgsActionManager
*
* @note Added in QGIS 3.0
*/
QgsAction action( const QString& id );
QgsAction action( const QUuid& id );

/**
* Each scope can have a default action. This will be saved in the project
* file.
*
* @note Added in QGIS 3.0
*/
void setDefaultAction( const QString& actionScope, const QString& actionId );
void setDefaultAction( const QString& actionScope, const QUuid& actionId );

/**
* Each scope can have a default action. This will be saved in the project
@@ -381,7 +381,7 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
/**
* Returns the action scope registry.
*
* @Note Added in QGIS 3.0
* @note Added in QGIS 3.0
*/
static QgsActionScopeRegistry* actionScopeRegistry();

@@ -229,7 +229,7 @@ class QgsAttributeTableAction : QAction
%End

public:
QgsAttributeTableAction( const QString &name, QgsDualView *dualView, const QString& action, const QModelIndex &fieldIdx );
QgsAttributeTableAction( const QString& name, QgsDualView* dualView, const QUuid& action, const QModelIndex& fieldIdx );

public slots:
void execute();
@@ -32,7 +32,7 @@
#include <QPushButton>
#include <QSettings>

QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *layer, const QString& actionId, int defaultAttr, QObject *parent )
QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *layer, const QUuid& actionId, int defaultAttr, QObject *parent )
: QAction( name, parent )
, mLayer( layer )
, mFeature( &f )
@@ -22,6 +22,7 @@
#include <QList>
#include <QPair>
#include <QAction>
#include <QUuid>

class QgsIdentifyResultsDialog;
class QgsVectorLayer;
@@ -33,7 +34,7 @@ class APP_EXPORT QgsFeatureAction : public QAction
Q_OBJECT

public:
QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *vl, const QString& actionId = QString(), int defaultAttr = -1, QObject *parent = nullptr );
QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *vl, const QUuid& actionId = QString(), int defaultAttr = -1, QObject *parent = nullptr );

public slots:
void execute();
@@ -59,7 +60,7 @@ class APP_EXPORT QgsFeatureAction : public QAction

QgsVectorLayer* mLayer;
QgsFeature* mFeature;
QString mActionId;
QUuid mActionId;
int mIdx;

bool mFeatureSaved;
@@ -91,3 +91,56 @@ void QgsAction::setActionScopes( const QSet<QString>& actionScopes )
{
mActionScopes = actionScopes;
}

void QgsAction::readXml( const QDomNode& actionNode )
{
QDomElement actionElement = actionNode.toElement();
QDomNodeList actionScopeNodes = actionElement.elementsByTagName( "actionScope" );

if ( actionScopeNodes.isEmpty() )
{
mActionScopes
<< QStringLiteral( "Canvas" )
<< QStringLiteral( "Field" )
<< QStringLiteral( "Feature" );
}
else
{
for ( int j = 0; j < actionScopeNodes.length(); ++j )
{
QDomElement actionScopeElem = actionScopeNodes.item( j ).toElement();
mActionScopes << actionScopeElem.attribute( "id" );
}
}

mType = static_cast< QgsAction::ActionType >( actionElement.attributeNode( QStringLiteral( "type" ) ).value().toInt() );
mDescription = actionElement.attributeNode( QStringLiteral( "name" ) ).value();
mCommand = actionElement.attributeNode( QStringLiteral( "action" ) ).value();
mIcon = actionElement.attributeNode( QStringLiteral( "icon" ) ).value();
mCaptureOutput = actionElement.attributeNode( QStringLiteral( "capture" ) ).value().toInt() != 0;
mShortTitle = actionElement.attributeNode( QStringLiteral( "shortTitle" ) ).value();
mId = QUuid( actionElement.attributeNode( QStringLiteral( "id" ) ).value() );
if ( mId.isNull() )
mId = QUuid::createUuid();
}

void QgsAction::writeXml( QDomNode& actionsNode ) const
{
QDomElement actionSetting = actionsNode.ownerDocument().createElement( QStringLiteral( "actionsetting" ) );
actionSetting.setAttribute( QStringLiteral( "type" ), mType );
actionSetting.setAttribute( QStringLiteral( "name" ), mDescription );
actionSetting.setAttribute( QStringLiteral( "shortTitle" ), mShortTitle );
actionSetting.setAttribute( QStringLiteral( "icon" ), mIcon );
actionSetting.setAttribute( QStringLiteral( "action" ), mCommand );
actionSetting.setAttribute( QStringLiteral( "capture" ), mCaptureOutput );
actionSetting.setAttribute( QStringLiteral( "id" ), mId.toString() );

Q_FOREACH ( const QString& scope, mActionScopes )
{
QDomElement actionScopeElem = actionsNode.ownerDocument().createElement( "actionScope" );
actionScopeElem.setAttribute( "id", scope );
actionSetting.appendChild( actionScopeElem );
}

actionsNode.appendChild( actionSetting );
}
@@ -20,6 +20,7 @@
#include <QString>
#include <QIcon>
#include <QAction>
#include <QUuid>

#include "qgsexpressioncontext.h"

@@ -53,14 +54,15 @@ class CORE_EXPORT QgsAction
*
* @param type The type of this action
* @param description A human readable description string
* @param action The action text. Its interpretation depends on the type
* @param command The action text. Its interpretation depends on the type
* @param capture If this is set to true, the output will be captured when an action is run
*/
QgsAction( ActionType type, const QString& description, const QString& action, bool capture )
QgsAction( ActionType type, const QString& description, const QString& command, bool capture = false )
: mType( type )
, mDescription( description )
, mCommand( action )
, mCommand( command )
, mCaptureOutput( capture )
, mId( QUuid::createUuid() )
{}

/**
@@ -82,6 +84,7 @@ class CORE_EXPORT QgsAction
, mCommand( action )
, mCaptureOutput( capture )
, mActionScopes( actionScopes )
, mId( QUuid::createUuid() )
{}

//! The name of the action. This may be a longer description.
@@ -95,14 +98,14 @@ class CORE_EXPORT QgsAction
*
* @note Added in QGIS 3.0
*/
QString id() const { return mShortTitle; }
QUuid id() const { return mId; }

/**
* Returns true if this action was a default constructed one.
*
* @note Added in QGIS 3.0
*/
bool isValid() const { return !mShortTitle.isNull(); }
bool isValid() const { return !mId.isNull(); }

//! The path to the icon
QString iconPath() const { return mIcon; }
@@ -161,6 +164,22 @@ class CORE_EXPORT QgsAction
*/
void setActionScopes( const QSet<QString>& actionScopes );

/**
* Reads an XML definition from actionNode
* into this object.
*
* @note Added in QGIS 3.0
*/
void readXml( const QDomNode& actionNode );

/**
* Appends an XML definition for this action as a new
* child node to actionsNode.
*
* @note Added in QGIS 3.0
*/
void writeXml( QDomNode& actionsNode ) const;

private:
ActionType mType;
QString mDescription;
@@ -170,6 +189,7 @@ class CORE_EXPORT QgsAction
bool mCaptureOutput;
QSet<QString> mActionScopes;
mutable QSharedPointer<QAction> mAction;
QUuid mId;
};

Q_DECLARE_METATYPE( QgsAction )

0 comments on commit a6eb7b6

Please sign in to comment.