Skip to content
Permalink
Browse files
Merge pull request #4279 from nyalldawson/layout_manager2
Rework handling of compositions and projects, and composer windows
  • Loading branch information
nyalldawson committed Mar 21, 2017
2 parents c412596 + ab11dfb commit f0709ae31e46774e872c904cf11032ad266a35fe
Showing with 1,660 additions and 1,495 deletions.
  1. +14 −1 doc/api_break.dox
  2. +20 −18 python/core/composer/qgscomposeritem.sip
  3. +0 −6 python/core/composer/qgscomposermap.sip
  4. +11 −54 python/core/composer/qgscomposition.sip
  5. +34 −0 python/core/composer/qgslayoutmanager.sip
  6. +1 −0 python/core/core.sip
  7. +4 −5 python/core/qgsproject.sip
  8. +1 −0 python/gui/gui.sip
  9. +7 −44 python/gui/qgisinterface.sip
  10. +15 −0 python/gui/qgscomposerinterface.sip
  11. +169 −612 src/app/composer/qgscomposer.cpp
  12. +36 −110 src/app/composer/qgscomposer.h
  13. +151 −184 src/app/composer/qgscomposermanager.cpp
  14. +27 −22 src/app/composer/qgscomposermanager.h
  15. +4 −0 src/app/composer/qgscomposermapwidget.cpp
  16. +157 −122 src/app/qgisapp.cpp
  17. +35 −15 src/app/qgisapp.h
  18. +21 −35 src/app/qgisappinterface.cpp
  19. +3 −24 src/app/qgisappinterface.h
  20. +4 −3 src/app/qgsprojectproperties.cpp
  21. +2 −0 src/core/CMakeLists.txt
  22. +1 −1 src/core/composer/qgscomposerattributetablev2.cpp
  23. +8 −0 src/core/composer/qgscomposeritem.cpp
  24. +32 −2 src/core/composer/qgscomposeritem.h
  25. +10 −15 src/core/composer/qgscomposerlabel.cpp
  26. +2 −2 src/core/composer/qgscomposerlabel.h
  27. +3 −0 src/core/composer/qgscomposerlegend.cpp
  28. +14 −7 src/core/composer/qgscomposermap.cpp
  29. +10 −15 src/core/composer/qgscomposermap.h
  30. +2 −1 src/core/composer/qgscomposermousehandles.h
  31. +35 −128 src/core/composer/qgscomposition.cpp
  32. +10 −25 src/core/composer/qgscomposition.h
  33. +234 −0 src/core/composer/qgslayoutmanager.cpp
  34. +149 −0 src/core/composer/qgslayoutmanager.h
  35. +17 −0 src/core/qgsproject.cpp
  36. +16 −1 src/core/qgsproject.h
  37. +1 −0 src/gui/CMakeLists.txt
  38. +35 −24 src/gui/qgisinterface.h
  39. +67 −0 src/gui/qgscomposerinterface.h
  40. +1 −2 src/gui/qgscomposerview.cpp
  41. +2 −2 src/ui/composer/qgscomposermanagerbase.ui
  42. +2 −2 tests/src/core/testqgsatlascomposition.cpp
  43. +6 −6 tests/src/core/testqgscomposergroup.cpp
  44. +1 −1 tests/src/core/testqgscomposermap.cpp
  45. +1 −0 tests/src/python/CMakeLists.txt
  46. +2 −4 tests/src/python/test_qgscomposermap.py
  47. +281 −0 tests/src/python/test_qgslayoutmanager.py
  48. +2 −2 tests/src/python/test_qgsserver.py
  49. BIN ...ta/control_images/composer_map/expected_composermap_crs3857/expected_composermap_crs3857_mask.png
  50. BIN ...ta/control_images/composer_map/expected_composermap_crs4326/expected_composermap_crs4326_mask.png
  51. BIN .../testdata/control_images/qgis_server/WMS_GetLegendGraphic_test/WMS_GetLegendGraphic_test_mask.png
  52. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Background/WMS_GetMap_Background_mask.png
  53. BIN .../testdata/control_images/qgis_server/WMS_GetMap_Background_Hex/WMS_GetMap_Background_Hex_mask.png
  54. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic/WMS_GetMap_Basic_mask.png
  55. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter/WMS_GetMap_Filter_mask.png
  56. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_LayerOrder/WMS_GetMap_LayerOrder_mask.png
  57. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Opacities/WMS_GetMap_Opacities_mask.png
  58. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_SRS/WMS_GetMap_SRS_mask.png
  59. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Selection/WMS_GetMap_Selection_mask.png
  60. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_StyleCustom/WMS_GetMap_StyleCustom_mask.png
  61. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_StyleDefault/WMS_GetMap_StyleDefault_mask.png
  62. BIN tests/testdata/control_images/qgis_server/WMS_GetPrint_Basic/WMS_GetPrint_Basic_mask.png
  63. BIN tests/testdata/control_images/qgis_server/WMS_GetPrint_Grid/WMS_GetPrint_Grid_mask.png
  64. BIN tests/testdata/control_images/qgis_server/WMS_GetPrint_Rotation/WMS_GetPrint_Rotation_mask.png
  65. BIN tests/testdata/control_images/qgis_server/WMS_GetPrint_Scale/WMS_GetPrint_Scale_mask.png
  66. BIN tests/testdata/control_images/qgis_server/WMS_GetPrint_Selection/WMS_GetPrint_Selection_mask.png
