Skip to content

Commit 17aca2d

Browse files
mbernasocchipka
authored andcommitted
added suppor for signals for elevationDatasourceChanged and globeClosed, they don't work yet since I neet to understand how to set viever and mSettingsDialog as sender. see FIXME in globe_plugin.cpp
Regression: moving rows up and down bug -> work on it tomorrow
1 parent 23f0195 commit 17aca2d

File tree

6 files changed

+150
-95
lines changed

6 files changed

+150
-95
lines changed

src/plugins/globe/globe_plugin.cpp

+81-60
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
7676
mElevationManager( NULL ),
7777
mObjectPlacer( NULL )
7878
{
79+
mIsGlobeRunning = false;
7980
}
8081

8182
//destructor
@@ -104,12 +105,19 @@ void GlobePlugin::initGui()
104105

105106
connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
106107
this, SLOT( extentsChanged() ) );
107-
//connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
108-
// this, SLOT( layersChanged() ) );
108+
connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
109+
this, SLOT( layersChanged() ) );
110+
//FIXME: fix sender objact, must be mSettingsDialog
111+
connect( mQGisIface->mapCanvas(), SIGNAL( elevationDatasourcesChanged() ),
112+
this, SLOT( layersChanged() ) );
109113
connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this,
110114
SLOT( projectReady() ) );
111115
connect( mQGisIface->mainWindow(), SIGNAL( newProjectCreated() ), this,
112-
SLOT( blankProject() ) );
116+
SLOT( blankProjectReady() ) );
117+
//FIXME: fix sender objact, must be mSettingsDialog
118+
connect( mQGisIface->mainWindow(), SIGNAL( globeClosed() ), this,
119+
SLOT( setGlobeNotRunning() ) );
120+
113121
}
114122

115123
void GlobePlugin::run()
@@ -158,6 +166,8 @@ void GlobePlugin::run()
158166
#ifdef GLOBE_OSG_STANDALONE_VIEWER
159167
viewer.run();
160168
#endif
169+
170+
mIsGlobeRunning = true;
161171
}
162172

163173
void GlobePlugin::settings()
@@ -259,7 +269,7 @@ void GlobePlugin::projectReady()
259269
mSettingsDialog.readElevationDatasources();
260270
}
261271

