Skip to content

Commit 156dc45

Browse files
author
mhugent
committed
added a method in the vectordata provider which returns an index from a field name
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5459 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4dc837e commit 156dc45

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/core/qgsvectordataprovider.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "qgsvectordataprovider.h"
1818
#include "qgsfeature.h"
19+
#include "qgsfield.h"
1920
#include "qgssearchtreenode.h"
2021

2122
QgsVectorDataProvider::QgsVectorDataProvider()
@@ -197,3 +198,19 @@ bool QgsVectorDataProvider::setAttributeFilter(const QgsSearchString& attributeF
197198
// TODO: maybe check if all referenced columns are there, return false if not
198199
return true;
199200
}
201+
202+
int QgsVectorDataProvider::indexFromFieldName(const QString& fieldName) const
203+
{
204+
const std::vector<QgsField> theFields = fields();
205+
int counter = 0;
206+
207+
for(std::vector<QgsField>::const_iterator it = theFields.begin(); it != theFields.end(); ++it)
208+
{
209+
if(it->name() == fieldName)
210+
{
211+
return counter;
212+
}
213+
++counter;
214+
}
215+
return -1;
216+
}

src/core/qgsvectordataprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ class QgsVectorDataProvider : public QgsDataProvider
304304
*/
305305
virtual void setWKT(QString wkt){};
306306

307+
/**Returns the index of a field name or -1 if the field does not exist*/
308+
int indexFromFieldName(const QString& fieldName) const;
309+
307310
protected:
308311
/**Encoding*/
309312
QTextCodec* mEncoding;

src/gui/qgsvectorlayer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,6 +3170,7 @@ void QgsVectorLayer::saveAsShapefile()
31703170
dataProvider->saveAsShapefile();
31713171
// QMessageBox::information(0,"Save As Shapefile", "Someday...");
31723172
}
3173+
31733174
void QgsVectorLayer::setCoordinateSystem()
31743175
{
31753176
delete mCoordinateTransform;

0 commit comments

Comments
 (0)