Skip to content

Commit ccd8487

Browse files
blazekmach0
authored andcommittedNov 13, 2011
GRASS version support
Conflicts: src/plugins/grass/CMakeLists.txt
1 parent 5e2d947 commit ccd8487

11 files changed

+100
-32
lines changed
 

‎src/plugins/grass/CMakeLists.txt

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
IF (GRASS_NUM_VERSION LESS 60300)
2-
SET (GRASS_MODULES_DIR "modules-6.3")
3-
ELSE (GRASS_NUM_VERSION LESS 60300)
4-
SET (GRASS_MODULES_DIR "modules-${GRASS_MAJOR_VERSION}.${GRASS_MINOR_VERSION}")
5-
ENDIF (GRASS_NUM_VERSION LESS 60300)
6-
7-
IF (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")
8-
MESSAGE (SEND_ERROR "Your GRASS version is not supported (${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR} is not found).")
9-
ENDIF (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")
10-
IF (NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")
11-
MESSAGE (SEND_ERROR "Your GRASS version is not supported (${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR} is not a Directory).")
12-
ENDIF (NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${GRASS_MODULES_DIR}")
13-
14-
SUBDIRS(modules-common ${GRASS_MODULES_DIR} scripts themes)
1+
ADD_SUBDIRECTORY(modules)
2+
ADD_SUBDIRECTORY(scripts)
153

164
ADD_DEFINITIONS(-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\")
175
ADD_DEFINITIONS(-DHAVE_OPENPTY=${HAVE_OPENPTY})
6+
ADD_DEFINITIONS("-DGRASS_EXPORT=${DLLIMPORT} -DGRASS_LIB_EXPORT=${DLLIMPORT}")
187

198
IF (WIN32)
20-
ADD_DEFINITIONS(-DHAVE_GETPT "-DGRASS_EXPORT=__declspec(dllimport)")
9+
ADD_DEFINITIONS(-DHAVE_GETPT)
2110
ELSE (WIN32)
22-
ADD_DEFINITIONS(-DHAVE_POSIX_OPENPT -DGRASS_EXPORT=)
11+
ADD_DEFINITIONS(-DHAVE_POSIX_OPENPT)
2312
ENDIF (WIN32)
2413

2514
########################################################

‎src/plugins/grass/modules/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
FILE (GLOB MODULE_FILES *.qgm *.svg *.png)
33
INSTALL (FILES ${MODULE_FILES}
44
DESTINATION ${QGIS_DATA_DIR}/grass/modules)
5+
6+
FILE (GLOB CONFIG *.qgc)
7+
INSTALL (FILES ${CONFIG}
8+
DESTINATION ${QGIS_DATA_DIR}/grass/config)

‎src/plugins/grass/modules/default.qgc

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<grass name="r.in.gdal.qgis"/>
3030
<grass name="r.in.gdal.qgis.loc"/>
3131
</section>
32-
<section label="Register external data sources in GRASS">
32+
<section label="Register external data sources in GRASS" version_min="6.4">
3333
<grass name="r.external"/>
3434
<grass name="r.external.qgis"/>
3535
<grass name="r.external.all"/>
@@ -63,7 +63,7 @@
6363
<grass name="v.in.db"/>
6464
<grass name="v.in.garmin"/>
6565
<grass name="v.in.gpsbabel"/>
66-
<grass name="v.in.geonames"/>
66+
<grass name="v.in.geonames" version_min="6.4"/>
6767
<grass name="v.in.gns"/>
6868
</section>
6969
<section label="Import from database into GRASS">
@@ -101,7 +101,7 @@
101101
<grass name="v.out.vtk"/>
102102
</section>
103103
<section label="Export vector table from GRASS to database format">
104-
<grass name="db.out.ogr"/>
104+
<grass name="db.out.ogr" version_min="6.4"/>
105105
</section>
106106
</section>
107107
<section label="Map type conversion">
@@ -169,7 +169,7 @@
169169
<grass name="r.colors.table"/>
170170
<grass name="r.colors.rules"/>
171171
<grass name="r.colors.rast"/>
172-
<grass name="r.colors.stddev"/>
172+
<grass name="r.colors.stddev" version_min="6.4"/>
173173
<grass name="r.blend"/>
174174
<grass name="r.composite"/>
175175
<grass name="r.his"/>
@@ -211,7 +211,7 @@
211211
<grass name="r.texture"/>
212212
<grass name="r.texture.bis"/>
213213
<grass name="r.los"/>
214-
<grass name="r.grow.distance"/>
214+
<grass name="r.grow.distance" version_min="6.4"/>
215215
<grass name="r.walk.coord"/>
216216
<grass name="r.walk.vect"/>
217217
</section>
@@ -263,7 +263,7 @@
263263
<grass name="v.surf.bspline"/>
264264
<grass name="v.surf.idw"/>
265265
<grass name="v.surf.rst"/>
266-
<grass name="r.bilinear"/>
266+
<grass name="r.bilinear" version_min="6.4"/>
267267
<grass name="r.surf.idw"/>
268268
<grass name="r.surf.idw2"/>
269269
<grass name="r.fillnulls"/>
@@ -457,7 +457,7 @@
457457
<section label="Database management">
458458
<grass name="db.connect"/>
459459
<grass name="db.connect.schema"/>
460-
<grass name="db.connect-login.pg"/>
460+
<grass name="db.connect-login.pg" version_min="6.4"/>
461461
<grass name="v.db.reconnect.all"/>
462462
<grass name="db.login"/>
463463
</section>
@@ -472,7 +472,7 @@
472472
<grass name="v.db.update_query"/>
473473
<grass name="v.db.update_op"/>
474474
<grass name="v.db.update_op_query"/>
475-
<grass name="v.db.dropcol"/>
475+
<grass name="v.db.dropcol" version_min="6.4"/>
476476
<grass name="v.db.renamecol"/>
477477
<grass name="db.execute"/>
478478
<grass name="db.select"/>

‎src/plugins/grass/modules/r.surf.fractal.qgm

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">
33

44
<qgisgrassmodule label="Create fractal surface of given fractal dimension" module="r.surf.fractal">
5-
<option key="dimension" />
6-
<option key="number" />
7-
<option key="output" />
5+
<option key="d" version_max="6.3" />
6+
<option key="dimension" version_min="6.4" />
7+
<option key="n" version_max="6.3" />
8+
<option key="number" version_min="6.4" />
9+
<option key="out" version_max="6.3" />
10+
<option key="output" version_min="6.4" />
811
</qgisgrassmodule>

‎src/plugins/grass/modules/v.buffer.qgm

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<qgisgrassmodule label="Vector buffer" module="v.buffer">
55
<option key="input" typeoption="type" layeroption="layer" />
6-
<option key="distance"/>
6+
<option key="buffer" version_max="6.3"/>
7+
<option key="distance" version_min="6.4"/>
78
<option key="output" />
89
</qgisgrassmodule>

‎src/plugins/grass/modules/v.db.select.qgm

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<qgisgrassmodule label="Display vector attributes" module="v.db.select">
55
<option key="map" layeroption="layer" />
6-
<field key="columns" layer="map" type="integer,double,varchar"/>
6+
<field key="column" layer="map" type="integer,double,varchar" version_max="6.3"/>
7+
<field key="columns" layer="map" type="integer,double,varchar" version_min="6.4"/>
78
<option key="fs" answer="|" hidden="yes" />
89
</qgisgrassmodule>

‎src/plugins/grass/modules/v.db.select.where.qgm

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
<qgisgrassmodule label="Display vector map attributes with SQL" module="v.db.select">
55
<option key="map" layeroption="layer" />
6-
<field key="columns" layer="map" type="integer,double,varchar"/>
6+
<field key="column" layer="map" type="integer,double,varchar" version_max="6.3"/>
7+
<field key="columns" layer="map" type="integer,double,varchar" version_min="6.4"/>
78
<option key="where" />
89
<option key="fs" answer="|" hidden="yes" />
910
</qgisgrassmodule>

‎src/plugins/grass/modules/v.to.db.qgm

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<option key="map" layeroption="layer"/>
66
<option key="option"/>
77
<option key="units"/>
8-
<field key="columns" layer="map" type="integer,double" label="Attribute field" />
8+
<field key="column" layer="map" type="integer,double" label="Attribute field" version_max="6.3" />
9+
<field key="columns" layer="map" type="integer,double" label="Attribute field" version_min="6.4" />
910
</qgisgrassmodule>

‎src/plugins/grass/qgsgrassmodule.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,16 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions(
408408
QDomElement e = n.toElement();
409409
if ( !e.isNull() )
410410
{
411+
// Check GRASS version
412+
QString version_min = e.attribute( "version_min" );
413+
QString version_max = e.attribute( "version_max" );
414+
415+
if ( !QgsGrassModuleOption::checkVersion( e.attribute( "version_min" ), e.attribute( "version_max" ) ) )
416+
{
417+
n = n.nextSibling();
418+
continue;
419+
}
420+
411421
QString optionType = e.tagName();
412422
QgsDebugMsg( "optionType = " + optionType );
413423

@@ -2036,6 +2046,51 @@ QString QgsGrassModuleOption::value()
20362046
return value;
20372047
}
20382048

2049+
bool QgsGrassModuleOption::checkVersion( QString version_min, QString version_max )
2050+
{
2051+
QgsDebugMsg( "version_min = " + version_min );
2052+
QgsDebugMsg( "version_max = " + version_max );
2053+
2054+
QRegExp rxVersion( "(\\d+)\\.(\\d+)" );
2055+
if ( !version_min.isEmpty() )
2056+
{
2057+
if ( !rxVersion.exactMatch( version_min ) )
2058+
{
2059+
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot parse version_min %1" ).arg( version_min ) );
2060+
return false;
2061+
}
2062+
else
2063+
{
2064+
int versionMajor = rxVersion.cap( 1 ).toInt();
2065+
int versionMinor = rxVersion.cap( 2 ).toInt();
2066+
if ( QgsGrass::versionMajor() < versionMajor || ( QgsGrass::versionMajor() == versionMajor && QgsGrass::versionMinor() < versionMinor ) )
2067+
{
2068+
return false;
2069+
}
2070+
}
2071+
}
2072+
2073+
if ( !version_max.isEmpty() )
2074+
{
2075+
if ( !rxVersion.exactMatch( version_max ) )
2076+
{
2077+
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot parse version_max %1" ).arg( version_max ) );
2078+
return false;
2079+
}
2080+
else
2081+
{
2082+
int versionMajor = rxVersion.cap( 1 ).toInt();
2083+
int versionMinor = rxVersion.cap( 2 ).toInt();
2084+
if ( QgsGrass::versionMajor() > versionMajor || ( QgsGrass::versionMajor() == versionMajor && QgsGrass::versionMinor() > versionMinor ) )
2085+
{
2086+
return false;
2087+
}
2088+
}
2089+
}
2090+
2091+
return true;
2092+
}
2093+
20392094
QStringList QgsGrassModuleOption::options()
20402095
{
20412096
QStringList list;

‎src/plugins/grass/qgsgrassmodule.h

+3
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ class QgsGrassModuleOption: public QgsGrassModuleGroupBoxItem
481481
// Use of region can be forced by 'region' attribute in qgm
482482
bool usesRegion() { return mUsesRegion; }
483483

484+
//! Check min/max version
485+
static bool checkVersion( QString version_min, QString version_max );
486+
484487
public slots:
485488
// Add new line edit for multiple options
486489
void addLineEdit();

‎src/plugins/grass/qgsgrasstools.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,22 @@ void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element )
258258
{
259259
// QgsDebugMsg(QString("tag = %1").arg(e.tagName()));
260260

261-
if ( e.tagName() == "section" && e.tagName() == "grass" )
261+
if ( e.tagName() != "section" && e.tagName() != "grass" )
262262
{
263263
QgsDebugMsg( QString( "Unknown tag: %1" ).arg( e.tagName() ) );
264264
continue;
265265
}
266266

267+
// Check GRASS version
268+
QString version_min = e.attribute( "version_min" );
269+
QString version_max = e.attribute( "version_max" );
270+
271+
if ( !QgsGrassModuleOption::checkVersion( e.attribute( "version_min" ), e.attribute( "version_max" ) ) )
272+
{
273+
n = n.nextSibling();
274+
continue;
275+
}
276+
267277
if ( parent )
268278
{
269279
item = new QTreeWidgetItem( parent, lastItem );

0 commit comments

Comments
 (0)
Please sign in to comment.