3

I would like to load a .qgs file and get a composer from it, but I can't figure out how. Is there a way, or do I have to read the xml myself and individually set the appropriate values for the composer?

My question is somewhat related to this question, only I don't want to specify composer attributes myself, just load them from a .qgs file.

Conley Owens
  • 251
  • 2
  • 6

2 Answers2

2

You will need to call the method QgsComposer.readXML(node) with the XML node representing the composer you want to load.

The QGIS desktop app does it this way:

  1. create a slot method that takes a parameter loadComposers(doc)
    1. Search for doc.elementsByTagName("Composer")
    2. Iterate over all found xml_nodes and
      1. Create a new QgsComposer
      2. Call composer.readXML(xml_node.toElement(), doc)
  2. connect QgsProject.instance().readProject to loadComposers(doc)
Matthias Kuhn
  • 27,780
  • 3
  • 88
  • 129
1

After having investigated the QGIS code, I'd decided that custom code needs to be created to store and load composer configurations. The QGIS desktop app does it all with custom classes and not the common library, so a standalone app written in python is going to have to do the same for the time being.

relevant files:

However, I'd be happy to be proven wrong.

Conley Owens
  • 251
  • 2
  • 6
  • I'm discovering QgsComposition has a readXml and addItemsFromXml which need to be called successively on the same element and then writeXml handles all the writing. Once I have a full working example, I'll post it. – Conley Owens Aug 30 '15 at 22:44