Skip to content

Commit

Permalink
Store QgsBillBoardRegistry in QgsProject instead of making it a singl…
Browse files Browse the repository at this point in the history
…eton
  • Loading branch information
manisandro committed May 28, 2016
1 parent 90887f4 commit 3e73064
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 17 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -24,6 +24,7 @@
%Include qgsaggregatecalculator.sip
%Include qgsattributeaction.sip
%Include qgsattributetableconfig.sip
%Include qgsbillboardregistry.sip
%Include qgsbrowsermodel.sip
%Include qgsclipper.sip
%Include qgscolorscheme.sip
Expand Down
51 changes: 51 additions & 0 deletions python/core/qgsbillboardregistry.sip
@@ -0,0 +1,51 @@
/** Billboard items stored in the QgsBillBoardRegistry */
class QgsBillBoardItem
{
%TypeHeaderCode
#include <qgsbillboardregistry.h>
%End
public:
QImage image; /* The image of the billboard */
QgsPoint worldPos; /* The WGS84 world position of the billboard */
QString layerId; /* The layer which the image is part of, if any */
};

/**
* @brief The QgsBillBoardRegistry class stores images which should
* be displayed as billboards in the globe plugin.
* Map canvas items and layers may decide to add items which should
* be drawn as billboards in the globe.
*
* Retreive the instance pointer to a QgsBillBoardRegistry for a
* project via QgsProject::instance()->billboardRegistry().
*/
class QgsBillBoardRegistry : public QObject
{
%TypeHeaderCode
#include <qgsbillboardregistry.h>
%End
public:
/**
* @brief Adds a billboard to the registry
* @param parent The parent (i.e. a QgsMapLayer or a QgsMapCanvasItem) which is creating the billboard
* @param image The billboard image
* @param worldPos The geo position of the image, in WGS84
* @param layerId The id of the layer to which the item belongs, if any
*/
void addItem( void* parent, const QImage& image, const QgsPoint& worldPos, const QString& layerId = QString() );
/**
* @brief Removes all billboards which were created by the specified parent
* @param parent The parent
*/
void removeItem( void* parent );
QList<QgsBillBoardItem*> items() const;

signals:
/** Emitted when an item is added to the registry */
void itemAdded( QgsBillBoardItem* item );
/** Emitted when an item is removed from the registry */
void itemRemoved( QgsBillBoardItem* item );

private:
QgsBillBoardRegistry( QObject* parent = 0 );
};
5 changes: 5 additions & 0 deletions python/core/qgsproject.sip
Expand Up @@ -275,6 +275,11 @@ class QgsProject : QObject

QgsRelationManager* relationManager() const;

/** Return the project's billboard manager instance pointer
* @note added in QGIS 2.16
*/
QgsBillBoardRegistry* billboardRegistry() const;

