Skip to content

Commit

Permalink
Enhancements into the browser of the grass plug-in:
Browse files Browse the repository at this point in the history
* Added a context menu
* Changed the behavior of confirm dialogs


git-svn-id: http://svn.osgeo.org/qgis/trunk@11194 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rugginoso committed Jul 29, 2009
1 parent be89b8a commit b613abe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/plugins/grass/qgsgrassbrowser.cpp
Expand Up @@ -31,6 +31,7 @@
#include <QTextBrowser>
#include <QToolBar>
#include <QTreeView>
#include <QMenu>


QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
Expand Down Expand Up @@ -96,6 +97,7 @@ QgsGrassBrowser::QgsGrassBrowser( QgisInterface *iface,
mTree->header()->hide();
mTree->setModel( mModel );
mTree->setSelectionMode( QAbstractItemView::ExtendedSelection );
mTree->setContextMenuPolicy(Qt::CustomContextMenu);

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

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 ) ) );
Expand Down Expand Up @@ -189,6 +193,20 @@ void QgsGrassBrowser::doubleClicked( const QModelIndex & index )
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>" );
Expand Down Expand Up @@ -238,7 +256,7 @@ void QgsGrassBrowser::copyMap()
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;

Expand Down Expand Up @@ -302,7 +320,7 @@ void QgsGrassBrowser::renameMap()
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;

Expand Down Expand Up @@ -336,6 +354,9 @@ void QgsGrassBrowser::deleteMap()

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 )
{
Expand All @@ -353,12 +374,6 @@ void QgsGrassBrowser::deleteMap()
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" );
Expand Down Expand Up @@ -456,7 +471,7 @@ void QgsGrassBrowser::selectionChanged( const QItemSelection & selected, const Q
mActionDeleteMap->setEnabled( false );
mActionSetRegion->setEnabled( false );

QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
QModelIndexList indexes = selected.indexes();

mTextBrowser->clear();

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

int type = mModel->itemType( *it );

if ( type == QgsGrassModel::Raster ||
type == QgsGrassModel::Vector ||
type == QgsGrassModel::VectorLayer )
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/grass/qgsgrassbrowser.h
Expand Up @@ -77,6 +77,10 @@ class QgsGrassBrowser: public QMainWindow
// 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();
Expand Down

0 comments on commit b613abe

Please sign in to comment.