Skip to content

Commit

Permalink
Create a virtual QgsNative base class for platform services
Browse files Browse the repository at this point in the history
A QgsNative base class is added, that offers default implementations for
a platform interface. These methods can be overridded for the current
platform at compile time to allow specialized handling for integration
with the current system.
  • Loading branch information
m-kuhn authored and nyalldawson committed May 14, 2017
1 parent f6bd7b3 commit d1593ca
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 139 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,6 @@ ADD_CUSTOM_TARGET(version ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/qgsversion.h)
#TEST_DATA_DIR is also used by QgsRenderChecker currently in core
SET (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata")

SET(USE_NATIVE_LIB FALSE)
IF(APPLE)
SET(USE_NATIVE_LIB TRUE)
ENDIF(APPLE)

ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(doc)
ADD_SUBDIRECTORY(images)
Expand Down
4 changes: 1 addition & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
IF(USE_NATIVE_LIB)
ADD_SUBDIRECTORY(native)
ENDIF(USE_NATIVE_LIB)
ADD_SUBDIRECTORY(native)

ADD_SUBDIRECTORY(core)
ADD_SUBDIRECTORY(analysis)
Expand Down
20 changes: 8 additions & 12 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ INCLUDE_DIRECTORIES(
openstreetmap
dwg
dwg/libdxfrw
${CMAKE_SOURCE_DIR}/src/native
${CMAKE_BINARY_DIR}/src/native
)
INCLUDE_DIRECTORIES(SYSTEM
${SPATIALITE_INCLUDE_DIR}
Expand All @@ -535,16 +537,14 @@ IF(ENABLE_MODELTEST)
INCLUDE_DIRECTORIES(../../tests/qt_modeltest)
ENDIF(ENABLE_MODELTEST)

IF (USE_NATIVE_LIB)
IF(APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
ENDIF(APPLE)
ENDIF(USE_NATIVE_LIB)

IF (ANDROID)
INCLUDE_DIRECTORIES(SYSTEM ${ANDROID_NDK_TOOLCHAIN_ROOT}/sysroot/usr/include)
ENDIF (ANDROID)

IF (APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
ENDIF (APPLE)

IF (POSTGRES_FOUND)
INCLUDE_DIRECTORIES(SYSTEM ${POSTGRES_INCLUDE_DIR})
ENDIF (POSTGRES_FOUND)
Expand Down Expand Up @@ -572,6 +572,7 @@ TARGET_LINK_LIBRARIES(qgis_app
qgis_core
qgis_gui
qgis_analysis
qgis_native
libdxfrw
)

Expand All @@ -592,9 +593,6 @@ IF (APPLE)
TARGET_LINK_LIBRARIES(qgis_app ${APP_SERVICES_LIBRARY})
ENDIF(APPLE)

IF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(qgis_app qgis_native)
ENDIF(USE_NATIVE_LIB)

if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
SET_TARGET_PROPERTIES(qgis_app PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
Expand All @@ -615,9 +613,7 @@ IF(WIN32)
TARGET_LINK_LIBRARIES(qgis_app DbgHelp Qt5::WinExtras)
ENDIF(WIN32)

IF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} qgis_native)
ENDIF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} qgis_native)

IF (APPLE)
SET_TARGET_PROPERTIES(${QGIS_APP_NAME} PROPERTIES
Expand Down
23 changes: 9 additions & 14 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
//
#ifdef Q_OS_MACX
#include <ApplicationServices/ApplicationServices.h>

// Virtual interfaces to Cocoa objective-c frameworks/classes/calls
// cocoainitializer is to handle objective-c garbage collection
// see: http://el-tramo.be/blog/mixing-cocoa-and-qt/
//#include "cocoainitializer.h"
#include "qgsmacappkit.h"
#include "qgsmacnative.h"

// check macro breaks QItemDelegate
#ifdef check
Expand Down Expand Up @@ -1205,6 +1200,12 @@ 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()
Expand All @@ -1216,7 +1217,7 @@ QgisApp::QgisApp()
, mMapToolGroup( nullptr )
, mPreviewGroup( nullptr )
#ifdef Q_OS_MAC
, mWindowMenu( 0 )
, mWindowMenu( nullptr )
#endif
, mPanelMenu( nullptr )
, mToolbarMenu( nullptr )
Expand Down Expand Up @@ -6124,13 +6125,7 @@ void QgisApp::activate()

void QgisApp::bringAllToFront()
{
#ifdef Q_OS_MAC
// Bring forward all open windows while maintaining layering order
// method valid for Mac OS X >= 10.6
QgsNSRunningApplication* nsrapp = new QgsNSRunningApplication();
nsrapp->currentAppActivateIgnoringOtherApps();
delete nsrapp;
#endif
mNative->currentAppActivateIgnoringOtherApps();
}

void QgisApp::addWindow( QAction *action )
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class QgsDiagramProperties;
#include "ui_qgisapp.h"
#include "qgis_app.h"

#include "qgsnative.h"

#include <QGestureEvent>
#include <QTapAndHoldGesture>

Expand Down Expand Up @@ -1967,6 +1969,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QHash< QgsComposition *, QgsMapLayerAction * > mAtlasFeatureActions;

QgsNative *mNative = nullptr;

int mProjOpen;

bool gestureEvent( QGestureEvent *event );
Expand Down
9 changes: 1 addition & 8 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1044,11 +1044,6 @@ INCLUDE_DIRECTORIES(SYSTEM
${QTKEYCHAIN_INCLUDE_DIR}
)

IF(USE_NATIVE_LIB)
IF(APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
ENDIF(APPLE)
ENDIF(USE_NATIVE_LIB)

#for PAL classes
IF (WIN32)
Expand Down Expand Up @@ -1118,9 +1113,7 @@ IF (WIN32)
TARGET_LINK_LIBRARIES(qgis_core wsock32 ${SETUPAPI_LIBRARY} DbgHelp)
ENDIF (WIN32)

IF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(qgis_core qgis_native)
ENDIF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(qgis_core qgis_native)

IF (NOT WITH_INTERNAL_QEXTSERIALPORT)
TARGET_LINK_LIBRARIES(qgis_core ${QEXTSERIALPORT_LIBRARY})
Expand Down
45 changes: 24 additions & 21 deletions src/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,56 @@ ENDIF(APPLE)
#############################################################
# sources

SET(QGIS_CORE_SRCS)
SET(QGIS_NATIVE_SRCS
qgsnative.cpp
)

IF(APPLE)
SET(QGIS_APP_OBJC_SRCS
mac/cocoainitializer.mm
mac/qgsmacappkit.mm
mac/qgsmacnative.mm
)

SET_SOURCE_FILES_PROPERTIES(${QGIS_APP_OBJC_SRCS} PROPERTIES COMPILE_FLAGS "-x objective-c++")

SET(QGIS_CORE_SRCS ${QGIS_CORE_SRCS}
SET(QGIS_NATIVE_SRCS ${QGIS_NATIVE_SRCS}
${QGIS_APP_OBJC_SRCS}
mac/qgsmacnative.cpp
)
ENDIF(APPLE)

SET(QGIS_CORE_MOC_HDRS)

QT4_WRAP_CPP(QGIS_CORE_MOC_SRCS ${QGIS_CORE_MOC_HDRS})
SET(QGIS_NATIVE_HDRS
qgsnative.h
)

# install headers

IF(APPLE)
SET (QGIS_CORE_HDRS ${QGIS_CORE_HDRS}
SET (QGIS_NATIVE_HDRS ${QGIS_NATIVE_HDRS}
mac/qgsmacnative.h
mac/cocoainitializer.h
mac/qgsmacappkit.h
)
ENDIF(APPLE)

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)

IF(APPLE)
INCLUDE_DIRECTORIES(mac)
ENDIF(APPLE)

# Test data dir for QgsRenderChecker
ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")

#############################################################
# qgis_native library

ADD_LIBRARY(qgis_native SHARED ${QGIS_CORE_SRCS} ${QGIS_CORE_MOC_SRCS} ${QGIS_CORE_HDRS} ${QGIS_CORE_MOC_HDRS})
ADD_LIBRARY(qgis_native SHARED ${QGIS_NATIVE_SRCS} ${QGIS_NATIVE_HDRS})

GENERATE_EXPORT_HEADER(
qgis_native
BASE_NAME NATIVE
EXPORT_FILE_NAME qgis_native.h
)

SET(QGIS_NATIVE_HDRS ${QGIS_NATIVE_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/qgis_native.h)

IF(NOT APPLE)
INSTALL(FILES ${QGIS_CORE_HDRS} ${QGIS_CORE_MOC_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
INSTALL(FILES ${QGIS_NATIVE_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
ELSE(NOT APPLE)
SET_TARGET_PROPERTIES(qgis_native PROPERTIES
CLEAN_DIRECT_OUTPUT 1
Expand All @@ -84,7 +86,7 @@ ELSE(NOT APPLE)
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${COMPLETE_VERSION}
MACOSX_FRAMEWORK_IDENTIFIER org.qgis.qgis2_native
BUILD_WITH_INSTALL_RPATH TRUE
PUBLIC_HEADER "${QGIS_CORE_HDRS};${QGIS_CORE_MOC_HDRS}"
PUBLIC_HEADER "${QGIS_NATIVE_HDRS}"
LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
)
ENDIF(NOT APPLE)
Expand All @@ -94,7 +96,7 @@ IF(NOT ANDROID)
SET_TARGET_PROPERTIES(qgis_native PROPERTIES
VERSION ${COMPLETE_VERSION}
SOVERSION ${COMPLETE_VERSION}
)
)
ENDIF(NOT ANDROID)

TARGET_LINK_LIBRARIES(qgis_native "${NATIVE_LINK_LIBS}")
Expand All @@ -106,7 +108,8 @@ INSTALL(TARGETS qgis_native
LIBRARY DESTINATION ${QGIS_LIB_DIR}
ARCHIVE DESTINATION ${QGIS_LIB_DIR}
FRAMEWORK DESTINATION ${QGIS_FW_SUBDIR}
PUBLIC_HEADER DESTINATION ${QGIS_INCLUDE_DIR})
PUBLIC_HEADER DESTINATION ${QGIS_INCLUDE_DIR}
)

# Mac dev frameworks

Expand Down
11 changes: 6 additions & 5 deletions src/native/mac/qgsmacnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#ifndef QGSMACNATIVE_H
#define QGSMACNATIVE_H

class QgsMacAppKit
#include "qgsnative.h"

class NATIVE_EXPORT QgsMacNative : public QgsNative
{
public:
virtual ~QgsMacAppKit();
virtual ~QgsMacNative();

// NSRunningApplication interface
virtual const char* currentAppLocalizedName() = 0;
virtual void currentAppActivateIgnoringOtherApps() = 0;
virtual const char* currentAppLocalizedName();
virtual void currentAppActivateIgnoringOtherApps() override;
};

#endif // QGSMACNATIVE_H
25 changes: 5 additions & 20 deletions src/native/mac/qgsmacappkit.mm → src/native/mac/qgsmacnative.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
qgsmacappkit.mm - interface to Mac objective-c AppKit.framework
qgsmacnative.cpp - abstracted interface to native Mac objective-c
-------------------
begin : January 2014
copyright : (C) 2014 by Larry Shaffer
Expand All @@ -15,35 +15,20 @@
* *
***************************************************************************/

#include "qgsmacappkit.h"
#include "qgsmacnative.h"

#include <Cocoa/Cocoa.h>

class QgsNSRunningApplication::Private
QgsMacNative::~QgsMacNative()
{
public:
// NSObject *obj;
};

QgsNSRunningApplication::QgsNSRunningApplication()
{
// d = new Private;
// d->obj = [NSObject someFunction];
}

QgsNSRunningApplication::~QgsNSRunningApplication()
{
// [d->obj release];
// delete d;
// d = 0;
}

const char* QgsNSRunningApplication::currentAppLocalizedName()
const char* QgsMacNative::currentAppLocalizedName()
{
return [[[NSRunningApplication currentApplication] localizedName] UTF8String];
}

void QgsNSRunningApplication::currentAppActivateIgnoringOtherApps()
void QgsMacNative::currentAppActivateIgnoringOtherApps()
{
// valid for Mac OS X >= 10.6
[[NSRunningApplication currentApplication] activateWithOptions:
Expand Down
16 changes: 10 additions & 6 deletions src/native/mac/qgsmacnative.cpp → src/native/qgsnative.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/***************************************************************************
qgsmacnative.cpp - abstracted interface to native Mac objective-c
qgsnative.cpp - abstracted interface to native system calls
-------------------
begin : January 2014
copyright : (C) 2014 by Larry Shaffer
email : larrys at dakotacarto dot com
begin : January 2017
copyright : (C) 2017 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************/

/***************************************************************************
Expand All @@ -15,8 +15,12 @@
* *
***************************************************************************/

#include "qgsmacnative.h"
#include "qgsnative.h"

QgsMacAppKit::~QgsMacAppKit()
QgsNative::QgsNative()
{
}

void QgsNative::currentAppActivateIgnoringOtherApps()
{
}
Loading

0 comments on commit d1593ca

Please sign in to comment.