Skip to content

Commit 14f9cd1

Browse files
committedSep 4, 2017
[Globe] Adapt for QGIS API changes, add Qt5 compatibility, support osgEarth up to current git master
1 parent 399c2ca commit 14f9cd1

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();

‎src/plugins/globe/globe_plugin.cpp

Lines changed: 105 additions & 56 deletions
Large diffs are not rendered by default.

‎src/plugins/globe/globe_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class GLOBE_EXPORT GlobePlugin : public QObject, public QgisPlugin
125125
osgEarth::QtGui::ViewerWidget *mViewerWidget = nullptr;
126126
QgsGlobeWidget *mDockWidget = nullptr;
127127
QgsGlobePluginDialog *mSettingsDialog = nullptr;
128+
128129
QString mBaseLayerUrl;
129130
QList<QgsGlobePluginDialog::LayerDataSource> mImagerySources;
130131
QList<QgsGlobePluginDialog::LayerDataSource> mElevationSources;

‎src/plugins/globe/qgsglobefeatureidentify.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
***************************************************************************/
1515

1616
#include "qgsglobefeatureidentify.h"
17-
1817
#include "qgsmapcanvas.h"
1918
#include "qgsproject.h"
20-
#include <qgsrubberband.h>
21-
#include <qgsvectorlayer.h>
22-
#include <qgslogger.h>
23-
19+
#include "qgsrubberband.h"
20+
#include "qgsvectorlayer.h"
21+
#include "qgslogger.h"
2422
#include "featuresource/qgsglobefeaturesource.h"
2523

2624
#include <osg/ValueObject>

‎src/plugins/globe/qgsglobefrustumhighlight.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "qgsglobefrustumhighlight.h"
2323

2424
QgsGlobeFrustumHighlightCallback::QgsGlobeFrustumHighlightCallback( osg::View *view, osgEarth::Terrain *terrain, QgsMapCanvas *mapCanvas, QColor color )
25-
: osg::NodeCallback()
25+
: osg::Callback()
2626
, mView( view )
2727
, mTerrain( terrain )
2828
, mRubberBand( new QgsRubberBand( mapCanvas, QgsWkbTypes::PolygonGeometry ) )
@@ -36,23 +36,33 @@ QgsGlobeFrustumHighlightCallback::~QgsGlobeFrustumHighlightCallback()
3636
delete mRubberBand;
3737
}
3838

39-
void QgsGlobeFrustumHighlightCallback::operator()( osg::Node *, osg::NodeVisitor * )
39+
bool QgsGlobeFrustumHighlightCallback::run( osg::Object *object, osg::Object *data )
4040
{
41-
const osg::Viewport::value_type &width = mView->getCamera()->getViewport()->width();
42-
const osg::Viewport::value_type &height = mView->getCamera()->getViewport()->height();
41+
osg::Node *node = dynamic_cast<osg::Node *>( object );
42+
osg::NodeVisitor *nv = dynamic_cast<osg::NodeVisitor *>( data );
43+
if ( node && nv )
44+
{
45+
const osg::Viewport::value_type &width = mView->getCamera()->getViewport()->width();
46+
const osg::Viewport::value_type &height = mView->getCamera()->getViewport()->height();
4347

44-
osg::Vec3d corners[4];
48+
osg::Vec3d corners[4];
4549

46-
mTerrain->getWorldCoordsUnderMouse( mView, 0, 0, corners[0] );
47-
mTerrain->getWorldCoordsUnderMouse( mView, 0, height - 1, corners[1] );
48-
mTerrain->getWorldCoordsUnderMouse( mView, width - 1, height - 1, corners[2] );
49-
mTerrain->getWorldCoordsUnderMouse( mView, width - 1, 0, corners[3] );
50+
mTerrain->getWorldCoordsUnderMouse( mView, 0, 0, corners[0] );
51+
mTerrain->getWorldCoordsUnderMouse( mView, 0, height - 1, corners[1] );
52+
mTerrain->getWorldCoordsUnderMouse( mView, width - 1, height - 1, corners[2] );
53+
mTerrain->getWorldCoordsUnderMouse( mView, width - 1, 0, corners[3] );
5054

51-
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
52-
for ( int i = 0; i < 4; i++ )
55+
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
56+
for ( int i = 0; i < 4; i++ )
57+
{
58+
osg::Vec3d localCoords;
59+
mSrs->transformFromWorld( corners[i], localCoords );
60+
mRubberBand->addPoint( QgsPointXY( localCoords.x(), localCoords.y() ) );
61+
}
62+
return true;
63+
}
64+
else
5365
{
54-
osg::Vec3d localCoords;
55-
mSrs->transformFromWorld( corners[i], localCoords );
56-
mRubberBand->addPoint( QgsPointXY( localCoords.x(), localCoords.y() ) );
66+
return traverse( object, data );
5767
}
5868
}

