48
48
// non qt includes
49
49
#include < iostream>
50
50
51
+ #include < qgsproject.h>
52
+
51
53
extern " C" {
52
54
#include < grass/gis.h>
53
55
#include < grass/Vect.h>
@@ -81,7 +83,7 @@ static const char *pluginVersion = "0.1";
81
83
* @param theQgisInterFace Pointer to the QGIS interface object
82
84
*/
83
85
QgsGrassPlugin::QgsGrassPlugin (QgisApp * theQGisApp, QgisIface * theQgisInterFace):
84
- qgisMainWindowPointer (theQGisApp), qGisInterface(theQgisInterFace)
86
+ mQgis (theQGisApp), qGisInterface(theQgisInterFace)
85
87
{
86
88
/* * Initialize the plugin and set the required attributes */
87
89
pluginNameQString = " GrassVector" ;
@@ -137,6 +139,10 @@ void QgsGrassPlugin::initGui()
137
139
138
140
mCanvas = qGisInterface->getMapCanvas ();
139
141
142
+ // Connect project
143
+ connect ( mQgis , SIGNAL ( projectRead () ), this , SLOT ( projectRead ()));
144
+ connect ( mQgis , SIGNAL ( newProject () ), this , SLOT (newProject ()));
145
+
140
146
// Create the action for tool
141
147
mOpenMapsetAction = new QAction ( " Open mapset" , this );
142
148
mNewMapsetAction = new QAction ( " New mapset" , this );
@@ -194,7 +200,7 @@ void QgsGrassPlugin::initGui()
194
200
mNewVectorAction ->addTo (pluginMenu);
195
201
196
202
// Add the toolbar to the main window
197
- toolBarPointer = qgisMainWindowPointer ->addToolBar (" GRASS" );
203
+ toolBarPointer = mQgis ->addToolBar (" GRASS" );
198
204
toolBarPointer->setLabel (tr (" GRASS" ));
199
205
toolBarPointer->setIconSize (QSize (24 ,24 ));
200
206
@@ -247,6 +253,16 @@ void QgsGrassPlugin::mapsetChanged ()
247
253
mTools ->mapsetChanged ();
248
254
}
249
255
}
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 () );
250
266
}
251
267
252
268
// Slot called when the "Add GRASS vector layer" menu item is activated
@@ -380,7 +396,7 @@ void QgsGrassPlugin::addRaster()
380
396
void QgsGrassPlugin::openTools ()
381
397
{
382
398
if ( !mTools )
383
- mTools = new QgsGrassTools ( qgisMainWindowPointer , qGisInterface, qgisMainWindowPointer , 0 , Qt::WType_Dialog );
399
+ mTools = new QgsGrassTools ( mQgis , qGisInterface, mQgis , 0 , Qt::WType_Dialog );
384
400
385
401
mTools ->show ();
386
402
}
@@ -394,7 +410,7 @@ void QgsGrassPlugin::edit()
394
410
return ;
395
411
}
396
412
397
- QgsGrassEdit *ed = new QgsGrassEdit ( qgisMainWindowPointer , qGisInterface, qgisMainWindowPointer , Qt::WType_Dialog );
413
+ QgsGrassEdit *ed = new QgsGrassEdit ( mQgis , qGisInterface, mQgis , Qt::WType_Dialog );
398
414
399
415
if ( ed->isValid () ) {
400
416
ed->show ();
@@ -498,8 +514,8 @@ void QgsGrassPlugin::newVector()
498
514
return ;
499
515
}
500
516
501
- QgsGrassEdit *ed = new QgsGrassEdit ( qgisMainWindowPointer ,
502
- qGisInterface, provider, qgisMainWindowPointer ,
517
+ QgsGrassEdit *ed = new QgsGrassEdit ( mQgis ,
518
+ qGisInterface, provider, mQgis ,
503
519
Qt::WType_Dialog );
504
520
505
521
if ( ed->isValid () ) {
@@ -620,8 +636,8 @@ void QgsGrassPlugin::changeRegion(void)
620
636
return ;
621
637
}
622
638
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 );
625
641
626
642
reg->show ();
627
643
}
@@ -686,13 +702,57 @@ void QgsGrassPlugin::newMapset()
686
702
if ( !QgsGrassNewMapset::isRunning () )
687
703
{
688
704
mNewMapset = new QgsGrassNewMapset (
689
- qgisMainWindowPointer , qGisInterface,
690
- this , qgisMainWindowPointer );
705
+ mQgis , qGisInterface,
706
+ this , mQgis );
691
707
}
692
708
mNewMapset ->show ();
693
709
mNewMapset ->raise ();
694
710
}
695
711
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
+
696
756
// Unload the plugin by cleaning up the GUI
697
757
void QgsGrassPlugin::unload ()
698
758
{
0 commit comments