262-
void GlobePlugin::blankProject()
272+
void GlobePlugin::blankProjectReady()
263273
{//TODO
264274
QMessageBox m;
265275
m.setText("new");
@@ -600,74 +610,80 @@ typedef std::list< osg::ref_ptr<VersionedTile> > TileList;
600610
void GlobePlugin::layersChanged()
601611
{
602612
QgsDebugMsg( "layersChanged" );
613+
if ( mIsGlobeRunning ){
614+
osg::ref_ptr<Map> map = mMapNode->getMap();
603615

604-
osg::ref_ptr<Map> map = mMapNode->getMap();
605-
606-
if( map->getImageMapLayers().size() > 1 || map->getHeightFieldMapLayers().size() > 1)
607-
{
608-
viewer.getDatabasePager()->clear();
609-
}
610-
611-
// Remove elevation layers
612-
MapLayerList list = map->getHeightFieldMapLayers();
613-
for( MapLayerList::iterator i = list.begin(); i != list.end(); i++ )
614-
{
615-
map->removeMapLayer( *i );
616-
}
617-
618-
// Add elevation layers
619-
QSettings settings;
620-
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
621-
QTableWidget* table = mSettingsDialog.elevationDatasources();
622-
for(int i = 0; i < table->rowCount(); ++i)
623-
{
624-
QString type = table->item(i, 0)->text();
625-
bool cache = table->item(i, 1)->checkState();
626-
QString uri = table->item(i, 2)->text();
627-
MapLayer* layer = 0;
616+
if( map->getImageMapLayers().size() > 1 || map->getHeightFieldMapLayers().size() > 1)
617+
{
618+
viewer.getDatabasePager()->clear();
619+
}
628620

629-
if( "Raster" == type)
621+
// Remove elevation layers
622+
MapLayerList list = map->getHeightFieldMapLayers();
623+
for( MapLayerList::iterator i = list.begin(); i != list.end(); i++ )
630624
{
631-
GDALOptions* options = new GDALOptions();
632-
options->url() = uri.toStdString();
633-
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
625+
map->removeMapLayer( *i );
634626
}
635-
else if ( "Worldwind" == type )
627+
628+
// Add elevation layers
629+
QSettings settings;
630+
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
631+
QTableWidget* table = mSettingsDialog.elevationDatasources();
632+
for(int i = 0; i < table->rowCount(); ++i)
636633
{
637-
EarthFile* tmpEarth = new EarthFile(); //Hack for programatic WorldWind layer generation
638-
std::string xml = "<map name=\"Dummy\" type=\"geocentric\"><heightfield name=\"WorldWind bil\" driver=\"worldwind\"><worldwind_cache>" + cacheDirectory.toStdString() + "/globe/worldwind_srtm</worldwind_cache></heightfield></map>";
639-
std::stringstream strstr(xml);
640-
tmpEarth->readXML( strstr, "" );
641-
layer = tmpEarth->getMap()->getHeightFieldMapLayers().front();
634+
QString type = table->item(i, 0)->text();
635+
bool cache = table->item(i, 1)->checkState();
636+
QString uri = table->item(i, 2)->text();
637+
MapLayer* layer = 0;
638+
639+
if( "Raster" == type)
640+
{
641+
GDALOptions* options = new GDALOptions();
642+
options->url() = uri.toStdString();
643+
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
644+
}
645+
else if ( "Worldwind" == type )
646+
{
647+
EarthFile* tmpEarth = new EarthFile(); //Hack for programatic WorldWind layer generation
648+
std::string xml = "<map name=\"Dummy\" type=\"geocentric\"><heightfield name=\"WorldWind bil\" driver=\"worldwind\"><worldwind_cache>" + cacheDirectory.toStdString() + "/globe/worldwind_srtm</worldwind_cache></heightfield></map>";
649+
std::stringstream strstr(xml);
650+
tmpEarth->readXML( strstr, "" );
651+
layer = tmpEarth->getMap()->getHeightFieldMapLayers().front();
652+
}
653+
else if ( "TMS" == type )
654+
{
655+
TMSOptions* options = new TMSOptions();
656+
options->url() = uri.toStdString();
657+
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
658+
//osgEarth 2.0 API:
659+
//TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
660+
//map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
661+
}
662+
map->addMapLayer( layer );
663+
664+
if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
642665
}
643-
else if ( "TMS" == type )
666+
667+
//remove QGIS layer
668+
if( mQgisMapLayer )
644669
{
645-
TMSOptions* options = new TMSOptions();
646-
options->url() = uri.toStdString();
647-
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
648-
//osgEarth 2.0 API:
649-
//TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
650-
//map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
670+
QgsDebugMsg( "removeMapLayer" );
671+
map->removeMapLayer( mQgisMapLayer );
651672
}
652-
map->addMapLayer( layer );
653673

654-
if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
674+
//add QGIS layer
675+
QgsDebugMsg( "addMapLayer" );
676+
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
677+
mTileSource->initialize( "", 0 );
678+
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
679+
map->addMapLayer( mQgisMapLayer );
680+
mQgisMapLayer->setCache( 0 ); //disable caching
655681
}
656-
657-
//remove QGIS layer
658-
if( mQgisMapLayer )
682+
else
659683
{
660-
QgsDebugMsg( "removeMapLayer" );
661-
map->removeMapLayer( mQgisMapLayer );
684+
QgsDebugMsg( "EXITING layersChanged, globe not running" );
685+
return;
662686
}
663-
664-
//add QGIS layer
665-
QgsDebugMsg( "addMapLayer" );
666-
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
667-
mTileSource->initialize( "", 0 );
668-
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
669-
map->addMapLayer( mQgisMapLayer );
670-
mQgisMapLayer->setCache( 0 ); //disable caching
671687
}
672688

673689
void GlobePlugin::unload()
@@ -725,6 +741,11 @@ void GlobePlugin::copyFolder( QString sourceFolder, QString destFolder )
725741
}
726742
}
727743

744+
void GlobePlugin::setGlobeNotRunning()
745+
{
746+
mIsGlobeRunning = false;
747+
}
748+
728749
bool NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
729750
{
730751
switch( ea.getEventType() )

src/plugins/globe/globe_plugin.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class GlobePlugin : public QObject, public QgisPlugin
7070
void syncExtent();
7171

7272
void projectReady();
73-
void blankProject();
73+
void blankProjectReady();
74+
void setGlobeNotRunning();
7475

7576
//! Place an OSG model on the globe
7677
void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 );
@@ -86,7 +87,7 @@ class GlobePlugin : public QObject, public QgisPlugin
8687
//! Setup map controls
8788
void setupControls();
8889

89-
private:
90+
private://! Checks if the globe is open
9091
int mPluginType;
9192
//! Pointer to the QGIS interface object
9293
QgisInterface *mQGisIface;
@@ -114,6 +115,8 @@ class GlobePlugin : public QObject, public QgisPlugin
114115
osgEarthUtil::ElevationManager* mElevationManager;
115116
//! Object placer
116117
osgEarthUtil::ObjectPlacer* mObjectPlacer;
118+
//! tracks if the globe is open
119+
bool mIsGlobeRunning;
117120
};
118121

119122
class FlyToExtentHandler : public osgGA::GUIEventHandler

src/plugins/globe/globe_plugin_dialog.cpp

+42-27
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,11 @@ void QgsGlobePluginDialog::showMessageBox( QString text )
120120
msgBox.exec();
121121
}
122122

