Skip to content

Commit 916dbce

Browse files
authoredSep 4, 2017
Merge pull request #5128 from manisandro/globe
[Globe] Adapt for QGIS API changes, add Qt5 compatibility, support osgEarth up to current git master
2 parents c43cd99 + 14f9cd1 commit 916dbce

22 files changed

+267
-253
lines changed
 

‎cmake/FindOSGEARTH.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ FIND_OSGEARTH_INCLUDE( OSGEARTH_ELEVATION_QUERY osgEarth/ElevationQuery )
4848

4949
###### libraries ######
5050

51-
MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY MYLIBRARYNAME )
51+
MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY )
5252

5353
FIND_LIBRARY(${MYLIBRARY}
5454
NAMES
55-
${MYLIBRARYNAME}
55+
${ARGN}
5656
PATHS
5757
${OSGEARTH_DIR}
5858
$ENV{OSGEARTH_BUILD_DIR}
@@ -93,8 +93,8 @@ FIND_OSGEARTH_LIBRARY( OSGEARTHFEATURES_LIBRARY_DEBUG osgEarthFeaturesd )
9393
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY osgEarthSymbology )
9494
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY_DEBUG osgEarthSymbologyd )
9595

96-
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt )
97-
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY_DEBUG osgEarthQtd )
96+
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt5 osgEarthQt)
97+
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY_DEBUG osgEarthQtd osgEarthQt5d)
9898

9999
FIND_OSGEARTH_LIBRARY( OSGEARTHANNOTATION_LIBRARY osgEarthAnnotation )
100100
FIND_OSGEARTH_LIBRARY( OSGEARTHANNOTATION_LIBRARY_DEBUG osgEarthAnnotationd )

‎src/plugins/globe/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PA
33

44
FIND_PACKAGE(OSG REQUIRED)
55
FIND_PACKAGE(OSGEARTH REQUIRED)
6-
FIND_PACKAGE(Threads)
6+
FIND_PACKAGE(Qt5OpenGL REQUIRED)
77

88
########################################################
99
# Files
@@ -55,18 +55,18 @@ QT5_WRAP_CPP (GLOBE_PLUGIN_MOC_SRCS ${GLOBE_PLUGIN_MOC_HDRS})
5555
QT5_ADD_RESOURCES(GLOBE_PLUGIN_RCC_SRCS ${GLOBE_PLUGIN_RCCS})
5656

5757
ADD_LIBRARY (globeplugin SHARED ${GLOBE_PLUGIN_SRCS} ${GLOBE_PLUGIN_MOC_SRCS} ${GLOBE_PLUGIN_RCC_SRCS} ${GLOBE_PLUGIN_UIS_H} ${GLOBE_PLUGIN_HDRS})
58-
5958
INCLUDE_DIRECTORIES(
6059
${CMAKE_CURRENT_BINARY_DIR}
60+
${Qt5OpenGL_INCLUDE_DIRS}
6161
${OSGEARTH_INCLUDE_DIR}
6262
${OSG_INCLUDE_DIR}
6363
${GEOS_INCLUDE_DIR}
6464
${SIP_INCLUDE_DIR}
6565
../../core
66+
../../core/expression
6667
../../core/geometry
6768
../../core/metadata
6869
../../core/raster
69-
../../core/symbology
7070
../../gui
7171
..
7272
${CMAKE_BINARY_DIR}/src/core
@@ -76,7 +76,7 @@ INCLUDE_DIRECTORIES(
7676
TARGET_LINK_LIBRARIES(globeplugin
7777
qgis_core
7878
qgis_gui
79-
${QT_QTOPENGL_LIBRARY}
79+
Qt5::OpenGL
8080
${OSGDB_LIBRARY}
8181
${OSGGA_LIBRARY}
8282
${OSGUTIL_LIBRARY}

‎src/plugins/globe/CMakeModules/FindOSG.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ FIND_OSG_LIBRARY( OSGVIEWER_LIBRARY_DEBUG osgViewerd )
106106
FIND_OSG_LIBRARY( OSGGA_LIBRARY osgGA )
107107
FIND_OSG_LIBRARY( OSGGA_LIBRARY_DEBUG osgGAd )
108108

109-
FIND_OSG_LIBRARY( OSGQT_LIBRARY osgQt )
110-
FIND_OSG_LIBRARY( OSGQT_LIBRARY_DEBUG osgQtd )
109+
FIND_OSG_LIBRARY( OSGQT_LIBRARY osgQt5 osgQt )
110+
FIND_OSG_LIBRARY( OSGQT_LIBRARY_DEBUG osgQt5d osgQtd )
111111

112112
FIND_OSG_LIBRARY( OSGWIDGET_LIBRARY osgWidget )
113113
FIND_OSG_LIBRARY( OSGWIDGET_LIBRARY_DEBUG osgWidgetd )

‎src/plugins/globe/WorldWindOptions

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎src/plugins/globe/featuresource/qgsglobefeatureoptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class QgsGlobeFeatureOptions : public osgEarth::Features::FeatureSourceOptions /
7474
}
7575

7676
osgEarth::optional<std::string> mLayerId;
77-
QgsVectorLayer *mLayer = nullptr;
77+
QgsVectorLayer *mLayer = nullptr;
7878
};
7979

8080
#endif // QGSGLOBEFEATUREOPTIONS_H

‎src/plugins/globe/featuresource/qgsglobefeaturesource.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#include <osgDB/ReaderWriter>
1617
#include <osgDB/FileNameUtils>
1718

@@ -27,32 +28,48 @@
2728
#include "qgsglobefeaturesource.h"
2829

2930

30-
QgsGlobeFeatureSource::QgsGlobeFeatureSource( const QgsGlobeFeatureOptions &options ) :
31-
mOptions( options ),
32-
mLayer( 0 ),
33-
mProfile( 0 )
31+
QgsGlobeFeatureSource::QgsGlobeFeatureSource( const QgsGlobeFeatureOptions &options )
32+
: mOptions( options )
33+
, mLayer( 0 )
34+
#if OSGEARTH_VERSION_LESS_THAN(2, 8, 0)
35+
, mProfile( 0 )
36+
#endif
3437
{
3538
}
3639

40+
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
41+
osgEarth::Status QgsGlobeFeatureSource::initialize( const osgDB::Options *dbOptions )
42+
{
43+
#else
3744
void QgsGlobeFeatureSource::initialize( const osgDB::Options *dbOptions )
3845
{
46+
#endif
3947
Q_UNUSED( dbOptions )
4048
mLayer = mOptions.layer();
4149

4250
connect( mLayer, SIGNAL( attributeValueChanged( QgsFeatureId, int, QVariant ) ), this, SLOT( attributeValueChanged( QgsFeatureId, int, QVariant ) ) );
43-
connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, const QgsGeometry & ) ), this, SLOT( geometryChanged( QgsFeatureId, const QgsGeometry & ) ) );
51+
connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry ) ), this, SLOT( geometryChanged( QgsFeatureId, QgsGeometry ) ) );
4452

