Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
save working mapset in project file
git-svn-id: http://svn.osgeo.org/qgis/trunk@5025 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 15, 2006
1 parent ef8166c commit 9c72b9a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 11 deletions.
80 changes: 70 additions & 10 deletions src/plugins/grass/qgsgrassplugin.cpp
Expand Up @@ -48,6 +48,8 @@
//non qt includes
#include <iostream>

#include <qgsproject.h>

extern "C" {
#include <grass/gis.h>
#include <grass/Vect.h>
Expand Down Expand Up @@ -81,7 +83,7 @@ static const char *pluginVersion = "0.1";
* @param theQgisInterFace Pointer to the QGIS interface object
*/
QgsGrassPlugin::QgsGrassPlugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
qgisMainWindowPointer(theQGisApp), qGisInterface(theQgisInterFace)
mQgis(theQGisApp), qGisInterface(theQgisInterFace)
{
/** Initialize the plugin and set the required attributes */
pluginNameQString = "GrassVector";
Expand Down Expand Up @@ -137,6 +139,10 @@ void QgsGrassPlugin::initGui()

mCanvas = qGisInterface->getMapCanvas();

// Connect project
connect( mQgis, SIGNAL( projectRead() ), this, SLOT( projectRead()));
connect( mQgis, SIGNAL( newProject() ), this, SLOT(newProject()));

// Create the action for tool
mOpenMapsetAction = new QAction( "Open mapset", this );
mNewMapsetAction = new QAction( "New mapset", this );
Expand Down Expand Up @@ -194,7 +200,7 @@ void QgsGrassPlugin::initGui()
mNewVectorAction->addTo(pluginMenu);

// Add the toolbar to the main window
toolBarPointer = qgisMainWindowPointer->addToolBar("GRASS");
toolBarPointer = mQgis->addToolBar("GRASS");
toolBarPointer->setLabel(tr("GRASS"));
toolBarPointer->setIconSize(QSize(24,24));

Expand Down Expand Up @@ -247,6 +253,16 @@ void QgsGrassPlugin::mapsetChanged ()
mTools->mapsetChanged();
}
}

// Save working mapset in project file
QgsProject::instance()->writeEntry("GRASS","/WorkingGisdbase",
QgsGrass::getDefaultGisdbase() );

QgsProject::instance()->writeEntry("GRASS","/WorkingLocation",
QgsGrass::getDefaultLocation() );

QgsProject::instance()->writeEntry("GRASS","/WorkingMapset",
QgsGrass::getDefaultMapset() );
}

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

mTools->show();
}
Expand All @@ -394,7 +410,7 @@ void QgsGrassPlugin::edit()
return;
}

QgsGrassEdit *ed = new QgsGrassEdit( qgisMainWindowPointer, qGisInterface, qgisMainWindowPointer, Qt::WType_Dialog );
QgsGrassEdit *ed = new QgsGrassEdit( mQgis, qGisInterface, mQgis, Qt::WType_Dialog );

if ( ed->isValid() ) {
ed->show();
Expand Down Expand Up @@ -498,8 +514,8 @@ void QgsGrassPlugin::newVector()
return;
}

QgsGrassEdit *ed = new QgsGrassEdit( qgisMainWindowPointer,
qGisInterface, provider, qgisMainWindowPointer,
QgsGrassEdit *ed = new QgsGrassEdit( mQgis,
qGisInterface, provider, mQgis,
Qt::WType_Dialog );

if ( ed->isValid() ) {
Expand Down Expand Up @@ -620,8 +636,8 @@ void QgsGrassPlugin::changeRegion(void)
return;
}

QgsGrassRegion *reg = new QgsGrassRegion(this, qgisMainWindowPointer, qGisInterface,
qgisMainWindowPointer, Qt::WType_Dialog );
QgsGrassRegion *reg = new QgsGrassRegion(this, mQgis, qGisInterface,
mQgis, Qt::WType_Dialog );

reg->show();
}
Expand Down Expand Up @@ -686,13 +702,57 @@ void QgsGrassPlugin::newMapset()
if ( !QgsGrassNewMapset::isRunning() )
{
mNewMapset = new QgsGrassNewMapset (
qgisMainWindowPointer, qGisInterface,
this, qgisMainWindowPointer );
mQgis, qGisInterface,
this, mQgis );
}
mNewMapset->show();
mNewMapset->raise();
}

void QgsGrassPlugin::projectRead()
{
#ifdef QGISDEBUG
std::cout << "QgsGrassPlugin::projectRead" << std::endl;
#endif
QString err = QgsGrass::closeMapset ();
if ( !err.isNull() )
{
QMessageBox::warning( 0, "Warning",
"Cannot close current mapset. " + err );
return;
}

bool ok;
QString gisdbase = QgsProject::instance()->readEntry(
"GRASS", "/WorkingGisdbase", "", &ok).trimmed();
QString location = QgsProject::instance()->readEntry(
"GRASS", "/WorkingLocation", "", &ok).trimmed();
QString mapset = QgsProject::instance()->readEntry(
"GRASS", "/WorkingMapset", "", &ok).trimmed();

if ( gisdbase.length() > 0 && location.length() > 0 &&
mapset.length() > 0 )
{
err = QgsGrass::openMapset ( gisdbase, location, mapset );

if ( !err.isNull() )
{
QMessageBox::warning( 0, "Warning", "Cannot open GRASS mapset. " + err );
return;
}

}
mapsetChanged();
}

void QgsGrassPlugin::newProject()
{
#ifdef QGISDEBUG
std::cout << "QgsGrassPlugin::newProject" << std::endl;
#endif

}

// Unload the plugin by cleaning up the GUI
void QgsGrassPlugin::unload()
{
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/grass/qgsgrassplugin.h
Expand Up @@ -100,6 +100,11 @@ public slots:
void mapsetChanged();
//! Create new vector
void newVector();
//! Read project
void projectRead();
//! New project
void newProject();


private:
//! Name of the plugin
Expand All @@ -115,7 +120,7 @@ public slots:
//! Pointer to our toolbar
QToolBar *toolBarPointer;
//! Pionter to QGIS main application object
QgisApp *qgisMainWindowPointer;
QgisApp *mQgis;
//! Pointer to the QGIS interface object
QgisIface *qGisInterface;
//! Pointer to canvas
Expand Down

0 comments on commit 9c72b9a

Please sign in to comment.