Skip to content
Permalink
Browse files

Merge pull request #4807 from nyalldawson/layout_item_registry

Create a layout item registry for item types
  • Loading branch information
nyalldawson committed Jul 6, 2017
2 parents f3a6df5 + ada01d8 commit ddf5acebe7d1f653c61f5b8b239271cc3b62b3fe
Showing with 2,120 additions and 5 deletions.
  1. +1 −0 python/CMakeLists.txt
  2. +4 −0 python/core/core_auto.sip
  3. +35 −0 python/core/layout/qgslayout.sip
  4. +62 −0 python/core/layout/qgslayoutitem.sip
  5. +178 −0 python/core/layout/qgslayoutitemregistry.sip
  6. +52 −0 python/core/layout/qgslayoutobject.sip
  7. +7 −1 python/core/qgsapplication.sip
  8. +1 −1 python/core/symbology-ng/qgssymbollayerregistry.sip
  9. +1 −0 python/gui/gui_auto.sip
  10. +57 −0 python/gui/layout/qgslayoutdesignerinterface.sip
  11. +41 −0 python/gui/qgisinterface.sip
  12. +7 −0 src/app/CMakeLists.txt
  13. +184 −0 src/app/layout/qgslayoutdesignerdialog.cpp
  14. +124 −0 src/app/layout/qgslayoutdesignerdialog.h
  15. +43 −0 src/app/qgisapp.cpp
  16. +42 −0 src/app/qgisapp.h
  17. +38 −0 src/app/qgisappinterface.cpp
  18. +4 −0 src/app/qgisappinterface.h
  19. +10 −0 src/core/CMakeLists.txt
  20. +23 −0 src/core/layout/qgslayout.cpp
  21. +41 −0 src/core/layout/qgslayout.h
  22. +65 −0 src/core/layout/qgslayoutitem.cpp
  23. +77 −0 src/core/layout/qgslayoutitem.h
  24. +79 −0 src/core/layout/qgslayoutitemregistry.cpp
  25. +272 −0 src/core/layout/qgslayoutitemregistry.h
  26. +27 −0 src/core/layout/qgslayoutobject.cpp
  27. +66 −0 src/core/layout/qgslayoutobject.h
  28. +8 −0 src/core/qgsapplication.cpp
  29. +8 −1 src/core/qgsapplication.h
  30. +1 −1 src/core/symbology-ng/qgssymbollayerregistry.h
  31. +4 −0 src/gui/CMakeLists.txt
  32. +64 −0 src/gui/layout/qgslayoutdesignerinterface.h
  33. +41 −0 src/gui/qgisinterface.h
  34. +2 −1 src/ui/CMakeLists.txt
  35. +111 −0 src/ui/layout/qgslayoutdesignerbase.ui
  36. +3 −0 tests/src/core/CMakeLists.txt
  37. +73 −0 tests/src/core/testqgslayout.cpp
  38. +179 −0 tests/src/core/testqgslayoutitem.cpp
  39. +85 −0 tests/src/core/testqgslayoutobject.cpp
  40. BIN tests/testdata/control_images/expected_layoutitem_debugrect/expected_layoutitem_debugrect.png
  41. BIN tests/testdata/control_images/expected_layoutitem_draw/expected_layoutitem_draw.png
@@ -123,6 +123,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
${CMAKE_SOURCE_DIR}/src/gui/effects
${CMAKE_SOURCE_DIR}/src/gui/layertree
${CMAKE_SOURCE_DIR}/src/gui/layout
${CMAKE_SOURCE_DIR}/src/gui/locator
${CMAKE_SOURCE_DIR}/src/plugins

@@ -153,6 +153,7 @@
%Include composer/qgscomposermultiframecommand.sip
%Include composer/qgscomposertexttable.sip
%Include composer/qgspaperitem.sip
%Include layout/qgslayout.sip
%Include layout/qgslayoutmeasurement.sip
%Include layout/qgslayoutmeasurementconverter.sip
%Include layout/qgspagesizeregistry.sip
@@ -371,6 +372,9 @@
%Include gps/qgsgpsdetector.sip
%Include gps/qgsnmeaconnection.sip
%Include gps/qgsgpsdconnection.sip
%Include layout/qgslayoutitem.sip
%Include layout/qgslayoutitemregistry.sip
%Include layout/qgslayoutobject.sip
%Include symbology-ng/qgscptcityarchive.sip
%Include symbology-ng/qgssvgcache.sip
%Include symbology-ng/qgsstyle.sip
@@ -0,0 +1,35 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayout.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/


