mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-26 00:02:08 -05:00
Replaced QgsVectorDataProvider::support... functions with QgsVectorDataProvider::capabilities()
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@2769 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
9b4aa3796a
commit
ec0b110a2c
@ -725,11 +725,12 @@ bool QgsDelimitedTextProvider::boundsCheck(double x, double y)
|
||||
return inBounds;
|
||||
}
|
||||
|
||||
bool QgsDelimitedTextProvider::supportsSaveAsShapefile() const
|
||||
int QgsDelimitedTextProvider::capabilities() const
|
||||
{
|
||||
return true;
|
||||
return QgsVectorDataProvider::SaveAsShapefile;
|
||||
}
|
||||
|
||||
|
||||
bool QgsDelimitedTextProvider::saveAsShapefile()
|
||||
{
|
||||
// save the layer as a shapefile
|
||||
|
@ -206,9 +206,7 @@ public:
|
||||
*/
|
||||
bool boundsCheck(double x, double y);
|
||||
|
||||
//! We support saving as shapefile - used to add item to the
|
||||
// layers context menu
|
||||
bool supportsSaveAsShapefile() const;
|
||||
int capabilities() const;
|
||||
|
||||
//! Save the layer as a shapefile
|
||||
bool saveAsShapefile();
|
||||
|
@ -933,6 +933,12 @@ bool QgsOgrProvider::changeAttributeValues(std::map<int,std::map<QString,QString
|
||||
return true;
|
||||
}
|
||||
|
||||
int QgsOgrProvider::capabilities() const
|
||||
{
|
||||
return (QgsVectorDataProvider::AddFeatures
|
||||
| QgsVectorDataProvider::ChangeAttributeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class factory to return a pointer to a newly created
|
||||
* QgsOgrProvider object
|
||||
|
@ -146,16 +146,14 @@ class QgsOgrProvider:public QgsVectorDataProvider
|
||||
/**Changes attribute values of existing features */
|
||||
bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & attr_map);
|
||||
|
||||
bool supportsFeatureAddition() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QgsDataSourceURI * getURI()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**Returns a bitmask containing the supported capabilities*/
|
||||
int capabilities() const;
|
||||
|
||||
private:
|
||||
unsigned char *getGeometryPointer(OGRFeature * fet);
|
||||
std::vector < QgsField > attributeFields;
|
||||
|
@ -1151,11 +1151,11 @@ bool QgsPostgresProvider::supportsSaveAsShapefile() const
|
||||
return false;
|
||||
}
|
||||
|
||||
int QgsPostgresProvider::capabilities()
|
||||
int QgsPostgresProvider::capabilities() const
|
||||
{
|
||||
return ( QgsVectorDataProvider::AddFeatures |
|
||||
QgsVectorDataProvider::DeleteFeatures |
|
||||
QgsVectorDataProvider::ChangeAttributes |
|
||||
QgsVectorDataProvider::ChangeAttributeValues |
|
||||
QgsVectorDataProvider::AddAttributes |
|
||||
QgsVectorDataProvider::DeleteAttributes );
|
||||
}
|
||||
|
@ -220,15 +220,6 @@ public:
|
||||
@return true in case of success and false in case of failure*/
|
||||
bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & attr_map);
|
||||
|
||||
bool supportsFeatureAddition() const
|
||||
{ return true; }
|
||||
|
||||
bool supportsFeatureDeletion() const
|
||||
{return true;}
|
||||
|
||||
bool supportsAttributeEditing() const
|
||||
{return true;}
|
||||
|
||||
//! Flag to indicate if the provider can export to shapefile
|
||||
bool supportsSaveAsShapefile() const;
|
||||
|
||||
@ -245,7 +236,7 @@ public:
|
||||
void setSubsetString(QString theSQL); //{sqlWhereClause = theSQL;};
|
||||
|
||||
/**Returns a bitmask containing the supported capabilities*/
|
||||
int capabilities();
|
||||
int capabilities() const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -2649,13 +2649,15 @@ void QgisApp::currentLayerChanged(QListViewItem * lvi)
|
||||
{
|
||||
// disable/enable toolbar buttons as appropriate based on selected
|
||||
// layer type
|
||||
|
||||
toolPopupCapture->setItemEnabled(0,FALSE);
|
||||
toolPopupCapture->setItemEnabled(1,FALSE);
|
||||
toolPopupCapture->setItemEnabled(2,FALSE);
|
||||
toolPopupCapture->setItemEnabled(3,FALSE);
|
||||
|
||||
QgsMapLayer *layer = ((QgsLegendItem *) lvi)->layer();
|
||||
if (layer->type() == QgsMapLayer::RASTER)
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(0,FALSE);
|
||||
toolPopupCapture->setItemEnabled(1,FALSE);
|
||||
toolPopupCapture->setItemEnabled(2,FALSE);
|
||||
toolPopupCapture->setItemEnabled(3,FALSE);
|
||||
actionIdentify->setEnabled(FALSE);
|
||||
actionSelect->setEnabled(FALSE);
|
||||
actionOpenTable->setEnabled(FALSE);
|
||||
@ -2673,57 +2675,31 @@ void QgisApp::currentLayerChanged(QListViewItem * lvi)
|
||||
QgsVectorLayer* vlayer=dynamic_cast<QgsVectorLayer*>(((QgsLegendItem *) lvi)->layer());
|
||||
if(vlayer)
|
||||
{
|
||||
if(vlayer->vectorType()==QGis::Point)
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(0,TRUE);
|
||||
toolPopupCapture->setItemEnabled(1,FALSE);
|
||||
toolPopupCapture->setItemEnabled(2,FALSE);
|
||||
if(mMapCanvas->mapTool() == QGis::CaptureLine || mMapCanvas->mapTool() == QGis::CapturePolygon)
|
||||
QgsVectorDataProvider* provider=vlayer->getDataProvider();
|
||||
if(provider)
|
||||
{
|
||||
int cap=vlayer->getDataProvider()->capabilities();
|
||||
if(cap&QgsVectorDataProvider::DeleteFeatures)
|
||||
{
|
||||
mMapCanvas->setMapTool(QGis::CapturePoint);
|
||||
toolPopupCapture->setItemEnabled(3,TRUE);
|
||||
}
|
||||
}
|
||||
else if(vlayer->vectorType()==QGis::Line)
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("QgisApp::currentLayerChanged: Line type recognized");
|
||||
qWarning("current map tool is: "+QString::number(mMapCanvas->mapTool()));
|
||||
#endif
|
||||
toolPopupCapture->setItemEnabled(0,FALSE);
|
||||
toolPopupCapture->setItemEnabled(1,TRUE);
|
||||
toolPopupCapture->setItemEnabled(2,FALSE);
|
||||
if(mMapCanvas->mapTool() == QGis::CapturePoint || mMapCanvas->mapTool() == QGis::CapturePolygon)
|
||||
if(cap&QgsVectorDataProvider::AddFeatures)
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("Changing map tool");
|
||||
#endif
|
||||
mMapCanvas->setMapTool(QGis::CaptureLine);
|
||||
if(vlayer->vectorType()==QGis::Point)
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(0,TRUE);
|
||||
}
|
||||
else if(vlayer->vectorType()==QGis::Line)
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(1,TRUE);
|
||||
}
|
||||
else if(vlayer->vectorType()==QGis::Polygon)
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(2,TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(vlayer->vectorType()==QGis::Polygon)
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(0,FALSE);
|
||||
toolPopupCapture->setItemEnabled(1,FALSE);
|
||||
toolPopupCapture->setItemEnabled(2,TRUE);
|
||||
if(mMapCanvas->mapTool() == QGis::CapturePoint || mMapCanvas->mapTool() == QGis::CaptureLine)
|
||||
{
|
||||
mMapCanvas->setMapTool(QGis::CapturePolygon);
|
||||
}
|
||||
}
|
||||
|
||||
QgsVectorDataProvider* dprov=vlayer->getDataProvider();
|
||||
if(dprov)
|
||||
{
|
||||
if(dprov->supportsFeatureDeletion())
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(3,TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
toolPopupCapture->setItemEnabled(3,FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actionIdentify->setEnabled(TRUE);
|
||||
actionSelect->setEnabled(TRUE);
|
||||
|
@ -49,7 +49,14 @@ QgsAttributeTableDisplay::QgsAttributeTableDisplay(QgsVectorLayer* layer):QgsAtt
|
||||
edit->setItemEnabled(1,false);
|
||||
|
||||
btnStopEditing->setEnabled(false);
|
||||
if(!layer->getDataProvider()->supportsAttributeEditing())
|
||||
int cap=layer->getDataProvider()->capabilities();
|
||||
if((cap&QgsVectorDataProvider::ChangeAttributeValues)
|
||||
||(cap&QgsVectorDataProvider::AddAttributes)
|
||||
||(cap&QgsVectorDataProvider::DeleteAttributes))
|
||||
{
|
||||
btnStartEditing->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
btnStartEditing->setEnabled(false);
|
||||
}
|
||||
@ -113,7 +120,7 @@ void QgsAttributeTableDisplay::startEditing()
|
||||
edit->setItemEnabled(1,true);
|
||||
editing=true;
|
||||
}
|
||||
if(provider->capabilities()&QgsVectorDataProvider::ChangeAttributes)
|
||||
if(provider->capabilities()&QgsVectorDataProvider::ChangeAttributeValues)
|
||||
{
|
||||
table()->setReadOnly(false);
|
||||
table()->setColumnReadOnly(0,true);//id column is not editable
|
||||
|
@ -1354,7 +1354,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
|
||||
//only do the rest for provider with feature addition support
|
||||
//note that for the grass provider, this will return false since
|
||||
//grass provider has its own mechanism of feature addition
|
||||
if(vlayer->getDataProvider()->supportsFeatureAddition())
|
||||
if(vlayer->getDataProvider()->capabilities()&QgsVectorDataProvider::AddFeatures)
|
||||
{
|
||||
if(!vlayer->isEditable() )
|
||||
{
|
||||
|
@ -53,27 +53,3 @@ QString QgsVectorDataProvider::getDefaultValue(const QString& attr,
|
||||
QgsFeature* f) {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool QgsVectorDataProvider::supportsFeatureAddition() const
|
||||
{
|
||||
//needs to be overwritten by providers if they provide feature editing
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QgsVectorDataProvider::supportsFeatureDeletion() const
|
||||
{
|
||||
//needs to be overwritten by providers supporting this
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QgsVectorDataProvider::supportsAttributeEditing() const
|
||||
{
|
||||
//needs to be overwritten by providers supporting this
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QgsVectorDataProvider::supportsSaveAsShapefile() const
|
||||
{
|
||||
// default implementation is no support
|
||||
return false;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class QgsVectorDataProvider : public QgsDataProvider
|
||||
NoCapabilities = 0,
|
||||
AddFeatures = 1,
|
||||
DeleteFeatures = 1 << 1,
|
||||
ChangeAttributes = 1 << 2,
|
||||
ChangeAttributeValues = 1 << 2,
|
||||
AddAttributes = 1 << 3,
|
||||
DeleteAttributes = 1 << 4,
|
||||
SaveAsShapefile = 1 << 5
|
||||
@ -166,19 +166,6 @@ class QgsVectorDataProvider : public QgsDataProvider
|
||||
*/
|
||||
virtual std::vector<QgsFeature>& identify(QgsRect *rect) = 0;
|
||||
|
||||
/**Returns true if a provider supports feature editing*/
|
||||
virtual bool supportsFeatureAddition() const;
|
||||
|
||||
/**Returns true if a provider supports deleting features*/
|
||||
virtual bool supportsFeatureDeletion() const;
|
||||
|
||||
/*Returns true if a provider supports adding/ removing attributes and
|
||||
attribute changes to already existing features*/
|
||||
virtual bool supportsAttributeEditing() const;
|
||||
|
||||
/** Returns true is the provider supports saving to shapefile*/
|
||||
virtual bool supportsSaveAsShapefile() const;
|
||||
|
||||
/** saves current data as Shape file, if it can */
|
||||
virtual bool saveAsShapefile()
|
||||
{
|
||||
@ -186,7 +173,7 @@ class QgsVectorDataProvider : public QgsDataProvider
|
||||
}
|
||||
|
||||
/**Returns a bitmask containing the supported capabilities*/
|
||||
virtual int capabilities(){return QgsVectorDataProvider::NoCapabilities;}
|
||||
virtual int capabilities() const {return QgsVectorDataProvider::NoCapabilities;}
|
||||
|
||||
const std::list<QString>& nonNumericalTypes(){return mNonNumericalTypes;}
|
||||
const std::list<QString>& numericalTypes(){return mNumericalTypes;}
|
||||
|
@ -872,14 +872,16 @@ void QgsVectorLayer::initContextMenu_(QgisApp * app)
|
||||
|
||||
popMenu->insertSeparator(); // XXX should this move to QgsMapLayer::initContextMenu()?
|
||||
|
||||
if(dataProvider->supportsFeatureAddition())
|
||||
int cap=dataProvider->capabilities();
|
||||
if((cap&QgsVectorDataProvider::AddFeatures)
|
||||
||(cap&QgsVectorDataProvider::DeleteFeatures))
|
||||
{
|
||||
popMenu->insertItem(tr("Start editing"),this,SLOT(startEditing()));
|
||||
popMenu->insertItem(tr("Stop editing"),this,SLOT(stopEditing()));
|
||||
}
|
||||
|
||||
// XXX Can we ask the provider if it wants to add things to the context menu?
|
||||
if(dataProvider->supportsSaveAsShapefile())
|
||||
if(cap&QgsVectorDataProvider::SaveAsShapefile)
|
||||
{
|
||||
// add the save as shapefile menu item
|
||||
popMenu->insertSeparator();
|
||||
@ -1314,19 +1316,19 @@ QString QgsVectorLayer::getDefaultValue(const QString& attr,
|
||||
|
||||
bool QgsVectorLayer::deleteSelectedFeatures()
|
||||
{
|
||||
if(!dataProvider->supportsFeatureDeletion())
|
||||
{
|
||||
QMessageBox::information(0, tr("Provider does not support deletion"), tr("Data provider does not support deleting features"));
|
||||
return false;
|
||||
}
|
||||
if(dataProvider->capabilities()&QgsVectorDataProvider::DeleteFeatures)
|
||||
{
|
||||
QMessageBox::information(0, tr("Provider does not support deletion"), tr("Data provider does not support deleting features"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!isEditable())
|
||||
{
|
||||
QMessageBox::information(0, tr("Layer not editable"), tr("The current layer is not editable. Choose 'start editing' in the legend item right click menu"));
|
||||
return false;
|
||||
}
|
||||
if(!isEditable())
|
||||
{
|
||||
QMessageBox::information(0, tr("Layer not editable"), tr("The current layer is not editable. Choose 'start editing' in the legend item right click menu"));
|
||||
return false;
|
||||
}
|
||||
|
||||
for(std::set<int>::iterator it=mSelected.begin();it!=mSelected.end();++it)
|
||||
for(std::set<int>::iterator it=mSelected.begin();it!=mSelected.end();++it)
|
||||
{
|
||||
bool notcommitedfeature=false;
|
||||
//first test, if the feature with this id is a not-commited feature
|
||||
@ -1346,21 +1348,21 @@ bool QgsVectorLayer::deleteSelectedFeatures()
|
||||
mDeleted.insert(*it);
|
||||
}
|
||||
|
||||
if(mSelected.size()>0)
|
||||
{
|
||||
mModified=true;
|
||||
mSelected.clear();
|
||||
triggerRepaint();
|
||||
|
||||
//hide and delete the table because it is not up to date any more
|
||||
if (tabledisplay)
|
||||
if(mSelected.size()>0)
|
||||
{
|
||||
tabledisplay->close();
|
||||
delete tabledisplay;
|
||||
tabledisplay=0;
|
||||
}
|
||||
mModified=true;
|
||||
mSelected.clear();
|
||||
triggerRepaint();
|
||||
|
||||
}
|
||||
//hide and delete the table because it is not up to date any more
|
||||
if (tabledisplay)
|
||||
{
|
||||
tabledisplay->close();
|
||||
delete tabledisplay;
|
||||
tabledisplay=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1384,18 +1386,18 @@ void QgsVectorLayer::startEditing()
|
||||
{
|
||||
if(dataProvider)
|
||||
{
|
||||
if(!dataProvider->supportsFeatureAddition())
|
||||
{
|
||||
QMessageBox::information(0,"Start editing failed","Provider cannot be opened for editing",QMessageBox::Ok);
|
||||
}
|
||||
else
|
||||
{
|
||||
mEditable=true;
|
||||
if(isValid())
|
||||
if(!(dataProvider->capabilities()&QgsVectorDataProvider::AddFeatures))
|
||||
{
|
||||
updateItemPixmap();
|
||||
QMessageBox::information(0,"Start editing failed","Provider cannot be opened for editing",QMessageBox::Ok);
|
||||
}
|
||||
else
|
||||
{
|
||||
mEditable=true;
|
||||
if(isValid())
|
||||
{
|
||||
updateItemPixmap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user