Skip to content

Commit

Permalink
added suppor for signals for elevationDatasourceChanged and globeClos…
Browse files Browse the repository at this point in the history
…ed, 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
  • Loading branch information
mbernasocchi authored and pka committed Jul 5, 2011
1 parent 23f0195 commit 17aca2d
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 95 deletions.
141 changes: 81 additions & 60 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -76,6 +76,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
mElevationManager( NULL ), mElevationManager( NULL ),
mObjectPlacer( NULL ) mObjectPlacer( NULL )
{ {
mIsGlobeRunning = false;
} }


//destructor //destructor
Expand Down Expand Up @@ -104,12 +105,19 @@ void GlobePlugin::initGui()


connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ), connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
this, SLOT( extentsChanged() ) ); this, SLOT( extentsChanged() ) );
//connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ), connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
// this, SLOT( layersChanged() ) ); this, SLOT( layersChanged() ) );
//FIXME: fix sender objact, must be mSettingsDialog
connect( mQGisIface->mapCanvas(), SIGNAL( elevationDatasourcesChanged() ),
this, SLOT( layersChanged() ) );
connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this, connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this,
SLOT( projectReady() ) ); SLOT( projectReady() ) );
connect( mQGisIface->mainWindow(), SIGNAL( newProjectCreated() ), this, connect( mQGisIface->mainWindow(), SIGNAL( newProjectCreated() ), this,
SLOT( blankProject() ) ); SLOT( blankProjectReady() ) );
//FIXME: fix sender objact, must be mSettingsDialog
connect( mQGisIface->mainWindow(), SIGNAL( globeClosed() ), this,
SLOT( setGlobeNotRunning() ) );

} }


void GlobePlugin::run() void GlobePlugin::run()
Expand Down Expand Up @@ -158,6 +166,8 @@ void GlobePlugin::run()
#ifdef GLOBE_OSG_STANDALONE_VIEWER #ifdef GLOBE_OSG_STANDALONE_VIEWER
viewer.run(); viewer.run();
#endif #endif

mIsGlobeRunning = true;
} }


void GlobePlugin::settings() void GlobePlugin::settings()
Expand Down Expand Up @@ -259,7 +269,7 @@ void GlobePlugin::projectReady()
mSettingsDialog.readElevationDatasources(); mSettingsDialog.readElevationDatasources();
} }


void GlobePlugin::blankProject() void GlobePlugin::blankProjectReady()
{//TODO {//TODO
QMessageBox m; QMessageBox m;
m.setText("new"); m.setText("new");
Expand Down Expand Up @@ -600,74 +610,80 @@ typedef std::list< osg::ref_ptr<VersionedTile> > TileList;
void GlobePlugin::layersChanged() void GlobePlugin::layersChanged()
{ {
QgsDebugMsg( "layersChanged" ); QgsDebugMsg( "layersChanged" );
if ( mIsGlobeRunning ){
osg::ref_ptr<Map> map = mMapNode->getMap();


osg::ref_ptr<Map> map = mMapNode->getMap(); if( map->getImageMapLayers().size() > 1 || map->getHeightFieldMapLayers().size() > 1)

{
if( map->getImageMapLayers().size() > 1 || map->getHeightFieldMapLayers().size() > 1) viewer.getDatabasePager()->clear();
{ }
viewer.getDatabasePager()->clear();
}

// Remove elevation layers
MapLayerList list = map->getHeightFieldMapLayers();
for( MapLayerList::iterator i = list.begin(); i != list.end(); i++ )
{
map->removeMapLayer( *i );
}

// Add elevation layers
QSettings settings;
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
QTableWidget* table = mSettingsDialog.elevationDatasources();
for(int i = 0; i < table->rowCount(); ++i)
{
QString type = table->item(i, 0)->text();
bool cache = table->item(i, 1)->checkState();
QString uri = table->item(i, 2)->text();
MapLayer* layer = 0;


if( "Raster" == type) // Remove elevation layers
MapLayerList list = map->getHeightFieldMapLayers();
for( MapLayerList::iterator i = list.begin(); i != list.end(); i++ )
{ {
GDALOptions* options = new GDALOptions(); map->removeMapLayer( *i );
options->url() = uri.toStdString();
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
} }
else if ( "Worldwind" == type )
// Add elevation layers
QSettings settings;
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
QTableWidget* table = mSettingsDialog.elevationDatasources();
for(int i = 0; i < table->rowCount(); ++i)
{ {
EarthFile* tmpEarth = new EarthFile(); //Hack for programatic WorldWind layer generation QString type = table->item(i, 0)->text();
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>"; bool cache = table->item(i, 1)->checkState();
std::stringstream strstr(xml); QString uri = table->item(i, 2)->text();
tmpEarth->readXML( strstr, "" ); MapLayer* layer = 0;
layer = tmpEarth->getMap()->getHeightFieldMapLayers().front();
if( "Raster" == type)
{
GDALOptions* options = new GDALOptions();
options->url() = uri.toStdString();
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
}
else if ( "Worldwind" == type )
{
EarthFile* tmpEarth = new EarthFile(); //Hack for programatic WorldWind layer generation
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>";
std::stringstream strstr(xml);
tmpEarth->readXML( strstr, "" );
layer = tmpEarth->getMap()->getHeightFieldMapLayers().front();
}
else if ( "TMS" == type )
{
TMSOptions* options = new TMSOptions();
options->url() = uri.toStdString();
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
//osgEarth 2.0 API:
//TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
//map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
}
map->addMapLayer( layer );

if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
} }
else if ( "TMS" == type )
//remove QGIS layer
if( mQgisMapLayer )
{ {
TMSOptions* options = new TMSOptions(); QgsDebugMsg( "removeMapLayer" );
options->url() = uri.toStdString(); map->removeMapLayer( mQgisMapLayer );
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
//osgEarth 2.0 API:
//TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
//map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
} }
map->addMapLayer( layer );


if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache) //add QGIS layer
QgsDebugMsg( "addMapLayer" );
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
mTileSource->initialize( "", 0 );
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
map->addMapLayer( mQgisMapLayer );
mQgisMapLayer->setCache( 0 ); //disable caching
} }

else
//remove QGIS layer
if( mQgisMapLayer )
{ {
QgsDebugMsg( "removeMapLayer" ); QgsDebugMsg( "EXITING layersChanged, globe not running" );
map->removeMapLayer( mQgisMapLayer ); return;
} }

//add QGIS layer
QgsDebugMsg( "addMapLayer" );
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
mTileSource->initialize( "", 0 );
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
map->addMapLayer( mQgisMapLayer );
mQgisMapLayer->setCache( 0 ); //disable caching
} }


