[Qgis-developer] Composer Management

Larry Shaffer larrys at dakotacarto.com
Thu Feb 28 08:38:15 PST 2013


Hi,

On Thu, Feb 28, 2013 at 12:01 AM, Bernhard Ströbl
<bernhard.stroebl at jena.de>wrote:

> Hi Kelly,
>
> I am doing something similar for my company but I am developing it for the
> next release, because master has QgsComposition::**loadFromTemplate
> method, which 1.8 has not.
>
> However to get a new printComposer you can use
> self.iface.**actionPrintComposer().trigger(**)
> which adds a new composer to the project's list of composers.


In master branch, and in the last week, the actionPrintComposer() (i.e.
QgisApp::createNewComposer) action will now present the user with a dialog
to help choose a unique composer title, before the composer is created.
Since iface.actionPrintComposer().trigger() still appears to be the best
means of programmatically creating a new composer, this presents an issue.

There are a couple of possible solutions:

* Expose Qgis::createNewComposer in iface (which returns pointer to new
composer). Maybe adding duplicateComposer, deleteComposer and
deletePrintComposers, as well. Makes the most sense to me. New PyQGIS code
would be different from 1.8.

* Add a preference in Options for turning it on/off (e.g. [x] Prompt for
composer name), and maybe simple get/set methods to QgisApp and iface. New
PyQGIS code would require a couple of lines of additional code if the
prompt was not to be shown.

* Use a different action in the GUI than actionPrintComposer(). Might lead
to some confusion, having semi-redundant actions. New PyQGIS code remains
identical to 1.8.


But AFAIK you can not load a template into it with 1.8
>

I think this is possible. QgsComposition has readXML and addItemsFromXML
exposed in 1.8 [0]. If you look at loadFromTemplate [1], the initial
routines are for clearing a composition's existing items (btw: I think that
is bad. IMO loading from a template should always be in a fresh composer).
Not a concern if you are starting with a fresh composer anyway. After that,
there is substitution replacement (not sure if relevant to 1.8), reading of
the XML doc, then adding the items, all of which should be doable in
Python, unless I am mistaken.

[0] http://qgis.org/api/1.8/classQgsComposition.html
[1]
https://github.com/qgis/Quantum-GIS/blob/master/src/core/composer/qgscomposition.cpp#L382

Regards,

Larry

Bernhard
>
> Am 28.02.2013 03:38, schrieb Kelly Thomas:
>
>> Hello,
>>
>>
>> I am building a python plugin for QGIS 1.8 and am trying to manipulate
>> the map composers.
>>
>> The goal is to load a template, customise a few elements, and then leave
>> the composer window up for the user to modify / print / etc.
>>
>> I know that current composers can be listed by calling qgis.utils.iface.*
>> *activeComposers().
>>
>> However I have been unable to create or destroy composer windows without
>> resorting to spoofing user input to the composer manager dialog!
>>
>> Is there a technique by which I can add/remove composers programmatically?
>>
>> Thanks,
>> Kelly Thomas
>> ______________________________**_________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/**mailman/listinfo/qgis-**developer<http://lists.osgeo.org/mailman/listinfo/qgis-developer>
>>
>>
>> __________ Information from ESET Mail Security, version of virus
>> signature database 8058 (20130227) __________
>>
>> The message was checked by ESET Mail Security.
>> http://www.eset.com
>>
>>
>>
>
> __________ Information from ESET Mail Security, version of virus signature
> database 8058 (20130227) __________
>
> The message was checked by ESET Mail Security.
> http://www.eset.com
>
>
> ______________________________**_________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/**mailman/listinfo/qgis-**developer<http://lists.osgeo.org/mailman/listinfo/qgis-developer>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130228/ceca7b49/attachment-0001.html>


More information about the Qgis-developer mailing list