[Qgis-developer] QgsMapLayerAction and QgsAttributeAction
Matthias Kuhn
matthias.kuhn at gmx.ch
Tue Aug 12 03:42:55 PDT 2014
On 12.08.2014 06:34, Nyall Dawson wrote:
> On 12 August 2014 01:25, Matthias Kuhn <matthias.kuhn at gmx.ch> wrote:
>
>> While working on this, I stumbled upon the class QgsMapLayerAction which
>> I am having a hard time to understand the purpose of.
>>
>> Some comments in qgsdualview.cpp suggest that it is related to user
>> defined actions vs standard actions [1]. I wondered also if it is
>> related to vector layer vs raster layer (as QgsMapLayer is a common base
>> class of the two and QgsMapLayerAction therefore might be interpreted as
>> "also valid for raster layers").
> I can help you out here - QgsMapLayerActions are built-in c++ actions,
> or actions which are defined by a python plugin. Unlike the standard
> vector layer actions, these are not editable by users, and are not
> listed in the vector layer properties dialog. As far as I'm aware,
> there's only a single implementation currently in QGIS:
> https://github.com/qgis/QGIS/blob/master/src/app/composer/qgscomposer.cpp#L3566
> This action allows users to jump directly to a specific atlas feature,
> and is only shown for vector layers which are set as the coverage
> layer for a composition.
>
> There's also some useful sample python code on how these actions can
> be used here:
> http://gis.stackexchange.com/a/94665/28443
>
> Nyall
Thank you for the explanation.
I also figured out, that they can be layer independent in contrast to
the attribute actions which are always defined for a specific layer.
As I am working on a menu, I am more interested in listing/triggering
the action than creating a new one (like the one in your link).
>From this point (usage/triggering) there is not much difference as far
as I can tell. So I think that it would be good to be able to query them
in one particular place. Therefore I wondered, what you think about also
exposing the attribute actions (custom) in the MapLayerActionRegistry?
I also have noticed, that the MapLayerActions are a subclass of the type
QAction, but I don't think they can be used like that (I did not test,
so please correct me if I am wrong. I just noticed that the trigger
method is not connected, so if you add them to a menu there is not much
happening I think). If this is true, I think it would not be nice to get
a fully functional QAction similar to QgsAttributeTableMapLayerAction,
that adds exactly this functionality around QgsMapLayerAction.
Then there is only one small bit left - as far as I can tell - that is
different between the two action types, which is that the custom actions
support a type of "parameter" by substitution which allows to run them
for a certain attribute or coordinate.
Do you have any comments on these thoughts?
Matthias
More information about the Qgis-developer
mailing list