123-
void QgsGlobePluginDialog::restartGlobe()
124-
{
125-
//showMessageBox("TODO: restart globe");
126-
}
127-
128-
bool QgsGlobePluginDialog::globeRunning()
129-
{
130-
//TODO: method that tells if the globe plugin is running
131-
return true;
132-
}
133-
134123
void QgsGlobePluginDialog::on_buttonBox_accepted()
135124
{
136125
setStereoConfig();
137126
saveStereoConfig();
138127

139-
if ( globeRunning() )
140-
{
141-
restartGlobe();
142-
}
143-
144128
saveElevationDatasources();
145129
accept();
146130
}
@@ -171,7 +155,7 @@ void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged(QString type)
171155
else if ( "TMS" == type )
172156
{
173157
elevationActions->setCurrentIndex(1);
174-
elevationPath->setText("http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/linktothepast/");
158+
elevationPath->setText("http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml");
175159
}
176160
}
177161

@@ -293,19 +277,50 @@ void QgsGlobePluginDialog::readElevationDatasources()
293277

294278
void QgsGlobePluginDialog::saveElevationDatasources()
295279
{
296-
QgsProject::instance()->removeEntry("Globe-Plugin", "/elevationDatasources/");
297-
for(int i = 0; i < elevationDatasourcesWidget->rowCount(); ++i)
298-
{
299-
QString type = elevationDatasourcesWidget->item(i, 0)->text();
300-
bool cache = elevationDatasourcesWidget->item(i, 1)->checkState();
301-
QString uri = elevationDatasourcesWidget->item(i, 2)->text();
280+
bool somethingChanged = false;
281+
int keysCount = QgsProject::instance()->subkeyList("Globe-Plugin", "/elevationDatasources/").count();
282+
int rowsCount = elevationDatasourcesWidget->rowCount();
302283

284+
for (int i = 0; i < rowsCount; ++i) {
303285
QString iNum;
304286
iNum.setNum(i);
287+
QString typeKey = QgsProject::instance()->readEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type");
288+
QString uriKey = QgsProject::instance()->readEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri");
289+
bool cacheKey = QgsProject::instance()->readBoolEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache");
290+
291+
QString type = elevationDatasourcesWidget->item(i, 0)->text();
292+
QString uri = elevationDatasourcesWidget->item(i, 2)->text();
293+
bool cache = elevationDatasourcesWidget->item(i, 1)->checkState();
305294

306-
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type", type);
307-
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri", uri);
308-
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache", cache);
295+
if ( typeKey != type || uriKey != uri || cacheKey != cache )
296+
{
297+
somethingChanged = true;
298+
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type", type);
299+
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri", uri);
300+
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache", cache);
301+
QgsDebugMsg( "editing at "+iNum );
302+
}
303+
else
304+
{
305+
QgsDebugMsg( "nothing to do at "+iNum );
306+
}
307+
}
308+
309+
if (keysCount > rowsCount )
310+
{
311+
//elminate superfluous keys
312+
for (int i = rowsCount; i < keysCount; ++i) {
313+
QString iNum;
314+
iNum.setNum(i);
315+
QgsDebugMsg( "deleting "+iNum );
316+
QgsProject::instance()->removeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/");
317+
}
318+
}
319+
320+
if ( somethingChanged )
321+
{
322+
QgsDebugMsg( "emitting elevationDatasourcesChanged" );
323+
emit elevationDatasourcesChanged();
309324
}
310325
}
311326
//END ELEVATION
@@ -511,4 +526,4 @@ void QgsGlobePluginDialog::updateStereoDialog()
511526
msgBox.exec();
512527
}
513528
}
514-
//END STEREO
529+
//END STEREO

src/plugins/globe/globe_plugin_dialog.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <QDialog>
2323
#include <QSettings>
2424
#include <QCheckBox>
25+
#include "qgsosgviewer.h"
2526
#include "qgscontexthelp.h"
2627
#include <qgsproject.h>
2728

@@ -30,16 +31,17 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
3031
Q_OBJECT
3132

3233
public:
33-
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 );
34+
QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget * parent = 0, Qt::WFlags fl = 0 );
3435
~QgsGlobePluginDialog();
3536
void readElevationDatasources();
37+
QTableWidget *elevationDatasources() { return elevationDatasourcesWidget; }
3638

3739
private:
40+
QgsOsgViewer* mViewer;
3841
QSettings settings;
42+
private:
3943
QString openFile();
4044
void updateStereoDialog();
41-
void restartGlobe();
42-
bool globeRunning();
4345
bool validateResource( QString type, QString uri, QString& error);
4446
void saveElevationDatasources();
4547
void moveRow( QTableWidget* widget, bool up);
@@ -78,6 +80,9 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
7880
void on_elevationRemove_clicked();
7981
void on_elevationUp_clicked();
8082
void on_elevationDown_clicked();
83+
84+
signals:
85+
void elevationDatasourcesChanged();
8186
};
8287

8388
#endif // QGIS_GLOBE_PLUGIN_DIALOG_H

src/plugins/globe/qgsosgviewer.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,10 @@ void QgsGLWidgetAdapter::wheelEvent(QWheelEvent *event)
8585
{
8686
_gw->getEventQueue()->mouseScroll((event->delta()>0) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP);
8787
}
88+
89+
//reimplement the close event to emit a signal
90+
void QgsGLWidgetAdapter::closeEvent(QCloseEvent *event)
91+
{
92+
emit globeClosed();
93+
event->accept();
94+
}

0 commit comments

Comments
 (0)