Move QgsNative instance from app->QgsGui singleton

This allows gui widgets to utilise native platform interfaces.
Additionally attaching the instance to QgsGui allows QgsNative
to become a QObject in future if required and for use
of signals/slots in the native interfaces.
This commit is contained in:
Nyall Dawson 2017-05-15 09:56:52 +10:00
parent cbc2a3df64
commit 6efe160a65
11 changed files with 41 additions and 24 deletions

View File

@ -31,6 +31,7 @@ class QgsGui
:rtype: QgsGui
%End
static QgsEditorWidgetRegistry *editorWidgetRegistry();
%Docstring
Returns the global editor widget registry, used for managing all known edit widget factories.

View File

@ -206,6 +206,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsmimedatautils.h"
#include "qgsmessagelog.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsnative.h"
#include "qgsnewvectorlayerdialog.h"
#include "qgsnewmemorylayerdialog.h"
#include "qgsoptions.h"
@ -1200,12 +1201,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}
#endif
#ifdef Q_OS_MAC
mNative = new QgsMacNative();
#else
mNative = new QgsNative();
#endif
} // QgisApp ctor
QgisApp::QgisApp()
@ -6125,7 +6120,7 @@ void QgisApp::activate()
void QgisApp::bringAllToFront()
{
mNative->currentAppActivateIgnoringOtherApps();
QgsGui::nativePlatformInterface()->currentAppActivateIgnoringOtherApps();
}
void QgisApp::addWindow( QAction *action )

View File

@ -139,8 +139,6 @@ class QgsDiagramProperties;
#include "ui_qgisapp.h"
#include "qgis_app.h"
#include "qgsnative.h"
#include <QGestureEvent>
#include <QTapAndHoldGesture>
@ -1969,8 +1967,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QHash< QgsComposition *, QgsMapLayerAction * > mAtlasFeatureActions;
QgsNative *mNative = nullptr;
int mProjOpen;
bool gestureEvent( QGestureEvent *event );

View File

@ -744,6 +744,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/effects
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/gui
${CMAKE_BINARY_DIR}/src/native
../core
../core/annotations
../core/auth
@ -758,6 +759,7 @@ INCLUDE_DIRECTORIES(
../core/symbology-ng
../core/effects
../core/metadata
../native
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../ui
)
@ -804,6 +806,7 @@ SET(QGIS_GUI_HDRS ${QGIS_GUI_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/qgis_gui.h)
IF(NOT APPLE)
INSTALL(FILES ${QGIS_GUI_HDRS} ${QGIS_GUI_MOC_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
ELSE(NOT APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
SET_TARGET_PROPERTIES(qgis_gui PROPERTIES
CLEAN_DIRECT_OUTPUT 1
FRAMEWORK 1
@ -838,6 +841,7 @@ ADD_DEPENDENCIES(qgis_gui ui)
TARGET_LINK_LIBRARIES(qgis_gui
qgis_core
qgis_native
${QT_QTUITOOLS_LIBRARY}
${QWT_LIBRARY}
${QSCINTILLA_LIBRARY}

View File

@ -19,6 +19,7 @@
#include "qgseditorwidgetregistry.h"
#include "qgslayertreeembeddedwidgetregistry.h"
#include "qgsmaplayeractionregistry.h"
#include "qgsnative.h"
#include "qgsshortcutsmanager.h"
QgsGui *QgsGui::instance()
@ -27,6 +28,11 @@ QgsGui *QgsGui::instance()
return sInstance;
}
QgsNative *QgsGui::nativePlatformInterface()
{
return instance()->mNative;
}
QgsEditorWidgetRegistry *QgsGui::editorWidgetRegistry()
{
return instance()->mEditorWidgetRegistry;
@ -53,10 +59,17 @@ QgsGui::~QgsGui()
delete mEditorWidgetRegistry;
delete mMapLayerActionRegistry;
delete mShortcutsManager;
delete mNative;
}
QgsGui::QgsGui()
{
#ifdef Q_OS_MAC
mNative = new QgsMacNative();
#else
mNative = new QgsNative();
#endif
mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
mShortcutsManager = new QgsShortcutsManager();
mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();

View File

@ -19,11 +19,13 @@
#define QGSGUI_H
#include "qgis_gui.h"
#include "qgis_sip.h"
class QgsEditorWidgetRegistry;
class QgsShortcutsManager;
class QgsLayerTreeEmbeddedWidgetRegistry;
class QgsMapLayerActionRegistry;
class QgsNative;
/**
* \ingroup gui
@ -46,6 +48,13 @@ class GUI_EXPORT QgsGui
*/
static QgsGui *instance();
/**
* Returns the global native interface, which offers abstraction to the host OS's underlying public
* interfaces.
* \note Not available in Python bindings
*/
SIP_SKIP static QgsNative *nativePlatformInterface();
/**
* Returns the global editor widget registry, used for managing all known edit widget factories.
*/
@ -72,6 +81,7 @@ class GUI_EXPORT QgsGui
QgsGui();
QgsNative *mNative = nullptr;
QgsEditorWidgetRegistry *mEditorWidgetRegistry = nullptr;
QgsShortcutsManager *mShortcutsManager = nullptr;
QgsLayerTreeEmbeddedWidgetRegistry *mLayerTreeEmbeddedWidgetRegistry = nullptr;

View File

@ -17,10 +17,6 @@
#include "qgsnative.h"
QgsNative::QgsNative()
{
}
void QgsNative::currentAppActivateIgnoringOtherApps()
{
}

View File

@ -21,18 +21,20 @@
#include "qgis_native.h"
/**
* \class QgsNative
* \ingroup native
* Base class for implementing methods for native system calls that
* are implemented in subclasses to provide platform abstraction.
* \since QGIS 3.0
*/
class NATIVE_EXPORT QgsNative
{
public:
QgsNative();
virtual ~QgsNative() = default;
/**
* Bring QGIS to front. Default implementation does nothing.
*
* @note Added in QGIS 3.0
* Brings the QGIS app to front. The default implementation does nothing.
*/
virtual void currentAppActivateIgnoringOtherApps();
};

View File

@ -22,8 +22,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/app
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/app/pluginmanager
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/test
${CMAKE_SOURCE_DIR}/src/native
${CMAKE_BINARY_DIR}/src/native
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/gui
${CMAKE_BINARY_DIR}/src/python
@ -79,8 +77,6 @@ MACRO (ADD_QGIS_TEST testname testsrc)
TARGET_LINK_LIBRARIES(qgis_${testname} ${APP_SERVICES_LIBRARY} )
ENDIF(APPLE)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
TARGET_LINK_LIBRARIES(qgis_${testname} qgis_native)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
#SET_TARGET_PROPERTIES(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )

View File

@ -21,6 +21,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/raster
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/symbology-ng
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/test
${CMAKE_SOURCE_DIR}/src/native
${CMAKE_BINARY_DIR}/src/native
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/gui
)
@ -87,6 +89,8 @@ MACRO (ADD_QGIS_TEST testname testsrc)
qgis_core
qgis_gui)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
TARGET_LINK_LIBRARIES(qgis_${testname} qgis_native)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
#SET_TARGET_PROPERTIES(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )

View File

@ -65,7 +65,7 @@ MACRO (ADD_QGIS_TEST testname testsrc)
TARGET_LINK_LIBRARIES(qgis_${testname}
${QT_QTCORE_LIBRARY}
${QT_QTTEST_LIBRARY}
qgis_app
qgis_gui
qgis_native
)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)