31
31
#include < QTextBrowser>
32
32
#include < QToolBar>
33
33
#include < QTreeView>
34
+ #include < QMenu>
34
35
35
36
36
37
QgsGrassBrowser::QgsGrassBrowser ( QgisInterface *iface,
@@ -96,6 +97,7 @@ QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
96
97
mTree ->header ()->hide ();
97
98
mTree ->setModel ( mModel );
98
99
mTree ->setSelectionMode ( QAbstractItemView::ExtendedSelection );
100
+ mTree ->setContextMenuPolicy (Qt::CustomContextMenu);
99
101
100
102
mTextBrowser = new QTextBrowser ( 0 );
101
103
mTextBrowser ->setReadOnly ( TRUE );
@@ -106,6 +108,8 @@ QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
106
108
107
109
this ->setCentralWidget ( mSplitter );
108
110
111
+ connect ( mTree , SIGNAL (customContextMenuRequested (const QPoint&)),
112
+ this , SLOT (showContextMenu (const QPoint&)));
109
113
connect ( mTree ->selectionModel (),
110
114
SIGNAL ( selectionChanged ( QItemSelection, QItemSelection ) ),
111
115
this , SLOT ( selectionChanged ( QItemSelection, QItemSelection ) ) );
@@ -189,6 +193,20 @@ void QgsGrassBrowser::doubleClicked( const QModelIndex & index )
189
193
addMap ();
190
194
}
191
195
196
+ void QgsGrassBrowser::showContextMenu (const QPoint &position)
197
+ {
198
+ QList<QAction *> actions;
199
+ if (mTree ->indexAt (position).isValid ()) {
200
+ actions.append (mActionAddMap );
201
+ actions.append (mActionDeleteMap );
202
+ actions.append (mActionCopyMap );
203
+ actions.append (mActionRenameMap );
204
+ actions.append (mActionSetRegion );
205
+ }
206
+ if (actions.count () > 0 )
207
+ QMenu::exec (actions, mTree ->mapToGlobal (position));
208
+ }
209
+
192
210
QString QgsGrassBrowser::formatMessage ( QString msg )
193
211
{
194
212
return msg.replace ( " <" , " <" ).replace ( " >" , " >" ).replace ( " \n " , " <br>" );
@@ -238,7 +256,7 @@ void QgsGrassBrowser::copyMap()
238
256
suggest = map;
239
257
}
240
258
QString newName = ed.getItem ( element, tr ( " New name" ),
241
- tr ( " New name" ), suggest, source, &ok );
259
+ tr ( " New name for layer \" %1 \" " ). arg (map ), suggest, source, &ok );
242
260
243
261
if ( !ok ) return ;
244
262
@@ -302,7 +320,7 @@ void QgsGrassBrowser::renameMap()
302
320
QgsGrassElementDialog ed;
303
321
bool ok;
304
322
QString newName = ed.getItem ( element, tr ( " New name" ),
305
- tr ( " New name" ), " " , map, &ok );
323
+ tr ( " New name for layer \" %1 \" " ). arg (map ), " " , map, &ok );
306
324
307
325
if ( !ok ) return ;
308
326
@@ -336,6 +354,9 @@ void QgsGrassBrowser::deleteMap()
336
354
337
355
QModelIndexList indexes = mTree ->selectionModel ()->selectedIndexes ();
338
356
357
+ if (!QMessageBox::question (this , tr (" Question" ), tr (" Are you sure you want to delete the %1 selected layer(s)?" ).arg (indexes.size ())))
358
+ return ;
359
+
339
360
QList<QModelIndex>::const_iterator it = indexes.begin ();
340
361
for ( ; it != indexes.end (); ++it )
341
362
{
@@ -353,12 +374,6 @@ void QgsGrassBrowser::deleteMap()
353
374
continue ; // should not happen
354
375
}
355
376
356
- QMessageBox::StandardButton ret = QMessageBox::question ( 0 , tr ( " Warning" ),
357
- tr ( " Delete map <b>%1</b>" ).arg ( map ),
358
- QMessageBox::Ok | QMessageBox::Cancel );
359
-
360
- if ( ret == QMessageBox::Cancel ) continue ;
361
-
362
377
QString module = " g.remove" ;
363
378
#ifdef WIN32
364
379
module .append ( " .exe" );
@@ -456,7 +471,7 @@ void QgsGrassBrowser::selectionChanged( const QItemSelection & selected, const Q
456
471
mActionDeleteMap ->setEnabled ( false );
457
472
mActionSetRegion ->setEnabled ( false );
458
473
459
- QModelIndexList indexes = mTree -> selectionModel ()-> selectedIndexes ();
474
+ QModelIndexList indexes = selected. indexes ();
460
475
461
476
mTextBrowser ->clear ();
462
477
@@ -467,6 +482,7 @@ void QgsGrassBrowser::selectionChanged( const QItemSelection & selected, const Q
467
482
mTextBrowser ->verticalScrollBar ()->setValue ( 0 );
468
483
469
484
int type = mModel ->itemType ( *it );
485
+
470
486
if ( type == QgsGrassModel::Raster ||
471
487
type == QgsGrassModel::Vector ||
472
488
type == QgsGrassModel::VectorLayer )
0 commit comments