Skip to content
Permalink
Browse files

globe fix: don't crash on quit

  • Loading branch information
jef-n committed Jul 14, 2011
1 parent 13cc17d commit b81c63ccd263176d96c4c3d2424233b66f4e2b7e
Showing with 31 additions and 30 deletions.
  1. +25 −24 src/plugins/globe/globe_plugin.cpp
  2. +2 −2 src/plugins/globe/globe_plugin.h
  3. +4 −4 src/plugins/globe/globe_plugin_dialog.cpp
49 src/plugins/globe/globe_plugin.cpp 100644 → 100755
@@ -69,24 +69,25 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;

//constructor
GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
: QgisPlugin( sName, sDescription, sPluginVersion, sPluginType ),
mQGisIface( theQgisInterface ),
mQActionPointer( NULL ),
mQActionSettingsPointer( NULL ),
viewer(),
mQDockWidget( tr( "Globe" ) ),
mSettingsDialog( &viewer, theQgisInterface->mainWindow(), QgisGui::ModalDialogFlags ),
mQgisMapLayer( 0 ),
mTileSource( 0 ),
mElevationManager( NULL ),
mObjectPlacer( NULL )
: QgisPlugin( sName, sDescription, sPluginVersion, sPluginType )
, mQGisIface( theQgisInterface )
, mQActionPointer( NULL )
, mQActionSettingsPointer( NULL )
, viewer()
, mQgisMapLayer( 0 )
, mTileSource( 0 )
, mElevationManager( NULL )
, mObjectPlacer( NULL )
{
mIsGlobeRunning = false;
//needed to be "seen" by other plugins by doing
//iface.mainWindow().findChild( QObject, "globePlugin" )
//needed until https://trac.osgeo.org/qgis/changeset/15224
this->setObjectName( "globePlugin" );
this->setParent( theQgisInterface->mainWindow() );

mSettingsDialog = new QgsGlobePluginDialog( &viewer, theQgisInterface->mainWindow(), QgisGui::ModalDialogFlags );
mQDockWidget = new QDockWidgetGlobe( tr( "Globe" ), theQgisInterface->mainWindow() );
}

//destructor
@@ -190,19 +191,19 @@ void GlobePlugin::initGui()
//Add menu
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionPointer );
mQGisIface->addPluginToMenu( tr( "&Globe" ), mQActionSettingsPointer );
mQDockWidget.setWidget( &viewer );
mQDockWidget->setWidget( &viewer );

connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
this, SLOT( extentsChanged() ) );
connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
this, SLOT( layersChanged() ) );
connect( &mSettingsDialog, SIGNAL( elevationDatasourcesChanged() ),
connect( mSettingsDialog, SIGNAL( elevationDatasourcesChanged() ),
this, SLOT( layersChanged() ) );
connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this,
SLOT( projectReady() ) );
connect( mQGisIface, SIGNAL( newProjectCreated() ), this,
SLOT( blankProjectReady() ) );
connect( &mQDockWidget, SIGNAL( globeClosed() ), this,
connect( mQDockWidget, SIGNAL( globeClosed() ), this,
SLOT( setGlobeNotRunning() ) );
connect( this, SIGNAL( xyCoordinates( const QgsPoint & ) ),
mQGisIface->mapCanvas(), SIGNAL( xyCoordinates( const QgsPoint & ) ) );
@@ -214,7 +215,7 @@ void GlobePlugin::run()
if ( !getenv( "OSGNOTIFYLEVEL" ) ) osgEarth::setNotifyLevel( osg::DEBUG_INFO );
#endif

mQGisIface->addDockWidget( Qt::RightDockWidgetArea, &mQDockWidget );
mQGisIface->addDockWidget( Qt::RightDockWidgetArea, mQDockWidget );

viewer.show();

@@ -266,8 +267,8 @@ void GlobePlugin::run()

void GlobePlugin::settings()
{
mSettingsDialog.updatePointLayers();
if ( mSettingsDialog.exec() )
mSettingsDialog->updatePointLayers();
if ( mSettingsDialog->exec() )
{
//viewer stereo settings set by mSettingsDialog and stored in QSettings
}
@@ -324,12 +325,12 @@ void GlobePlugin::setupMap()
mObjectPlacer = new osgEarth::Util::ObjectPlacer( mMapNode );

// place 3D model on point layer
if ( mSettingsDialog.modelLayer() && !mSettingsDialog.modelPath().isEmpty() )
if ( mSettingsDialog->modelLayer() && !mSettingsDialog->modelPath().isEmpty() )
{
osg::Node* model = osgDB::readNodeFile( mSettingsDialog.modelPath().toStdString() );
osg::Node* model = osgDB::readNodeFile( mSettingsDialog->modelPath().toStdString() );
if ( model )
{
QgsVectorLayer* layer = mSettingsDialog.modelLayer();
QgsVectorLayer* layer = mSettingsDialog->modelLayer();
QgsAttributeList fetchAttributes;
layer->select( fetchAttributes ); //TODO: select only visible features
QgsFeature feature;
@@ -346,13 +347,13 @@ void GlobePlugin::setupMap()
void GlobePlugin::projectReady()
{
blankProjectReady();
mSettingsDialog.readElevationDatasources();
mSettingsDialog->readElevationDatasources();
}

void GlobePlugin::blankProjectReady()
{ //needs at least http://trac.osgeo.org/qgis/changeset/14452
mSettingsDialog.elevationDatasources()->clearContents();
mSettingsDialog.elevationDatasources()->setRowCount( 0 );
mSettingsDialog->elevationDatasources()->clearContents();
mSettingsDialog->elevationDatasources()->setRowCount( 0 );
}

void GlobePlugin::showCurrentCoordinates( double lon, double lat )
@@ -696,7 +697,7 @@ void GlobePlugin::layersChanged()
// Add elevation layers
QSettings settings;
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
QTableWidget* table = mSettingsDialog.elevationDatasources();
QTableWidget* table = mSettingsDialog->elevationDatasources();
for ( int i = 0; i < table->rowCount(); ++i )
{
QString type = table->item( i, 0 )->text();
@@ -110,9 +110,9 @@ class GlobePlugin : public QObject, public QgisPlugin
//! OSG Viewer
QgsOsgViewer viewer;
//! Dock widget for viewer
QDockWidgetGlobe mQDockWidget;
QDockWidgetGlobe *mQDockWidget;
//! Settings Dialog
QgsGlobePluginDialog mSettingsDialog;
QgsGlobePluginDialog *mSettingsDialog;
//! OSG root node
osg::Group* mRootNode;
//! Map node
@@ -58,13 +58,13 @@ QgsGlobePluginDialog::~QgsGlobePluginDialog()
QString QgsGlobePluginDialog::openRasterFile()
{
//see http://www.gdal.org/formats_list.html
const char* filter = "GDAL files (*.dem *.tif *.tiff *.jpg *.jpeg *.asc) \
;;DEM files (*.dem) \
;;All files (*.*)";
QString filter = tr( "GDAL files" ) + " (*.dem *.tif *.tiff *.jpg *.jpeg *.asc);;"
+ tr( "DEM files" ) + " (*.dem);;"
+ tr( "All files" ) + " (*.*)";
QString path = QFileDialog::getOpenFileName( this,
tr( "Open raster file" ),
QDir::homePath(),
tr( filter ) );
filter );

return path;
}

0 comments on commit b81c63c

Please sign in to comment.
You can’t perform that action at this time.