Skip to content

Commit a1069f9

Browse files
author
mhugent
committed
Made 'saveAsShapefile' a slot in QgsVectorLayer such that it works again. Enter the 'save as shapefile' option into the legend layer right click menu
git-svn-id: http://svn.osgeo.org/qgis/trunk@5717 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 18d2744 commit a1069f9

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/gui/qgsvectorlayer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3445,7 +3445,6 @@ void QgsVectorLayer::saveAsShapefile()
34453445
{
34463446
// call the dataproviders saveAsShapefile method
34473447
dataProvider->saveAsShapefile();
3448-
// QMessageBox::information(0,"Save As Shapefile", "Someday...");
34493448
}
34503449

34513450
void QgsVectorLayer::setCoordinateSystem()

src/gui/qgsvectorlayer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ public slots:
209209
*/
210210
virtual void updateExtents();
211211

212+
//! Save as shapefile
213+
virtual void saveAsShapefile();
214+
212215

213216
public:
214217

@@ -378,9 +381,6 @@ public slots:
378381
/**Returns true if the provider has been modified since the last commit*/
379382
virtual bool isModified() const {return mModified;}
380383

381-
//! Save as shapefile
382-
virtual void saveAsShapefile();
383-
384384
/**Snaps a point to the closest vertex if there is one within the snapping tolerance
385385
@param point The point which is set to the position of a vertex if there is one within the snapping tolerance.
386386
If there is no point within this tolerance, point is left unchanged.

src/legend/qgslegend.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgsmaplayerregistry.h"
3333
#include "qgsproject.h"
3434
#include "qgsrasterlayerproperties.h"
35+
#include "qgsvectordataprovider.h"
3536

3637
#include <cfloat>
3738
#include <QCoreApplication>
@@ -435,6 +436,13 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
435436
{
436437
toggleEditingAction->setEnabled(false);
437438
}
439+
else
440+
{
441+
if(theVectorLayer->getDataProvider()->capabilities() | QgsVectorDataProvider::SaveAsShapefile)
442+
{
443+
theMenu.addAction(tr("&Save as shapefile..."), this, SLOT(legendLayerSaveAsShapefile()));
444+
}
445+
}
438446
if(theVectorLayer)
439447
{
440448
toggleEditingAction->setChecked(theVectorLayer->isEditable());
@@ -717,6 +725,21 @@ void QgsLegend::legendLayerToggleEditing()
717725
}
718726
}
719727

728+
void QgsLegend::legendLayerSaveAsShapefile()
729+
{
730+
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(currentItem());
731+
if(!ll)
732+
{
733+
return;
734+
}
735+
QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(ll->firstMapLayer());
736+
if(!theVectorLayer)
737+
{
738+
return;
739+
}
740+
theVectorLayer->saveAsShapefile();
741+
}
742+
720743
void QgsLegend::expandAll()
721744
{
722745
QTreeWidgetItem* theItem = firstItem();

src/legend/qgslegend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ this item may be moved back to the original position with resetToInitialPosition
265265
void legendLayerShowProperties();
266266
/**Toggles the editing mode of the first layer file of a legend layer*/
267267
void legendLayerToggleEditing();
268+
/**Saves the current layer to shapefile (if the provider supports it)*/
269+
void legendLayerSaveAsShapefile();
268270
/**Sets all listview items to open*/
269271
void expandAll();
270272
/**Sets all listview items to closed*/

0 commit comments

Comments
 (0)