Skip to content

Commit b323d75

Browse files
author
rugginoso
committedJul 29, 2009
Enhancements into the browser of the grass plug-in:
* Added a context menu * Changed the behavior of confirm dialogs git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11194 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed
 

‎src/plugins/grass/qgsgrassbrowser.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <QTextBrowser>
3232
#include <QToolBar>
3333
#include <QTreeView>
34+
#include <QMenu>
3435

3536

3637
QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
@@ -96,6 +97,7 @@ QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
9697
mTree->header()->hide();
9798
mTree->setModel( mModel );
9899
mTree->setSelectionMode( QAbstractItemView::ExtendedSelection );
100+
mTree->setContextMenuPolicy(Qt::CustomContextMenu);
99101

100102
mTextBrowser = new QTextBrowser( 0 );
101103
mTextBrowser->setReadOnly( TRUE );
@@ -106,6 +108,8 @@ QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
106108

107109
this->setCentralWidget( mSplitter );
108110

111+
connect( mTree, SIGNAL(customContextMenuRequested(const QPoint&)),
112+
this, SLOT(showContextMenu(const QPoint&)));
109113
connect( mTree->selectionModel(),
110114
SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
111115
this, SLOT( selectionChanged( QItemSelection, QItemSelection ) ) );
@@ -189,6 +193,20 @@ void QgsGrassBrowser::doubleClicked( const QModelIndex & index )
189193
addMap();
190194
}
191195

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+
192210
QString QgsGrassBrowser::formatMessage( QString msg )
193211
{
194212
return msg.replace( "<", "&lt;" ).replace( ">", "&gt;" ).replace( "\n", "<br>" );
@@ -238,7 +256,7 @@ void QgsGrassBrowser::copyMap()
238256
suggest = map;
239257
}
240258
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 );
242260

243261
if ( !ok ) return;
244262

@@ -302,7 +320,7 @@ void QgsGrassBrowser::renameMap()
302320
QgsGrassElementDialog ed;
303321
bool ok;
304322
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 );
306324

307325
if ( !ok ) return;
308326

@@ -336,6 +354,9 @@ void QgsGrassBrowser::deleteMap()
336354

337355
QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
338356

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+
339360
QList<QModelIndex>::const_iterator it = indexes.begin();
340361
for ( ; it != indexes.end(); ++it )
341362
{
@@ -353,12 +374,6 @@ void QgsGrassBrowser::deleteMap()
353374
continue; // should not happen
354375
}
355376

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-
362377
QString module = "g.remove";
363378
#ifdef WIN32
364379
module.append( ".exe" );
@@ -456,7 +471,7 @@ void QgsGrassBrowser::selectionChanged( const QItemSelection & selected, const Q
456471
mActionDeleteMap->setEnabled( false );
457472
mActionSetRegion->setEnabled( false );
458473

459-
QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
474+
QModelIndexList indexes = selected.indexes();
460475

461476
mTextBrowser->clear();
462477

@@ -467,6 +482,7 @@ void QgsGrassBrowser::selectionChanged( const QItemSelection & selected, const Q
467482
mTextBrowser->verticalScrollBar()->setValue( 0 );
468483

469484
int type = mModel->itemType( *it );
485+
470486
if ( type == QgsGrassModel::Raster ||
471487
type == QgsGrassModel::Vector ||
472488
type == QgsGrassModel::VectorLayer )

‎src/plugins/grass/qgsgrassbrowser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class QgsGrassBrowser: public QMainWindow
7777
// Double click
7878
void doubleClicked( const QModelIndex & index );
7979

80+
private slots:
81+
// Context menu
82+
void showContextMenu( const QPoint &position );
83+
8084
signals:
8185
// emited when something in GRASS Tools changed region
8286
void regionChanged();

0 commit comments

Comments
 (0)
Please sign in to comment.