‎src/plugins/globe/qgsglobefrustumhighlight.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifndef QGSGLOBEFRUSTUMHIGHLIGHT_H
1717
#define QGSGLOBEFRUSTUMHIGHLIGHT_H
1818

19-
#include <osg/NodeCallback>
19+
#include <osg/Callback>
2020

2121
class QgsRubberBand;
2222
namespace osg { class View; }
@@ -26,13 +26,13 @@ namespace osgEarth
2626
class SpatialReference;
2727
}
2828

29-
class QgsGlobeFrustumHighlightCallback : public osg::NodeCallback
29+
struct QgsGlobeFrustumHighlightCallback : public osg::Callback
3030
{
3131
public:
3232
QgsGlobeFrustumHighlightCallback( osg::View *view, osgEarth::Terrain *terrain, QgsMapCanvas *mapCanvas, QColor color );
3333
~QgsGlobeFrustumHighlightCallback();
3434

35-
void operator()( osg::Node *, osg::NodeVisitor * ) override;
35+
bool run( osg::Object *object, osg::Object *data ) override;
3636

3737
private:
3838
osg::View *mView = nullptr;

‎src/plugins/globe/qgsglobeplugindialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void QgsGlobePluginDialog::readProjectSettings()
210210
{
211211
// Imagery settings
212212
mImageryTreeView->clear();
213-
foreach ( const LayerDataSource &ds, getImageryDataSources() )
213+
for ( const LayerDataSource &ds : getImageryDataSources() )
214214
{
215215
QTreeWidgetItem *item = new QTreeWidgetItem( QStringList() << ds.type << ds.uri );
216216
item->setFlags( item->flags() & ~Qt::ItemIsDropEnabled );
@@ -220,7 +220,7 @@ void QgsGlobePluginDialog::readProjectSettings()
220220

221221
// Elevation settings
222222
mElevationTreeView->clear();
223-
foreach ( const LayerDataSource &ds, getElevationDataSources() )
223+
for ( const LayerDataSource &ds : getElevationDataSources() )
224224
{
225225
QTreeWidgetItem *item = new QTreeWidgetItem( QStringList() << ds.type << ds.uri );
226226
item->setFlags( item->flags() & ~Qt::ItemIsDropEnabled );
@@ -236,7 +236,7 @@ void QgsGlobePluginDialog::readProjectSettings()
236236
groupBoxSky->setChecked( QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/skyEnabled", true ) );
237237
checkBoxDateTime->setChecked( QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/overrideDateTime", false ) );
238238
dateTimeEditSky->setDateTime( QDateTime::fromString( QgsProject::instance()->readEntry( "Globe-Plugin", "/skyDateTime", QDateTime::currentDateTime().toString() ) ) );
239-
checkBoxSkyAutoAmbient->setChecked( QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/skyAutoAmbient", true ) );
239+
checkBoxSkyAutoAmbient->setChecked( QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/skyAutoAmbient", false ) );
240240
horizontalSliderMinAmbient->setValue( QgsProject::instance()->readDoubleEntry( "Globe-Plugin", "/skyMinAmbient", 30. ) );
241241
}
242242

@@ -485,7 +485,7 @@ QDateTime QgsGlobePluginDialog::getSkyDateTime() const
485485

486486
bool QgsGlobePluginDialog::getSkyAutoAmbience() const
487487
{
488-
return QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/skyAutoAmbient", true );
488+
return QgsProject::instance()->readBoolEntry( "Globe-Plugin", "/skyAutoAmbient", false );
489489
}
490490

491491
double QgsGlobePluginDialog::getSkyMinAmbient() const

‎src/plugins/globe/qgsglobeplugindialog.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</sizepolicy>
6969
</property>
7070
<property name="text">
71-
<string>Override Date / Time (UTC)</string>
71+
<string>Override Date / Time (UTC):</string>
7272
</property>
7373
</widget>
7474
</item>
@@ -229,7 +229,7 @@
229229
</sizepolicy>
230230
</property>
231231
<property name="text">
232-
<string>Vertical scale</string>
232+
<string>Vertical scale:</string>
233233
</property>
234234
</widget>
235235
</item>
@@ -602,7 +602,7 @@
602602
<item row="2" column="0">
603603
<widget class="QLabel" name="labelScrollSensitivity">
604604
<property name="text">
605-
<string>Sensitivity</string>
605+
<string>Sensitivity:</string>
606606
</property>
607607
</widget>
608608
</item>

‎src/plugins/globe/qgsglobetilesource.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
#include <osgEarth/Registry>
1919
#include <osgEarth/ImageUtils>
2020

21-
#include "qgscoordinatereferencesystem.h"
21+
#include "qgscrscache.h"
2222
#include "qgsglobetilesource.h"
2323
#include "qgscoordinatetransform.h"
2424
#include "qgslogger.h"
25+
#include "qgsmapcanvas.h"
2526
#include "qgsmaprenderercustompainterjob.h"
2627
#include "qgsmaprendererparalleljob.h"
2728

@@ -73,7 +74,7 @@ QgsGlobeTileImage::QgsGlobeTileImage( QgsGlobeTileSource *tileSource, const QgsR
7374
#else
7475
QImage qImage( mTileData, mTileSize, mTileSize, QImage::Format_ARGB32_Premultiplied );
7576
QPainter painter( &qImage );
76-
QgsMapRendererCustomPainterJob job( createSettings( qImage.logicalDpiX(), mTileSource->mLayerSet ), &painter );
77+
QgsMapRendererCustomPainterJob job( createSettings( qImage.logicalDpiX(), mTileSource->mLayers ), &painter );
7778
job.renderSynchronously();
7879

7980
setImage( mTileSize, mTileSize, 1, 4, // width, height, depth, internal_format
@@ -94,18 +95,16 @@ QgsGlobeTileImage::~QgsGlobeTileImage()
9495
#endif
9596
}
9697

97-
QgsMapSettings QgsGlobeTileImage::createSettings( int dpi, const QStringList &layerSet ) const
98+
QgsMapSettings QgsGlobeTileImage::createSettings( int dpi, const QList<QgsMapLayer *> &layers ) const
9899
{
99100
QgsMapSettings settings;
100101
settings.setBackgroundColor( QColor( Qt::transparent ) );
101102
settings.setDestinationCrs( QgsCoordinateReferenceSystem::fromOgcWmsCrs( GEO_EPSG_CRS_AUTHID ) );
102-
settings.setCrsTransformEnabled( true );
103103
settings.setExtent( mTileExtent );
104-
settings.setLayers( layerSet );
104+
settings.setLayers( layers );
105105
settings.setFlag( QgsMapSettings::DrawEditingInfo, false );
106106
settings.setFlag( QgsMapSettings::DrawLabeling, false );
107107
settings.setFlag( QgsMapSettings::DrawSelection, false );
108-
settings.setMapUnits( QgsUnitTypes::DistanceDegrees );
109108
settings.setOutputSize( QSize( mTileSize, mTileSize ) );
110109
settings.setOutputImageFormat( QImage::Format_ARGB32_Premultiplied );
111110
settings.setOutputDpi( dpi );
@@ -179,6 +178,14 @@ void QgsGlobeTileUpdateManager::removeTile( QgsGlobeTileImage *tile )
179178
}
180179
}
181180

181+
void QgsGlobeTileUpdateManager::waitForFinished() const
182+
{
183+
if ( mRenderer )
184+
{
185+
mRenderer->waitForFinished();
186+
}
187+
}
188+
182189
void QgsGlobeTileUpdateManager::start()
183190
{
184191
if ( mRenderer == 0 && !mTileQueue.isEmpty() )
@@ -187,7 +194,7 @@ void QgsGlobeTileUpdateManager::start()
187194
#ifdef GLOBE_SHOW_TILE_STATS
188195
QgsGlobeTileStatistics::instance()->updateQueueTileCount( mTileQueue.size() );
189196
#endif
190-
mRenderer = new QgsMapRendererParallelJob( mCurrentTile->createSettings( mCurrentTile->dpi(), mLayerSet ) );
197+
mRenderer = new QgsMapRendererParallelJob( mCurrentTile->createSettings( mCurrentTile->dpi(), mLayers ) );
191198
connect( mRenderer, SIGNAL( finished() ), this, SLOT( renderingFinished() ) );
192199
mRenderer->start();
193200
}
@@ -214,20 +221,31 @@ void QgsGlobeTileUpdateManager::renderingFinished()
214221

215222
///////////////////////////////////////////////////////////////////////////////
216223

217-
QgsGlobeTileSource::QgsGlobeTileSource( const osgEarth::TileSourceOptions &options )
224+
QgsGlobeTileSource::QgsGlobeTileSource( QgsMapCanvas *canvas, const osgEarth::TileSourceOptions &options )
218225
: TileSource( options )
226+
, mCanvas( canvas )
219227
{
220228
osgEarth::GeoExtent geoextent( osgEarth::SpatialReference::get( "wgs84" ), -180., -90., 180., 90. );
221229
osgEarth::DataExtentList extents;
222230
extents.push_back( geoextent );
223231
getDataExtents() = extents;
232+
#if OSGEARTH_VERSION_LESS_THAN(2, 9, 0)
224233
dirtyDataExtents();
234+
#endif
225235
}
226236

237+
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
238+
osgEarth::Status QgsGlobeTileSource::initialize( const osgDB::Options * /*dbOptions*/ )
239+
#else
227240
osgEarth::TileSource::Status QgsGlobeTileSource::initialize( const osgDB::Options * /*dbOptions*/ )
241+
#endif
228242
{
229243
setProfile( osgEarth::Registry::instance()->getGlobalGeodeticProfile() );
244+
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
245+
return osgEarth::Status( osgEarth::Status::NoError );
246+
#else
230247
return STATUS_OK;
248+
#endif
231249
}
232250

233251
osg::Image *QgsGlobeTileSource::createImage( const osgEarth::TileKey &key, osgEarth::ProgressCallback *progress )
@@ -250,9 +268,9 @@ osg::Image *QgsGlobeTileSource::createImage( const osgEarth::TileKey &key, osgEa
250268

251269
void QgsGlobeTileSource::refresh( const QgsRectangle &dirtyExtent )
252270
{
253-
mTileUpdateManager.updateLayerSet( mLayerSet );
271+
mTileUpdateManager.updateLayerSet( mLayers );
254272
mTileListLock.lock();
255-
foreach ( QgsGlobeTileImage *tile, mTiles )
273+
for ( QgsGlobeTileImage *tile : mTiles )
256274
{
257275
if ( tile->extent().intersects( dirtyExtent ) )
258276
{
@@ -262,16 +280,6 @@ void QgsGlobeTileSource::refresh( const QgsRectangle &dirtyExtent )
262280
mTileListLock.unlock();
263281
}
264282

265-
void QgsGlobeTileSource::setLayerSet( const QStringList &layerSet )
266-
{
267-
mLayerSet = layerSet;
268-
}
269-
270-
const QStringList &QgsGlobeTileSource::layerSet() const
271-
{
272-
return mLayerSet;
273-
}
274-
275283
void QgsGlobeTileSource::addTile( QgsGlobeTileImage *tile )
276284
{
277285
mTileListLock.lock();

‎src/plugins/globe/qgsglobetilesource.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define QGSGLOBETILESOURCE_H
2020

2121
#include <osgEarth/TileSource>
22+
#include <osgEarth/Version>
2223
#include <osg/ImageStream>
2324
#include <QImage>
2425
#include <QStringList>
@@ -30,6 +31,7 @@
3031

3132
class QgsCoordinateTransform;
3233
class QgsMapCanvas;
34+
class QgsMapLayer;
3335
class QgsMapRenderer;
3436
class QgsMapSettings;
3537
class QgsGlobeTileSource;
@@ -61,7 +63,7 @@ class QgsGlobeTileImage : public osg::Image
6163
QgsGlobeTileImage( QgsGlobeTileSource *tileSource, const QgsRectangle &tileExtent, int tileSize, int tileLod );
6264
~QgsGlobeTileImage();
6365
bool requiresUpdateCall() const { return !mUpdatedImage.isNull(); }
64-
QgsMapSettings createSettings( int dpi, const QStringList &layerSet ) const;
66+
QgsMapSettings createSettings( int dpi, const QList<QgsMapLayer *> &layers ) const;
6567
void setUpdatedImage( const QImage &image ) { mUpdatedImage = image; }
6668
int dpi() const { return mDpi; }
6769
const QgsRectangle &extent() { return mTileExtent; }
@@ -71,7 +73,7 @@ class QgsGlobeTileImage : public osg::Image
7173
static bool lodSort( const QgsGlobeTileImage *lhs, const QgsGlobeTileImage *rhs ) { return lhs->mLod > rhs->mLod; }
7274

7375
private:
74-
QgsGlobeTileSource *mTileSource = nullptr;
76+
osg::ref_ptr<QgsGlobeTileSource> mTileSource;
7577
QgsRectangle mTileExtent;
7678
int mTileSize;
7779
unsigned char *mTileData;
@@ -86,16 +88,17 @@ class QgsGlobeTileUpdateManager : public QObject
8688
public:
8789
QgsGlobeTileUpdateManager( QObject *parent = 0 );
8890
~QgsGlobeTileUpdateManager();
89-
void updateLayerSet( const QStringList &layerSet ) { mLayerSet = layerSet; }
91+
void updateLayerSet( const QList<QgsMapLayer *> &layers ) { mLayers = layers; }
9092
void addTile( QgsGlobeTileImage *tile );
9193
void removeTile( QgsGlobeTileImage *tile );
94+
void waitForFinished() const;
9295

9396
signals:
9497
void startRendering();
9598
void cancelRendering();
9699

97100
private:
98-
QStringList mLayerSet;
101+
QList<QgsMapLayer *> mLayers;
99102
QList<QgsGlobeTileImage *> mTileQueue;
100103
QgsGlobeTileImage *mCurrentTile = nullptr;
101104
QgsMapRendererParallelJob *mRenderer = nullptr;
@@ -109,23 +112,34 @@ class QgsGlobeTileUpdateManager : public QObject
109112
class QgsGlobeTileSource : public osgEarth::TileSource
110113
{
111114
public:
112-
QgsGlobeTileSource( const osgEarth::TileSourceOptions &options = osgEarth::TileSourceOptions() );
115+
QgsGlobeTileSource( QgsMapCanvas *canvas, const osgEarth::TileSourceOptions &options = osgEarth::TileSourceOptions() );
116+
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
117+
osgEarth::Status initialize( const osgDB::Options *dbOptions ) override;
118+
#else
113119
Status initialize( const osgDB::Options *dbOptions ) override;
120+
#endif
114121
osg::Image *createImage( const osgEarth::TileKey &key, osgEarth::ProgressCallback *progress ) override;
115122
osg::HeightField *createHeightField( const osgEarth::TileKey &/*key*/, osgEarth::ProgressCallback * /*progress*/ ) override { return 0; }
116123

117124
bool isDynamic() const override { return true; }
125+
osgEarth::CachePolicy getCachePolicyHint( const osgEarth::Profile * /*profile*/ ) const override { return osgEarth::CachePolicy::NO_CACHE; }
118126

119127
void refresh( const QgsRectangle &dirtyExtent );
120-
void setLayerSet( const QStringList &layerSet );
121-
const QStringList &layerSet() const;
128+
void setLayers( const QList<QgsMapLayer *> &layers ) { mLayers = layers; }
129+
const QList<QgsMapLayer *> &layers() const { return mLayers; }
130+
131+
void waitForFinished() const
132+
{
133+
mTileUpdateManager.waitForFinished();
134+
}
122135

123136
private:
124137
friend class QgsGlobeTileImage;
125138

126139
QMutex mTileListLock;
127140
QList<QgsGlobeTileImage *> mTiles;
128-
QStringList mLayerSet;
141+
QgsMapCanvas *mCanvas = nullptr;
142+
QList<QgsMapLayer *> mLayers;
129143
QgsGlobeTileUpdateManager mTileUpdateManager;
130144

131145
void addTile( QgsGlobeTileImage *tile );

‎src/plugins/globe/qgsglobevectorlayerproperties.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,11 @@ QgsGlobeVectorLayerPropertiesPage::QgsGlobeVectorLayerPropertiesPage( QgsVectorL
9797
checkBoxExtrusionFlatten->setChecked( layerConfig->extrusionFlatten );
9898
spinBoxExtrusionWallGradient->setValue( layerConfig->extrusionWallGradient );
9999

100-
#if OSGEARTH_VERSION_LESS_THAN(2, 7, 0)
100+
#if OSGEARTH_VERSION_LESS_THAN(2, 7, 0) || OSGEARTH_VERSION_GREATER_THAN(2, 9, 0)
101101
groupBoxLabelingEnabled->setChecked( layerConfig->labelingEnabled );
102102
checkBoxLabelingDeclutter->setChecked( layerConfig->labelingDeclutter );
103103
#else
104-
#ifdef _MSC_VER
105-
#pragma message("TODO: labeling broken with osgEarth 2.7")
106-
#else
107-
#warning "TODO: labeling broken with osgEarth 2.7"
108-
#endif
104+
// labeling broken with osgEarth 2.8
109105
groupBoxLabelingEnabled->setChecked( false );
110106
checkBoxLabelingDeclutter->setChecked( false );
111107
groupBoxLabelingEnabled->setVisible( false );

‎src/plugins/globe/qgsglobevectorlayerproperties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class QListWidgetItem;
3232

3333
class QgsGlobeVectorLayerConfig : public QObject
3434
{
35+
Q_OBJECT
3536
public:
3637
enum RenderingMode
3738
{

‎src/plugins/globe/qgsglobevectorlayerpropertiespage.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<item row="1" column="0" colspan="2">
1818
<widget class="QStackedWidget" name="stackedWidgetRenderingMode">
1919
<property name="currentIndex">
20-
<number>0</number>
20+
<number>1</number>
2121
</property>
2222
<widget class="QWidget" name="pageRasterized">
2323
<layout class="QVBoxLayout" name="verticalLayout"/>
@@ -233,7 +233,7 @@
233233
<item row="0" column="0">
234234
<widget class="QLabel" name="labelRenderingMode">
235235
<property name="text">
236-
<string>Rendering mode</string>
236+
<string>Rendering mode:</string>
237237
</property>
238238
</widget>
239239
</item>

‎src/plugins/globe/qgsglobewidget.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************
22
qgsglobewidget.cpp
33
---------------------
4-
begin : August 2010
4+
begin : August 2016
55
copyright : (C) 2016 Sandro Mani
66
email : smani at sourcepole dot ch
77
***************************************************************************
@@ -94,25 +94,25 @@ QgsGlobeWidget::QgsGlobeWidget( QgisInterface *iface, QWidget *parent )
9494
void QgsGlobeWidget::updateLayerSelectionMenu()
9595
{
9696
QStringList prevLayers;
97-
QStringList prevDisabledLayers;
98-
QStringList prevEnabledLayers;
99-
foreach ( QAction *action, mLayerSelectionMenu->actions() )
97+
QStringList prevDisabledLayerIds;
98+
QStringList prevEnabledLayerIds;
99+
for ( QAction *action : mLayerSelectionMenu->actions() )
100100
{
101101
prevLayers.append( action->data().toString() );
102102
if ( !action->isChecked() )
103103
{
104-
prevDisabledLayers.append( action->data().toString() );
104+
prevDisabledLayerIds.append( action->data().toString() );
105105
}
106106
else
107107
{
108-
prevEnabledLayers.append( action->data().toString() );
108+
prevEnabledLayerIds.append( action->data().toString() );
109109
}
110110
}
111111

112112
mLayerSelectionMenu->clear();
113113
QString heightmap = QgsProject::instance()->readEntry( "Heightmap", "layer" );
114114
// Use layerTreeRoot to get layers ordered as in the layer tree
115-
foreach ( QgsLayerTreeLayer *layerTreeLayer, QgsProject::instance()->layerTreeRoot()->findLayers() )
115+
for ( QgsLayerTreeLayer *layerTreeLayer : QgsProject::instance()->layerTreeRoot()->findLayers() )
116116
{
117117
QgsMapLayer *layer = layerTreeLayer->layer();
118118
if ( !layer )
@@ -121,29 +121,29 @@ void QgsGlobeWidget::updateLayerSelectionMenu()
121121
layerAction->setData( layer->id() );
122122
// Check if was not previously unchecked, unless it is a new layer with url=http in datasource
123123
layerAction->setCheckable( true );
124-
bool wasUnchecked = prevDisabledLayers.contains( layer->id() );
124+
bool wasUnchecked = prevDisabledLayerIds.contains( layer->id() );
125125
bool isNew = !prevLayers.contains( layer->id() );
126126
bool isRemote = layer->source().contains( "url=http" );
127127
bool isHeightmap = layer->id() == heightmap;
128128
layerAction->setChecked( !wasUnchecked && !( isNew && ( isRemote || isHeightmap ) ) );
129129
connect( layerAction, SIGNAL( toggled( bool ) ), this, SIGNAL( layersChanged() ) );
130130
mLayerSelectionMenu->addAction( layerAction );
131131
}
132-
if ( prevEnabledLayers != getSelectedLayers() )
132+
if ( prevEnabledLayerIds != getSelectedLayerIds() )
133133
emit layersChanged();
134134
}
135135

136-
QStringList QgsGlobeWidget::getSelectedLayers() const
136+
QStringList QgsGlobeWidget::getSelectedLayerIds() const
137137
{
138-
QStringList selectedLayers;
139-
foreach ( QAction *layerAction, mLayerSelectionMenu->actions() )
138+
QStringList selectedLayerIds;
139+
for ( QAction *layerAction : mLayerSelectionMenu->actions() )
140140
{
141141
if ( layerAction->isChecked() )
142142
{
143-
selectedLayers.append( layerAction->data().toString() );
143+
selectedLayerIds.append( layerAction->data().toString() );
144144
}
145145
}
146-
return selectedLayers;
146+
return selectedLayerIds;
147147
}
148148

149149
void QgsGlobeWidget::contextMenuEvent( QContextMenuEvent *e )

‎src/plugins/globe/qgsglobewidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************
22
qgsglobewidget.h
33
---------------------
4-
begin : August 2010
4+
begin : August 2016
55
copyright : (C) 2016 Sandro Mani
66
email : smani at sourcepole dot ch
77
***************************************************************************
@@ -24,7 +24,7 @@ class QgsGlobeWidget : public QDockWidget
2424
Q_OBJECT
2525
public:
2626
QgsGlobeWidget( QgisInterface *iface, QWidget *parent = 0 );
27-
QStringList getSelectedLayers() const;
27+
QStringList getSelectedLayerIds() const;
2828

2929
signals:
3030
void layersChanged();

0 commit comments

Comments
 (0)
Please sign in to comment.