@@ -365,6 +365,14 @@ QgisInterface {#qgis_api_break_3_0_QgisInterface}
- fileMenu() has been removed, use projectMenu() instead.
- actionRemoveLayer was removed as it no longer exists.
- actionTouch was removed, as the corresponding action no longer exists (see notes on QgsMapToolTouch)
- activeComposers(), createNewComposer(), duplicateComposer(), deleteComposer(), composerAdded(),
composerWillBeRemoved(), composerRemoved() were all removed. Composer windows are now only created
on demand, and destroyed when the window is closed. The new interface methods openComposers(),
openComposer(), closeComposer(), composerOpened(), composerWillBeClosed() and composerClosed()
are similar, but only apply to composer windows when they are exist. To access all compositions
from a project, the new QgsProject.instance().layoutManager() class should be used instead.
Additionally, the new interface methods work with QgsComposerInterface objects instead
of QgsComposerView objects.


QgsAbstractGeometry {#qgis_api_break_3_0_QgsAbstractGeometry}
@@ -720,7 +728,12 @@ were removed. Use setSnapTolerance() and snapTolerance() instead.
- dataDefinedProperty() and setDataDefinedProperty() now use the QgsProperty framework instead
of QgsDataDefined objects.
- mapSettings() was removed. Use QgsComposerMap::mapSettings() instead.

- The composerArrowAdded, composerPolygonAdded, composerPolylineAdded, composerHtmlFrameAdded, composerItemGroupAdded,
composerLabelAdded, composerMapAdded, composerScaleBarAdded, composerLegendAdded, composerPictureAdded,
composerShapeAdded, and composerTableFrameAdded were removed. Use the general itemAdded signal instead to catch
all these item added events.
- addComposerMap no longer takes a setDefaultPreviewStyle argument.
- the mapsToRestore parameter has been removed from addItemsFromXml

QgsCoordinateReferenceSystem {#qgis_api_break_3_0_QgsCoordinateReferenceSystem}
----------------------------
@@ -544,26 +544,28 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
*/
void setIsGroupMember( const bool isGroupMember );

/** Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
* @note this method was added in version 2.4
* @see setCurrentExportLayer
*/
int numberExportLayers() const;

/** Sets the current layer to draw for exporting
* @param layerIdx can be set to -1 to draw all item layers, and must be less than numberExportLayers()
* @note this method was added in version 2.4
* @see numberExportLayers
*/
void setCurrentExportLayer( const int layerIdx = -1 );

/** Creates an expression context relating to the item's current state. The context includes
* scopes for global, project, composition, atlas and item properties.
* @note added in QGIS 2.12
*/
QgsExpressionContext createExpressionContext() const;




virtual int numberExportLayers() const;






virtual void setCurrentExportLayer( const int layerIdx = -1 );





virtual QgsExpressionContext createExpressionContext() const;
void setUpdatesEnabled( bool enabled );
bool updatesEnabled() const;

public slots:

@@ -318,12 +318,6 @@ class QgsComposerMap : QgsComposerItem
*/
void setAtlasMargin( double margin );

/** Sets whether updates to the composer map are enabled. */
void setUpdatesEnabled( bool enabled );

/** Returns whether updates to the composer map are enabled. */
bool updatesEnabled() const;

/** Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
@@ -253,32 +253,16 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
/** Reads settings from xml file*/
bool readXml( const QDomElement& compositionElem, const QDomDocument& doc );

/** Load a template document
* @param doc template document
* @param substitutionMap map with text to replace. Text needs to be enclosed by brackets (e.g. '[text]' )
* @param addUndoCommands whether or not to add undo commands
* @param clearComposition set to true to clear the existing composition and read all composition and
* atlas properties from the template. Set to false to only add new items from the template, without
* overwriting the existing items or composition settings.
*/
bool loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0,
bool addUndoCommands = false, const bool clearComposition = true );
void addItemsFromXml( const QDomElement &elem, const QDomDocument &doc,
bool addUndoCommands = false, QPointF *pos = 0, bool pasteInPlace = false );

/** Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
* @param elem items parent element, e.g. \verbatim <Composer> \endverbatim or \verbatim <ComposerItemClipboard> \endverbatim
* @param doc xml document
* @param mapsToRestore for reading from project file: set preview move 'rectangle' to all maps and save the preview states to show composer maps on demand
* @param addUndoCommands insert AddItem commands if true (e.g. for copy/paste)
* @param pos item position. Optional, take position from xml if 0
* @param pasteInPlace whether the position should be kept but mapped to the page origin. (the page is the page under to the mouse cursor)
* @note parameters mapsToRestore, addUndoCommands pos and pasteInPlace not available in python bindings
*/
void addItemsFromXml( const QDomElement& elem, const QDomDocument& doc );

/** Adds item to z list. Usually called from constructor of QgsComposerItem*/
void addItemToZList( QgsComposerItem* item );
/** Removes item from z list. Usually called from destructor of QgsComposerItem*/
void removeItemFromZList( QgsComposerItem* item );
void addItemToZList( QgsComposerItem *item );

void removeItemFromZList( QgsComposerItem *item );


//functions to move selected items in hierarchy
void raiseSelectedItems();
@@ -382,7 +366,7 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
/** Adds label to the graphics scene and advises composer to create a widget for it (through signal)*/
void addComposerLabel( QgsComposerLabel* label );
/** Adds map to the graphics scene and advises composer to create a widget for it (through signal)*/
void addComposerMap( QgsComposerMap* map, const bool setDefaultPreviewStyle = true );
void addComposerMap( QgsComposerMap* map );
/** Adds scale bar to the graphics scene and advises composer to create a widget for it (through signal)*/
void addComposerScaleBar( QgsComposerScaleBar* scaleBar );
/** Adds legend to the graphics scene and advises composer to create a widget for it (through signal)*/
@@ -659,37 +643,10 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
void paperSizeChanged();
void nPagesChanged();
void printResolutionChanged();

/** Is emitted when selected item changed. If 0, no item is selected*/
void selectedItemChanged( QgsComposerItem* selected );
/** Is emitted when new composer arrow has been added to the view*/
void composerArrowAdded( QgsComposerArrow* arrow );
/** Is emitted when new composer polygon has been added to the view*/
void composerPolygonAdded( QgsComposerPolygon* polygon );
/** Is emitted when new composer polyline has been added to the view*/
void composerPolylineAdded( QgsComposerPolyline* polyline );
/** Is emitted when a new composer html has been added to the view*/
void composerHtmlFrameAdded( QgsComposerHtml* html, QgsComposerFrame* frame );
/** Is emitted when a new item group has been added to the view*/
void composerItemGroupAdded( QgsComposerItemGroup* group );
/** Is emitted when new composer label has been added to the view*/
void composerLabelAdded( QgsComposerLabel* label );
/** Is emitted when new composer map has been added to the view*/
void composerMapAdded( QgsComposerMap* map );
/** Is emitted when new composer scale bar has been added*/
void composerScaleBarAdded( QgsComposerScaleBar* scalebar );
/** Is emitted when a new composer legend has been added*/
void composerLegendAdded( QgsComposerLegend* legend );
/** Is emitted when a new composer picture has been added*/
void composerPictureAdded( QgsComposerPicture* picture );
/** Is emitted when a new composer shape has been added*/
void composerShapeAdded( QgsComposerShape* shape );
/** Is emitted when a new composer table frame has been added to the view*/
void composerTableFrameAdded( QgsComposerAttributeTableV2* table, QgsComposerFrame* frame );
/** Is emitted when a composer item has been removed from the scene*/
void itemRemoved( QgsComposerItem* );

/** Is emitted when item in the composition must be refreshed*/
void selectedItemChanged( QgsComposerItem *selected );
void itemAdded( QgsComposerItem *item );
void composerItemGroupAdded( QgsComposerItemGroup *group );
void itemRemoved( QgsComposerItem * );
void refreshItemsTriggered();

/** Is emitted when the composition has an updated status bar message for the composer window*/
@@ -0,0 +1,34 @@

class QgsLayoutManager : QObject
{
%TypeHeaderCode
#include <qgslayoutmanager.h>
%End
public:

explicit QgsLayoutManager( QgsProject* project /TransferThis/ = 0 );

~QgsLayoutManager();
bool addComposition( QgsComposition* composition /Transfer/ );
bool removeComposition( QgsComposition* composition );

void clear();
QList< QgsComposition * > compositions() const;
QgsComposition *compositionByName( const QString &name ) const;
bool readXml( const QDomElement &element, const QDomDocument &doc );
QDomElement writeXml( QDomDocument &doc ) const;
bool saveAsTemplate( const QString &name, QDomDocument &doc ) const;
QgsComposition *duplicateComposition( const QString &name, const QString &newName );
QString generateUniqueTitle() const;

signals:

void compositionAboutToBeAdded( const QString &name );
void compositionAdded( const QString &name );
void compositionRemoved( const QString &name );
void compositionAboutToBeRemoved( const QString &name );
void compositionRenamed( QgsComposition *composition, const QString &newName );


};

@@ -225,6 +225,7 @@
%Include composer/qgscomposerutils.sip
%Include composer/qgscomposition.sip
%Include composer/qgsdoubleboxscalebarstyle.sip
%Include composer/qgslayoutmanager.sip
%Include composer/qgsnumericscalebarstyle.sip
%Include composer/qgspaperitem.sip
%Include composer/qgsscalebarstyle.sip
@@ -309,12 +309,11 @@ class QgsProject : QObject, QgsExpressionContextGenerator
@return home path of project (or QString::null if not set) */
QString homePath() const;

QgsRelationManager* relationManager() const;
QgsRelationManager *relationManager() const;

/** Return pointer to the root (invisible) node of the project's layer tree
* @note added in 2.4
*/
QgsLayerTreeGroup* layerTreeRoot() const;
//const QgsLayoutManager *layoutManager() const;
QgsLayoutManager *layoutManager();
QgsLayerTreeGroup *layerTreeRoot() const;

/** Return pointer to the helper class that synchronizes map layer registry with layer tree
* @note added in 2.4
@@ -44,6 +44,7 @@
%Include qgscolorschemelist.sip
%Include qgscolorswatchgrid.sip
%Include qgscolorwidgets.sip
%Include qgscomposerinterface.sip
%Include qgscomposeritemcombobox.sip
%Include qgscomposerruler.sip
%Include qgscomposerview.sip
@@ -210,28 +210,10 @@ class QgisInterface : QObject
/** Adds a widget to the user input tool bar.*/
virtual void addUserInputWidget( QWidget* widget ) = 0;

/** Return mainwindows / composer views of running composer instances (currently only one) */
virtual QList<QgsComposerView*> activeComposers() = 0;
virtual QList<QgsComposerInterface *> openComposers() = 0;
virtual QgsComposerInterface *openComposer( QgsComposition *composition ) = 0;
virtual void closeComposer( QgsComposition *composition ) = 0;

/** Create a new composer
* @param title window title for new composer (one will be generated if empty)
* @return pointer to composer's view
* @note new composer window will be shown and activated
*/
virtual QgsComposerView* createNewComposer( const QString& title = QString() ) = 0;

/** Duplicate an existing parent composer from composer view
* @param composerView pointer to existing composer view
* @param title window title for duplicated composer (one will be generated if empty)
* @return pointer to duplicate composer's view
* @note duplicate composer window will be hidden until loaded, then shown and activated
*/
virtual QgsComposerView* duplicateComposer( QgsComposerView* composerView, const QString& title = QString() ) = 0;

/** Deletes parent composer of composer view, after closing composer window */
virtual void deleteComposer( QgsComposerView* composerView ) = 0;

/** Return changeable options built from settings and/or defaults */
virtual QMap<QString, QVariant> defaultStyleSheetOptions() = 0;

/** Generate stylesheet
@@ -527,29 +509,10 @@ class QgisInterface : QObject
virtual int messageTimeout() = 0;

signals:
/** Emitted whenever current (selected) layer changes.
* The pointer to layer can be null if no layer is selected
*/
void currentLayerChanged( QgsMapLayer * layer );

/**
* This signal is emitted when a new composer instance has been created
*/
void composerAdded( QgsComposerView* v );

/**
* This signal is emitted before a new composer instance is going to be removed
*/
void composerWillBeRemoved( QgsComposerView* v );

/** This signal is emitted when a composer instance has been removed
* @note added in version 2.9
*/
void composerRemoved( QgsComposerView* v );

/**
* This signal is emitted when the initialization is complete
*/
void currentLayerChanged( QgsMapLayer *layer );
void composerOpened( QgsComposerInterface *composer );
void composerWillBeClosed( QgsComposerInterface *composer );
void composerClosed( QgsComposerInterface *composer );
void initializationCompleted();
/** Emitted when a project file is successfully read
* @note
@@ -0,0 +1,15 @@
class QgsComposerInterface: QObject
{
%TypeHeaderCode
#include <qgscomposerinterface.h>
%End
public:
QgsComposerInterface( QObject *parent /TransferThis/ = 0 );

virtual ~QgsComposerInterface();
virtual QgsComposerView *view() = 0;
virtual QgsComposition *composition() = 0;
virtual void close() = 0;

};

0 comments on commit f0709ae

Please sign in to comment.