Skip to content
Permalink
Browse files

Store QgsBillBoardRegistry in QgsProject instead of making it a singl…

…eton
  • Loading branch information
manisandro committed May 28, 2016
1 parent 90887f4 commit 3e73064c4aa94f5a84758f707f5a372408ad4006
@@ -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
@@ -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 );
};
@@ -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
*/
@@ -81,6 +81,7 @@ SET(QGIS_CORE_SRCS
qgsactionmanager.cpp
qgsaggregatecalculator.cpp
qgsattributetableconfig.cpp
qgsbillboardregistry.cpp
qgsbrowsermodel.cpp
qgscachedfeatureiterator.cpp
qgscacheindex.cpp
@@ -448,6 +449,7 @@ ENDIF(NOT MSVC)

SET(QGIS_CORE_MOC_HDRS
qgsapplication.h
qgsbillboardregistry.h
qgsbrowsermodel.h
qgscontexthelp.h
qgscoordinatetransform.h
@@ -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 );
@@ -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;
@@ -17,6 +17,7 @@

#include "qgsproject.h"

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

@@ -41,6 +41,7 @@ class QDomDocument;
class QDomElement;
class QDomNode;

class QgsBillBoardRegistry;
class QgsLayerTreeGroup;
class QgsLayerTreeRegistryBridge;
class QgsMapLayer;
@@ -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
*/
@@ -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;

@@ -169,7 +169,6 @@ SET(QGIS_GUI_SRCS
qgsattributeforminterface.cpp
qgsattributeformlegacyinterface.cpp
qgsattributetypeloaddialog.cpp
qgsbillboardregistry.cpp
qgsblendmodecombobox.cpp
qgsbrowsertreeview.cpp
qgsbusyindicatordialog.cpp
@@ -323,7 +322,6 @@ SET(QGIS_GUI_MOC_HDRS
qgsattributeform.h
qgsattributeformeditorwidget.h
qgsattributetypeloaddialog.h
qgsbillboardregistry.h
qgsblendmodecombobox.h
qgsbrowsertreeview.h
qgsbusyindicatordialog.h
@@ -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>
@@ -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() ) );
@@ -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 );
}

0 comments on commit 3e73064

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