[QGIS-Developer] QgsLayout returns different types on different platforms

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[QGIS-Developer] QgsLayout returns different types on different platforms

Adam Borczyk
Hi all,
Using PyQGIS I load a layout .qpt file, then I access items in the composition. I do it using

        document = QDomDocument()
        document.setContent(content) # content is .qpt file content
        composition = QgsPrintLayout( QgsProject.instance() )
        composition.loadFromTemplate( document, QgsReadWriteContext() )
       
        map_item = composition.itemById('main_map')
        map_item.setExtent(canvas.extent())


Now map_item is of type QgsLayoutItemMap while I'm on Ubuntu, but it is QgsLayoutItem when I use Windows and therefore I receive an error (QgsLayoutItem does not have setExtent method). Does anybody have an idea why this happens?

Ubuntu 16.04 x64 + QGIS 3.0.2 with Python 3.5.2 installed last week
Windows 7 x64 + QGIS 3.0.3 with Python 3.6.0 (fresh now from OSGeo Installer)

Best regards
Adam Borczyk

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: QgsLayout returns different types on different platforms

Tim Sutton-6
Hi

It is probably a well known issue with SIP bindings not recognising the object type returned for the layout. A work around is here:


Regards

Tim

On 25 May 2018, at 19:51, Adam Borczyk <[hidden email]> wrote:

Hi all,
Using PyQGIS I load a layout .qpt file, then I access items in the composition. I do it using

        document = QDomDocument()
        document.setContent(content) # content is .qpt file content
        composition = QgsPrintLayout( QgsProject.instance() )
        composition.loadFromTemplate( document, QgsReadWriteContext() )
       
        map_item = composition.itemById('main_map')
        map_item.setExtent(canvas.extent())


Now map_item is of type QgsLayoutItemMap while I'm on Ubuntu, but it is QgsLayoutItem when I use Windows and therefore I receive an error (QgsLayoutItem does not have setExtent method). Does anybody have an idea why this happens?

Ubuntu 16.04 x64 + QGIS 3.0.2 with Python 3.5.2 installed last week
Windows 7 x64 + QGIS 3.0.3 with Python 3.6.0 (fresh now from OSGeo Installer)

Best regards
Adam Borczyk
_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer








Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net


_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QgsLayout returns different types on different platforms

Adam Borczyk
Thanks a lot Tim, I'll give it a try. Looks like it's API 2 workaround and the issue propagated to API 3 as well?

Adam Borczyk

---------------------------------

GIS Support Sp. z o.o.

Dobrzańskiego 3, Lublin 20-262

tel. +48 81 451 14 90, NIP: 9462641761


On 25 May 2018 at 21:43, Tim Sutton <[hidden email]> wrote:
Hi

It is probably a well known issue with SIP bindings not recognising the object type returned for the layout. A work around is here:


Regards

Tim

On 25 May 2018, at 19:51, Adam Borczyk <[hidden email]> wrote:

Hi all,
Using PyQGIS I load a layout .qpt file, then I access items in the composition. I do it using

        document = QDomDocument()
        document.setContent(content) # content is .qpt file content
        composition = QgsPrintLayout( QgsProject.instance() )
        composition.loadFromTemplate( document, QgsReadWriteContext() )
       
        map_item = composition.itemById('main_map')
        map_item.setExtent(canvas.extent())


Now map_item is of type QgsLayoutItemMap while I'm on Ubuntu, but it is QgsLayoutItem when I use Windows and therefore I receive an error (QgsLayoutItem does not have setExtent method). Does anybody have an idea why this happens?

Ubuntu 16.04 x64 + QGIS 3.0.2 with Python 3.5.2 installed last week
Windows 7 x64 + QGIS 3.0.3 with Python 3.6.0 (fresh now from OSGeo Installer)

Best regards
Adam Borczyk
_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer








Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net



_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: QgsLayout returns different types on different platforms

Tim Sutton-6
Hi