/** Return pointer to the root (invisible) node of the project's layer tree
* @note added in 2.4
*/
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -81,6 +81,7 @@ SET(QGIS_CORE_SRCS
qgsactionmanager.cpp
qgsaggregatecalculator.cpp
qgsattributetableconfig.cpp
qgsbillboardregistry.cpp
qgsbrowsermodel.cpp
qgscachedfeatureiterator.cpp
qgscacheindex.cpp
Expand Down Expand Up @@ -448,6 +449,7 @@ ENDIF(NOT MSVC)

SET(QGIS_CORE_MOC_HDRS
qgsapplication.h
qgsbillboardregistry.h
qgsbrowsermodel.h
qgscontexthelp.h
qgscoordinatetransform.h
Expand Down
Expand Up @@ -17,12 +17,6 @@

#include "qgsbillboardregistry.h"

QgsBillBoardRegistry* QgsBillBoardRegistry::instance()
{
static QgsBillBoardRegistry instance;
return &instance;
}

void QgsBillBoardRegistry::addItem( void* parent, const QImage &image, const QgsPoint &worldPos , const QString &layerId )
{
QMap<void*, QgsBillBoardItem*>::iterator it = mItems.find( parent );
Expand Down
35 changes: 29 additions & 6 deletions src/gui/qgsbillboardregistry.h → src/core/qgsbillboardregistry.h
Expand Up @@ -24,28 +24,51 @@

class QgsMapCanvasItem;

class GUI_EXPORT QgsBillBoardItem
/** Billboard items stored in the QgsBillBoardRegistry */
class CORE_EXPORT QgsBillBoardItem
{
public:
QImage image;
QgsPoint worldPos;
QString layerId;
QImage image; /* The image of the billboard */
QgsPoint worldPos; /* The WGS84 world position of the billboard */
QString layerId; /* The layer which the image is part of, if any */
};

class GUI_EXPORT QgsBillBoardRegistry : public QObject
/**
* @brief The QgsBillBoardRegistry class stores images which should
* be displayed as billboards in the globe plugin.
* Map canvas items and layers may decide to add items which should
* be drawn as billboards in the globe.
*
* Retreive the instance pointer to a QgsBillBoardRegistry for a
* project via QgsProject::instance()->billboardRegistry().
*/
class CORE_EXPORT QgsBillBoardRegistry : public QObject
{
Q_OBJECT
public:
static QgsBillBoardRegistry* instance();
/**
* @brief Adds a billboard to the registry
* @param parent The parent (i.e. a QgsMapLayer or a QgsMapCanvasItem) which is creating the billboard
* @param image The billboard image
* @param worldPos The geo position of the image, in WGS84
* @param layerId The id of the layer to which the item belongs, if any
*/
void addItem( void* parent, const QImage& image, const QgsPoint& worldPos, const QString& layerId = QString() );
/**
* @brief Removes all billboards which were created by the specified parent
* @param parent The parent
*/
void removeItem( void* parent );
QList<QgsBillBoardItem*> items() const;

signals:
/** Emitted when an item is added to the registry */
void itemAdded( QgsBillBoardItem* item );
/** Emitted when an item is removed from the registry */
void itemRemoved( QgsBillBoardItem* item );

private:
friend class QgsProject; // Only QgsProject is allowed to construct this class
QgsBillBoardRegistry( QObject* parent = 0 ) : QObject( parent ) {}

QMap<void*, QgsBillBoardItem*> mItems;
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -17,6 +17,7 @@

#include "qgsproject.h"

#include "qgsbillboardregistry.h"
#include "qgsdatasourceuri.h"
#include "qgsexception.h"
#include "qgslayertree.h"
Expand Down Expand Up @@ -361,6 +362,7 @@ QgsProject::QgsProject()
, mBadLayerHandler( new QgsProjectBadLayerDefaultHandler() )
, mRelationManager( new QgsRelationManager( this ) )
, mRootGroup( new QgsLayerTreeGroup )
, mBillboardRegistry( new QgsBillBoardRegistry( this ) )
{
clear();

Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsproject.h
Expand Up @@ -41,6 +41,7 @@ class QDomDocument;
class QDomElement;
class QDomNode;

class QgsBillBoardRegistry;
class QgsLayerTreeGroup;
class QgsLayerTreeRegistryBridge;
class QgsMapLayer;
Expand Down Expand Up @@ -323,6 +324,11 @@ class CORE_EXPORT QgsProject : public QObject

QgsRelationManager* relationManager() const;

/** Return the project's billboard manager instance pointer
* @note added in QGIS 2.16
*/
QgsBillBoardRegistry* billboardRegistry() const { return mBillboardRegistry; }

/** Return pointer to the root (invisible) node of the project's layer tree
* @note added in 2.4
*/
Expand Down Expand Up @@ -487,6 +493,8 @@ class CORE_EXPORT QgsProject : public QObject

QgsLayerTreeRegistryBridge* mLayerTreeRegistryBridge;

QgsBillBoardRegistry* mBillboardRegistry;

//! map of transaction group: QPair( providerKey, connString ) -> transactionGroup
QMap< QPair< QString, QString>, QgsTransactionGroup*> mTransactionGroups;

Expand Down
2 changes: 0 additions & 2 deletions src/gui/CMakeLists.txt
Expand Up @@ -169,7 +169,6 @@ SET(QGIS_GUI_SRCS
qgsattributeforminterface.cpp
qgsattributeformlegacyinterface.cpp
qgsattributetypeloaddialog.cpp
qgsbillboardregistry.cpp
qgsblendmodecombobox.cpp
qgsbrowsertreeview.cpp
qgsbusyindicatordialog.cpp
Expand Down Expand Up @@ -323,7 +322,6 @@ SET(QGIS_GUI_MOC_HDRS
qgsattributeform.h
qgsattributeformeditorwidget.h
qgsattributetypeloaddialog.h
qgsbillboardregistry.h
qgsblendmodecombobox.h
qgsbrowsertreeview.h
qgsbusyindicatordialog.h
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -39,6 +39,7 @@
#include <qgsmaplayerregistry.h>
#include <qgsfeature.h>
#include <qgsgeometry.h>
#include <qgsproject.h>
#include <qgspoint.h>
#include <qgsdistancearea.h>
#include <symbology-ng/qgsrendererv2.h>
Expand Down Expand Up @@ -281,8 +282,8 @@ void GlobePlugin::initGui()

connect( mActionToggleGlobe, SIGNAL( triggered( bool ) ), this, SLOT( setGlobeEnabled( bool ) ) );
// connect( mQGisIface->mapCanvas(), SIGNAL( annotationItemChanged( QgsAnnotationItem* ) ), this, SLOT( updateAnnotationItem( QgsAnnotationItem* ) ) );
connect( QgsBillBoardRegistry::instance(), SIGNAL( itemAdded( QgsBillBoardItem* ) ), this, SLOT( addBillboard( QgsBillBoardItem* ) ) );
connect( QgsBillBoardRegistry::instance(), SIGNAL( itemRemoved( QgsBillBoardItem* ) ), this, SLOT( removeBillboard( QgsBillBoardItem* ) ) );
connect( QgsProject::instance()->billboardRegistry(), SIGNAL( itemAdded( QgsBillBoardItem* ) ), this, SLOT( addBillboard( QgsBillBoardItem* ) ) );
connect( QgsProject::instance()->billboardRegistry(), SIGNAL( itemRemoved( QgsBillBoardItem* ) ), this, SLOT( removeBillboard( QgsBillBoardItem* ) ) );
connect( mLayerPropertiesFactory, SIGNAL( layerSettingsChanged( QgsMapLayer* ) ), this, SLOT( layerChanged( QgsMapLayer* ) ) );
connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ), mQGisIface->mapCanvas(), SIGNAL( xyCoordinates( const QgsPoint & ) ) );
connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
Expand Down Expand Up @@ -391,7 +392,7 @@ void GlobePlugin::run()

mAnnotationsGroup = new osg::Group();
mRootNode->addChild( mAnnotationsGroup );
foreach ( QgsBillBoardItem* item, QgsBillBoardRegistry::instance()->items() )
foreach ( QgsBillBoardItem* item, QgsProject::instance()->billboardRegistry()->items() )
{
addBillboard( item );
}
Expand Down

0 comments on commit 3e73064

Please sign in to comment.