@@ -201,6 +201,12 @@ void QgsGrassBrowser::addMap()
201
201
mIface ->addVectorLayer ( uri, name, " grass" );
202
202
mapSelected = true ;
203
203
}
204
+ else if ( type == QgsGrassModel::Region )
205
+ {
206
+ struct Cell_head window;
207
+ if ( !getItemRegion (*it, &window) ) continue ;
208
+ writeRegion ( &window );
209
+ }
204
210
}
205
211
}
206
212
@@ -246,10 +252,20 @@ void QgsGrassBrowser::copyMap()
246
252
typeName = " region" ;
247
253
}
248
254
249
- QgsGrassElementDialog *ed = new QgsGrassElementDialog () ;
255
+ QgsGrassElementDialog ed ;
250
256
bool ok;
251
- QString newName = ed->getItem ( element, map, &ok );
252
- delete ed;
257
+ QString source;
258
+ QString suggest;
259
+ if ( mapset == QgsGrass::getDefaultMapset () )
260
+ {
261
+ source = map;
262
+ }
263
+ else
264
+ {
265
+ suggest = map;
266
+ }
267
+ QString newName = ed.getItem ( element, " New name" ,
268
+ " New name" , suggest, source, &ok );
253
269
254
270
if ( !ok ) return ;
255
271
@@ -262,7 +278,7 @@ void QgsGrassBrowser::copyMap()
262
278
if ( !process.waitForFinished () )
263
279
{
264
280
QMessageBox::warning ( 0 , " Warning" , " Cannot copy map "
265
- + map );
281
+ + map + " @ " + mapset );
266
282
}
267
283
else
268
284
{
@@ -277,7 +293,57 @@ void QgsGrassBrowser::renameMap()
277
293
std::cerr << " QgsGrassBrowser::renameMap()" << std::endl;
278
294
#endif
279
295
280
- QMessageBox::warning ( 0 , " Warning" , " Not yet implemented" );
296
+ QModelIndexList indexes = mTree ->selectionModel ()->selectedIndexes ();
297
+
298
+ QList<QModelIndex>::const_iterator it = indexes.begin ();
299
+ for (; it != indexes.end (); ++it)
300
+ {
301
+ int type = mModel ->itemType (*it);
302
+ QString mapset = mModel ->itemMapset (*it);
303
+ QString map = mModel ->itemMap (*it);
304
+
305
+ if ( mapset != QgsGrass::getDefaultMapset () ) continue ; // should not happen
306
+
307
+ QString typeName;
308
+ QString element;
309
+ if ( type == QgsGrassModel::Raster )
310
+ {
311
+ element = " cell" ;
312
+ typeName = " rast" ;
313
+ }
314
+ else if ( type == QgsGrassModel::Vector )
315
+ {
316
+ element = " vector" ;
317
+ typeName = " vect" ;
318
+ }
319
+ else if ( type == QgsGrassModel::Region )
320
+ {
321
+ element = " windows" ;
322
+ typeName = " region" ;
323
+ }
324
+
325
+ QgsGrassElementDialog ed;
326
+ bool ok;
327
+ QString newName = ed.getItem ( element, " New name" ,
328
+ " New name" , " " , map, &ok );
329
+
330
+ if ( !ok ) return ;
331
+
332
+ QString module = " g.rename" ;
333
+ #ifdef WIN32
334
+ module .append (" .exe" );
335
+ #endif
336
+ QProcess process (this );
337
+ process.start (module , QStringList ( typeName + " =" + map + " ," + newName ) );
338
+ if ( !process.waitForFinished () )
339
+ {
340
+ QMessageBox::warning ( 0 , " Warning" , " Cannot rename map " + map );
341
+ }
342
+ else
343
+ {
344
+ refresh ();
345
+ }
346
+ }
281
347
}
282
348
283
349
void QgsGrassBrowser::deleteMap ()
@@ -336,76 +402,29 @@ void QgsGrassBrowser::setRegion()
336
402
#endif
337
403
338
404
struct Cell_head window;
339
-
340
- QModelIndexList indexes = mTree ->selectionModel ()->selectedIndexes ();
341
405
342
- QgsGrass::setLocation ( QgsGrass::getDefaultGisdbase (),
343
- QgsGrass::getDefaultLocation () );
406
+ QModelIndexList indexes = mTree ->selectionModel ()->selectedIndexes ();
344
407
345
408
// TODO multiple selection - extent region to all maps
346
409
QList<QModelIndex>::const_iterator it = indexes.begin ();
347
410
for (; it != indexes.end (); ++it)
348
411
{
349
- int type = mModel ->itemType (*it);
350
- QString uri = mModel ->uri (*it);
351
- QString mapset = mModel ->itemMapset (*it);
352
- QString map = mModel ->itemMap (*it);
353
-
354
- if ( type == QgsGrassModel::Raster )
355
- {
356
-
357
- if ( G_get_cellhd ( map.toLocal8Bit ().data (),
358
- mapset.toLocal8Bit ().data (), &window) < 0 )
359
- {
360
- QMessageBox::warning ( 0 , " Warning" ,
361
- " Cannot read raster map region" );
362
- return ;
363
- }
364
- }
365
- else if ( type == QgsGrassModel::Vector )
366
- {
367
- G_get_window ( &window ); // get current resolution
368
-
369
- struct Map_info Map;
370
-
371
- int level = Vect_open_old_head ( &Map,
372
- map.toLocal8Bit ().data (), mapset.toLocal8Bit ().data ());
373
-
374
- if ( level < 2 )
375
- {
376
- QMessageBox::warning ( 0 , " Warning" ,
377
- " Cannot read vector map region" );
378
- return ;
379
- }
380
-
381
- BOUND_BOX box;
382
- Vect_get_map_box (&Map, &box );
383
- window.north = box.N ;
384
- window.south = box.S ;
385
- window.west = box.W ;
386
- window.east = box.E ;
387
-
388
- Vect_close (&Map);
389
- }
390
- else if ( type == QgsGrassModel::Region )
391
- {
392
- if ( G__get_window (&window, " windows" ,
393
- map.toLocal8Bit ().data (),
394
- mapset.toLocal8Bit ().data () ) != NULL )
395
- {
396
- QMessageBox::warning ( 0 , " Warning" ,
397
- " Cannot read region" );
398
- return ;
399
- }
400
- }
412
+ if ( !getItemRegion (*it, &window) ) return ;
401
413
}
414
+ writeRegion ( &window );
415
+ }
416
+
417
+ void QgsGrassBrowser::writeRegion (struct Cell_head *window )
418
+ {
419
+ #ifdef QGISDEBUG
420
+ std::cerr << " QgsGrassBrowser::writeRegion()" << std::endl;
421
+ #endif
402
422
403
- // Reset mapset (selected maps could be in a different one)
404
423
QgsGrass::setMapset ( QgsGrass::getDefaultGisdbase (),
405
424
QgsGrass::getDefaultLocation (),
406
425
QgsGrass::getDefaultMapset () );
407
426
408
- if ( G_put_window ( & window ) == -1 )
427
+ if ( G_put_window ( window ) == -1 )
409
428
{
410
429
QMessageBox::warning ( 0 , " Warning" ,
411
430
" Cannot write new region" );
@@ -414,6 +433,70 @@ void QgsGrassBrowser::setRegion()
414
433
emit regionChanged ();
415
434
}
416
435
436
+ bool QgsGrassBrowser::getItemRegion ( QModelIndex index, struct Cell_head *window )
437
+ {
438
+ #ifdef QGISDEBUG
439
+ std::cerr << " QgsGrassBrowser::setRegion()" << std::endl;
440
+ #endif
441
+
442
+ QgsGrass::setLocation ( QgsGrass::getDefaultGisdbase (),
443
+ QgsGrass::getDefaultLocation () );
444
+
445
+ int type = mModel ->itemType (index);
446
+ QString uri = mModel ->uri (index);
447
+ QString mapset = mModel ->itemMapset (index);
448
+ QString map = mModel ->itemMap (index);
449
+
450
+ if ( type == QgsGrassModel::Raster )
451
+ {
452
+
453
+ if ( G_get_cellhd ( map.toLocal8Bit ().data (),
454
+ mapset.toLocal8Bit ().data (), window) < 0 )
455
+ {
456
+ QMessageBox::warning ( 0 , " Warning" ,
457
+ " Cannot read raster map region" );
458
+ return false ;
459
+ }
460
+ }
461
+ else if ( type == QgsGrassModel::Vector )
462
+ {
463
+ G_get_window ( window ); // get current resolution
464
+
465
+ struct Map_info Map;
466
+
467
+ int level = Vect_open_old_head ( &Map,
468
+ map.toLocal8Bit ().data (), mapset.toLocal8Bit ().data ());
469
+
470
+ if ( level < 2 )
471
+ {
472
+ QMessageBox::warning ( 0 , " Warning" ,
473
+ " Cannot read vector map region" );
474
+ return false ;
475
+ }
476
+
477
+ BOUND_BOX box;
478
+ Vect_get_map_box (&Map, &box );
479
+ window->north = box.N ;
480
+ window->south = box.S ;
481
+ window->west = box.W ;
482
+ window->east = box.E ;
483
+
484
+ Vect_close (&Map);
485
+ }
486
+ else if ( type == QgsGrassModel::Region )
487
+ {
488
+ if ( G__get_window (window, " windows" ,
489
+ map.toLocal8Bit ().data (),
490
+ mapset.toLocal8Bit ().data () ) != NULL )
491
+ {
492
+ QMessageBox::warning ( 0 , " Warning" ,
493
+ " Cannot read region" );
494
+ return false ;
495
+ }
496
+ }
497
+ return true ;
498
+ }
499
+
417
500
void QgsGrassBrowser::selectionChanged (const QItemSelection & selected, const QItemSelection & deselected)
418
501
{
419
502
#ifdef QGISDEBUG
0 commit comments