@@ -714,14 +714,6 @@ void QgsGrassPlugin::projectRead()
714
714
#ifdef QGISDEBUG
715
715
std::cout << " QgsGrassPlugin::projectRead" << std::endl;
716
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
717
bool ok;
726
718
QString gisdbase = QgsProject::instance ()->readEntry (
727
719
" GRASS" , " /WorkingGisdbase" , " " , &ok).trimmed ();
@@ -730,18 +722,43 @@ void QgsGrassPlugin::projectRead()
730
722
QString mapset = QgsProject::instance ()->readEntry (
731
723
" GRASS" , " /WorkingMapset" , " " , &ok).trimmed ();
732
724
733
- if ( gisdbase.length () > 0 && location.length () > 0 &&
734
- mapset.length () > 0 )
725
+ if ( gisdbase.length () == 0 || location.length () == 0 ||
726
+ mapset.length () == 0 )
727
+ {
728
+ // Mapset not specified
729
+ return ;
730
+ }
731
+
732
+ QString currentPath = QgsGrass::getDefaultGisdbase () + " /"
733
+ + QgsGrass::getDefaultLocation () + " /"
734
+ + QgsGrass::getDefaultMapset ();
735
+
736
+ QString newPath = gisdbase + " /" + location + " /" + mapset;
737
+
738
+ if ( QFileInfo (currentPath).canonicalPath () ==
739
+ QFileInfo (newPath).canonicalPath () )
740
+ {
741
+ // The same mapset is already open
742
+ return ;
743
+ }
744
+
745
+ QString err = QgsGrass::closeMapset ();
746
+ if ( !err.isNull () )
735
747
{
736
- err = QgsGrass::openMapset ( gisdbase, location, mapset );
748
+ QMessageBox::warning ( 0 , " Warning" ,
749
+ " Cannot close current mapset. " + err );
750
+ return ;
751
+ }
752
+ mapsetChanged ();
737
753
738
- if ( !err.isNull () )
739
- {
740
- QMessageBox::warning ( 0 , " Warning" , " Cannot open GRASS mapset. " + err );
741
- return ;
742
- }
754
+ err = QgsGrass::openMapset ( gisdbase, location, mapset );
743
755
756
+ if ( !err.isNull () )
757
+ {
758
+ QMessageBox::warning ( 0 , " Warning" , " Cannot open GRASS mapset. " + err );
759
+ return ;
744
760
}
761
+
745
762
mapsetChanged ();
746
763
}
747
764
0 commit comments