Skip to content

Commit af29521

Browse files
author
rblazek
committed
pepare for G_is_gisbase, G_is_location, G_is_mapset, G_list
git-svn-id: http://svn.osgeo.org/qgis/trunk@5488 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e4b984c commit af29521

File tree

1 file changed

+43
-36
lines changed

1 file changed

+43
-36
lines changed

src/plugins/grass/qgsgrassselect.cpp

+43-36
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,32 @@ void QgsGrassSelect::setLocations()
152152
for ( unsigned int i = 0; i < d.count(); i++ ) {
153153
if ( d[i] == "." || d[i] == ".." ) continue;
154154

155-
QString chf = egisdbase->text() + "/" + d[i] + "/PERMANENT/DEFAULT_WIND";
156-
157-
if ( !QFile::exists ( chf ) ) continue;
155+
QString ldpath = egisdbase->text() + "/" + d[i];
156+
157+
/* TODO: G_is_location() was added to GRASS 6.1 06-05-24,
158+
enable its use after some period (others do update) */
159+
/*
160+
if ( QgsGrass::versionMajor() > 6 || QgsGrass::versionMinor() > 0 )
161+
{
162+
if ( !G_is_location( ldpath.toLocal8Bit().constData() ) ) continue;
163+
}
164+
else
165+
{
166+
*/
167+
QString chf = egisdbase->text() + "/" + d[i] + "/PERMANENT/DEFAULT_WIND";
168+
if ( !QFile::exists ( chf ) ) continue;
169+
//}
158170

159-
// if type is MAPSET check also if at least one mapset woned by user exists
171+
// if type is MAPSET check also if at least one mapset owned by user exists
160172
if ( QgsGrassSelect::type == QgsGrassSelect::MAPSET )
161173
{
162174
bool exists = false;
163175

164-
QString ldpath = egisdbase->text() + "/" + d[i];
165176
QDir ld = QDir( ldpath );
166177

167-
for ( unsigned int j = 0; j < ld.count(); j++ ) {
168-
QString windf = ldpath + "/" + ld[j] + "/WIND";
169-
if ( !QFile::exists ( windf ) ) continue;
178+
for ( unsigned int j = 0; j < ld.count(); j++ )
179+
{
180+
if ( !QgsGrass::isMapset( ldpath + "/" + ld[j] ) ) continue;
170181

171182
QFileInfo info ( ldpath + "/" + ld[j] );
172183
if ( !info.isWritable() ) continue;
@@ -214,10 +225,10 @@ void QgsGrassSelect::setMapsets()
214225
int sel = -1;
215226

216227
// Go through all subdirs and add all subdirs from vector/
217-
for ( unsigned int i = 0; i < ld.count(); i++ ) {
218-
QString windf = ldpath + "/" + ld[i] + "/WIND";
219-
220-
if ( QFile::exists ( windf ) ) {
228+
for ( unsigned int i = 0; i < ld.count(); i++ )
229+
{
230+
if ( QgsGrass::isMapset( ldpath + "/" + ld[i] ) )
231+
{
221232
emapset->insertItem ( ld[i], -1 );
222233
if ( ld[i] == lastMapset ) {
223234
sel = idx;
@@ -251,38 +262,34 @@ void QgsGrassSelect::setMaps()
251262
int idx = 0;
252263
int sel = -1;
253264

254-
if (type == VECTOR ) { // vector
255-
ldpath.append ( "/vector/" );
256-
QDir md = QDir( ldpath );
265+
if (type == VECTOR ) // vector
266+
{
267+
QStringList list = QgsGrass::vectors ( egisdbase->text(),
268+
elocation->currentText(), emapset->currentText() );
257269

258-
for ( unsigned int j = 0; j < md.count(); j++ ) {
259-
QString chf = ldpath + md[j] + "/head";
260-
261-
if ( QFile::exists ( chf ) ) {
262-
QString m = QString( md[j] );
263-
emap->insertItem ( m, -1 );
264-
if ( m == lastVectorMap ) {
265-
sel = idx;
266-
}
267-
idx++;
268-
}
270+
for ( int j = 0; j < list.count(); j++ )
271+
{
272+
emap->insertItem ( list[j], -1 );
273+
if ( list[j] == lastVectorMap ) sel = idx;
274+
idx++;
269275
}
270-
} else if ( type == RASTER ) {
276+
}
277+
else if ( type == RASTER )
278+
{
271279
/* add cells */
272-
QDir md = QDir( ldpath + "/cell/" );
273-
md.setFilter (QDir::Files);
280+
QStringList list = QgsGrass::rasters ( egisdbase->text(),
281+
elocation->currentText(), emapset->currentText() );
274282

275-
for ( unsigned int j = 0; j < md.count(); j++ ) {
276-
QString m = QString( md[j] );
277-
emap->insertItem ( m, -1 );
278-
if ( m == lastRasterMap ) {
279-
sel = idx;
280-
}
283+
for ( int j = 0; j < list.count(); j++ )
284+
{
285+
emap->insertItem ( list[j], -1 );
286+
if ( list[j] == lastRasterMap ) sel = idx;
281287
idx++;
282288
}
283289

284290
/* add groups */
285-
md = QDir( ldpath + "/group/" );
291+
// TODO add QgsGrass::groups ( use G_list( G_ELEMENT_GROUP) )
292+
QDir md = QDir( ldpath + "/group/" );
286293
md.setFilter (QDir::Dirs);
287294

288295
for ( unsigned int j = 0; j < md.count(); j++ ) {

0 commit comments

Comments
 (0)