Skip to content

Commit

Permalink
GRASS fixes: remember last mapset, update layer list in tools if a la…
Browse files Browse the repository at this point in the history
…yer is added/removed
  • Loading branch information
blazek committed May 30, 2013
1 parent 2fcd2da commit 923be58
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/core/qgsmaplayerregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ void QgsMapLayerRegistry::removeMapLayers( QStringList theLayerIds )
mOwnedLayers.remove( lyr );
}
mMapLayers.remove( myId );
emit layerRemoved( myId );
}
emit layersRemoved( theLayerIds );
}

void QgsMapLayerRegistry::removeMapLayer( const QString& theLayerId )
Expand Down
16 changes: 16 additions & 0 deletions src/core/qgsmaplayerregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
*/
void layerWillBeRemoved( QString theLayerId );

/**
* Emitted after one or more layers were removed from the registry
*
* @param theLayerIds A list of ids of the layers which were removed.
*/
void layersRemoved( QStringList theLayerIds );

/**
* Emitted after a layer was removed from the registry
*
* @param theLayerId The id of the layer removed
*
* @note Consider using {@link layersRemoved()} instead
*/
void layerRemoved( QString theLayerId );


/**
* Emitted, when all layers are removed, before {@link layersWillBeRemoved()} and
Expand Down
13 changes: 4 additions & 9 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2710,8 +2710,7 @@ QgsGrassModuleInput::QgsGrassModuleInput( QgsGrassModule *module,

connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer *> ) ),
this, SLOT( updateQgisLayers() ) );
// layersWillBeRemoved is emitted AFTER the layer was removed from registry
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ),
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ),
this, SLOT( updateQgisLayers() ) );

connect( mLayerComboBox, SIGNAL( activated( int ) ), this, SLOT( changed( int ) ) );
Expand Down Expand Up @@ -3348,8 +3347,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput(

connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer *> ) ),
this, SLOT( updateQgisLayers() ) );
// layersWillBeRemoved is emitted after the layer was removed from registry
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ),
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ),
this, SLOT( updateQgisLayers() ) );

// Fill in QGIS layers
Expand All @@ -3375,12 +3373,9 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
mLayerComboBox->addItem( tr( "Select a layer" ), QVariant() );
}

QgsMapCanvas *canvas = mModule->qgisIface()->mapCanvas();

int nlayers = canvas->layerCount();
for ( int i = 0; i < nlayers; i++ )
foreach ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() )
{
QgsMapLayer *layer = canvas->layer( i );
if ( !layer ) continue;

if ( mType == Ogr && layer->type() == QgsMapLayer::VectorLayer )
{
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void QgsGrassPlugin::newMapset()

void QgsGrassPlugin::projectRead()
{
// QgsDebugMsg("entered.");
QgsDebugMsg( "entered." );

bool ok;
QString gisdbase = QgsProject::instance()->readEntry(
Expand All @@ -774,13 +774,13 @@ void QgsGrassPlugin::projectRead()
QString mapset = QgsProject::instance()->readEntry(
"GRASS", "/WorkingMapset", "", &ok ).trimmed();

if ( gisdbase.length() == 0 || location.length() == 0 ||
mapset.length() == 0 )
if ( gisdbase.isEmpty() || location.isEmpty() || mapset.isEmpty() )
{
// Mapset not specified
return;
}

QgsDebugMsg( "Working mapset specified" );

QString currentPath = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset();
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/grass/qgsgrassselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ QgsGrassSelect::QgsGrassSelect( QWidget *parent, int type ): QDialog( parent ),
QDir home = QDir::home();
lastGisdbase = QString( home.path() );
}
lastMapset = settings.value( "/GRASS/lastMapset" ).toString();
}
first = false;
}
Expand Down Expand Up @@ -416,6 +417,8 @@ void QgsGrassSelect::accept()
mapset = emapset->currentText();
lastMapset = mapset;

settings.setValue( "/GRASS/lastMapset", lastMapset );

map = emap->currentText().trimmed();

if ( type != QgsGrassSelect::MAPSET && map.isEmpty() )
Expand Down

0 comments on commit 923be58

Please sign in to comment.