void GlobePlugin::unload() void GlobePlugin::unload()
Expand Down Expand Up @@ -725,6 +741,11 @@ void GlobePlugin::copyFolder( QString sourceFolder, QString destFolder )
} }
} }


void GlobePlugin::setGlobeNotRunning()
{
mIsGlobeRunning = false;
}

bool NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx ) bool NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
{ {
switch( ea.getEventType() ) switch( ea.getEventType() )
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -70,7 +70,8 @@ class GlobePlugin : public QObject, public QgisPlugin
void syncExtent(); void syncExtent();


void projectReady(); void projectReady();
void blankProject(); void blankProjectReady();
void setGlobeNotRunning();


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


private: private://! Checks if the globe is open
int mPluginType; int mPluginType;
//! Pointer to the QGIS interface object //! Pointer to the QGIS interface object
QgisInterface *mQGisIface; QgisInterface *mQGisIface;
Expand Down Expand Up @@ -114,6 +115,8 @@ class GlobePlugin : public QObject, public QgisPlugin
osgEarthUtil::ElevationManager* mElevationManager; osgEarthUtil::ElevationManager* mElevationManager;
//! Object placer //! Object placer
osgEarthUtil::ObjectPlacer* mObjectPlacer; osgEarthUtil::ObjectPlacer* mObjectPlacer;
//! tracks if the globe is open
bool mIsGlobeRunning;
}; };


class FlyToExtentHandler : public osgGA::GUIEventHandler class FlyToExtentHandler : public osgGA::GUIEventHandler
Expand Down
69 changes: 42 additions & 27 deletions src/plugins/globe/globe_plugin_dialog.cpp
Expand Up @@ -120,27 +120,11 @@ void QgsGlobePluginDialog::showMessageBox( QString text )
msgBox.exec(); msgBox.exec();
} }


void QgsGlobePluginDialog::restartGlobe()
{
//showMessageBox("TODO: restart globe");
}

bool QgsGlobePluginDialog::globeRunning()
{
//TODO: method that tells if the globe plugin is running
return true;
}

void QgsGlobePluginDialog::on_buttonBox_accepted() void QgsGlobePluginDialog::on_buttonBox_accepted()
{ {
setStereoConfig(); setStereoConfig();
saveStereoConfig(); saveStereoConfig();


if ( globeRunning() )
{
restartGlobe();
}

saveElevationDatasources(); saveElevationDatasources();
accept(); accept();
} }
Expand Down Expand Up @@ -171,7 +155,7 @@ void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged(QString type)
else if ( "TMS" == type ) else if ( "TMS" == type )
{ {
elevationActions->setCurrentIndex(1); elevationActions->setCurrentIndex(1);
elevationPath->setText("http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/linktothepast/"); elevationPath->setText("http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml");
} }
} }


Expand Down Expand Up @@ -293,19 +277,50 @@ void QgsGlobePluginDialog::readElevationDatasources()


