Skip to content

Commit

Permalink
QgsFeatureAttribute class has been removed and QVariant is used inste…
Browse files Browse the repository at this point in the history
…ad (supports arbitrary data types).

All providers and python bindings have been updated accordingly.
Currently supported variant types by providers are String, Int and Double.

Other API changes:
- QgsField
  - type info as QString is now typeName() and setTypeName()
  - added variant type (QVariant::Type) info: type(), setType()
- QgsFeature
  - removed fields() - use QgsVectorDataProvider::fields()
  - removed boundingBox() - use QgsGeometry::boundingBox()
- QgsVectorLayer - removed fields(), fieldCount(), getDefaultValue() - use directly QgsVectorDataProvider
- QgsVectorDataProvider - getDefaultValue() - field now addressed by id, returns variant
- QgsLabel - setLabelField() - field now addressed by id


git-svn-id: http://svn.osgeo.org/qgis/trunk@6833 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 24, 2007
1 parent 39f11cf commit 00a43bc
Show file tree
Hide file tree
Showing 62 changed files with 727 additions and 2,146 deletions.
1 change: 0 additions & 1 deletion python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
%Include qgsdatasourceuri.sip
%Include qgsdistancearea.sip
%Include qgsfeature.sip
%Include qgsfeatureattribute.sip
%Include qgsfield.sip
%Include qgsgeometry.sip
%Include qgsgeometryvertexindex.sip
Expand Down
17 changes: 4 additions & 13 deletions python/core/qgsfeature.sip
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class QgsFeature
want a copy of the "current" feature, not the on-disk feature.
*/
QgsFeature( const QgsFeature & rhs,
const QMap<int, QMap<int, QgsFeatureAttribute> >& changedAttributes,
const QMap<int, QMap<int, QVariant> >& changedAttributes,
const QMap<int, QgsGeometry> & changedGeometries );

/** copy ctor needed due to internal pointer */
Expand Down Expand Up @@ -58,26 +58,20 @@ class QgsFeature
* Get the attributes for this feature.
* @return A std::map containing the field name/value mapping
*/
const QMap<int, QgsFeatureAttribute> & attributeMap() const;
const QMap<int, QVariant> & attributeMap() const;

/**
* Add an attribute to the map
*/
void addAttribute(int field, QgsFeatureAttribute attr);
void addAttribute(int field, QVariant attr);

/**Deletes an attribute and its value*/
void deleteAttribute(int field);

/**Changes an existing attribute value
@param field index of the field
@param attr attribute name and value to be set */
void changeAttribute(int field, QgsFeatureAttribute attr);

/**
* Get the fields for this feature
* @return A std::map containing field position (index) and field name
*/
QMap<int, QString> fields() const;
void changeAttribute(int field, QVariant attr);

/**
* Return the validity of this feature. This is normally set by
Expand Down Expand Up @@ -125,9 +119,6 @@ class QgsFeature
*/
void setGeometryAndOwnership(unsigned char * geom, size_t length);

/**Returns the bounding box of this feature*/
QgsRect boundingBox() const;


}; // class QgsFeature

53 changes: 0 additions & 53 deletions python/core/qgsfeatureattribute.sip

This file was deleted.

41 changes: 27 additions & 14 deletions python/core/qgsfield.sip
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,41 @@ class QgsField
public:
/** Constructor. Constructs a new QgsField object.
* @param nam Field name
* @param typ Field type (eg. char, varchar, text, int, serial, double).
* @param type Field variant type, currently supported: String / Int / Double
* @param typeName Field type (eg. char, varchar, text, int, serial, double).
Field types are usually unique to the source and are stored exactly
as returned from the data store.
* @param len Field length
* @param prec Field precision. Usually decimal places but may also be
* used in conjunction with other fields types (eg. variable character fields)
* @param num Has to be true if field contains numeric values.
* @param comment Comment for the field
*/
QgsField(QString nam = "", QString typ = "", int len = 0, int prec = 0, bool num = false);

