Skip to content

Commit

Permalink
added a method to activate/deactivate actions depending on the curren…
Browse files Browse the repository at this point in the history
…t layer type and the provider capabilities (though the ogr provider seems to return strange capabilities)

git-svn-id: http://svn.osgeo.org/qgis/trunk@4970 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 5, 2006
1 parent ae94398 commit 6ca6264
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 3 deletions.
85 changes: 85 additions & 0 deletions src/gui/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4842,6 +4842,91 @@ QgsClipboard * QgisApp::clipboard()
return &mInternalClipboard;
}

void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
{
if(!layer)
{
return;
}
if(layer->type() == QgsMapLayer::VECTOR || layer->type() == QgsMapLayer::DATABASE)
{
mActionSelect->setEnabled(true);
mActionOpenTable->setEnabled(true);
const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>(layer);
const QgsVectorDataProvider* dprovider = vlayer->getDataProvider();
if(vlayer)
{
//does provider allow deleting of features?
if(dprovider->capabilities() | QgsVectorDataProvider::DeleteFeatures)
{
mActionDeleteSelected->setEnabled(true);
}
else
{
mActionDeleteSelected->setEnabled(false);
}


if(vlayer->vectorType() == QGis::Point)
{
if(dprovider->capabilities() | QgsVectorDataProvider::AddFeatures)
{
mActionCapturePoint->setEnabled(true);
}
else
{
mActionCapturePoint->setEnabled(false);
}
mActionCaptureLine->setEnabled(false);
mActionCapturePolygon->setEnabled(false);
mActionAddVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
mActionMoveVertex->setEnabled(false);
return;
}
else if(vlayer->vectorType() == QGis::Line)
{
mActionCaptureLine->setEnabled(true);
mActionCapturePoint->setEnabled(false);
mActionCapturePolygon->setEnabled(false);
}
else if(vlayer->vectorType() == QGis::Polygon)
{
mActionCapturePolygon->setEnabled(true);
mActionCapturePoint->setEnabled(false);
mActionCaptureLine->setEnabled(false);
}

//are add/delete/move vertex supported?
if(dprovider->capabilities() | QgsVectorDataProvider::ChangeGeometries)
{
mActionAddVertex->setEnabled(true);
mActionMoveVertex->setEnabled(true);
mActionDeleteVertex->setEnabled(true);
}
else
{
mActionAddVertex->setEnabled(false);
mActionMoveVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
}
return;
}
}
else if(layer->type() == QgsMapLayer::RASTER)
{
mActionSelect->setEnabled(false);
mActionOpenTable->setEnabled(false);
mActionCapturePoint->setEnabled(false);
mActionCaptureLine->setEnabled(false);
mActionCapturePolygon->setEnabled(false);
mActionDeleteSelected->setEnabled(false);
mActionAddVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
mActionMoveVertex->setEnabled(false);
}
}


//copy the click coord to clipboard and let the user know its there
void QgisApp::showCapturePointCoordinate(QgsPoint & theQgsPoint)
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
void setupToolbarPopups(QString themeName);
//! Returns a pointer to the internal clipboard
QgsClipboard * clipboard();
/** Activates or deactivates actions depending on the current maplayer type.
Is called from the legend when the current legend item has changed*/
void activateDeactivateLayerRelatedActions(const QgsMapLayer* layer);

//private slots:
public slots:
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ QgsMapLayer::~QgsMapLayer()
{
//delete mCoordinateTransform; //crash when removing layers. Why?
}
const int QgsMapLayer::type()

int QgsMapLayer::type() const
{
return layerType;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class QgsMapLayer : public QObject
/*! Get the type of the layer
* @return Integer matching a value in the LAYERS enum
*/
const int type();
int type() const;

/*! Get this layer's unique ID */
QString const & getLayerID() const;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,11 @@ QgsVectorDataProvider* QgsVectorLayer::getDataProvider()
return dataProvider;
}

const QgsVectorDataProvider* QgsVectorLayer::getDataProvider() const
{
return dataProvider;
}

void QgsVectorLayer::setProviderEncoding(const QString& encoding)
{
if(dataProvider)
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ const QString displayField() const { return fieldIndex; }
//! Setup the coordinate system tranformation for the layer
void setCoordinateSystem();

/**Returns the data provider*/
QgsVectorDataProvider* getDataProvider();

/**Returns the data provider in a const-correct manner*/
const QgsVectorDataProvider* getDataProvider() const;

/**Sets the textencoding of the data provider*/
void setProviderEncoding(const QString& encoding);

Expand Down
9 changes: 8 additions & 1 deletion src/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ QgsLegend::~QgsLegend()

void QgsLegend::handleCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous)
{
mMapCanvas->setCurrentLayer(currentLayer());
if(mApp)
{
mApp->activateDeactivateLayerRelatedActions(currentLayer());
}
if(mMapCanvas)
{
mMapCanvas->setCurrentLayer(currentLayer());
}
}

void QgsLegend::addGroup()
Expand Down

0 comments on commit 6ca6264

Please sign in to comment.