Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the definition of public interfaces for plugins #1370

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
%Include qgsowsconnection.sip
%Include qgspaintenginehack.sip
%Include qgspallabeling.sip
%Include qgsplugininterface.sip
%Include qgspluginlayer.sip
%Include qgspluginlayerregistry.sip
%Include qgspoint.sip
Expand Down
25 changes: 25 additions & 0 deletions python/core/qgsplugininterface.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/***************************************************************************
qgsplugininterface.sip
--------------------------------------
Date : 21.8.2013
Copyright : (C) 2013 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* 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. *
* *
***************************************************************************/

class QgsPluginInterface : QObject
{
%TypeHeaderCode
#include "qgsplugininterface.h"
%End

// Should only be instantiated from subclasses
private:
QgsPluginInterface();
};
4 changes: 1 addition & 3 deletions python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class QgisInterface : QObject

virtual QgsPluginManagerInterface* pluginManagerInterface() = 0;

public slots: // TODO: do these functions really need to be slots?

/* Exposed functions */
virtual QgsPluginInterface* pluginInterface( const QString& pluginName ) = 0;

//! Zoom to full extent of map layers
virtual void zoomFull() = 0;
Expand Down
10 changes: 10 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,16 @@ QgsPluginManager *QgisApp::pluginManager()
return mPluginManager;
}

QgsPluginInterface* QgisApp::pluginInterface( const QString& pluginName )
{
QgisPlugin* plugin = QgsPluginRegistry::instance()->plugin( pluginName );
if ( plugin )
{
return plugin->pluginInterface();
}
return NULL;
}