QgsField(QString name = QString(),
QVariant::Type type = QVariant::Invalid,
QString typeName = QString(),
int len = 0,
int prec = 0,
QString comment = QString());

//! Destructor
~QgsField();

bool operator==(const QgsField other) const;
bool operator!=(const QgsField other) const;
bool operator==(const QgsField& other) const;

//! Gets the name of the field
const QString & name() const;

//! Gets variant type of the field as it will be retreived from data source
QVariant::Type type() const;

/**
Gets the field type. Field types vary depending on the data source. Examples
are char, int, double, blob, geometry, etc. The type is stored exactly as
the data store reports it, with no attenpt to standardize the value.
@return QString containing the field type
*/
const QString & type() const;
const QString & typeName() const;


/**
Expand All @@ -59,23 +67,27 @@ public:
*/
int precision() const;

/**
Returns true if field contains numeric values. This information is set by provider.
*/
bool isNumeric() const;

/**
Returns the field comment
*/
const QString & comment() const;

/**
Set the field name.
@param nam Name of the field
*/
void setName(const QString & nam);

/**
Set variant type.
*/
void setType(QVariant::Type type);

/**
Set the field type.
@param typ Field type
*/
void setType(const QString & typ);
void setTypeName(const QString & typ);

/**
Set the field length.
Expand All @@ -89,10 +101,11 @@ public:
*/
void setPrecision(int prec);


/**
Set whether field is numeric
Set the field comment
*/
void setNumeric(bool num);
void setComment(const QString & comment);

}; // class QgsField

2 changes: 1 addition & 1 deletion python/core/qgslabel.sip
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public:
QgsLabelAttributes *layerAttributes ( );

//! Set label field
void setLabelField ( int attr, const QString str );
void setLabelField ( int attr, int fieldId );

//! label field
QString labelField ( int attr );
Expand Down
6 changes: 3 additions & 3 deletions python/core/qgsvectordataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ class QgsVectorDataProvider : QgsDataProvider
* @param attr_map a map containing changed attributes
* @return true in case of success and false in case of failure
*/
virtual bool changeAttributeValues(const QMap<int, QMap<int, QgsFeatureAttribute> > & attr_map);
virtual bool changeAttributeValues(const QMap<int, QMap<int, QVariant> > & attr_map);

/**
* Returns the default value for attribute @c attr for feature @c f.
* Returns the default value for field specified by @c fieldId
*/
virtual QString getDefaultValue(const QString & attr, QgsFeature* f);
virtual QVariant getDefaultValue(int fieldId);

/**
* Changes geometries of existing features
Expand Down
18 changes: 2 additions & 16 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,6 @@ public:
*/
virtual QString subsetString();

/**
* Number of attribute fields for a feature in the layer
*/
virtual int fieldCount() const;

/**
Return a list of field names for this layer
@return vector of field names
*/
virtual const QMap<int, QgsField> & fields() const;

/** Adds a feature
@param lastFeatureInBatch If True, will also go to the effort of e.g. updating the extents.
@return Irue in case of success and False in case of error
Expand Down Expand Up @@ -194,9 +183,6 @@ public:
*/
bool deleteSelectedFeatures();

/** Returns the default value for the attribute @c attr for the feature @c f. */
QString getDefaultValue(const QString& attr, QgsFeature* f);

/** Set labels on */
void setLabelOn( bool on );

Expand Down Expand Up @@ -270,7 +256,7 @@ public:
*/
bool commitAttributeChanges(const QSet<int>& deleted,
const QMap<QString, QString>& added,
const QMap<int, QMap<int, QgsFeatureAttribute> >& changed);
const QMap<int, QMap<int, QVariant> >& changed);

/** Draws the layer using coordinate transformation
* @return FALSE if an error occurred during drawing
Expand Down Expand Up @@ -308,7 +294,7 @@ public:
QSet<int>& deletedFeatureIds();

/** returns array of features with changed attributes */
QMap<int, QMap<int, QgsFeatureAttribute> >& changedAttributes();
QMap<int, QMap<int, QVariant> >& changedAttributes();

