Skip to content
Permalink
Browse files

added suppor for signals for elevationDatasourceChanged and globeClos…

…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 Dec 10, 2010
1 parent 23f0195 commit 17aca2d1fda364430ea5abf5e9bf0bccaaedc51c
@@ -76,6 +76,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
mElevationManager( NULL ),
mObjectPlacer( NULL )
{
mIsGlobeRunning = false;
}

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

connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
this, SLOT( extentsChanged() ) );
//connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
// this, SLOT( layersChanged() ) );
connect( mQGisIface->mapCanvas(), SIGNAL( 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,
SLOT( projectReady() ) );
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()
@@ -158,6 +166,8 @@ void GlobePlugin::run()
#ifdef GLOBE_OSG_STANDALONE_VIEWER
viewer.run();
#endif

mIsGlobeRunning = true;
}

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

void GlobePlugin::blankProject()
void GlobePlugin::blankProjectReady()
{//TODO
QMessageBox m;
m.setText("new");
@@ -600,74 +610,80 @@ typedef std::list< osg::ref_ptr<VersionedTile> > TileList;
void GlobePlugin::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)
{
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( map->getImageMapLayers().size() > 1 || map->getHeightFieldMapLayers().size() > 1)
{
viewer.getDatabasePager()->clear();
}

if( "Raster" == type)
// Remove elevation layers
MapLayerList list = map->getHeightFieldMapLayers();
for( MapLayerList::iterator i = list.begin(); i != list.end(); i++ )
{
GDALOptions* options = new GDALOptions();
options->url() = uri.toStdString();
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
map->removeMapLayer( *i );
}
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
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();
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)
{
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();
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 ) );
QgsDebugMsg( "removeMapLayer" );
map->removeMapLayer( mQgisMapLayer );
}
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
}

//remove QGIS layer
if( mQgisMapLayer )
else
{
QgsDebugMsg( "removeMapLayer" );
map->removeMapLayer( mQgisMapLayer );
QgsDebugMsg( "EXITING layersChanged, globe not running" );
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()
@@ -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 )
{
switch( ea.getEventType() )
@@ -70,7 +70,8 @@ class GlobePlugin : public QObject, public QgisPlugin
void syncExtent();

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

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

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

class FlyToExtentHandler : public osgGA::GUIEventHandler
@@ -120,27 +120,11 @@ void QgsGlobePluginDialog::showMessageBox( QString text )
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()
{
setStereoConfig();
saveStereoConfig();

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

saveElevationDatasources();
accept();
}
@@ -171,7 +155,7 @@ void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged(QString type)
else if ( "TMS" == type )
{
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");
}
}

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

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

for (int i = 0; i < rowsCount; ++i) {
QString iNum;
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);
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/uri", uri);
QgsProject::instance()->writeEntry("Globe-Plugin", "/elevationDatasources/L"+iNum+"/cache", cache);
if ( typeKey != type || uriKey != uri || cacheKey != 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
@@ -511,4 +526,4 @@ void QgsGlobePluginDialog::updateStereoDialog()
msgBox.exec();
}
}
//END STEREO
//END STEREO
@@ -22,6 +22,7 @@
#include <QDialog>
#include <QSettings>
#include <QCheckBox>
#include "qgsosgviewer.h"
#include "qgscontexthelp.h"
#include <qgsproject.h>

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

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

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

signals:
void elevationDatasourcesChanged();
};

#endif // QGIS_GLOBE_PLUGIN_DIALOG_H
@@ -85,3 +85,10 @@ void QgsGLWidgetAdapter::wheelEvent(QWheelEvent *event)
{
_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.
You can’t perform that action at this time.