4553
// create the profile
4654
osgEarth::SpatialReference *ref = osgEarth::SpatialReference::create( mLayer->crs().toWkt().toStdString() );
4755
if ( 0 == ref )
4856
{
4957
std::cout << "Cannot find the spatial reference" << std::endl;
58+
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
59+
return osgEarth::Status( osgEarth::Status::ConfigurationError );
60+
#else
5061
return;
62+
#endif
5163
}
5264
QgsRectangle ext = mLayer->extent();
5365
osgEarth::GeoExtent geoext( ref, ext.xMinimum(), ext.yMinimum(), ext.xMaximum(), ext.yMaximum() );
54-
mProfile = new osgEarth::Features::FeatureProfile( geoext );
5566
mSchema = QgsGlobeFeatureUtils::schemaForFields( mLayer->pendingFields() );
67+
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
68+
setFeatureProfile( new osgEarth::Features::FeatureProfile( geoext ) );
69+
return osgEarth::Status( osgEarth::Status::NoError );
70+
#else
71+
mProfile = new osgEarth::Features::FeatureProfile( geoext );
72+
#endif
5673
}
5774

5875
osgEarth::Features::FeatureCursor *QgsGlobeFeatureSource::createFeatureCursor( const osgEarth::Symbology::Query &query )

‎src/plugins/globe/featuresource/qgsglobefeaturesource.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
1516
#ifndef QGSGLOBEFEATURESOURCE_H
1617
#define QGSGLOBEFEATURESOURCE_H
1718

1819
#include <osgEarthFeatures/FeatureSource>
20+
#include <osgEarth/Version>
1921
#include <QObject>
2022

2123
#include "qgsglobefeatureoptions.h"
@@ -38,18 +40,26 @@ class QgsGlobeFeatureSource : public QObject, public osgEarth::Features::Feature
3840
const char *className() const override { return "QGISFeatureSource"; }
3941
const char *libraryName() const override { return "QGIS"; }
4042

41-
void initialize( const osgDB::Options *dbOptions ) override;
43+
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
44+
osgEarth::Status initialize( const osgDB::Options *dbOptions );
45+
#else
46+
void initialize( const osgDB::Options *dbOptions );
47+
#endif
4248

4349
protected:
50+
#if OSGEARTH_VERSION_LESS_THAN(2, 8, 0)
4451
const osgEarth::Features::FeatureProfile *createFeatureProfile() override { return mProfile; }
52+
#endif
4553
const osgEarth::Features::FeatureSchema &getSchema() const override { return mSchema; }
4654

4755
~QgsGlobeFeatureSource() {}
4856

