Skip to content

Commit bbaddc9

Browse files
author
rblazek
committed
delete map tool
git-svn-id: http://svn.osgeo.org/qgis/trunk@4945 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e6668e2 commit bbaddc9

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

src/plugins/grass/qgsgrassbrowser.cpp

+67-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <QAction>
3636
#include <QTextBrowser>
3737
#include <QSplitter>
38+
#include <QProcess>
3839

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

72+
mActionDeleteMap = new QAction(
73+
QIcon(myIconPath+"grass_delete_map.png"),
74+
tr("Delete selected map"), this);
75+
mActionDeleteMap->setEnabled(false);
76+
ag->addAction ( mActionDeleteMap );
77+
tb->addAction ( mActionDeleteMap );
78+
connect ( mActionDeleteMap, SIGNAL(triggered()), this, SLOT(deleteMap()) );
79+
7180
mActionRefresh = new QAction(
7281
QIcon(myIconPath+"grass_refresh.png"),
7382
tr("Refresh"), this);
@@ -147,13 +156,63 @@ void QgsGrassBrowser::addMap()
147156
}
148157
}
149158

159+
void QgsGrassBrowser::deleteMap()
160+
{
161+
#ifdef QGISDEBUG
162+
std::cerr << "QgsGrassBrowser::deleteMap()" << std::endl;
163+
#endif
164+
165+
QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
166+
bool mapSelected = false;
167+
168+
QList<QModelIndex>::const_iterator it = indexes.begin();
169+
for (; it != indexes.end(); ++it)
170+
{
171+
int type = mModel->itemType(*it);
172+
QString mapset = mModel->itemMapset(*it);
173+
QString map = mModel->itemMap(*it);
174+
175+
QString typeName;
176+
if ( type == QgsGrassModel::Raster ) typeName = "rast";
177+
else if ( type == QgsGrassModel::Vector ) typeName = "vect";
178+
179+
if ( mapset != QgsGrass::getDefaultMapset() )
180+
{
181+
continue; // should not happen
182+
}
183+
184+
int ret = QMessageBox::question ( 0, "Warning",
185+
"Delete map <b>" + map + "</b>",
186+
QMessageBox::Yes, QMessageBox::No );
187+
188+
if ( ret == QMessageBox::No ) continue;
189+
190+
QString module = "g.remove";
191+
#ifdef WIN32
192+
module.append(".exe");
193+
#endif
194+
QProcess process(this);
195+
process.start(module, QStringList( typeName + "=" + map ) );
196+
if ( !process.waitForFinished() )
197+
{
198+
QMessageBox::warning( 0, "Warning", "Cannot delete map "
199+
+ map );
200+
}
201+
else
202+
{
203+
refresh();
204+
}
205+
}
206+
}
207+
150208
void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
151209
{
152210
#ifdef QGISDEBUG
153211
std::cerr << "QgsGrassBrowser::selectionChanged()" << std::endl;
154212
#endif
155213

156214
mActionAddMap->setEnabled(false);
215+
mActionDeleteMap->setEnabled(false);
157216

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

@@ -169,8 +228,15 @@ void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QI
169228
{
170229
mActionAddMap->setEnabled(true);
171230
}
231+
if ( type == QgsGrassModel::Raster || type == QgsGrassModel::Vector )
232+
{
233+
QString mapset = mModel->itemMapset(*it);
234+
if ( mapset == QgsGrass::getDefaultMapset() )
235+
{
236+
mActionDeleteMap->setEnabled(true);
237+
}
238+
}
172239
}
173-
174240
}
175241

176242
void QgsGrassBrowser::currentChanged(const QModelIndex & current, const QModelIndex & previous)

src/plugins/grass/qgsgrassbrowser.h

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public slots:
4444
// Add selected map to canvas
4545
void addMap();
4646

47+
// Delete selected map
48+
void deleteMap();
49+
4750
// Refresh model
4851
void refresh();
4952

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

7275
//! Actions
7376
QAction *mActionAddMap;
77+
QAction *mActionDeleteMap;
7478
QAction *mActionRefresh;
7579
};
7680

src/plugins/grass/qgsgrassmodel.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,26 @@ QString QgsGrassModel::itemName ( const QModelIndex &index)
615615
return item->name();
616616
}
617617

618+
QString QgsGrassModel::itemMapset ( const QModelIndex &index)
619+
{
620+
if (!index.isValid()) { return QString(); }
621+
622+
QgsGrassModelItem *item;
623+
item = static_cast<QgsGrassModelItem*>(index.internalPointer());
624+
625+
return item->mMapset;
626+
}
627+
628+
QString QgsGrassModel::itemMap ( const QModelIndex &index)
629+
{
630+
if (!index.isValid()) { return QString(); }
631+
632+
QgsGrassModelItem *item;
633+
item = static_cast<QgsGrassModelItem*>(index.internalPointer());
634+
635+
return item->mMap;
636+
}
637+
618638
QString QgsGrassModel::itemInfo ( const QModelIndex &index)
619639
{
620640
if (!index.isValid()) { return QString(); }

src/plugins/grass/qgsgrassmodel.h

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ class QgsGrassModel: public QAbstractItemModel
7474
// Name
7575
QString itemName(const QModelIndex &index);
7676

77+
// Item mapset (raster and vector)
78+
QString itemMapset(const QModelIndex &index);
79+
80+
// Item map (raster and vector)
81+
QString itemMap(const QModelIndex &index);
82+
7783
// Get info in HTML format
7884
QString itemInfo(const QModelIndex &index);
7985

0 commit comments

Comments
 (0)