/** Sets whether some features are modified or not */
void setModified(bool modified = TRUE, bool onlyGeometryWasModified = FALSE);
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3437,7 +3437,7 @@ void QgisApp::editCut(QgsMapLayer * layerContainingSelection)
if (selectionVectorLayer != 0)
{
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
clipboard()->replaceWithCopyOf( features );
clipboard()->replaceWithCopyOf( selectionVectorLayer->getDataProvider()->fields(), features );
selectionVectorLayer->deleteSelectedFeatures();
}
}
Expand All @@ -3458,7 +3458,7 @@ void QgisApp::editCopy(QgsMapLayer * layerContainingSelection)
if (selectionVectorLayer != 0)
{
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
clipboard()->replaceWithCopyOf( features );
clipboard()->replaceWithCopyOf( selectionVectorLayer->getDataProvider()->fields(), features );
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/app/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
***************************************************************************/
/* $Id$ */
#include "qgsattributedialog.h"
#include "qgsfeatureattribute.h"
#include "qgsfield.h"
#include "qgslogger.h"

#include <QTableWidgetItem>
#include <QSettings>

QgsAttributeDialog::QgsAttributeDialog(const QgsAttributeMap& attributes)
QgsAttributeDialog::QgsAttributeDialog(const QgsFieldMap& fields, const QgsAttributeMap& attributes)
: QDialog(),
_settingsPath("/Windows/AttributeDialog/"),
mRowIsDirty(attributes.size(), FALSE)
Expand All @@ -35,14 +36,16 @@ QgsAttributeDialog::QgsAttributeDialog(const QgsAttributeMap& attributes)
for (QgsAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); ++it)
{
// set attribute name

QString fieldName = fields[it.key()].name();

QTableWidgetItem * myFieldItem = new QTableWidgetItem((*it).fieldName());
QTableWidgetItem * myFieldItem = new QTableWidgetItem(fieldName);
myFieldItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
mTable->setItem(index, 0, myFieldItem);

// set attribute value

QTableWidgetItem * myValueItem = new QTableWidgetItem((*it).fieldValue());
QTableWidgetItem * myValueItem = new QTableWidgetItem((*it).toString());
mTable->setItem(index, 1, myValueItem);

++index;
Expand Down Expand Up @@ -72,16 +75,16 @@ bool QgsAttributeDialog::isDirty(int row)
return mRowIsDirty.at(row);
}

bool QgsAttributeDialog::queryAttributes(QgsFeature& f)
bool QgsAttributeDialog::queryAttributes(const QgsFieldMap& fields, QgsFeature& f)
{
QgsAttributeMap featureAttributes = f.attributeMap();
QgsAttributeDialog attdialog(featureAttributes);
QgsAttributeDialog attdialog(fields, featureAttributes);

if (attdialog.exec() == QDialog::Accepted)
{
for (int i = 0; i < featureAttributes.size(); ++i)
{
f.changeAttribute(i, QgsFeatureAttribute(featureAttributes[i].fieldName(), attdialog.value(i)));
f.changeAttribute(i, QVariant(attdialog.value(i)) );
}
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/app/qgsattributedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
class QDialog;
class QgsFeature;

class QgsField;
typedef QMap<int, QgsField> QgsFieldMap;

class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
{
Q_OBJECT

public:
QgsAttributeDialog(const QgsAttributeMap& attributes);
QgsAttributeDialog(const QgsFieldMap& fields, const QgsAttributeMap& attributes);

~QgsAttributeDialog();

Expand All @@ -45,7 +48,7 @@ class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
attribute values are set to the feature if the dialog is accepted.
\retval true if accepted
\retval false if canceled */
static bool queryAttributes(QgsFeature& f);
static bool queryAttributes(const QgsFieldMap& fields, QgsFeature& f);

// Saves and restores the size and position from the last time
// this dialog box was used.
Expand Down
Loading

0 comments on commit 00a43bc

Please sign in to comment.