4957
private:
5058
QgsGlobeFeatureOptions mOptions;
5159
QgsVectorLayer *mLayer = nullptr;
60+
#if OSGEARTH_VERSION_LESS_THAN(2, 8, 0)
5261
osgEarth::Features::FeatureProfile *mProfile = nullptr;
62+
#endif
5363
osgEarth::Features::FeatureSchema mSchema;
5464
typedef std::map<osgEarth::Features::FeatureID, osg::observer_ptr<osgEarth::Features::Feature> > FeatureMap_t;
5565
FeatureMap_t mFeatures;

‎src/plugins/globe/featuresource/qgsglobefeatureutils.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class QgsGlobeFeatureUtils
3636
return QgsPoint( QgsWkbTypes::PointZ, pt.x(), pt.y(), pt.z() );
3737
}
3838

39-
static inline osg::Vec3d pointFromQgsPointXY( const QgsPoint &pt )
39+
static inline osg::Vec3d pointFromQgsPoint( const QgsPoint &pt )
4040
{
4141
return osg::Vec3d( pt.x(), pt.y(), pt.z() );
4242
}
@@ -47,7 +47,7 @@ class QgsGlobeFeatureUtils
4747
osgEarth::Features::LineString *retLineString = new osgEarth::Features::LineString();
4848
for ( int iVtx = 0, nVtx = linearString->vertexCount(); iVtx < nVtx; ++iVtx )
4949
{
50-
retLineString->push_back( pointFromQgsPointXY( linearString->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
50+
retLineString->push_back( pointFromQgsPoint( linearString->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
5151
}
5252
delete linearString;
5353
return retLineString;
@@ -63,7 +63,7 @@ class QgsGlobeFeatureUtils
6363
// the outer ring
6464
for ( int iVtx = 0, nVtx = linearPolygon->vertexCount( 0, 0 ); iVtx < nVtx; ++iVtx )
6565
{
66-
retPoly->push_back( pointFromQgsPointXY( linearPolygon->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
66+
retPoly->push_back( pointFromQgsPoint( linearPolygon->vertexAt( QgsVertexId( 0, 0, iVtx ) ) ) );
6767
}
6868
retPoly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );
6969

@@ -72,7 +72,7 @@ class QgsGlobeFeatureUtils
7272
osgEarth::Features::Ring *innerRing = new osgEarth::Features::Ring();
7373
for ( int iVtx = 0, nVtx = linearPolygon->vertexCount( 0, iRing ); iVtx < nVtx; ++iVtx )
7474
{
75-
innerRing->push_back( pointFromQgsPointXY( linearPolygon->vertexAt( QgsVertexId( 0, iRing, iVtx ) ) ) );
75+
innerRing->push_back( pointFromQgsPoint( linearPolygon->vertexAt( QgsVertexId( 0, iRing, iVtx ) ) ) );
7676
}
7777
innerRing->rewind( osgEarth::Symbology::Ring::ORIENTATION_CW );
7878
retPoly->getHoles().push_back( osg::ref_ptr<osgEarth::Features::Ring>( innerRing ) );
@@ -97,7 +97,7 @@ class QgsGlobeFeatureUtils
9797
case QgsWkbTypes::Point:
9898
{
9999
osgEarth::Features::PointSet *pointSet = new osgEarth::Features::PointSet();
100-
pointSet->push_back( pointFromQgsPointXY( *static_cast<QgsPoint *>( geom.geometry() ) ) );
100+
pointSet->push_back( pointFromQgsPoint( *static_cast<QgsPoint *>( geom.geometry() ) ) );
101101
return pointSet;
102102
}
103103

@@ -107,7 +107,7 @@ class QgsGlobeFeatureUtils
107107
QgsMultiPointV2 *multiPoint = static_cast<QgsMultiPointV2 *>( geom.geometry() );
108108
for ( int i = 0, n = multiPoint->numGeometries(); i < n; ++i )
109109
{
110-
pointSet->push_back( pointFromQgsPointXY( *static_cast<QgsPoint *>( multiPoint->geometryN( i ) ) ) );
110+
pointSet->push_back( pointFromQgsPoint( *static_cast<QgsPoint *>( multiPoint->geometryN( i ) ) ) );
111111
}
112112
return pointSet;
113113
}
@@ -156,7 +156,8 @@ class QgsGlobeFeatureUtils
156156
static osgEarth::Features::Feature *featureFromQgsFeature( QgsVectorLayer *layer, QgsFeature &feat )
157157
{
158158
osgEarth::Features::Geometry *nGeom = geometryFromQgsGeometry( feat.geometry() );
159-
osgEarth::Features::Feature *retFeat = new osgEarth::Features::Feature( nGeom, 0, osgEarth::Style(), feat.id() );
159+
osgEarth::SpatialReference *ref = osgEarth::SpatialReference::create( layer->crs().toWkt().toStdString() );
160+
osgEarth::Features::Feature *retFeat = new osgEarth::Features::Feature( nGeom, ref, osgEarth::Style(), feat.id() );
160161

161162
const QgsFields &fields = layer->pendingFields();
162163
const QgsAttributes &attrs = feat.attributes();

0 commit comments

Comments
 (0)
Please sign in to comment.