mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add some base classes for layouts
This commit is contained in:
parent
cd979d8ab0
commit
18b2b5240b
@ -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
|
||||
|
35
python/core/layout/qgslayout.sip
Normal file
35
python/core/layout/qgslayout.sip
Normal file
@ -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 *
|
||||
************************************************************************/
|
60
python/core/layout/qgslayoutitem.sip
Normal file
60
python/core/layout/qgslayoutitem.sip
Normal file
@ -0,0 +1,60 @@
|
||||
/************************************************************************
|
||||
* 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 );
|
||||
|
||||
virtual int type() const = 0;
|
||||
%Docstring
|
||||
Return correct graphics item type.
|
||||
:rtype: int
|
||||
%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
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/core/layout/qgslayoutitem.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
58
python/core/layout/qgslayoutitemregistry.sip
Normal file
58
python/core/layout/qgslayoutitemregistry.sip
Normal file
@ -0,0 +1,58 @@
|
||||
/************************************************************************
|
||||
* 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 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
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/core/layout/qgslayoutitemregistry.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
52
python/core/layout/qgslayoutobject.sip
Normal file
52
python/core/layout/qgslayoutobject.sip
Normal file
@ -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.
|
||||
|
@ -343,8 +343,12 @@ SET(QGIS_CORE_SRCS
|
||||
dxf/qgsdxfpaintengine.cpp
|
||||
dxf/qgsdxfpallabeling.cpp
|
||||
|
||||
layout/qgslayout.cpp
|
||||
layout/qgslayoutitem.cpp
|
||||
layout/qgslayoutitemregistry.cpp
|
||||
layout/qgslayoutmeasurement.cpp
|
||||
layout/qgslayoutmeasurementconverter.cpp
|
||||
layout/qgslayoutobject.cpp
|
||||
layout/qgspagesizeregistry.cpp
|
||||
layout/qgslayoutpoint.cpp
|
||||
layout/qgslayoutsize.cpp
|
||||
@ -660,6 +664,11 @@ SET(QGIS_CORE_MOC_HDRS
|
||||
gps/qgsnmeaconnection.h
|
||||
gps/qgsgpsdconnection.h
|
||||
|
||||
layout/qgslayout.h
|
||||
layout/qgslayoutitem.h
|
||||
layout/qgslayoutitemregistry.h
|
||||
layout/qgslayoutobject.h
|
||||
|
||||
symbology-ng/qgscptcityarchive.h
|
||||
symbology-ng/qgssvgcache.h
|
||||
symbology-ng/qgsstyle.h
|
||||
@ -901,6 +910,7 @@ SET(QGIS_CORE_HDRS
|
||||
composer/qgscomposertexttable.h
|
||||
composer/qgspaperitem.h
|
||||
|
||||
layout/qgslayout.h
|
||||
layout/qgslayoutmeasurement.h
|
||||
layout/qgslayoutmeasurementconverter.h
|
||||
layout/qgspagesizeregistry.h
|
||||
|
23
src/core/layout/qgslayout.cpp
Normal file
23
src/core/layout/qgslayout.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/***************************************************************************
|
||||
qgslayout.cpp
|
||||
-------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslayout.h"
|
||||
|
||||
QgsLayout::QgsLayout()
|
||||
: QGraphicsScene()
|
||||
{
|
||||
|
||||
}
|
41
src/core/layout/qgslayout.h
Normal file
41
src/core/layout/qgslayout.h
Normal file
@ -0,0 +1,41 @@
|
||||
/***************************************************************************
|
||||
qgslayout.h
|
||||
-------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
#ifndef QGSLAYOUT_H
|
||||
#define QGSLAYOUT_H
|
||||
|
||||
#include "qgis_core.h"
|
||||
#include <QGraphicsScene>
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* \class QgsLayout
|
||||
* \brief Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsLayout : public QGraphicsScene
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
QgsLayout();
|
||||
|
||||
};
|
||||
|
||||
#endif //QGSLAYOUT_H
|
||||
|
||||
|
||||
|
65
src/core/layout/qgslayoutitem.cpp
Normal file
65
src/core/layout/qgslayoutitem.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
qgslayoutitem.cpp
|
||||
-------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslayoutitem.h"
|
||||
#include "qgslayout.h"
|
||||
#include <QPainter>
|
||||
|
||||
QgsLayoutItem::QgsLayoutItem( QgsLayout *layout )
|
||||
: QgsLayoutObject( layout )
|
||||
, QGraphicsRectItem( 0 )
|
||||
{
|
||||
setCacheMode( QGraphicsItem::DeviceCoordinateCache );
|
||||
}
|
||||
|
||||
void QgsLayoutItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
|
||||
{
|
||||
if ( !painter || !painter->device() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO - remember to disable saving/restoring on graphics view!!
|
||||
painter->save();
|
||||
preparePainter( painter );
|
||||
|
||||
draw( painter, itemStyle, pWidget );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void QgsLayoutItem::drawDebugRect( QPainter *painter )
|
||||
{
|
||||
if ( !painter )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint( QPainter::Antialiasing, false );
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QColor( 100, 255, 100, 200 ) );
|
||||
painter->drawRect( rect() );
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void QgsLayoutItem::preparePainter( QPainter *painter )
|
||||
{
|
||||
if ( !painter || !painter->device() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
75
src/core/layout/qgslayoutitem.h
Normal file
75
src/core/layout/qgslayoutitem.h
Normal file
@ -0,0 +1,75 @@
|
||||
/***************************************************************************
|
||||
qgslayoutitem.h
|
||||
-------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSLAYOUTITEM_H
|
||||
#define QGSLAYOUTITEM_H
|
||||
|
||||
#include "qgis_core.h"
|
||||
#include "qgslayoutobject.h"
|
||||
#include "qgslayoutitemregistry.h"
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
class QgsLayout;
|
||||
class QPainter;
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* \class QgsLayoutItem
|
||||
* \brief Base class for graphical items within a QgsLayout.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
QgsLayoutItem( QgsLayout *layout );
|
||||
|
||||
//! Return correct graphics item type.
|
||||
virtual int type() const = 0;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
|
||||
|
||||
protected:
|
||||
|
||||
/** Draws a debugging rectangle of the item's current bounds within the specified
|
||||
* painter.
|
||||
* @param painter destination QPainter
|
||||
*/
|
||||
virtual void drawDebugRect( QPainter *painter );
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Draws the item's contents on a specified \a painter.
|
||||
*/
|
||||
virtual void draw( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) = 0;
|
||||
|
||||
//! Prepares a painter by setting rendering flags
|
||||
void preparePainter( QPainter *painter );
|
||||
|
||||
friend class TestQgsLayoutItem;
|
||||
};
|
||||
|
||||
#endif //QGSLAYOUTITEM_H
|
||||
|
||||
|
||||
|
23
src/core/layout/qgslayoutitemregistry.cpp
Normal file
23
src/core/layout/qgslayoutitemregistry.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/***************************************************************************
|
||||
qgslayoutitemregistry.cpp
|
||||
-------------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslayoutitemregistry.h"
|
||||
|
||||
QgsLayoutItemRegistry::QgsLayoutItemRegistry( QObject *parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
|
||||
}
|
68
src/core/layout/qgslayoutitemregistry.h
Normal file
68
src/core/layout/qgslayoutitemregistry.h
Normal file
@ -0,0 +1,68 @@
|
||||
/***************************************************************************
|
||||
qgslayoutitemregistry.h
|
||||
------------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
#ifndef QGSLAYOUTITEMREGISTRY_H
|
||||
#define QGSLAYOUTITEMREGISTRY_H
|
||||
|
||||
#include "qgis_core.h"
|
||||
#include <QGraphicsItem> //for QGraphicsItem::UserType
|
||||
|
||||
class QgsLayoutItem;
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* \class QgsLayoutItemRegistry
|
||||
* \brief Registry of available layout item types.
|
||||
*
|
||||
* QgsLayoutItemRegistry is not usually directly created, but rather accessed through
|
||||
* QgsApplication::layoutItemRegistry().
|
||||
*
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsLayoutItemRegistry : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
//! Item types
|
||||
enum ItemType
|
||||
{
|
||||
LayoutItem = QGraphicsItem::UserType + 100, //!< Base class for items
|
||||
|
||||
// known item types
|
||||
LayoutPage, //!< Page items
|
||||
|
||||
// item types provided by plugins
|
||||
PluginItem, //!< Starting point for plugin item types
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a registry and populates it with standard item types.
|
||||
*
|
||||
* QgsLayoutItemRegistry is not usually directly created, but rather accessed through
|
||||
* QgsApplication::layoutItemRegistry().
|
||||
*/
|
||||
QgsLayoutItemRegistry( QObject *parent = nullptr );
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif //QGSLAYOUTITEMREGISTRY_H
|
||||
|
||||
|
||||
|
27
src/core/layout/qgslayoutobject.cpp
Normal file
27
src/core/layout/qgslayoutobject.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/***************************************************************************
|
||||
qgslayoutobject.cpp
|
||||
-------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#include "qgslayout.h"
|
||||
#include "qgslayoutobject.h"
|
||||
|
||||
QgsLayoutObject::QgsLayoutObject( QgsLayout *layout )
|
||||
: QObject( nullptr )
|
||||
, mLayout( layout )
|
||||
{
|
||||
}
|
66
src/core/layout/qgslayoutobject.h
Normal file
66
src/core/layout/qgslayoutobject.h
Normal file
@ -0,0 +1,66 @@
|
||||
/***************************************************************************
|
||||
qgslayoutobject.h
|
||||
-------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
#ifndef QGSLAYOUTOBJECT_H
|
||||
#define QGSLAYOUTOBJECT_H
|
||||
|
||||
#include "qgis_core.h"
|
||||
#include "qgis_sip.h"
|
||||
#include <QObject>
|
||||
#include <QDomNode>
|
||||
#include <QMap>
|
||||
|
||||
class QgsLayout;
|
||||
class QPainter;
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* A base class for objects which belong to a layout.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class CORE_EXPORT QgsLayoutObject: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor for QgsLayoutObject, with the specified parent \a 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.
|
||||
*/
|
||||
QgsLayoutObject( QgsLayout *layout );
|
||||
|
||||
/**
|
||||
* Returns the layout the object is attached to.
|
||||
*/
|
||||
SIP_SKIP const QgsLayout *layout() const { return mLayout; }
|
||||
|
||||
/**
|
||||
* Returns the layout the object is attached to.
|
||||
*/
|
||||
QgsLayout *layout() { return mLayout; }
|
||||
|
||||
protected:
|
||||
|
||||
QgsLayout *mLayout = nullptr;
|
||||
|
||||
private:
|
||||
|
||||
friend class TestQgsLayoutObject;
|
||||
};
|
||||
|
||||
#endif //QGSLAYOUTOBJECT_H
|
@ -18,6 +18,7 @@
|
||||
#include "qgsdataitemproviderregistry.h"
|
||||
#include "qgsexception.h"
|
||||
#include "qgsgeometry.h"
|
||||
#include "qgslayoutitemregistry.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgsproject.h"
|
||||
#include "qgsnetworkaccessmanager.h"
|
||||
@ -1534,6 +1535,11 @@ QgsSymbolLayerRegistry *QgsApplication::symbolLayerRegistry()
|
||||
return members()->mSymbolLayerRegistry;
|
||||
}
|
||||
|
||||
QgsLayoutItemRegistry *QgsApplication::layoutItemRegistry()
|
||||
{
|
||||
return members()->mLayoutItemRegistry;
|
||||
}
|
||||
|
||||
QgsGPSConnectionRegistry *QgsApplication::gpsConnectionRegistry()
|
||||
{
|
||||
return members()->mGpsConnectionRegistry;
|
||||
@ -1589,6 +1595,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
|
||||
mPluginLayerRegistry = new QgsPluginLayerRegistry();
|
||||
mProcessingRegistry = new QgsProcessingRegistry();
|
||||
mPageSizeRegistry = new QgsPageSizeRegistry();
|
||||
mLayoutItemRegistry = new QgsLayoutItemRegistry();
|
||||
mProcessingRegistry->addProvider( new QgsNativeAlgorithms( mProcessingRegistry ) );
|
||||
mAnnotationRegistry = new QgsAnnotationRegistry();
|
||||
}
|
||||
@ -1605,6 +1612,7 @@ QgsApplication::ApplicationMembers::~ApplicationMembers()
|
||||
delete mPluginLayerRegistry;
|
||||
delete mProcessingRegistry;
|
||||
delete mPageSizeRegistry;
|
||||
delete mLayoutItemRegistry;
|
||||
delete mProfiler;
|
||||
delete mRasterRendererRegistry;
|
||||
delete mRendererRegistry;
|
||||
|
@ -40,7 +40,7 @@ class QgsMessageLog;
|
||||
class QgsProcessingRegistry;
|
||||
class QgsAnnotationRegistry;
|
||||
class QgsPageSizeRegistry;
|
||||
|
||||
class QgsLayoutItemRegistry;
|
||||
|
||||
/** \ingroup core
|
||||
* Extends QApplication to provide access to QGIS specific resources such
|
||||
@ -522,6 +522,12 @@ class CORE_EXPORT QgsApplication : public QApplication
|
||||
*/
|
||||
static QgsSymbolLayerRegistry *symbolLayerRegistry();
|
||||
|
||||
/**
|
||||
* Returns the application's layout item registry, used for layout item types.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
static QgsLayoutItemRegistry *layoutItemRegistry();
|
||||
|
||||
/**
|
||||
* Returns the application's GPS connection registry, used for managing GPS connections.
|
||||
* \since QGIS 3.0
|
||||
@ -709,6 +715,7 @@ class CORE_EXPORT QgsApplication : public QApplication
|
||||
QgsSvgCache *mSvgCache = nullptr;
|
||||
QgsSymbolLayerRegistry *mSymbolLayerRegistry = nullptr;
|
||||
QgsTaskManager *mTaskManager = nullptr;
|
||||
QgsLayoutItemRegistry *mLayoutItemRegistry = nullptr;
|
||||
QString mNullRepresentation;
|
||||
|
||||
ApplicationMembers();
|
||||
|
@ -125,6 +125,9 @@ SET(TESTS
|
||||
testqgsjsonutils.cpp
|
||||
testqgslabelingengine.cpp
|
||||
testqgslayertree.cpp
|
||||
testqgslayout.cpp
|
||||
testqgslayoutitem.cpp
|
||||
testqgslayoutobject.cpp
|
||||
testqgslayoutunits.cpp
|
||||
testqgslegendrenderer.cpp
|
||||
testqgscentroidfillsymbol.cpp
|
||||
|
73
tests/src/core/testqgslayout.cpp
Normal file
73
tests/src/core/testqgslayout.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
testqgslayout.cpp
|
||||
-----------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslayout.h"
|
||||
#include "qgstest.h"
|
||||
|
||||
class TestQgsLayout: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();// will be called before the first testfunction is executed.
|
||||
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||
void init();// will be called before each testfunction is executed.
|
||||
void cleanup();// will be called after every testfunction.
|
||||
void creation(); //test creation of QgsLayout
|
||||
|
||||
private:
|
||||
QString mReport;
|
||||
|
||||
};
|
||||
|
||||
void TestQgsLayout::initTestCase()
|
||||
{
|
||||
mReport = "<h1>Layout Tests</h1>\n";
|
||||
}
|
||||
|
||||
void TestQgsLayout::cleanupTestCase()
|
||||
{
|
||||
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
|
||||
QFile myFile( myReportFile );
|
||||
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
|
||||
{
|
||||
QTextStream myQTextStream( &myFile );
|
||||
myQTextStream << mReport;
|
||||
myFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsLayout::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayout::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayout::creation()
|
||||
{
|
||||
QgsLayout *layout = new QgsLayout();
|
||||
QVERIFY( layout );
|
||||
delete layout;
|
||||
}
|
||||
|
||||
|
||||
QGSTEST_MAIN( TestQgsLayout )
|
||||
#include "testqgslayout.moc"
|
121
tests/src/core/testqgslayoutitem.cpp
Normal file
121
tests/src/core/testqgslayoutitem.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/***************************************************************************
|
||||
testqgslayoutitem.cpp
|
||||
-----------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslayoutitem.h"
|
||||
#include "qgslayout.h"
|
||||
#include "qgsmultirenderchecker.h"
|
||||
#include "qgstest.h"
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
#include <QImage>
|
||||
|
||||
class TestQgsLayoutItem: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();// will be called before the first testfunction is executed.
|
||||
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||
void init();// will be called before each testfunction is executed.
|
||||
void cleanup();// will be called after every testfunction.
|
||||
void creation(); //test creation of QgsLayoutItem
|
||||
|
||||
private:
|
||||
|
||||
//simple item for testing, since some methods in QgsLayoutItem are pure virtual
|
||||
class TestItem : public QgsLayoutItem
|
||||
{
|
||||
public:
|
||||
|
||||
TestItem( QgsLayout *layout ) : QgsLayoutItem( layout ) {}
|
||||
~TestItem() {}
|
||||
|
||||
//implement pure virtual methods
|
||||
int type() const { return QgsLayoutItemRegistry::LayoutItem + 101; }
|
||||
void draw( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
|
||||
{
|
||||
Q_UNUSED( itemStyle );
|
||||
Q_UNUSED( pWidget );
|
||||
painter->save();
|
||||
painter->setRenderHint( QPainter::Antialiasing, false );
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QColor( 255, 100, 100, 200 ) );
|
||||
painter->drawRect( rect() );
|
||||
painter->restore();
|
||||
}
|
||||
};
|
||||
|
||||
QgsLayout *mLayout = nullptr;
|
||||
QString mReport;
|
||||
|
||||
bool renderCheck( QString testName, QImage &image, int mismatchCount );
|
||||
|
||||
};
|
||||
|
||||
void TestQgsLayoutItem::initTestCase()
|
||||
{
|
||||
mLayout = new QgsLayout();
|
||||
mReport = "<h1>Layout Item Tests</h1>\n";
|
||||
}
|
||||
|
||||
void TestQgsLayoutItem::cleanupTestCase()
|
||||
{
|
||||
delete mLayout;
|
||||
|
||||
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
|
||||
QFile myFile( myReportFile );
|
||||
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
|
||||
{
|
||||
QTextStream myQTextStream( &myFile );
|
||||
myQTextStream << mReport;
|
||||
myFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsLayoutItem::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutItem::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutItem::creation()
|
||||
{
|
||||
TestItem *item = new TestItem( mLayout );
|
||||
QVERIFY( item );
|
||||
delete item;
|
||||
}
|
||||
|
||||
bool TestQgsLayoutItem::renderCheck( QString testName, QImage &image, int mismatchCount )
|
||||
{
|
||||
mReport += "<h2>" + testName + "</h2>\n";
|
||||
QString myTmpDir = QDir::tempPath() + QDir::separator();
|
||||
QString myFileName = myTmpDir + testName + ".png";
|
||||
image.save( myFileName, "PNG" );
|
||||
QgsRenderChecker myChecker;
|
||||
myChecker.setControlName( "expected_" + testName );
|
||||
myChecker.setRenderedImage( myFileName );
|
||||
bool myResultFlag = myChecker.compareImages( testName, mismatchCount );
|
||||
mReport += myChecker.report();
|
||||
return myResultFlag;
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsLayoutItem )
|
||||
#include "testqgslayoutitem.moc"
|
65
tests/src/core/testqgslayoutitemregistry.cpp
Normal file
65
tests/src/core/testqgslayoutitemregistry.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
testqgslayoutitemregistry.cpp
|
||||
-----------------------------
|
||||
begin : November 2014
|
||||
copyright : (C) 2014 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslayoutitemregistry.h"
|
||||
#include "qgis.h"
|
||||
#include <QObject>
|
||||
#include <QtTest>
|
||||
|
||||
class TestQgsLayoutItemRegistry : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
private slots:
|
||||
void initTestCase();// will be called before the first testfunction is executed.
|
||||
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||
void init();// will be called before each testfunction is executed.
|
||||
void cleanup();// will be called after every testfunction.
|
||||
void createInstance(); // create global instance of QgsLayoutItemRegistry
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
void TestQgsLayoutItemRegistry::initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutItemRegistry::cleanupTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutItemRegistry::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutItemRegistry::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutItemRegistry::createInstance()
|
||||
{
|
||||
QgsLayoutItemRegistry *registry = QgsLayoutItemRegistry::instance();
|
||||
QVERIFY( registry );
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsLayoutItemRegistry )
|
||||
#include "testqgslayoutitemregistry.moc"
|
85
tests/src/core/testqgslayoutobject.cpp
Normal file
85
tests/src/core/testqgslayoutobject.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/***************************************************************************
|
||||
testqgslayoutobject.cpp
|
||||
-----------------------
|
||||
begin : June 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslayoutobject.h"
|
||||
#include "qgslayout.h"
|
||||
#include "qgstest.h"
|
||||
|
||||
class TestQgsLayoutObject: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();// will be called before the first testfunction is executed.
|
||||
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||
void init();// will be called before each testfunction is executed.
|
||||
void cleanup();// will be called after every testfunction.
|
||||
void creation(); //test creation of QgsLayoutObject
|
||||
void layout(); //test fetching layout from QgsLayoutObject
|
||||
|
||||
private:
|
||||
QgsLayout *mLayout = nullptr;
|
||||
QString mReport;
|
||||
|
||||
};
|
||||
|
||||
void TestQgsLayoutObject::initTestCase()
|
||||
{
|
||||
mLayout = new QgsLayout();
|
||||
mReport = "<h1>Layout Object Tests</h1>\n";
|
||||
}
|
||||
|
||||
void TestQgsLayoutObject::cleanupTestCase()
|
||||
{
|
||||
delete mLayout;
|
||||
|
||||
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
|
||||
QFile myFile( myReportFile );
|
||||
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
|
||||
{
|
||||
QTextStream myQTextStream( &myFile );
|
||||
myQTextStream << mReport;
|
||||
myFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsLayoutObject::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutObject::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsLayoutObject::creation()
|
||||
{
|
||||
QgsLayoutObject *object = new QgsLayoutObject( mLayout );
|
||||
QVERIFY( object );
|
||||
delete object;
|
||||
}
|
||||
|
||||
void TestQgsLayoutObject::layout()
|
||||
{
|
||||
QgsLayoutObject *object = new QgsLayoutObject( mLayout );
|
||||
QCOMPARE( object->layout(), mLayout );
|
||||
delete object;
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsLayoutObject )
|
||||
#include "testqgslayoutobject.moc"
|
BIN
tests/testdata/control_images/expected_layoutitem_debugrect/expected_layoutitem_debugrect.png
vendored
Normal file
BIN
tests/testdata/control_images/expected_layoutitem_debugrect/expected_layoutitem_debugrect.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
tests/testdata/control_images/expected_layoutitem_draw/expected_layoutitem_draw.png
vendored
Normal file
BIN
tests/testdata/control_images/expected_layoutitem_draw/expected_layoutitem_draw.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Loading…
x
Reference in New Issue
Block a user