On 25 May 2018, at 22:06, Adam Borczyk <[hidden email]> wrote:

Thanks a lot Tim, I'll give it a try. Looks like it's API 2 workaround and the issue propagated to API 3 as well?

Correct.

Regards

Tim


Adam Borczyk
---------------------------------
GIS Support Sp. z o.o.
tel. +48 81 451 14 90, NIP: 9462641761

On 25 May 2018 at 21:43, Tim Sutton <[hidden email]> wrote:
Hi

It is probably a well known issue with SIP bindings not recognising the object type returned for the layout. A work around is here:


Regards

Tim

On 25 May 2018, at 19:51, Adam Borczyk <[hidden email]> wrote:

Hi all,
Using PyQGIS I load a layout .qpt file, then I access items in the composition. I do it using

        document = QDomDocument()
        document.setContent(content) # content is .qpt file content
        composition = QgsPrintLayout( QgsProject.instance() )
        composition.loadFromTemplate( document, QgsReadWriteContext() )
       
        map_item = composition.itemById('main_map')
        map_item.setExtent(canvas.extent())


Now map_item is of type QgsLayoutItemMap while I'm on Ubuntu, but it is QgsLayoutItem when I use Windows and therefore I receive an error (QgsLayoutItem does not have setExtent method). Does anybody have an idea why this happens?

Ubuntu 16.04 x64 + QGIS 3.0.2 with Python 3.5.2 installed last week
Windows 7 x64 + QGIS 3.0.3 with Python 3.6.0 (fresh now from OSGeo Installer)

Best regards
Adam Borczyk
_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer



<KartozaNewLogoThumbnail.jpg>





Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net










Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net


_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QgsLayout returns different types on different platforms

Adam Borczyk
Just in case someone has similar problem - this workaround has some methods that probably don't have (or I haven't found them) equivalents in API 3 - iterating over QgsPrintLayout did return a list of objects and their correct types, but except for the map. Map item was described as QgsLayoutItem instead of QgsLayoutItemMap and the only way I found to get QgsLayoutItemMap object was to use .referenceMap() method. Fortunately I only use one map per layout project, so it was enough. The workaround works fine for other types of objects.

Regards


On 25 May 2018 at 22:23, Tim Sutton <[hidden email]> wrote:
Hi

On 25 May 2018, at 22:06, Adam Borczyk <[hidden email]> wrote:

Thanks a lot Tim, I'll give it a try. Looks like it's API 2 workaround and the issue propagated to API 3 as well?

Correct.

Regards

Tim


Adam Borczyk
---------------------------------
GIS Support Sp. z o.o.
tel. +48 81 451 14 90, NIP: 9462641761

On 25 May 2018 at 21:43, Tim Sutton <[hidden email]> wrote:
Hi

It is probably a well known issue with SIP bindings not recognising the object type returned for the layout. A work around is here:


Regards

Tim

On 25 May 2018, at 19:51, Adam Borczyk <[hidden email]> wrote:

Hi all,
Using PyQGIS I load a layout .qpt file, then I access items in the composition. I do it using

        document = QDomDocument()
        document.setContent(content) # content is .qpt file content
        composition = QgsPrintLayout( QgsProject.instance() )
        composition.loadFromTemplate( document, QgsReadWriteContext() )
       
        map_item = composition.itemById('main_map')
        map_item.setExtent(canvas.extent())


Now map_item is of type QgsLayoutItemMap while I'm on Ubuntu, but it is QgsLayoutItem when I use Windows and therefore I receive an error (QgsLayoutItem does not have setExtent method). Does anybody have an idea why this happens?

Ubuntu 16.04 x64 + QGIS 3.0.2 with Python 3.5.2 installed last week
Windows 7 x64 + QGIS 3.0.3 with Python 3.6.0 (fresh now from OSGeo Installer)

Best regards
Adam Borczyk
_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer



<KartozaNewLogoThumbnail.jpg>





Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net










Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net



_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer