Skip to content

Commit 9c72b9a

Browse files
author
rblazek
committed
save working mapset in project file
git-svn-id: http://svn.osgeo.org/qgis/trunk@5025 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ef8166c commit 9c72b9a

File tree

2 files changed

+76
-11
lines changed

2 files changed

+76
-11
lines changed

src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
//non qt includes
4949
#include <iostream>
5050

51+
#include <qgsproject.h>
52+
5153
extern "C" {
5254
#include <grass/gis.h>
5355
#include <grass/Vect.h>
@@ -81,7 +83,7 @@ static const char *pluginVersion = "0.1";
8183
* @param theQgisInterFace Pointer to the QGIS interface object
8284
*/
8385
QgsGrassPlugin::QgsGrassPlugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
84-
qgisMainWindowPointer(theQGisApp), qGisInterface(theQgisInterFace)
86+
mQgis(theQGisApp), qGisInterface(theQgisInterFace)
8587
{
8688
/** Initialize the plugin and set the required attributes */
8789
pluginNameQString = "GrassVector";
@@ -137,6 +139,10 @@ void QgsGrassPlugin::initGui()
137139

138140
mCanvas = qGisInterface->getMapCanvas();
139141

142+
// Connect project
143+
connect( mQgis, SIGNAL( projectRead() ), this, SLOT( projectRead()));
144+
connect( mQgis, SIGNAL( newProject() ), this, SLOT(newProject()));
145+
140146
// Create the action for tool
141147
mOpenMapsetAction = new QAction( "Open mapset", this );
142148
mNewMapsetAction = new QAction( "New mapset", this );
@@ -194,7 +200,7 @@ void QgsGrassPlugin::initGui()
194200
mNewVectorAction->addTo(pluginMenu);
195201

196202
// Add the toolbar to the main window
197-
toolBarPointer = qgisMainWindowPointer->addToolBar("GRASS");
203+
toolBarPointer = mQgis->addToolBar("GRASS");
198204
toolBarPointer->setLabel(tr("GRASS"));
199205
toolBarPointer->setIconSize(QSize(24,24));
200206

@@ -247,6 +253,16 @@ void QgsGrassPlugin::mapsetChanged ()
247253
mTools->mapsetChanged();
248254
}
249255
}
256+
257+
// Save working mapset in project file
258+
QgsProject::instance()->writeEntry("GRASS","/WorkingGisdbase",
259+
QgsGrass::getDefaultGisdbase() );
260+
261+
QgsProject::instance()->writeEntry("GRASS","/WorkingLocation",
262+
QgsGrass::getDefaultLocation() );
263+
264+
QgsProject::instance()->writeEntry("GRASS","/WorkingMapset",
265+
QgsGrass::getDefaultMapset() );
250266
}
251267

252268
// Slot called when the "Add GRASS vector layer" menu item is activated
@@ -380,7 +396,7 @@ void QgsGrassPlugin::addRaster()
380396
void QgsGrassPlugin::openTools()
381397
{
382398
if ( !mTools )
383-
mTools = new QgsGrassTools ( qgisMainWindowPointer, qGisInterface, qgisMainWindowPointer, 0, Qt::WType_Dialog );
399+
mTools = new QgsGrassTools ( mQgis, qGisInterface, mQgis, 0, Qt::WType_Dialog );
384400

385401
mTools->show();
386402
}
@@ -394,7 +410,7 @@ void QgsGrassPlugin::edit()
394410
return;
395411
}
396412

397-
QgsGrassEdit *ed = new QgsGrassEdit( qgisMainWindowPointer, qGisInterface, qgisMainWindowPointer, Qt::WType_Dialog );
413+
QgsGrassEdit *ed = new QgsGrassEdit( mQgis, qGisInterface, mQgis, Qt::WType_Dialog );
398414

399415
if ( ed->isValid() ) {
400416
ed->show();
@@ -498,8 +514,8 @@ void QgsGrassPlugin::newVector()
498514
return;
499515
}
500516

501-
QgsGrassEdit *ed = new QgsGrassEdit( qgisMainWindowPointer,
502-
qGisInterface, provider, qgisMainWindowPointer,
517+
QgsGrassEdit *ed = new QgsGrassEdit( mQgis,
518+
qGisInterface, provider, mQgis,
503519
Qt::WType_Dialog );
504520

505521
if ( ed->isValid() ) {
@@ -620,8 +636,8 @@ void QgsGrassPlugin::changeRegion(void)
620636
return;
621637
}
622638

623-
QgsGrassRegion *reg = new QgsGrassRegion(this, qgisMainWindowPointer, qGisInterface,
624-
qgisMainWindowPointer, Qt::WType_Dialog );
639+
QgsGrassRegion *reg = new QgsGrassRegion(this, mQgis, qGisInterface,
640+
mQgis, Qt::WType_Dialog );
625641

626642
reg->show();
627643
}
@@ -686,13 +702,57 @@ void QgsGrassPlugin::newMapset()
686702
if ( !QgsGrassNewMapset::isRunning() )
687703
{
688704
mNewMapset = new QgsGrassNewMapset (
689-
qgisMainWindowPointer, qGisInterface,
690-
this, qgisMainWindowPointer );
705+
mQgis, qGisInterface,
706+
this, mQgis );
691707
}
692708
mNewMapset->show();
693709
mNewMapset->raise();
694710
}
695711

712+
void QgsGrassPlugin::projectRead()
713+
{
714+
#ifdef QGISDEBUG
715+
std::cout << "QgsGrassPlugin::projectRead" << std::endl;
716+
#endif
717+
QString err = QgsGrass::closeMapset ();
718+
if ( !err.isNull() )
719+
{
720+
QMessageBox::warning( 0, "Warning",
721+
"Cannot close current mapset. " + err );
722+
return;
723+
}
724+
725+
bool ok;
726+
QString gisdbase = QgsProject::instance()->readEntry(
727+
"GRASS", "/WorkingGisdbase", "", &ok).trimmed();
728+
QString location = QgsProject::instance()->readEntry(
729+
"GRASS", "/WorkingLocation", "", &ok).trimmed();
730+
QString mapset = QgsProject::instance()->readEntry(
731+
"GRASS", "/WorkingMapset", "", &ok).trimmed();
732+
733+
if ( gisdbase.length() > 0 && location.length() > 0 &&
734+
mapset.length() > 0 )
735+
{
736+
err = QgsGrass::openMapset ( gisdbase, location, mapset );
737+
738+
if ( !err.isNull() )
739+
{
740+
QMessageBox::warning( 0, "Warning", "Cannot open GRASS mapset. " + err );
741+
return;
742+
}
743+
744+
}
745+
mapsetChanged();
746+
}
747+
748+
void QgsGrassPlugin::newProject()
749+
{
750+
#ifdef QGISDEBUG
751+
std::cout << "QgsGrassPlugin::newProject" << std::endl;
752+
#endif
753+
754+
}
755+
696756
// Unload the plugin by cleaning up the GUI
697757
void QgsGrassPlugin::unload()
698758
{

src/plugins/grass/qgsgrassplugin.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public slots:
100100
void mapsetChanged();
101101
//! Create new vector
102102
void newVector();
103+
//! Read project
104+
void projectRead();
105+
//! New project
106+
void newProject();
107+
103108

104109
private:
105110
//! Name of the plugin
@@ -115,7 +120,7 @@ public slots:
115120
//! Pointer to our toolbar
116121
QToolBar *toolBarPointer;
117122
//! Pionter to QGIS main application object
118-
QgisApp *qgisMainWindowPointer;
123+
QgisApp *mQgis;
119124
//! Pointer to the QGIS interface object
120125
QgisIface *qGisInterface;
121126
//! Pointer to canvas

0 commit comments

Comments
 (0)