Skip to content

Commit 2c88f73

Browse files
author
mhugent
committedMar 5, 2006
added a method to activate/deactivate actions depending on the current layer type and the provider capabilities (though the ogr provider seems to return strange capabilities)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4970 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

7 files changed

+108
-3
lines changed

7 files changed

+108
-3
lines changed
 

‎src/gui/qgisapp.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4842,6 +4842,91 @@ QgsClipboard * QgisApp::clipboard()
48424842
return &mInternalClipboard;
48434843
}
48444844

4845+
void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
4846+
{
4847+
if(!layer)
4848+
{
4849+
return;
4850+
}
4851+
if(layer->type() == QgsMapLayer::VECTOR || layer->type() == QgsMapLayer::DATABASE)
4852+
{
4853+
mActionSelect->setEnabled(true);
4854+
mActionOpenTable->setEnabled(true);
4855+
const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>(layer);
4856+
const QgsVectorDataProvider* dprovider = vlayer->getDataProvider();
4857+
if(vlayer)
4858+
{
4859+
//does provider allow deleting of features?
4860+
if(dprovider->capabilities() | QgsVectorDataProvider::DeleteFeatures)
4861+
{
4862+
mActionDeleteSelected->setEnabled(true);
4863+
}
4864+
else
4865+
{
4866+
mActionDeleteSelected->setEnabled(false);
4867+
}
4868+
4869+
4870+
if(vlayer->vectorType() == QGis::Point)
4871+
{
4872+
if(dprovider->capabilities() | QgsVectorDataProvider::AddFeatures)
4873+
{
4874+
mActionCapturePoint->setEnabled(true);
4875+
}
4876+
else
4877+
{
4878+
mActionCapturePoint->setEnabled(false);
4879+
}
4880+
mActionCaptureLine->setEnabled(false);
4881+
mActionCapturePolygon->setEnabled(false);
4882+
mActionAddVertex->setEnabled(false);
4883+
mActionDeleteVertex->setEnabled(false);
4884+
mActionMoveVertex->setEnabled(false);
4885+
return;
4886+
}
4887+
else if(vlayer->vectorType() == QGis::Line)
4888+
{
4889+
mActionCaptureLine->setEnabled(true);
4890+
mActionCapturePoint->setEnabled(false);
4891+
mActionCapturePolygon->setEnabled(false);
4892+
}
4893+
else if(vlayer->vectorType() == QGis::Polygon)
4894+
{
4895+
mActionCapturePolygon->setEnabled(true);
4896+
mActionCapturePoint->setEnabled(false);
4897+
mActionCaptureLine->setEnabled(false);
4898+
}
4899+
4900+
//are add/delete/move vertex supported?
4901+
if(dprovider->capabilities() | QgsVectorDataProvider::ChangeGeometries)
4902+
{
4903+
mActionAddVertex->setEnabled(true);
4904+
mActionMoveVertex->setEnabled(true);
4905+
mActionDeleteVertex->setEnabled(true);
4906+
}
4907+
else
4908+
{
4909+
mActionAddVertex->setEnabled(false);
4910+
mActionMoveVertex->setEnabled(false);
4911+
mActionDeleteVertex->setEnabled(false);
4912+
}
4913+
return;
4914+
}
4915+
}
4916+
else if(layer->type() == QgsMapLayer::RASTER)
4917+
{
4918+
mActionSelect->setEnabled(false);
4919+
mActionOpenTable->setEnabled(false);
4920+
mActionCapturePoint->setEnabled(false);
4921+
mActionCaptureLine->setEnabled(false);
4922+
mActionCapturePolygon->setEnabled(false);
4923+
mActionDeleteSelected->setEnabled(false);
4924+
mActionAddVertex->setEnabled(false);
4925+
mActionDeleteVertex->setEnabled(false);
4926+
mActionMoveVertex->setEnabled(false);
4927+
}
4928+
}
4929+
48454930

48464931
//copy the click coord to clipboard and let the user know its there
48474932
void QgisApp::showCapturePointCoordinate(QgsPoint & theQgsPoint)

‎src/gui/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
164164
void setupToolbarPopups(QString themeName);
165165
//! Returns a pointer to the internal clipboard
166166
QgsClipboard * clipboard();
167+
/** Activates or deactivates actions depending on the current maplayer type.
168+
Is called from the legend when the current legend item has changed*/
169+
void activateDeactivateLayerRelatedActions(const QgsMapLayer* layer);
167170

168171
//private slots:
169172
public slots:

‎src/gui/qgsmaplayer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ QgsMapLayer::~QgsMapLayer()
9595
{
9696
//delete mCoordinateTransform; //crash when removing layers. Why?
9797
}
98-
const int QgsMapLayer::type()
98+
99+
int QgsMapLayer::type() const
99100
{
100101
return layerType;
101102
}

‎src/gui/qgsmaplayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class QgsMapLayer : public QObject
6565
/*! Get the type of the layer
6666
* @return Integer matching a value in the LAYERS enum
6767
*/
68-
const int type();
68+
int type() const;
6969

7070
/*! Get this layer's unique ID */
7171
QString const & getLayerID() const;

‎src/gui/qgsvectorlayer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,11 @@ QgsVectorDataProvider* QgsVectorLayer::getDataProvider()
11931193
return dataProvider;
11941194
}
11951195

1196+
const QgsVectorDataProvider* QgsVectorLayer::getDataProvider() const
1197+
{
1198+
return dataProvider;
1199+
}
1200+
11961201
void QgsVectorLayer::setProviderEncoding(const QString& encoding)
11971202
{
11981203
if(dataProvider)

‎src/gui/qgsvectorlayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ const QString displayField() const { return fieldIndex; }
117117
//! Setup the coordinate system tranformation for the layer
118118
void setCoordinateSystem();
119119

120+
/**Returns the data provider*/
120121
QgsVectorDataProvider* getDataProvider();
121122

123+
/**Returns the data provider in a const-correct manner*/
124+
const QgsVectorDataProvider* getDataProvider() const;
125+
122126
/**Sets the textencoding of the data provider*/
123127
void setProviderEncoding(const QString& encoding);
124128

‎src/legend/qgslegend.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ QgsLegend::~QgsLegend()
8989

9090
void QgsLegend::handleCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous)
9191
{
92-
mMapCanvas->setCurrentLayer(currentLayer());
92+
if(mApp)
93+
{
94+
mApp->activateDeactivateLayerRelatedActions(currentLayer());
95+
}
96+
if(mMapCanvas)
97+
{
98+
mMapCanvas->setCurrentLayer(currentLayer());
99+
}
93100
}
94101

95102
void QgsLegend::addGroup()

0 commit comments

Comments
 (0)
Please sign in to comment.