Skip to content

Commit

Permalink
Fix for bug 2188. Provider has the possibility to announce that it ha…
Browse files Browse the repository at this point in the history
…ndles geometry type handling not very strict, e.g. inserting multipolygon in polygon layers

git-svn-id: http://svn.osgeo.org/qgis/trunk@12340 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 6, 2009
1 parent 88a272f commit 3e5d66d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsvectordataprovider.sip
Expand Up @@ -275,4 +275,8 @@ class QgsVectorDataProvider : QgsDataProvider
*/
void enableGeometrylessFeatures(bool fetch);

/** Returns true if the provider is strict about the type of inserted features
(e.g. no multipolygon in a polygon layer)
@note: added in version 1.4*/
bool doesStrictFeatureTypeCheck() const;
};
11 changes: 9 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -4332,6 +4332,13 @@ void QgisApp::mergeSelectedFeatures()
return;
}

QgsVectorDataProvider* dp = vl->dataProvider();
bool providerChecksTypeStrictly = true;
if ( dp )
{
providerChecksTypeStrictly = dp->doesStrictFeatureTypeCheck();
}

//get selected feature ids (as a QSet<int> )
const QgsFeatureIds& featureIdSet = vl->selectedFeaturesIds();
if ( featureIdSet.size() < 2 )
Expand All @@ -4351,7 +4358,7 @@ void QgisApp::mergeSelectedFeatures()
//make a first geometry union and notify the user straight away if the union geometry type does not match the layer one
QGis::WkbType originalType = vl->wkbType();
QGis::WkbType newType = unionGeom->wkbType();
if ( unionGeom->wkbType() != vl->wkbType() )
if ( providerChecksTypeStrictly && unionGeom->wkbType() != vl->wkbType() )
{
QMessageBox::critical( 0, "Union operation canceled", tr( "The union operation would result in a geometry type that is not compatible with the current layer and therefore is canceled" ) );
delete unionGeom;
Expand Down Expand Up @@ -4387,7 +4394,7 @@ void QgisApp::mergeSelectedFeatures()

originalType = vl->wkbType();
newType = unionGeom->wkbType();
if ( unionGeom->wkbType() != vl->wkbType() )
if ( providerChecksTypeStrictly && unionGeom->wkbType() != vl->wkbType() )
{
QMessageBox::critical( 0, "Union operation canceled", tr( "The union operation would result in a geometry type that is not compatible with the current layer and therefore is canceled" ) );
delete unionGeom;
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsvectordataprovider.h
Expand Up @@ -71,7 +71,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
/** DEPRECATED - do not use */
RandomSelectGeometryAtId = 1 << 10,
/** DEPRECATED - do not use */
SequentialSelectGeometryAtId = 1 << 11
SequentialSelectGeometryAtId = 1 << 11,
};

/** bitmask of all provider's editing capabilities */
Expand Down Expand Up @@ -343,6 +343,11 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
*/
const QMap<QString, QVariant::Type> &supportedNativeTypes() const;

/** Returns true if the provider is strict about the type of inserted features
(e.g. no multipolygon in a polygon layer)
@note: added in version 1.4*/
virtual bool doesStrictFeatureTypeCheck() const { return true;}

protected:
QVariant convertValue( QVariant::Type type, QString value );

Expand Down
5 changes: 5 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -233,6 +233,11 @@ class QgsOgrProvider : public QgsVectorDataProvider
*/
QString description() const;

/** Returns true if the provider is strict about the type of inserted features
(e.g. no multipolygon in a polygon layer)
@note: added in version 1.4*/
virtual bool doesStrictFeatureTypeCheck() const { return false;}

protected:
/** loads fields from input file to member attributeFields */
void loadFields();
Expand Down

0 comments on commit 3e5d66d

Please sign in to comment.