Skip to content
Permalink
Browse files
added a method to activate/deactivate actions depending on the curren…
…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/qgis@4970 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 5, 2006
1 parent f1e17f7 commit 2c88f730ecea910ffb080104c3529453ebed8082
@@ -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)
@@ -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:
@@ -95,7 +95,8 @@ QgsMapLayer::~QgsMapLayer()
{
//delete mCoordinateTransform; //crash when removing layers. Why?
}
const int QgsMapLayer::type()

int QgsMapLayer::type() const
{
return layerType;
}
@@ -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;
@@ -1193,6 +1193,11 @@ QgsVectorDataProvider* QgsVectorLayer::getDataProvider()
return dataProvider;
}

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

void QgsVectorLayer::setProviderEncoding(const QString& encoding)
{
if(dataProvider)
@@ -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);

@@ -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()

0 comments on commit 2c88f73

Please sign in to comment.