Skip to content

Commit c078ce5

Browse files
committedAug 24, 2015
[GRASS] fixed path to modules used in browser
1 parent f82b8c6 commit c078ce5

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed
 

‎src/plugins/grass/qgsgrassmoduleoptions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ void QgsGrassModuleStandardOptions::freezeOutput()
542542

543543
QgsDebugMsg( "source = " + source );
544544

545-
// Check GISBASE and LOCATION
545+
// Check GISDBASE and LOCATION
546546
QStringList split = source.split( sep );
547547

548548
if ( split.size() < 4 )
@@ -617,7 +617,7 @@ void QgsGrassModuleStandardOptions::thawOutput()
617617

618618
QgsDebugMsg( "source = " + source );
619619

620-
// Check GISBASE and LOCATION
620+
// Check GISDBASE and LOCATION
621621
QStringList split = source.split( sep );
622622

623623
if ( split.size() < 4 )
@@ -1603,7 +1603,7 @@ void QgsGrassModuleInput::updateQgisLayers()
16031603

16041604
QgsDebugMsg( "source = " + source );
16051605

1606-
// Check GISBASE and LOCATION
1606+
// Check GISDBASE and LOCATION
16071607
QStringList split = source.split( sep, QString::SkipEmptyParts );
16081608

16091609
if ( split.size() < 4 )
@@ -1720,7 +1720,7 @@ void QgsGrassModuleInput::updateQgisLayers()
17201720
if ( source.contains( "cellhd" ) == 0 )
17211721
continue;
17221722

1723-
// Most probably GRASS layer, check GISBASE and LOCATION
1723+
// Most probably GRASS layer, check GISDBASE and LOCATION
17241724
QStringList split = source.split( sep, QString::SkipEmptyParts );
17251725

17261726
if ( split.size() < 4 )

‎src/providers/grass/qgsgrass.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void QgsGrass::init( void )
328328
#else
329329
QString gisBase = getenv( "GISBASE" );
330330
#endif
331-
QgsDebugMsg( QString( "GRASS gisBase from GISBASE env var is: %1" ).arg( gisBase ) );
331+
QgsDebugMsg( QString( "GRASS gisBase from GISBASE/WINGISBASE env var is: %1" ).arg( gisBase ) );
332332
if ( !isValidGrassBaseDir( gisBase ) )
333333
{
334334
// Look for gisbase in QSettings
@@ -381,7 +381,7 @@ void QgsGrass::init( void )
381381
break;
382382
}
383383

384-
// XXX Need to subclass this and add explantory message above to left side
384+
// XXX Need to subclass this and add explantory message aboveSencha to left side
385385
userGisbase = true;
386386
// For Mac, GISBASE folder may be inside GRASS bundle. Use Qt file dialog
387387
// since Mac native dialog doesn't allow user to browse inside bundles.
@@ -412,16 +412,18 @@ void QgsGrass::init( void )
412412
}
413413

414414
QgsDebugMsg( QString( "Valid GRASS gisBase is: %1" ).arg( gisBase ) );
415+
// GISBASE environment variable must be set because is required by directly called GRASS functions
415416
putEnv( "GISBASE", gisBase );
417+
mGisbase = gisBase;
416418

417419
// Create list of paths to GRASS modules
418420
// PATH environment variable is not used to search for modules (since 2.12) because it could
419421
// create a lot of confusion especially if both GRASS 6 and 7 are installed and path to one version
420422
// $GISBASE/bin somehow gets to PATH and another version plugin is loaded to QGIS, because if a module
421423
// is missing in one version, it could be found in another $GISBASE/bin and misleadin error could be reported
422424
mGrassModulesPaths.clear();
423-
mGrassModulesPaths << gisBase + "/bin";
424-
mGrassModulesPaths << gisBase + "/scripts";
425+
mGrassModulesPaths << gisbase() + "/bin";
426+
mGrassModulesPaths << gisbase() + "/scripts";
425427
mGrassModulesPaths << QgsApplication::pkgDataPath() + "/grass/scripts";
426428

427429
// On windows the GRASS libraries are in
@@ -450,7 +452,7 @@ void QgsGrass::init( void )
450452

451453
// TODO: move setting of PYTHONPATH to QProcess where necessary
452454
// Set PYTHONPATH
453-
QString pythonpath = gisBase + "/etc/python";
455+
QString pythonpath = gisbase() + "/etc/python";
454456
QString pp = getenv( "PYTHONPATH" );
455457
pythonpath.append( pathSeparator() + pp );
456458
QgsDebugMsg( QString( "set PYTHONPATH: %1" ).arg( pythonpath ) );
@@ -609,6 +611,7 @@ QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
609611

610612
QString QgsGrass::error_message;
611613