QgsMapCanvas *QgisApp::mapCanvas()
{
Q_ASSERT( mMapCanvas );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class QgsMapTool;
class QgsPoint;
class QgsProviderRegistry;
class QgsPythonUtils;
class QgsPluginInterface;
class QgsRectangle;
class QgsUndoWidget;
class QgsVectorLayer;
Expand Down Expand Up @@ -436,6 +437,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! returns pointer to plugin manager
QgsPluginManager *pluginManager();

QgsPluginInterface* pluginInterface( const QString& pluginName );

/** Return vector layers in edit mode
* @param modified whether to return only layers that have been modified
* @returns list of layers in legend order, or empty list
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,9 @@ int QgisAppInterface::messageTimeout()
{
return qgis->messageTimeout();
}

QgsPluginInterface* QgisAppInterface::pluginInterface( const QString& pluginName )
{
return qgis->pluginInterface( pluginName );
}

2 changes: 2 additions & 0 deletions src/app/qgisappinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class APP_EXPORT QgisAppInterface : public QgisInterface

QgsPluginManagerInterface* pluginManagerInterface();

QgsPluginInterface* pluginInterface( const QString& pluginName );

/* Exposed functions */

//! Zoom map to full extent
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ SET(QGIS_CORE_MOC_HDRS
qgscredentials.h
qgspluginlayer.h
qgsproject.h
qgsplugininterface.h
qgsrunprocess.h
qgsrelationmanager.h
qgsvectorlayer.h
Expand Down Expand Up @@ -456,6 +457,7 @@ SET(QGIS_CORE_HDRS
qgspluginlayerregistry.h
qgspoint.h
qgsproject.h
qgsplugininterface.h
qgsprojectfiletransform.h
qgsprojectproperty.h
qgsprojectversion.h
Expand Down
Empty file added src/core/qgsplugininterface.cpp
Empty file.
29 changes: 29 additions & 0 deletions src/core/qgsplugininterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/***************************************************************************
qgsplugininterface.h
--------------------------------------
Date : 21.8.2013
Copyright : (C) 2013 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* 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 QGSPLUGININTERFACE_H
#define QGSPLUGININTERFACE_H

#include <QObject>

class QgsPluginInterface : public QObject
{
Q_OBJECT

public:
QgsPluginInterface() : QObject() {}
};

#endif // QGSPLUGININTERFACE_H
18 changes: 10 additions & 8 deletions src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@
#define QGISINTERFACE_H

class QAction;
class QMenu;
class QToolBar;
class QDockWidget;
class QMainWindow;
class QMenu;
class QToolBar;
class QWidget;

class QgsComposerView;
class QgsMapLayer;
class QgsFeature;
class QgsLegendInterface;
class QgsMapCanvas;
class QgsMapLayer;
class QgsMapLayerPropertiesFactory;
class QgsMessageBar;
class QgsPluginInterface;
class QgsPluginManagerInterface;
class QgsRasterLayer;
class QgsVectorLayer;
class QgsLegendInterface;
class QgsPluginManagerInterface;
class QgsFeature;
class QgsMessageBar;
class QgsVectorLayerTools;

#include <QObject>
Expand Down Expand Up @@ -75,7 +77,7 @@ class GUI_EXPORT QgisInterface : public QObject

virtual QgsPluginManagerInterface* pluginManagerInterface() = 0;

public slots: // TODO: do these functions really need to be slots?
virtual QgsPluginInterface* pluginInterface( const QString& pluginName ) = 0;

/* Exposed functions */

Expand Down
29 changes: 28 additions & 1 deletion src/plugins/globe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SET (globe_plugin_SRCS
globe_plugin.cpp
qgsosgearthtilesource.cpp
globe_plugin_dialog.cpp
qgsglobeinterface.cpp
)
IF (NOT HAVE_OSGEARTHQT)
SET(globe_plugin_SRCS
Expand All @@ -36,26 +37,51 @@ SET (globe_plugin_UIS
SET (globe_plugin_MOC_HDRS
globe_plugin.h
globe_plugin_dialog.h
qgsglobeinterface.h
)

SET (globe_plugin_RCCS globe_plugin.qrc)

SET (GLOBE_PLUGIN_HDRS
qgsosgearthtilesource.h
qgsosgearthfeaturesource.h
qgsosgearthfeatureoptions.h

qgsglobefeatureutils.h
qgsglobeinterface.h
qgsglobestyleutils.h
qgsglobelayerpropertiesfactory.h
qgsglobevectorlayerpropertiespage.h
qgsglobevectorlayerconfig.h
)

SET (GLOBE_PLUGIN_RCCS globe_plugin.qrc)

########################################################
# Build

ADD_DEFINITIONS("-DGLOBE_EXPORT=")

IF(WIN32)
IF(MSVC)
ADD_DEFINITIONS("-DGLOBE_EXPORT=${DLLEXPORT}")
ENDIF(MSVC)
ENDIF(WIN32)

QT4_WRAP_UI (globe_plugin_UIS_H ${globe_plugin_UIS})

QT4_WRAP_CPP (globe_plugin_MOC_SRCS ${globe_plugin_MOC_HDRS})

QT4_ADD_RESOURCES(globe_plugin_RCC_SRCS ${globe_plugin_RCCS})

ADD_LIBRARY (globeplugin MODULE ${globe_plugin_SRCS} ${globe_plugin_MOC_SRCS} ${globe_plugin_RCC_SRCS} ${globe_plugin_UIS_H})
ADD_LIBRARY (globeplugin SHARED ${globe_plugin_SRCS} ${globe_plugin_MOC_SRCS} ${globe_plugin_RCC_SRCS} ${globe_plugin_UIS_H})

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${OSGEARTH_INCLUDE_DIR}
${OSG_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${SIP_INCLUDE_DIR}
../../core ../../core/raster
../../gui
..
Expand Down Expand Up @@ -86,6 +112,7 @@ TARGET_LINK_LIBRARIES(globeplugin
${OPENTHREADS_LIBRARY}
)

ADD_SUBDIRECTORY(python)

########################################################
# Install
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/globe/globe_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
, mTileSource( 0 )
, mElevationManager( 0 )
, mObjectPlacer( 0 )
, mGlobeInterface( this )
{
mIsGlobeRunning = false;
//needed to be "seen" by other plugins by doing
Expand Down Expand Up @@ -163,6 +164,11 @@ GlobePlugin::~GlobePlugin()
{
}

QgsPluginInterface* GlobePlugin::pluginInterface()
{
return &mGlobeInterface;
}

struct PanControlHandler : public NavigationControlHandler
{
PanControlHandler( osgEarth::Util::EarthManipulator* manip, double dx, double dy ) : _manip( manip ), _dx( dx ), _dy( dy ) { }
Expand Down
13 changes: 11 additions & 2 deletions src/plugins/globe/globe_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
#ifndef QGS_GLOBE_PLUGIN_H
#define QGS_GLOBE_PLUGIN_H

#include "qgsconfig.h"
#include "globe_plugin_dialog.h"
#include "qgisplugin.h"
#include "qgsconfig.h"
#include "qgsglobeinterface.h"
#include "qgsosgearthtilesource.h"
#include "globe_plugin_dialog.h"

#include <QObject>

#include <osgViewer/Viewer>
#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
Expand Down Expand Up @@ -66,6 +69,10 @@ class GlobePlugin : public QObject, public QgisPlugin
GlobePlugin( QgisInterface* theQgisInterface );
virtual ~GlobePlugin();

public:
//! offer an interface for python plugins
virtual QgsPluginInterface* pluginInterface();

public slots:
//! init the gui
virtual void initGui();
Expand Down Expand Up @@ -171,6 +178,8 @@ class GlobePlugin : public QObject, public QgisPlugin
osgEarth::ElevationQuery* mElevationManager;
//! Object placer
osgEarth::Util::ObjectLocator* mObjectPlacer;
//! The public interface for this plugin
QgsGlobeInterface mGlobeInterface;
#else
//! Elevation manager
osgEarth::Util::ElevationManager* mElevationManager;
Expand Down
Loading