class QgsLayout : QGraphicsScene
{
%Docstring
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayout.h"
%End
public:

QgsLayout();

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayout.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,62 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitem.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
{
%Docstring
Base class for graphical items within a QgsLayout.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutitem.h"
%End
public:

QgsLayoutItem( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItem, with the specified parent ``layout``.
%End

virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget );

%Docstring
Handles preparing a paint surface for the layout item and painting the item's
content. Derived classes must not override this method, but instead implement
the pure virtual method QgsLayoutItem.draw.
%End

protected:

virtual void drawDebugRect( QPainter *painter );
%Docstring
Draws a debugging rectangle of the item's current bounds within the specified
painter.
@param painter destination QPainter
%End

virtual void draw( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) = 0;
%Docstring
Draws the item's contents on a specified ``painter``.
%End

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitem.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,178 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutItemAbstractMetadata
{
%Docstring
Stores metadata about one layout item class.
.. note::

In C++ you can use QgsSymbolLayerMetadata convenience class.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutitemregistry.h"
%End
public:

QgsLayoutItemAbstractMetadata( int type, const QString &visibleName );
%Docstring
Constructor for QgsLayoutItemAbstractMetadata with the specified class ``type``
and ``visibleName``.
%End

virtual ~QgsLayoutItemAbstractMetadata();

int type() const;
%Docstring
Returns the unique item type code for the layout item class.
:rtype: int
%End

virtual QIcon icon() const;
%Docstring
Returns an icon representing the layout item type.
:rtype: QIcon
%End

QString visibleName() const;
%Docstring
Returns a translated, user visible name for the layout item class.
:rtype: str
%End

virtual QgsLayoutItem *createItem( QgsLayout *layout, const QVariantMap &properties ) = 0 /Factory/;
%Docstring
Creates a layout item of this class for a specified ``layout``, given the map of ``properties``.
:rtype: QgsLayoutItem
%End

virtual QWidget *createItemWidget() /Factory/;
%Docstring
Creates a configuration widget for layout items of this type. Can return None if no configuration GUI is required.
:rtype: QWidget
%End

virtual void resolvePaths( QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving );
%Docstring
Resolve paths in the item's ``properties`` (if there are any paths).
When ``saving`` is true, paths are converted from absolute to relative,
when ``saving`` is false, paths are converted from relative to absolute.
This ensures that paths in project files can be relative, but in item
instances the paths are always absolute.
%End

};







class QgsLayoutItemRegistry : QObject
{
%Docstring
Registry of available layout item types.

QgsLayoutItemRegistry is not usually directly created, but rather accessed through
QgsApplication.layoutItemRegistry().

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutitemregistry.h"
%End
public:

enum ItemType
{
LayoutItem,

// known
LayoutPage,

// item
PluginItem,
};

QgsLayoutItemRegistry( QObject *parent = 0 );
%Docstring
Creates a registry and populates it with standard item types.

QgsLayoutItemRegistry is not usually directly created, but rather accessed through
QgsApplication.layoutItemRegistry().
%End

~QgsLayoutItemRegistry();


QgsLayoutItemAbstractMetadata *itemMetadata( int type ) const;
%Docstring
Returns the metadata for the specified item ``type``. Returns None if
a corresponding type was not found in the registry.
:rtype: QgsLayoutItemAbstractMetadata
%End

bool addLayoutItemType( QgsLayoutItemAbstractMetadata *metadata /Transfer/ );
%Docstring
Registers a new layout item type. Takes ownership of the metadata instance.
:rtype: bool
%End

QgsLayoutItem *createItem( int type, QgsLayout *layout, const QVariantMap &properties = QVariantMap() ) const /Factory/;
%Docstring
Creates a new instance of a layout item given the item ``type``, target ``layout`` and ``properties``.
:rtype: QgsLayoutItem
%End

QWidget *createItemWidget( int type ) const /Factory/;
%Docstring
Creates a new instance of a layout item configuration widget for the specified item ``type``.
:rtype: QWidget
%End

void resolvePaths( int type, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) const;
%Docstring
Resolve paths in properties of a particular symbol layer.
This normally means converting relative paths to absolute paths when loading
and converting absolute paths to relative paths when saving.
%End

QMap< int, QString> itemTypes() const;
%Docstring
Returns a map of available item types to translated name.
:rtype: QMap< int, str>
%End

signals:

void typeAdded( int type, const QString &name );
%Docstring
Emitted whenever a new item type is added to the registry, with the specified
``type`` and visible ``name``.
%End

private:
QgsLayoutItemRegistry( const QgsLayoutItemRegistry &rh );
};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,52 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutobject.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutObject: QObject
{
%Docstring
A base class for objects which belong to a layout.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutobject.h"
%End
public:

QgsLayoutObject( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutObject, with the specified parent ``layout``.
.. note::

While ownership of a QgsLayoutObject is not passed to the layout,
classes which are derived from QgsLayoutObject (such as QgsLayoutItem)
may transfer their ownership to a layout upon construction.
%End


QgsLayout *layout();
%Docstring
Returns the layout the object is attached to.
:rtype: QgsLayout
%End

protected:


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutobject.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -10,7 +10,6 @@




class QgsApplication : QApplication
{
%Docstring
@@ -646,6 +645,13 @@ Returns path to the build output directory. Valid only when running from build d
:rtype: QgsSymbolLayerRegistry
%End

static QgsLayoutItemRegistry *layoutItemRegistry();
%Docstring
Returns the application's layout item registry, used for layout item types.
.. versionadded:: 3.0
:rtype: QgsLayoutItemRegistry
%End

static QgsGPSConnectionRegistry *gpsConnectionRegistry();
%Docstring
Returns the application's GPS connection registry, used for managing GPS connections.
@@ -63,7 +63,7 @@ Create a symbol layer of this type given the map of properties.
Resolve paths in symbol layer's properties (if there are any paths).
When saving is true, paths are converted from absolute to relative,
when saving is false, paths are converted from relative to absolute.
This ensures that paths in project files are absolute, but in symbol layer
This ensures that paths in project files can be relative, but in symbol layer
instances the paths are always absolute
.. versionadded:: 3.0
%End
@@ -273,6 +273,7 @@
%Include layertree/qgslayertreemapcanvasbridge.sip
%Include layertree/qgslayertreeview.sip
%Include layertree/qgslayertreeviewdefaultactions.sip
%Include layout/qgslayoutdesignerinterface.sip
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
%Include locator/qgslocatorwidget.sip

0 comments on commit ddf5ace

Please sign in to comment.
You can’t perform that action at this time.