614+
QString QgsGrass::mGisbase;
612615
QStringList QgsGrass::mGrassModulesPaths;
613616
QString QgsGrass::defaultGisdbase;
614617
QString QgsGrass::defaultLocation;
@@ -685,8 +688,7 @@ QString QgsGrass::openMapset( const QString& gisdbase,
685688
QString mapsetPath = gisdbase + "/" + location + "/" + mapset;
686689

687690
// Check if the mapset is in use
688-
QString gisBase = getenv( "GISBASE" );
689-
if ( gisBase.isEmpty() )
691+
if ( !isValidGrassBaseDir( gisbase() ) )
690692
return QObject::tr( "GISBASE is not set." );
691693

692694
QFileInfo fi( mapsetPath + "/WIND" );
@@ -708,7 +710,7 @@ QString QgsGrass::openMapset( const QString& gisdbase,
708710
#ifndef Q_OS_WIN
709711
QFile lockFile( lock );
710712
QProcess process;
711-
QString lockProgram( gisBase + "/etc/lock" );
713+
QString lockProgram( gisbase() + "/etc/lock" );
712714
QStringList lockArguments;
713715
lockArguments << lock << QString::number( pid );
714716
QString lockCommand = lockProgram + " " + lockArguments.join( " " ); // for debug
@@ -2028,7 +2030,7 @@ QMap<QString, QString> QgsGrass::query( QString gisdbase, QString location, QStr
20282030
void QgsGrass::renameObject( const QgsGrassObject & object, const QString& newName )
20292031
{
20302032
QgsDebugMsg( "entered" );
2031-
QString cmd = "g.rename";
2033+
QString cmd = gisbase() + "/bin/g.rename";
20322034
QStringList arguments;
20332035

20342036
arguments << object.elementShort() + "=" + object.name() + "," + newName;
@@ -2048,7 +2050,7 @@ void QgsGrass::copyObject( const QgsGrassObject & srcObject, const QgsGrassObjec
20482050
throw QgsGrass::Exception( QObject::tr( "Attempt to copy from different location." ) );
20492051
}
20502052

2051-
QString cmd = "g.copy";
2053+
QString cmd = gisbase() + "/bin/g.copy";
20522054
QStringList arguments;
20532055

20542056
arguments << srcObject.elementShort() + "=" + srcObject.name() + "@" + srcObject.mapset() + "," + destObject.name();
@@ -2074,8 +2076,7 @@ bool QgsGrass::deleteObject( const QgsGrassObject & object )
20742076
}
20752077
*/
20762078

2077-
// path to g.remove should be in PATH (added by QgsGrass::init())
2078-
QString cmd = "g.remove";
2079+
QString cmd = gisbase() + "/bin/g.remove";
20792080
QStringList arguments;
20802081

20812082
#if GRASS_VERSION_MAJOR < 7

‎src/providers/grass/qgsgrass.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class GRASS_LIB_EXPORT QgsGrassObject
126126
Type mType;
127127
};
128128

129-
/*!
129+
/** QString gisdbase()
130130
Methods for C library initialization and error handling.
131131
*/
132132
class GRASS_LIB_EXPORT QgsGrass : public QObject
@@ -159,6 +159,9 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
159159
/** Get singleton instance of this class. Used as signals proxy between provider and plugin. */
160160
static QgsGrass* instance();
161161

162+
/** Path to where GRASS is installed (GISBASE) */
163+
static QString gisbase() { return mGisbase; }
164+
162165
//! Get info about the mode
163166
/** QgsGrass may be running in active or passive mode.
164167
* Active mode means that GISRC is set up and GISRC file is available,
@@ -530,6 +533,7 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
530533
private:
531534
static int initialized; // Set to 1 after initialization
532535
static bool active; // is active mode
536+
static QString mGisbase;
533537
static QStringList mGrassModulesPaths;
534538
static QString defaultGisdbase;
535539
static QString defaultLocation;

‎src/providers/grass/qgsgrassprovider.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ int QgsGrassProvider::openMap( QString gisdbase, QString location, QString mapse
816816
}
817817
G_CATCH( QgsGrass::Exception &e )
818818
{
819-
Q_UNUSED( e );
820-
QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( e.what() ) );
819+
QgsGrass::warning( e );
821820
level = -1;
822821
}
823822

@@ -844,8 +843,7 @@ int QgsGrassProvider::openMap( QString gisdbase, QString location, QString mapse
844843
}
845844
G_CATCH( QgsGrass::Exception &e )
846845
{
847-
Q_UNUSED( e );
848-
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
846+
QgsGrass::warning( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
849847
return -1;
850848
}
851849

@@ -862,8 +860,7 @@ int QgsGrassProvider::openMap( QString gisdbase, QString location, QString mapse
862860
}
863861
G_CATCH( QgsGrass::Exception &e )
864862
{
865-
Q_UNUSED( e );
866-
QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( e.what() ) );
863+
QgsGrass::warning( QString( "Cannot build topology: %1" ).arg( e.what() ) );
867864
return -1;
868865
}
869866
}

0 commit comments

Comments
 (0)
Please sign in to comment.