[QGIS Commit] r11194 - trunk/qgis/src/plugins/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jul 28 20:49:07 EDT 2009


Author: rugginoso
Date: 2009-07-28 20:49:06 -0400 (Tue, 28 Jul 2009)
New Revision: 11194

Modified:
   trunk/qgis/src/plugins/grass/qgsgrassbrowser.cpp
   trunk/qgis/src/plugins/grass/qgsgrassbrowser.h
Log:
Enhancements into the browser of the grass plug-in:
* Added a context menu
* Changed the behavior of confirm dialogs


Modified: trunk/qgis/src/plugins/grass/qgsgrassbrowser.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassbrowser.cpp	2009-07-28 16:23:07 UTC (rev 11193)
+++ trunk/qgis/src/plugins/grass/qgsgrassbrowser.cpp	2009-07-29 00:49:06 UTC (rev 11194)
@@ -31,6 +31,7 @@
 #include <QTextBrowser>
 #include <QToolBar>
 #include <QTreeView>
+#include <QMenu>
 
 
 QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
@@ -96,6 +97,7 @@
   mTree->header()->hide();
   mTree->setModel( mModel );
   mTree->setSelectionMode( QAbstractItemView::ExtendedSelection );
+  mTree->setContextMenuPolicy(Qt::CustomContextMenu);
 
   mTextBrowser = new QTextBrowser( 0 );
   mTextBrowser->setReadOnly( TRUE );
@@ -106,6 +108,8 @@
 
   this->setCentralWidget( mSplitter );
 
+  connect( mTree, SIGNAL(customContextMenuRequested(const QPoint&)),
+           this,  SLOT(showContextMenu(const QPoint&)));
   connect( mTree->selectionModel(),
            SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
            this, SLOT( selectionChanged( QItemSelection, QItemSelection ) ) );
@@ -189,6 +193,20 @@
   addMap();
 }
 
+void QgsGrassBrowser::showContextMenu(const QPoint &position)
+{
+    QList<QAction *> actions;
+    if (mTree->indexAt(position).isValid()) {
+        actions.append(mActionAddMap);
+        actions.append(mActionDeleteMap);
+        actions.append(mActionCopyMap);
+        actions.append(mActionRenameMap);
+        actions.append(mActionSetRegion);
+    }
+    if (actions.count() > 0)
+        QMenu::exec(actions, mTree->mapToGlobal(position));
+}
+
 QString QgsGrassBrowser::formatMessage( QString msg )
 {
   return msg.replace( "<", "&lt;" ).replace( ">", "&gt;" ).replace( "\n", "<br>" );
@@ -238,7 +256,7 @@
       suggest = map;
     }
     QString newName = ed.getItem( element, tr( "New name" ),
-                                  tr( "New name" ), suggest, source, &ok );
+                                  tr( "New name for layer \"%1\"" ).arg(map), suggest, source, &ok );
 
     if ( !ok ) return;
 
@@ -302,7 +320,7 @@
     QgsGrassElementDialog ed;
     bool ok;
     QString newName = ed.getItem( element, tr( "New name" ),
-                                  tr( "New name" ), "", map, &ok );
+                                  tr( "New name for layer \"%1\"" ).arg(map), "", map, &ok );
 
     if ( !ok ) return;
 
@@ -336,6 +354,9 @@
 
   QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
 
+  if (!QMessageBox::question(this, tr("Question"), tr("Are you sure you want to delete the %1 selected layer(s)?").arg(indexes.size())))
+      return;
+
   QList<QModelIndex>::const_iterator it = indexes.begin();
   for ( ; it != indexes.end(); ++it )
   {
@@ -353,12 +374,6 @@
       continue; // should not happen
     }
 
-    QMessageBox::StandardButton ret = QMessageBox::question( 0, tr( "Warning" ),
-                                      tr( "Delete map <b>%1</b>" ).arg( map ),
-                                      QMessageBox::Ok | QMessageBox::Cancel );
-
-    if ( ret == QMessageBox::Cancel ) continue;
-
     QString module = "g.remove";
 #ifdef WIN32
     module.append( ".exe" );
@@ -456,7 +471,7 @@
   mActionDeleteMap->setEnabled( false );
   mActionSetRegion->setEnabled( false );
 
-  QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
+  QModelIndexList indexes = selected.indexes();
 
   mTextBrowser->clear();
 
@@ -467,6 +482,7 @@
     mTextBrowser->verticalScrollBar()->setValue( 0 );
 
     int type = mModel->itemType( *it );
+
     if ( type == QgsGrassModel::Raster ||
          type == QgsGrassModel::Vector ||
          type == QgsGrassModel::VectorLayer )

Modified: trunk/qgis/src/plugins/grass/qgsgrassbrowser.h
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassbrowser.h	2009-07-28 16:23:07 UTC (rev 11193)
+++ trunk/qgis/src/plugins/grass/qgsgrassbrowser.h	2009-07-29 00:49:06 UTC (rev 11194)
@@ -77,6 +77,10 @@
     // Double click
     void doubleClicked( const QModelIndex & index );
 
+  private slots:
+    // Context menu
+    void showContextMenu( const QPoint &position );
+
   signals:
     // emited when something in GRASS Tools changed region
     void regionChanged();



More information about the QGIS-commit mailing list