Skip to content
Permalink
Browse files
delete map tool
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4945 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 2, 2006
1 parent 294b7f6 commit 99bf578acc8c7c07b92036fd763e3ba2c4d1af1e
@@ -35,6 +35,7 @@
#include <QAction>
#include <QTextBrowser>
#include <QSplitter>
#include <QProcess>

#include "qgis.h"
#include "qgsapplication.h"
@@ -68,6 +69,14 @@ QgsGrassBrowser::QgsGrassBrowser ( QgisIface *iface,
tb->addAction ( mActionAddMap );
connect ( mActionAddMap, SIGNAL(triggered()), this, SLOT(addMap()) );

mActionDeleteMap = new QAction(
QIcon(myIconPath+"grass_delete_map.png"),
tr("Delete selected map"), this);
mActionDeleteMap->setEnabled(false);
ag->addAction ( mActionDeleteMap );
tb->addAction ( mActionDeleteMap );
connect ( mActionDeleteMap, SIGNAL(triggered()), this, SLOT(deleteMap()) );

mActionRefresh = new QAction(
QIcon(myIconPath+"grass_refresh.png"),
tr("Refresh"), this);
@@ -147,13 +156,63 @@ void QgsGrassBrowser::addMap()
}
}

void QgsGrassBrowser::deleteMap()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::deleteMap()" << std::endl;
#endif

QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
bool mapSelected = false;

QList<QModelIndex>::const_iterator it = indexes.begin();
for (; it != indexes.end(); ++it)
{
int type = mModel->itemType(*it);
QString mapset = mModel->itemMapset(*it);
QString map = mModel->itemMap(*it);

QString typeName;
if ( type == QgsGrassModel::Raster ) typeName = "rast";
else if ( type == QgsGrassModel::Vector ) typeName = "vect";

if ( mapset != QgsGrass::getDefaultMapset() )
{
continue; // should not happen
}

int ret = QMessageBox::question ( 0, "Warning",
"Delete map <b>" + map + "</b>",
QMessageBox::Yes, QMessageBox::No );

if ( ret == QMessageBox::No ) continue;

QString module = "g.remove";
#ifdef WIN32
module.append(".exe");
#endif
QProcess process(this);
process.start(module, QStringList( typeName + "=" + map ) );
if ( !process.waitForFinished() )
{
QMessageBox::warning( 0, "Warning", "Cannot delete map "
+ map );
}
else
{
refresh();
}
}
}

void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::selectionChanged()" << std::endl;
#endif

mActionAddMap->setEnabled(false);
mActionDeleteMap->setEnabled(false);

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

@@ -169,8 +228,15 @@ void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QI
{
mActionAddMap->setEnabled(true);
}
if ( type == QgsGrassModel::Raster || type == QgsGrassModel::Vector )
{
QString mapset = mModel->itemMapset(*it);
if ( mapset == QgsGrass::getDefaultMapset() )
{
mActionDeleteMap->setEnabled(true);
}
}
}

}

void QgsGrassBrowser::currentChanged(const QModelIndex & current, const QModelIndex & previous)
@@ -44,6 +44,9 @@ public slots:
// Add selected map to canvas
void addMap();

// Delete selected map
void deleteMap();

// Refresh model
void refresh();

@@ -71,6 +74,7 @@ public slots:

//! Actions
QAction *mActionAddMap;
QAction *mActionDeleteMap;
QAction *mActionRefresh;
};

@@ -615,6 +615,26 @@ QString QgsGrassModel::itemName ( const QModelIndex &index)
return item->name();
}

QString QgsGrassModel::itemMapset ( const QModelIndex &index)
{
if (!index.isValid()) { return QString(); }

QgsGrassModelItem *item;
item = static_cast<QgsGrassModelItem*>(index.internalPointer());

return item->mMapset;
}

QString QgsGrassModel::itemMap ( const QModelIndex &index)
{
if (!index.isValid()) { return QString(); }

QgsGrassModelItem *item;
item = static_cast<QgsGrassModelItem*>(index.internalPointer());

return item->mMap;
}

QString QgsGrassModel::itemInfo ( const QModelIndex &index)
{
if (!index.isValid()) { return QString(); }
@@ -74,6 +74,12 @@ class QgsGrassModel: public QAbstractItemModel
// Name
QString itemName(const QModelIndex &index);

// Item mapset (raster and vector)
QString itemMapset(const QModelIndex &index);

// Item map (raster and vector)
QString itemMap(const QModelIndex &index);

// Get info in HTML format
QString itemInfo(const QModelIndex &index);

0 comments on commit 99bf578

Please sign in to comment.