Skip to content

Commit

Permalink
Merge pull request #4279 from nyalldawson/layout_manager2
Browse files Browse the repository at this point in the history
Rework handling of compositions and projects, and composer windows
  • Loading branch information
nyalldawson committed Mar 21, 2017
2 parents c412596 + ab11dfb commit f0709ae
Show file tree
Hide file tree
Showing 66 changed files with 1,660 additions and 1,495 deletions.
15 changes: 14 additions & 1 deletion doc/api_break.dox
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
----------------------------
Expand Down
38 changes: 20 additions & 18 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -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:

Expand Down
6 changes: 0 additions & 6 deletions python/core/composer/qgscomposermap.sip
Expand Up @@ -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
Expand Down
65 changes: 11 additions & 54 deletions python/core/composer/qgscomposition.sip
Expand Up @@ -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();
Expand Down Expand Up @@ -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)*/
Expand Down Expand Up @@ -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*/
Expand Down
34 changes: 34 additions & 0 deletions python/core/composer/qgslayoutmanager.sip
@@ -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 );


};

1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions python/core/qgsproject.sip
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -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
Expand Down
51 changes: 7 additions & 44 deletions python/gui/qgisinterface.sip
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions python/gui/qgscomposerinterface.sip
@@ -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.