void QgsGlobePluginDialog::saveElevationDatasources() void QgsGlobePluginDialog::saveElevationDatasources()
{ {
QgsProject::instance()->removeEntry("Globe-Plugin", "/elevationDatasources/"); bool somethingChanged = false;
for(int i = 0; i < elevationDatasourcesWidget->rowCount(); ++i) int keysCount = QgsProject::instance()->subkeyList("Globe-Plugin", "/elevationDatasources/").count();
{ int rowsCount = elevationDatasourcesWidget->rowCount();
QString type = elevationDatasourcesWidget->item(i, 0)->text();
bool cache = elevationDatasourcesWidget->item(i, 1)->checkState();
QString uri = elevationDatasourcesWidget->item(i, 2)->text();


for (int i = 0; i < rowsCount; ++i) {
QString iNum; QString iNum;
iNum.setNum(i); iNum.setNum(i);
QString typeKey = QgsProject::instance()->readEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type");
QString uriKey = QgsProject::instance()->readEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri");
bool cacheKey = QgsProject::instance()->readBoolEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache");

QString type = elevationDatasourcesWidget->item(i, 0)->text();
QString uri = elevationDatasourcesWidget->item(i, 2)->text();
bool cache = elevationDatasourcesWidget->item(i, 1)->checkState();


QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type", type); if ( typeKey != type || uriKey != uri || cacheKey != cache )
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri", uri); {
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache", cache); somethingChanged = true;
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/type", type);
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri", uri);
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache", cache);
QgsDebugMsg( "editing at "+iNum );
}
else
{
QgsDebugMsg( "nothing to do at "+iNum );
}
}

if (keysCount > rowsCount )
{
//elminate superfluous keys
for (int i = rowsCount; i < keysCount; ++i) {
QString iNum;
iNum.setNum(i);
QgsDebugMsg( "deleting "+iNum );
QgsProject::instance()->removeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/");
}
}

if ( somethingChanged )
{
QgsDebugMsg( "emitting elevationDatasourcesChanged" );
emit elevationDatasourcesChanged();
} }
} }
//END ELEVATION //END ELEVATION
Expand Down Expand Up @@ -511,4 +526,4 @@ void QgsGlobePluginDialog::updateStereoDialog()
msgBox.exec(); msgBox.exec();
} }
} }
//END STEREO //END STEREO
11 changes: 8 additions & 3 deletions src/plugins/globe/globe_plugin_dialog.h
Expand Up @@ -22,6 +22,7 @@
#include <QDialog> #include <QDialog>
#include <QSettings> #include <QSettings>
#include <QCheckBox> #include <QCheckBox>
#include "qgsosgviewer.h"
#include "qgscontexthelp.h" #include "qgscontexthelp.h"
#include <qgsproject.h> #include <qgsproject.h>


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


public: public:
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 ); QgsGlobePluginDialog( QgsOsgViewer* viewer, QWidget * parent = 0, Qt::WFlags fl = 0 );
~QgsGlobePluginDialog(); ~QgsGlobePluginDialog();
void readElevationDatasources(); void readElevationDatasources();
QTableWidget *elevationDatasources() { return elevationDatasourcesWidget; }


private: private:
QgsOsgViewer* mViewer;
QSettings settings; QSettings settings;
private:
QString openFile(); QString openFile();
void updateStereoDialog(); void updateStereoDialog();
void restartGlobe();
bool globeRunning();
bool validateResource( QString type, QString uri, QString& error); bool validateResource( QString type, QString uri, QString& error);
void saveElevationDatasources(); void saveElevationDatasources();
void moveRow( QTableWidget* widget, bool up); void moveRow( QTableWidget* widget, bool up);
Expand Down Expand Up @@ -78,6 +80,9 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
void on_elevationRemove_clicked(); void on_elevationRemove_clicked();
void on_elevationUp_clicked(); void on_elevationUp_clicked();
void on_elevationDown_clicked(); void on_elevationDown_clicked();

signals:
void elevationDatasourcesChanged();
}; };


#endif // QGIS_GLOBE_PLUGIN_DIALOG_H #endif // QGIS_GLOBE_PLUGIN_DIALOG_H
7 changes: 7 additions & 0 deletions src/plugins/globe/qgsosgviewer.cpp
Expand Up @@ -85,3 +85,10 @@ void QgsGLWidgetAdapter::wheelEvent(QWheelEvent *event)
{ {
_gw->getEventQueue()->mouseScroll((event->delta()>0) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP); _gw->getEventQueue()->mouseScroll((event->delta()>0) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP);
} }

//reimplement the close event to emit a signal
void QgsGLWidgetAdapter::closeEvent(QCloseEvent *event)
{
emit globeClosed();
event->accept();
}

0 comments on commit 17aca2d

Please sign in to comment.