Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
delete map tool
git-svn-id: http://svn.osgeo.org/qgis/trunk@4945 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 2, 2006
1 parent e6668e2 commit bbaddc9
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/plugins/grass/qgsgrassbrowser.cpp
Expand Up @@ -35,6 +35,7 @@
#include <QAction>
#include <QTextBrowser>
#include <QSplitter>
#include <QProcess>

#include "qgis.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/grass/qgsgrassbrowser.h
Expand Up @@ -44,6 +44,9 @@ public slots:
// Add selected map to canvas
void addMap();

// Delete selected map
void deleteMap();

// Refresh model
void refresh();

Expand Down Expand Up @@ -71,6 +74,7 @@ public slots:

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

Expand Down
20 changes: 20 additions & 0 deletions src/plugins/grass/qgsgrassmodel.cpp
Expand Up @@ -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(); }
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/grass/qgsgrassmodel.h
Expand Up @@ -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);

Expand Down

0 comments on commit bbaddc9

Please sign in to comment.