mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-03 00:04:37 -05:00
QgsFeatureAttribute class has been removed and QVariant is used instead (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
This commit is contained in:
parent
39f11cf0b1
commit
00a43bc7dc
@ -16,7 +16,6 @@
|
|||||||
%Include qgsdatasourceuri.sip
|
%Include qgsdatasourceuri.sip
|
||||||
%Include qgsdistancearea.sip
|
%Include qgsdistancearea.sip
|
||||||
%Include qgsfeature.sip
|
%Include qgsfeature.sip
|
||||||
%Include qgsfeatureattribute.sip
|
|
||||||
%Include qgsfield.sip
|
%Include qgsfield.sip
|
||||||
%Include qgsgeometry.sip
|
%Include qgsgeometry.sip
|
||||||
%Include qgsgeometryvertexindex.sip
|
%Include qgsgeometryvertexindex.sip
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class QgsFeature
|
|||||||
want a copy of the "current" feature, not the on-disk feature.
|
want a copy of the "current" feature, not the on-disk feature.
|
||||||
*/
|
*/
|
||||||
QgsFeature( const QgsFeature & rhs,
|
QgsFeature( const QgsFeature & rhs,
|
||||||
const QMap<int, QMap<int, QgsFeatureAttribute> >& changedAttributes,
|
const QMap<int, QMap<int, QVariant> >& changedAttributes,
|
||||||
const QMap<int, QgsGeometry> & changedGeometries );
|
const QMap<int, QgsGeometry> & changedGeometries );
|
||||||
|
|
||||||
/** copy ctor needed due to internal pointer */
|
/** copy ctor needed due to internal pointer */
|
||||||
@ -58,12 +58,12 @@ class QgsFeature
|
|||||||
* Get the attributes for this feature.
|
* Get the attributes for this feature.
|
||||||
* @return A std::map containing the field name/value mapping
|
* @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
|
* Add an attribute to the map
|
||||||
*/
|
*/
|
||||||
void addAttribute(int field, QgsFeatureAttribute attr);
|
void addAttribute(int field, QVariant attr);
|
||||||
|
|
||||||
/**Deletes an attribute and its value*/
|
/**Deletes an attribute and its value*/
|
||||||
void deleteAttribute(int field);
|
void deleteAttribute(int field);
|
||||||
@ -71,13 +71,7 @@ class QgsFeature
|
|||||||
/**Changes an existing attribute value
|
/**Changes an existing attribute value
|
||||||
@param field index of the field
|
@param field index of the field
|
||||||
@param attr attribute name and value to be set */
|
@param attr attribute name and value to be set */
|
||||||
void changeAttribute(int field, QgsFeatureAttribute attr);
|
void changeAttribute(int field, QVariant attr);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the fields for this feature
|
|
||||||
* @return A std::map containing field position (index) and field name
|
|
||||||
*/
|
|
||||||
QMap<int, QString> fields() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the validity of this feature. This is normally set by
|
* Return the validity of this feature. This is normally set by
|
||||||
@ -125,9 +119,6 @@ class QgsFeature
|
|||||||
*/
|
*/
|
||||||
void setGeometryAndOwnership(unsigned char * geom, size_t length);
|
void setGeometryAndOwnership(unsigned char * geom, size_t length);
|
||||||
|
|
||||||
/**Returns the bounding box of this feature*/
|
|
||||||
QgsRect boundingBox() const;
|
|
||||||
|
|
||||||
|
|
||||||
}; // class QgsFeature
|
}; // class QgsFeature
|
||||||
|
|
||||||
|
|||||||
@ -1,53 +0,0 @@
|
|||||||
|
|
||||||
/** \class QgsFeatureAttribute - Feature attribute class.
|
|
||||||
* \brief Encapsulates a single feature attribute.
|
|
||||||
*@author Gary E.Sherman
|
|
||||||
*/
|
|
||||||
|
|
||||||
class QgsFeatureAttribute
|
|
||||||
{
|
|
||||||
%TypeHeaderCode
|
|
||||||
#include <qgsfeatureattribute.h>
|
|
||||||
%End
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
QgsFeatureAttribute(const QString & field = 0, const QString & value = 0, bool num = false);
|
|
||||||
|
|
||||||
//! Destructor
|
|
||||||
~QgsFeatureAttribute();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the field name for this feature attribute
|
|
||||||
* @return Field name
|
|
||||||
*/
|
|
||||||
const QString & fieldName() const;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the field value for this feature attribute
|
|
||||||
* @return Field value
|
|
||||||
*/
|
|
||||||
const QString & fieldValue() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether value is numeric or not
|
|
||||||
* @return Numeric flag
|
|
||||||
*/
|
|
||||||
bool isNumeric() const;
|
|
||||||
|
|
||||||
void setFieldName(QString name);
|
|
||||||
|
|
||||||
void setFieldValue(QString thevalue);
|
|
||||||
|
|
||||||
void setNumeric(bool num = true);
|
|
||||||
|
|
||||||
SIP_PYOBJECT __repr__();
|
|
||||||
%MethodCode
|
|
||||||
QString str = sipCpp->fieldName() + " = " + sipCpp->fieldValue();
|
|
||||||
sipRes = PyString_FromString(str.toLocal8Bit().data());
|
|
||||||
%End
|
|
||||||
|
|
||||||
}; // class QgsFeatureAttribute
|
|
||||||
|
|
||||||
@ -17,25 +17,33 @@ class QgsField
|
|||||||
public:
|
public:
|
||||||
/** Constructor. Constructs a new QgsField object.
|
/** Constructor. Constructs a new QgsField object.
|
||||||
* @param nam Field name
|
* @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
|
Field types are usually unique to the source and are stored exactly
|
||||||
as returned from the data store.
|
as returned from the data store.
|
||||||
* @param len Field length
|
* @param len Field length
|
||||||
* @param prec Field precision. Usually decimal places but may also be
|
* @param prec Field precision. Usually decimal places but may also be
|
||||||
* used in conjunction with other fields types (eg. variable character fields)
|
* 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
|
//! Destructor
|
||||||
~QgsField();
|
~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
|
//! Gets the name of the field
|
||||||
const QString & name() const;
|
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
|
Gets the field type. Field types vary depending on the data source. Examples
|
||||||
@ -43,7 +51,7 @@ public:
|
|||||||
the data store reports it, with no attenpt to standardize the value.
|
the data store reports it, with no attenpt to standardize the value.
|
||||||
@return QString containing the field type
|
@return QString containing the field type
|
||||||
*/
|
*/
|
||||||
const QString & type() const;
|
const QString & typeName() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,10 +68,9 @@ public:
|
|||||||
int precision() const;
|
int precision() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns true if field contains numeric values. This information is set by provider.
|
Returns the field comment
|
||||||
*/
|
*/
|
||||||
bool isNumeric() const;
|
const QString & comment() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the field name.
|
Set the field name.
|
||||||
@ -71,11 +78,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setName(const QString & nam);
|
void setName(const QString & nam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set variant type.
|
||||||
|
*/
|
||||||
|
void setType(QVariant::Type type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the field type.
|
Set the field type.
|
||||||
@param typ Field type
|
@param typ Field type
|
||||||
*/
|
*/
|
||||||
void setType(const QString & typ);
|
void setTypeName(const QString & typ);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the field length.
|
Set the field length.
|
||||||
@ -89,10 +101,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setPrecision(int prec);
|
void setPrecision(int prec);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set whether field is numeric
|
Set the field comment
|
||||||
*/
|
*/
|
||||||
void setNumeric(bool num);
|
void setComment(const QString & comment);
|
||||||
|
|
||||||
}; // class QgsField
|
}; // class QgsField
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,7 @@ public:
|
|||||||
QgsLabelAttributes *layerAttributes ( );
|
QgsLabelAttributes *layerAttributes ( );
|
||||||
|
|
||||||
//! Set label field
|
//! Set label field
|
||||||
void setLabelField ( int attr, const QString str );
|
void setLabelField ( int attr, int fieldId );
|
||||||
|
|
||||||
//! label field
|
//! label field
|
||||||
QString labelField ( int attr );
|
QString labelField ( int attr );
|
||||||
|
|||||||
@ -343,12 +343,12 @@ class QgsVectorDataProvider : QgsDataProvider
|
|||||||
* @param attr_map a map containing changed attributes
|
* @param attr_map a map containing changed attributes
|
||||||
* @return true in case of success and false in case of failure
|
* @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
|
* Changes geometries of existing features
|
||||||
|
|||||||
@ -151,17 +151,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual QString subsetString();
|
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
|
/** Adds a feature
|
||||||
@param lastFeatureInBatch If True, will also go to the effort of e.g. updating the extents.
|
@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
|
@return Irue in case of success and False in case of error
|
||||||
@ -194,9 +183,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool deleteSelectedFeatures();
|
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 */
|
/** Set labels on */
|
||||||
void setLabelOn( bool on );
|
void setLabelOn( bool on );
|
||||||
|
|
||||||
@ -270,7 +256,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool commitAttributeChanges(const QSet<int>& deleted,
|
bool commitAttributeChanges(const QSet<int>& deleted,
|
||||||
const QMap<QString, QString>& added,
|
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
|
/** Draws the layer using coordinate transformation
|
||||||
* @return FALSE if an error occurred during drawing
|
* @return FALSE if an error occurred during drawing
|
||||||
@ -308,7 +294,7 @@ public:
|
|||||||
QSet<int>& deletedFeatureIds();
|
QSet<int>& deletedFeatureIds();
|
||||||
|
|
||||||
/** returns array of features with changed attributes */
|
/** 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 */
|
/** Sets whether some features are modified or not */
|
||||||
void setModified(bool modified = TRUE, bool onlyGeometryWasModified = FALSE);
|
void setModified(bool modified = TRUE, bool onlyGeometryWasModified = FALSE);
|
||||||
|
|||||||
@ -3437,7 +3437,7 @@ void QgisApp::editCut(QgsMapLayer * layerContainingSelection)
|
|||||||
if (selectionVectorLayer != 0)
|
if (selectionVectorLayer != 0)
|
||||||
{
|
{
|
||||||
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
|
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
|
||||||
clipboard()->replaceWithCopyOf( features );
|
clipboard()->replaceWithCopyOf( selectionVectorLayer->getDataProvider()->fields(), features );
|
||||||
selectionVectorLayer->deleteSelectedFeatures();
|
selectionVectorLayer->deleteSelectedFeatures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3458,7 +3458,7 @@ void QgisApp::editCopy(QgsMapLayer * layerContainingSelection)
|
|||||||
if (selectionVectorLayer != 0)
|
if (selectionVectorLayer != 0)
|
||||||
{
|
{
|
||||||
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
|
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
|
||||||
clipboard()->replaceWithCopyOf( features );
|
clipboard()->replaceWithCopyOf( selectionVectorLayer->getDataProvider()->fields(), features );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,12 +16,13 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#include "qgsattributedialog.h"
|
#include "qgsattributedialog.h"
|
||||||
#include "qgsfeatureattribute.h"
|
#include "qgsfield.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
|
|
||||||
#include <QTableWidgetItem>
|
#include <QTableWidgetItem>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
QgsAttributeDialog::QgsAttributeDialog(const QgsAttributeMap& attributes)
|
QgsAttributeDialog::QgsAttributeDialog(const QgsFieldMap& fields, const QgsAttributeMap& attributes)
|
||||||
: QDialog(),
|
: QDialog(),
|
||||||
_settingsPath("/Windows/AttributeDialog/"),
|
_settingsPath("/Windows/AttributeDialog/"),
|
||||||
mRowIsDirty(attributes.size(), FALSE)
|
mRowIsDirty(attributes.size(), FALSE)
|
||||||
@ -36,13 +37,15 @@ QgsAttributeDialog::QgsAttributeDialog(const QgsAttributeMap& attributes)
|
|||||||
{
|
{
|
||||||
// set attribute name
|
// set attribute name
|
||||||
|
|
||||||
QTableWidgetItem * myFieldItem = new QTableWidgetItem((*it).fieldName());
|
QString fieldName = fields[it.key()].name();
|
||||||
|
|
||||||
|
QTableWidgetItem * myFieldItem = new QTableWidgetItem(fieldName);
|
||||||
myFieldItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
myFieldItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||||
mTable->setItem(index, 0, myFieldItem);
|
mTable->setItem(index, 0, myFieldItem);
|
||||||
|
|
||||||
// set attribute value
|
// set attribute value
|
||||||
|
|
||||||
QTableWidgetItem * myValueItem = new QTableWidgetItem((*it).fieldValue());
|
QTableWidgetItem * myValueItem = new QTableWidgetItem((*it).toString());
|
||||||
mTable->setItem(index, 1, myValueItem);
|
mTable->setItem(index, 1, myValueItem);
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
@ -72,16 +75,16 @@ bool QgsAttributeDialog::isDirty(int row)
|
|||||||
return mRowIsDirty.at(row);
|
return mRowIsDirty.at(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsAttributeDialog::queryAttributes(QgsFeature& f)
|
bool QgsAttributeDialog::queryAttributes(const QgsFieldMap& fields, QgsFeature& f)
|
||||||
{
|
{
|
||||||
QgsAttributeMap featureAttributes = f.attributeMap();
|
QgsAttributeMap featureAttributes = f.attributeMap();
|
||||||
QgsAttributeDialog attdialog(featureAttributes);
|
QgsAttributeDialog attdialog(fields, featureAttributes);
|
||||||
|
|
||||||
if (attdialog.exec() == QDialog::Accepted)
|
if (attdialog.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < featureAttributes.size(); ++i)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,12 +26,15 @@
|
|||||||
class QDialog;
|
class QDialog;
|
||||||
class QgsFeature;
|
class QgsFeature;
|
||||||
|
|
||||||
|
class QgsField;
|
||||||
|
typedef QMap<int, QgsField> QgsFieldMap;
|
||||||
|
|
||||||
class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
|
class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QgsAttributeDialog(const QgsAttributeMap& attributes);
|
QgsAttributeDialog(const QgsFieldMap& fields, const QgsAttributeMap& attributes);
|
||||||
|
|
||||||
~QgsAttributeDialog();
|
~QgsAttributeDialog();
|
||||||
|
|
||||||
@ -45,7 +48,7 @@ class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
|
|||||||
attribute values are set to the feature if the dialog is accepted.
|
attribute values are set to the feature if the dialog is accepted.
|
||||||
\retval true if accepted
|
\retval true if accepted
|
||||||
\retval false if canceled */
|
\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
|
// Saves and restores the size and position from the last time
|
||||||
// this dialog box was used.
|
// this dialog box was used.
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "qgsattributetable.h"
|
#include "qgsattributetable.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgsvectordataprovider.h"
|
#include "qgsvectordataprovider.h"
|
||||||
@ -512,7 +511,7 @@ void QgsAttributeTable::putFeatureInTable(int row, QgsFeature& fet)
|
|||||||
for (int i = 0; i < attr.size(); i++)
|
for (int i = 0; i < attr.size(); i++)
|
||||||
{
|
{
|
||||||
// get the field values
|
// get the field values
|
||||||
setText(row, i + 1, attr[i].fieldValue());
|
setText(row, i + 1, attr[i].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +534,7 @@ void QgsAttributeTable::storeChangedValue(int row, int column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint index = mFields.key(attribute);
|
uint index = mFields.key(attribute);
|
||||||
mChangedValues[id].insert(index, QgsFeatureAttribute(attribute, text(row,column)) );
|
mChangedValues[id].insert(index, QVariant(text(row,column)) );
|
||||||
|
|
||||||
QgsDebugMsg("value: " + text(row,column));
|
QgsDebugMsg("value: " + text(row,column));
|
||||||
mEdited=true;
|
mEdited=true;
|
||||||
|
|||||||
@ -250,7 +250,8 @@ void QgsAttributeTableDisplay::search()
|
|||||||
|
|
||||||
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
||||||
int item = mSearchColumns->currentItem();
|
int item = mSearchColumns->currentItem();
|
||||||
bool numeric = provider->fields()[item].isNumeric();
|
QVariant::Type type = provider->fields()[item].type();
|
||||||
|
bool numeric = (type == QVariant::Int || type == QVariant::Double);
|
||||||
|
|
||||||
QString str;
|
QString str;
|
||||||
str = mSearchColumns->currentText();
|
str = mSearchColumns->currentText();
|
||||||
@ -328,10 +329,11 @@ void QgsAttributeTableDisplay::doSearch(const QString& searchString)
|
|||||||
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
||||||
provider->reset();
|
provider->reset();
|
||||||
mSearchIds.clear();
|
mSearchIds.clear();
|
||||||
|
const QgsFieldMap& fields = provider->fields();
|
||||||
QgsAttributeList all = provider->allAttributesList();
|
QgsAttributeList all = provider->allAttributesList();
|
||||||
while (provider->getNextFeature(fet, false, all))
|
while (provider->getNextFeature(fet, false, all))
|
||||||
{
|
{
|
||||||
if (searchTree->checkAgainst(fet.attributeMap()))
|
if (searchTree->checkAgainst(fields, fet.attributeMap()))
|
||||||
{
|
{
|
||||||
mSearchIds.insert(fet.featureId());
|
mSearchIds.insert(fet.featureId());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,10 +27,11 @@
|
|||||||
|
|
||||||
#include "qgsclipboard.h"
|
#include "qgsclipboard.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
|
|
||||||
|
|
||||||
QgsClipboard::QgsClipboard()
|
QgsClipboard::QgsClipboard()
|
||||||
: mFeatureClipboard()
|
: mFeatureClipboard()
|
||||||
{
|
{
|
||||||
@ -40,7 +41,7 @@ QgsClipboard::~QgsClipboard()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsClipboard::replaceWithCopyOf( QgsFeatureList& features )
|
void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList& features )
|
||||||
{
|
{
|
||||||
|
|
||||||
// Replace the QGis clipboard.
|
// Replace the QGis clipboard.
|
||||||
@ -54,27 +55,22 @@ void QgsClipboard::replaceWithCopyOf( QgsFeatureList& features )
|
|||||||
|
|
||||||
QStringList textLines;
|
QStringList textLines;
|
||||||
QStringList textFields;
|
QStringList textFields;
|
||||||
bool firstFeature = TRUE;
|
|
||||||
|
// first do the field names
|
||||||
|
textFields += "wkt_geom";
|
||||||
|
for (QgsFieldMap::const_iterator fit = fields.begin(); fit != fields.end(); ++fit)
|
||||||
|
{
|
||||||
|
textFields += fit->name();
|
||||||
|
}
|
||||||
|
textLines += textFields.join(",");
|
||||||
|
textFields.clear();
|
||||||
|
|
||||||
|
|
||||||
// then the field contents
|
// then the field contents
|
||||||
for (QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it)
|
for (QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it)
|
||||||
{
|
{
|
||||||
QgsAttributeMap attributes = it->attributeMap();
|
QgsAttributeMap attributes = it->attributeMap();
|
||||||
|
|
||||||
// first do the field names
|
|
||||||
if (firstFeature)
|
|
||||||
{
|
|
||||||
textFields += "wkt_geom";
|
|
||||||
|
|
||||||
for (QgsAttributeMap::iterator it2 = attributes.begin(); it2 != attributes.end(); ++it2)
|
|
||||||
{
|
|
||||||
textFields += it2->fieldName();
|
|
||||||
}
|
|
||||||
|
|
||||||
textLines += textFields.join(",");
|
|
||||||
textFields.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Set up Paste Transformations to specify the order in which fields are added.
|
// TODO: Set up Paste Transformations to specify the order in which fields are added.
|
||||||
|
|
||||||
@ -93,13 +89,11 @@ void QgsClipboard::replaceWithCopyOf( QgsFeatureList& features )
|
|||||||
// << (it2->fieldName()).toLocal8Bit().data()
|
// << (it2->fieldName()).toLocal8Bit().data()
|
||||||
// << "'." << std::endl;
|
// << "'." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
textFields += it2->fieldValue();
|
textFields += it2->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
textLines += textFields.join(",");
|
textLines += textFields.join(",");
|
||||||
textFields.clear();
|
textFields.clear();
|
||||||
|
|
||||||
firstFeature = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString textCopy = textLines.join("\n");
|
QString textCopy = textLines.join("\n");
|
||||||
|
|||||||
@ -21,11 +21,13 @@
|
|||||||
#define QGSCLIPBOARD_H
|
#define QGSCLIPBOARD_H
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
class QgsFeature;
|
class QgsFeature;
|
||||||
|
class QgsField;
|
||||||
|
|
||||||
typedef QList<QgsFeature> QgsFeatureList;
|
typedef QList<QgsFeature> QgsFeatureList;
|
||||||
|
typedef QMap<int, QgsField> QgsFieldMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ public:
|
|||||||
* Place a copy of features on the internal clipboard,
|
* Place a copy of features on the internal clipboard,
|
||||||
* destroying the previous contents.
|
* destroying the previous contents.
|
||||||
*/
|
*/
|
||||||
void replaceWithCopyOf( QgsFeatureList& features );
|
void replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList& features );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a copy of features on the internal clipboard,
|
* Returns a copy of features on the internal clipboard,
|
||||||
|
|||||||
@ -48,8 +48,8 @@ QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer)
|
|||||||
|
|
||||||
for (QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
for (QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
||||||
{
|
{
|
||||||
QString type = (*it).type();
|
QVariant::Type type = (*it).type();
|
||||||
if (type != "String" && type != "varchar" && type != "geometry")
|
if (type == QVariant::Int || type == QVariant::Double)
|
||||||
{
|
{
|
||||||
str = (*it).name();
|
str = (*it).name();
|
||||||
classificationComboBox->insertItem(str);
|
classificationComboBox->insertItem(str);
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
#include "qgsgraduatedsymboldialog.h"
|
#include "qgsgraduatedsymboldialog.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsgraduatedsymbolrenderer.h"
|
#include "qgsgraduatedsymbolrenderer.h"
|
||||||
#include "qgsludialog.h"
|
#include "qgsludialog.h"
|
||||||
@ -50,8 +49,8 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
|
|||||||
it != fields.end();
|
it != fields.end();
|
||||||
++it)
|
++it)
|
||||||
{
|
{
|
||||||
QString type = (*it).type();
|
QVariant::Type type = (*it).type();
|
||||||
if (type != "String" && type != "varchar" && type != "geometry")
|
if (type == QVariant::Int || type == QVariant::Double)
|
||||||
{
|
{
|
||||||
str = (*it).name();
|
str = (*it).name();
|
||||||
classificationComboBox->insertItem(str);
|
classificationComboBox->insertItem(str);
|
||||||
@ -482,7 +481,7 @@ int QgsGraduatedSymbolDialog::quantilesFromVectorLayer(std::list<double>& result
|
|||||||
while(provider->getNextFeature(currentFeature, false, attList))
|
while(provider->getNextFeature(currentFeature, false, attList))
|
||||||
{
|
{
|
||||||
currentAttributeMap = currentFeature.attributeMap();
|
currentAttributeMap = currentFeature.attributeMap();
|
||||||
currentValue = currentAttributeMap[attributeIndex].fieldValue().toDouble();
|
currentValue = currentAttributeMap[attributeIndex].toDouble();
|
||||||
attributeValues[index] = currentValue;
|
attributeValues[index] = currentValue;
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -386,20 +386,30 @@ void QgsLabelDialog::apply()
|
|||||||
//TODO - transparency attributes for buffers
|
//TODO - transparency attributes for buffers
|
||||||
|
|
||||||
//set the label props that are data bound to a field in the attributes tbl
|
//set the label props that are data bound to a field in the attributes tbl
|
||||||
mLabel->setLabelField( QgsLabel::Text, cboLabelField->currentText() );
|
mLabel->setLabelField( QgsLabel::Text, fieldIndexFromName(cboLabelField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::Family, cboFontField->currentText() );
|
mLabel->setLabelField( QgsLabel::Family, fieldIndexFromName(cboFontField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::Bold, cboBoldField->currentText() );
|
mLabel->setLabelField( QgsLabel::Bold, fieldIndexFromName(cboBoldField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::Italic, cboItalicField->currentText() );
|
mLabel->setLabelField( QgsLabel::Italic, fieldIndexFromName(cboItalicField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::Underline, cboUnderlineField->currentText() );
|
mLabel->setLabelField( QgsLabel::Underline, fieldIndexFromName(cboUnderlineField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::Size, cboFontSizeField->currentText() );
|
mLabel->setLabelField( QgsLabel::Size, fieldIndexFromName(cboFontSizeField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::BufferSize, cboBufferSizeField->currentText() );
|
mLabel->setLabelField( QgsLabel::BufferSize, fieldIndexFromName(cboBufferSizeField->currentText()) );
|
||||||
//mLabel->setLabelField( QgsLabel::BufferTransparency, cboBufferTransparencyField->currentText() );
|
//mLabel->setLabelField( QgsLabel::BufferTransparency, cboBufferTransparencyField->currentText() );
|
||||||
mLabel->setLabelField( QgsLabel::XCoordinate, cboXCoordinateField->currentText() );
|
mLabel->setLabelField( QgsLabel::XCoordinate, fieldIndexFromName(cboXCoordinateField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::YCoordinate, cboYCoordinateField->currentText() );
|
mLabel->setLabelField( QgsLabel::YCoordinate, fieldIndexFromName(cboYCoordinateField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::XOffset, cboXOffsetField->currentText() );
|
mLabel->setLabelField( QgsLabel::XOffset, fieldIndexFromName(cboXOffsetField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::YOffset, cboYOffsetField->currentText() );
|
mLabel->setLabelField( QgsLabel::YOffset, fieldIndexFromName(cboYOffsetField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::Alignment, cboAlignmentField->currentText() );
|
mLabel->setLabelField( QgsLabel::Alignment, fieldIndexFromName(cboAlignmentField->currentText()) );
|
||||||
mLabel->setLabelField( QgsLabel::Angle, cboAngleField->currentText() );
|
mLabel->setLabelField( QgsLabel::Angle, fieldIndexFromName(cboAngleField->currentText()) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int QgsLabelDialog::fieldIndexFromName(QString name)
|
||||||
|
{
|
||||||
|
const QgsFieldMap& fields = mLabel->fields();
|
||||||
|
for (QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it->name() == name)
|
||||||
|
return it.key();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|||||||
@ -77,8 +77,10 @@ public slots:
|
|||||||
/* emitted when anitem in label source list is chosen */
|
/* emitted when anitem in label source list is chosen */
|
||||||
void labelSourceSet();
|
void labelSourceSet();
|
||||||
|
|
||||||
protected slots:
|
protected:
|
||||||
|
|
||||||
|
/** return field index based on field's name, -1 if not found */
|
||||||
|
int fieldIndexFromName(QString name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QgsLabel *mLabel;
|
QgsLabel *mLabel;
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
#include "qgsattributedialog.h"
|
#include "qgsattributedialog.h"
|
||||||
#include "qgscoordinatetransform.h"
|
#include "qgscoordinatetransform.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsmaptoolcapture.h"
|
#include "qgsmaptoolcapture.h"
|
||||||
#include "qgsmapcanvas.h"
|
#include "qgsmapcanvas.h"
|
||||||
#include "qgsmaprender.h"
|
#include "qgsmaprender.h"
|
||||||
@ -61,7 +60,9 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(vlayer->getDataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures))
|
QgsVectorDataProvider* provider = vlayer->getDataProvider();
|
||||||
|
|
||||||
|
if(!(provider->capabilities() & QgsVectorDataProvider::AddFeatures))
|
||||||
{
|
{
|
||||||
QMessageBox::information(0, QObject::tr("Layer cannot be added to"),
|
QMessageBox::information(0, QObject::tr("Layer cannot be added to"),
|
||||||
QObject::tr("The data provider for this layer does not support the addition of features."));
|
QObject::tr("The data provider for this layer does not support the addition of features."));
|
||||||
@ -97,7 +98,7 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
|
|||||||
//only do the rest for provider with feature addition support
|
//only do the rest for provider with feature addition support
|
||||||
//note that for the grass provider, this will return false since
|
//note that for the grass provider, this will return false since
|
||||||
//grass provider has its own mechanism of feature addition
|
//grass provider has its own mechanism of feature addition
|
||||||
if(vlayer->getDataProvider()->capabilities()&QgsVectorDataProvider::AddFeatures)
|
if(provider->capabilities() & QgsVectorDataProvider::AddFeatures)
|
||||||
{
|
{
|
||||||
QgsFeature* f = new QgsFeature(0,"WKBPoint");
|
QgsFeature* f = new QgsFeature(0,"WKBPoint");
|
||||||
// project to layer's SRS
|
// project to layer's SRS
|
||||||
@ -147,15 +148,14 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
|
|||||||
|
|
||||||
f->setGeometryAndOwnership(&wkb[0],size);
|
f->setGeometryAndOwnership(&wkb[0],size);
|
||||||
// add the fields to the QgsFeature
|
// add the fields to the QgsFeature
|
||||||
const QgsFieldMap& fields=vlayer->fields();
|
const QgsFieldMap& fields=provider->fields();
|
||||||
for(QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
for(QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
||||||
{
|
{
|
||||||
QString name = it->name();
|
f->addAttribute(it.key(), provider->getDefaultValue(it.key()) );
|
||||||
f->addAttribute(it.key(), QgsFeatureAttribute(name, vlayer->getDefaultValue(name,f)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the dialog to enter attribute values
|
// show the dialog to enter attribute values
|
||||||
if (QgsAttributeDialog::queryAttributes(*f))
|
if (QgsAttributeDialog::queryAttributes(fields, *f))
|
||||||
vlayer->addFeature(*f);
|
vlayer->addFeature(*f);
|
||||||
else
|
else
|
||||||
delete f;
|
delete f;
|
||||||
@ -371,14 +371,13 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
|
|||||||
f->setGeometryAndOwnership(&wkb[0],size);
|
f->setGeometryAndOwnership(&wkb[0],size);
|
||||||
|
|
||||||
// add the fields to the QgsFeature
|
// add the fields to the QgsFeature
|
||||||
const QgsFieldMap& fields = vlayer->fields();
|
const QgsFieldMap& fields = provider->fields();
|
||||||
for(QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
for(QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
||||||
{
|
{
|
||||||
QString name = it->name();
|
f->addAttribute(it.key(), provider->getDefaultValue(it.key()));
|
||||||
f->addAttribute(it.key(), QgsFeatureAttribute(name, vlayer->getDefaultValue(name, f)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QgsAttributeDialog::queryAttributes(*f))
|
if (QgsAttributeDialog::queryAttributes(fields, *f))
|
||||||
vlayer->addFeature(*f);
|
vlayer->addFeature(*f);
|
||||||
else
|
else
|
||||||
delete f;
|
delete f;
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include "qgsfield.h"
|
||||||
#include "qgsmessageviewer.h"
|
#include "qgsmessageviewer.h"
|
||||||
#include "qgsmaptoolidentify.h"
|
#include "qgsmaptoolidentify.h"
|
||||||
#include "qgsmapcanvas.h"
|
#include "qgsmapcanvas.h"
|
||||||
@ -25,7 +26,6 @@
|
|||||||
#include "qgsidentifyresults.h"
|
#include "qgsidentifyresults.h"
|
||||||
#include "qgsdistancearea.h"
|
#include "qgsdistancearea.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgsattributedialog.h"
|
#include "qgsattributedialog.h"
|
||||||
#include "qgscursors.h"
|
#include "qgscursors.h"
|
||||||
@ -210,6 +210,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
|||||||
QString fieldIndex = layer->displayField();
|
QString fieldIndex = layer->displayField();
|
||||||
QgsVectorDataProvider* dataProvider = layer->getDataProvider();
|
QgsVectorDataProvider* dataProvider = layer->getDataProvider();
|
||||||
QgsAttributeList allAttributes = dataProvider->allAttributesList();
|
QgsAttributeList allAttributes = dataProvider->allAttributesList();
|
||||||
|
const QgsFieldMap& fields = dataProvider->fields();
|
||||||
|
|
||||||
dataProvider->select(r, true);
|
dataProvider->select(r, true);
|
||||||
|
|
||||||
@ -251,13 +252,13 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
|||||||
|
|
||||||
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
|
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
|
||||||
{
|
{
|
||||||
QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
|
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
|
||||||
|
|
||||||
if (it->fieldName().lower() == fieldIndex)
|
if (fields[it.key()].name() == fieldIndex)
|
||||||
{
|
{
|
||||||
featureNode->setText(1, it->fieldValue());
|
featureNode->setText(1, it->toString());
|
||||||
}
|
}
|
||||||
mResults->addAttribute(featureNode, it->fieldName(), it->fieldValue());
|
mResults->addAttribute(featureNode, fields[it.key()].name(), it->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate derived attributes and insert:
|
// Calculate derived attributes and insert:
|
||||||
@ -350,7 +351,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
|||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
|
|
||||||
// Show the attribute value editing dialog
|
// Show the attribute value editing dialog
|
||||||
QgsAttributeDialog ad( old );
|
QgsAttributeDialog ad( dataProvider->fields(), old );
|
||||||
|
|
||||||
if (ad.exec() == QDialog::Accepted)
|
if (ad.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
@ -369,7 +370,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
|
|||||||
<< "." << std::endl;
|
<< "." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
QgsAttributeMap& chattr = changedAttributes[ feat.featureId() ];
|
QgsAttributeMap& chattr = changedAttributes[ feat.featureId() ];
|
||||||
chattr[i] = QgsFeatureAttribute(oldit->fieldName(), ad.value(i));
|
chattr[i] = ad.value(i);
|
||||||
|
|
||||||
// propagate "dirtyness" to the layer
|
// propagate "dirtyness" to the layer
|
||||||
layer->setModified();
|
layer->setModified();
|
||||||
|
|||||||
@ -121,7 +121,7 @@ void QgsPgQueryBuilder::populateFields()
|
|||||||
int fldtyp = PQftype(result, i);
|
int fldtyp = PQftype(result, i);
|
||||||
QString typOid = QString().setNum(fldtyp);
|
QString typOid = QString().setNum(fldtyp);
|
||||||
QgsLogger::debug("typOid is: " + typOid);
|
QgsLogger::debug("typOid is: " + typOid);
|
||||||
int fieldModifier = PQfmod(result, i);
|
//int fieldModifier = PQfmod(result, i);
|
||||||
QString sql = "select typelem from pg_type where typelem = " + typOid + " and typlen = -1";
|
QString sql = "select typelem from pg_type where typelem = " + typOid + " and typlen = -1";
|
||||||
// //--std::cout << sql << std::endl;
|
// //--std::cout << sql << std::endl;
|
||||||
PGresult *oidResult = PQexec(mPgConnection,
|
PGresult *oidResult = PQexec(mPgConnection,
|
||||||
@ -148,8 +148,8 @@ void QgsPgQueryBuilder::populateFields()
|
|||||||
std::cerr << "Field parms: Name = " << fieldName.toLocal8Bit().data()
|
std::cerr << "Field parms: Name = " << fieldName.toLocal8Bit().data()
|
||||||
<< ", Type = " << fieldType.toLocal8Bit().data() << std::endl;
|
<< ", Type = " << fieldType.toLocal8Bit().data() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mFieldMap[fieldName] = QgsField(fieldName, fieldType,
|
QVariant::Type type = QVariant::String; // TODO: should be set correctly [MD]
|
||||||
fieldSize.toInt(), fieldModifier);
|
mFieldMap[fieldName] = QgsField(fieldName, type, fieldType);
|
||||||
lstFields->insertItem(fieldName);
|
lstFields->insertItem(fieldName);
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
@ -191,7 +191,7 @@ void QgsPgQueryBuilder::on_btnSampleValues_clicked()
|
|||||||
lstValues->clear();
|
lstValues->clear();
|
||||||
// determine the field type
|
// determine the field type
|
||||||
QgsField field = mFieldMap[lstFields->currentText()];
|
QgsField field = mFieldMap[lstFields->currentText()];
|
||||||
bool isCharField = field.type().find("char") > -1;
|
bool isCharField = field.typeName().find("char") > -1;
|
||||||
PGresult *result = PQexec(mPgConnection, (const char *) (sql.utf8()));
|
PGresult *result = PQexec(mPgConnection, (const char *) (sql.utf8()));
|
||||||
|
|
||||||
if (PQresultStatus(result) == PGRES_TUPLES_OK)
|
if (PQresultStatus(result) == PGRES_TUPLES_OK)
|
||||||
@ -229,7 +229,7 @@ void QgsPgQueryBuilder::on_btnGetAllValues_clicked()
|
|||||||
lstValues->clear();
|
lstValues->clear();
|
||||||
// determine the field type
|
// determine the field type
|
||||||
QgsField field = mFieldMap[lstFields->currentText()];
|
QgsField field = mFieldMap[lstFields->currentText()];
|
||||||
bool isCharField = field.type().find("char") > -1;
|
bool isCharField = field.typeName().find("char") > -1;
|
||||||
|
|
||||||
PGresult *result = PQexec(mPgConnection, (const char *) (sql.utf8()));
|
PGresult *result = PQexec(mPgConnection, (const char *) (sql.utf8()));
|
||||||
|
|
||||||
|
|||||||
@ -53,12 +53,12 @@ QgsSearchQueryBuilder::~QgsSearchQueryBuilder()
|
|||||||
|
|
||||||
void QgsSearchQueryBuilder::populateFields()
|
void QgsSearchQueryBuilder::populateFields()
|
||||||
{
|
{
|
||||||
const QgsFieldMap& fields = mLayer->fields();
|
const QgsFieldMap& fields = mLayer->getDataProvider()->fields();
|
||||||
for (QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
for (QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it)
|
||||||
{
|
{
|
||||||
QgsField f = it.value();
|
QString fieldName = it->name();
|
||||||
QString fieldName = f.name();
|
|
||||||
mFieldMap[fieldName] = f;
|
mFieldMap[fieldName] = it.key();
|
||||||
lstFields->insertItem(fieldName);
|
lstFields->insertItem(fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,28 +68,24 @@ void QgsSearchQueryBuilder::getFieldValues(uint limit)
|
|||||||
// clear the values list
|
// clear the values list
|
||||||
lstValues->clear();
|
lstValues->clear();
|
||||||
|
|
||||||
|
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
||||||
|
|
||||||
// determine the field type
|
// determine the field type
|
||||||
QgsField field = mFieldMap[lstFields->currentText()];
|
QString fieldName = lstFields->currentText();
|
||||||
QString fieldName = field.name().lower();
|
int fieldIndex = mFieldMap[fieldName];
|
||||||
bool numeric = field.isNumeric();
|
QgsField field = provider->fields()[fieldIndex];
|
||||||
|
bool numeric = (field.type() == QVariant::Int || field.type() == QVariant::Double);
|
||||||
|
|
||||||
QgsFeature feat;
|
QgsFeature feat;
|
||||||
QString value;
|
QString value;
|
||||||
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
|
||||||
provider->reset();
|
provider->reset();
|
||||||
QgsAttributeList allAttributes = provider->allAttributesList();
|
QgsAttributeList attrs;
|
||||||
while (provider->getNextFeature(feat, false, allAttributes) &&
|
attrs.append(fieldIndex);
|
||||||
|
while (provider->getNextFeature(feat, false, attrs) &&
|
||||||
(limit == 0 || lstValues->count() != limit))
|
(limit == 0 || lstValues->count() != limit))
|
||||||
{
|
{
|
||||||
const QgsAttributeMap& attributes = feat.attributeMap();
|
const QgsAttributeMap& attributes = feat.attributeMap();
|
||||||
for (QgsAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); it++)
|
value = attributes[fieldIndex].toString();
|
||||||
{
|
|
||||||
if ( (*it).fieldName().lower() == fieldName)
|
|
||||||
{
|
|
||||||
value = (*it).fieldValue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!numeric)
|
if (!numeric)
|
||||||
{
|
{
|
||||||
@ -154,11 +150,12 @@ long QgsSearchQueryBuilder::countRecords(QString searchString)
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
QgsFeature feat;
|
QgsFeature feat;
|
||||||
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
QgsVectorDataProvider* provider = mLayer->getDataProvider();
|
||||||
|
const QgsFieldMap& fields = provider->fields();
|
||||||
provider->reset();
|
provider->reset();
|
||||||
QgsAttributeList allAttributes = provider->allAttributesList();
|
QgsAttributeList allAttributes = provider->allAttributesList();
|
||||||
while (provider->getNextFeature(feat, false, allAttributes))
|
while (provider->getNextFeature(feat, false, allAttributes))
|
||||||
{
|
{
|
||||||
if (searchTree->checkAgainst(feat.attributeMap()))
|
if (searchTree->checkAgainst(fields, feat.attributeMap()))
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,11 +111,8 @@ class QgsSearchQueryBuilder : public QDialog, private Ui::QgsPgQueryBuilderBase
|
|||||||
//! Layer for which is the query builder opened
|
//! Layer for which is the query builder opened
|
||||||
QgsVectorLayer* mLayer;
|
QgsVectorLayer* mLayer;
|
||||||
|
|
||||||
//! Vector of QgsField objects
|
|
||||||
std::vector<QgsField> mFields;
|
|
||||||
|
|
||||||
//! Map that holds field information, keyed by field name
|
//! Map that holds field information, keyed by field name
|
||||||
std::map<QString, QgsField> mFieldMap;
|
QMap<QString, int> mFieldMap;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif //QGSSEARCHQUERYBUILDER_H
|
#endif //QGSSEARCHQUERYBUILDER_H
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
#include "qgsuniquevaluedialog.h"
|
#include "qgsuniquevaluedialog.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgssymbol.h"
|
#include "qgssymbol.h"
|
||||||
#include "qgsuniquevaluerenderer.h"
|
#include "qgsuniquevaluerenderer.h"
|
||||||
#include "qgsvectordataprovider.h"
|
#include "qgsvectordataprovider.h"
|
||||||
@ -148,8 +147,8 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
|
|||||||
mClassListWidget->clear();
|
mClassListWidget->clear();
|
||||||
while(provider->getNextFeature(feat, false, attlist))
|
while(provider->getNextFeature(feat, false, attlist))
|
||||||
{
|
{
|
||||||
const QgsAttributeMap& vec = feat.attributeMap();
|
const QgsAttributeMap& attrs = feat.attributeMap();
|
||||||
value=vec[nr].fieldValue();
|
value = attrs[nr].toString();
|
||||||
|
|
||||||
if(mValues.find(value)==mValues.end())
|
if(mValues.find(value)==mValues.end())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -228,7 +228,7 @@ void QgsVectorLayerProperties::reset( void )
|
|||||||
QObject::connect(legendtypecombobox, SIGNAL(activated(const QString &)), this, SLOT(alterLayerDialog(const QString &)));
|
QObject::connect(legendtypecombobox, SIGNAL(activated(const QString &)), this, SLOT(alterLayerDialog(const QString &)));
|
||||||
|
|
||||||
// reset fields in label dialog
|
// reset fields in label dialog
|
||||||
layer->label()->setFields ( layer->fields() );
|
layer->label()->setFields ( layer->getDataProvider()->fields() );
|
||||||
|
|
||||||
//set the metadata contents
|
//set the metadata contents
|
||||||
teMetadata->setText(getMetadata());
|
teMetadata->setText(getMetadata());
|
||||||
@ -547,7 +547,7 @@ QString QgsVectorLayerProperties::getMetadata()
|
|||||||
myMetadataQString += myField.name();
|
myMetadataQString += myField.name();
|
||||||
myMetadataQString += "</td>";
|
myMetadataQString += "</td>";
|
||||||
myMetadataQString += "<td bgcolor=\"white\">";
|
myMetadataQString += "<td bgcolor=\"white\">";
|
||||||
myMetadataQString += myField.type();
|
myMetadataQString += myField.typeName();
|
||||||
myMetadataQString += "</td>";
|
myMetadataQString += "</td>";
|
||||||
myMetadataQString += "<td bgcolor=\"white\">";
|
myMetadataQString += "<td bgcolor=\"white\">";
|
||||||
myMetadataQString += QString("%1").arg(myField.length());
|
myMetadataQString += QString("%1").arg(myField.length());
|
||||||
|
|||||||
@ -14,7 +14,6 @@ qgsdatasourceuri.cpp
|
|||||||
qgsdistancearea.cpp
|
qgsdistancearea.cpp
|
||||||
qgsexception.cpp
|
qgsexception.cpp
|
||||||
qgsfeature.cpp
|
qgsfeature.cpp
|
||||||
qgsfeatureattribute.cpp
|
|
||||||
qgsfield.cpp
|
qgsfield.cpp
|
||||||
qgsgeometry.cpp
|
qgsgeometry.cpp
|
||||||
qgsgeometryvertexindex.cpp
|
qgsgeometryvertexindex.cpp
|
||||||
@ -173,7 +172,6 @@ qgsdatasourceuri.h
|
|||||||
qgsdistancearea.h
|
qgsdistancearea.h
|
||||||
qgsexception.h
|
qgsexception.h
|
||||||
qgsfeature.h
|
qgsfeature.h
|
||||||
qgsfeatureattribute.h
|
|
||||||
qgsfield.h
|
qgsfield.h
|
||||||
qgsgeometry.h
|
qgsgeometry.h
|
||||||
qgsgeometryvertexindex.h
|
qgsgeometryvertexindex.h
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -19,14 +19,14 @@ email : sherman at mrcc.com
|
|||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
class QgsFeatureAttribute;
|
|
||||||
class QgsGeometry;
|
class QgsGeometry;
|
||||||
class QgsRect;
|
class QgsRect;
|
||||||
|
|
||||||
|
|
||||||
// key = field index, value = field name and attribute value
|
// key = field index, value = field value
|
||||||
typedef QMap<int, QgsFeatureAttribute> QgsAttributeMap;
|
typedef QMap<int, QVariant> QgsAttributeMap;
|
||||||
|
|
||||||
// key = feature id, value = changed attributes
|
// key = feature id, value = changed attributes
|
||||||
typedef QMap<int, QgsAttributeMap> QgsChangedAttributesMap;
|
typedef QMap<int, QgsAttributeMap> QgsChangedAttributesMap;
|
||||||
@ -104,7 +104,7 @@ class CORE_EXPORT QgsFeature {
|
|||||||
/**
|
/**
|
||||||
* Add an attribute to the map
|
* Add an attribute to the map
|
||||||
*/
|
*/
|
||||||
void addAttribute(int field, QgsFeatureAttribute attr);
|
void addAttribute(int field, QVariant attr);
|
||||||
|
|
||||||
/**Deletes an attribute and its value*/
|
/**Deletes an attribute and its value*/
|
||||||
void deleteAttribute(int field);
|
void deleteAttribute(int field);
|
||||||
@ -112,13 +112,7 @@ class CORE_EXPORT QgsFeature {
|
|||||||
/**Changes an existing attribute value
|
/**Changes an existing attribute value
|
||||||
@param field index of the field
|
@param field index of the field
|
||||||
@param attr attribute name and value to be set */
|
@param attr attribute name and value to be set */
|
||||||
void changeAttribute(int field, QgsFeatureAttribute attr);
|
void changeAttribute(int field, QVariant attr);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the fields for this feature
|
|
||||||
* @return A std::map containing field position (index) and field name
|
|
||||||
*/
|
|
||||||
QgsFieldNameMap fields() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the validity of this feature. This is normally set by
|
* Return the validity of this feature. This is normally set by
|
||||||
@ -166,58 +160,6 @@ class CORE_EXPORT QgsFeature {
|
|||||||
*/
|
*/
|
||||||
void setGeometryAndOwnership(unsigned char * geom, size_t length);
|
void setGeometryAndOwnership(unsigned char * geom, size_t length);
|
||||||
|
|
||||||
/** Set bulk-modified WKB geometry
|
|
||||||
\note this function assumes the Geometry is not committed.
|
|
||||||
*/
|
|
||||||
/* void setModifiedGeometry(unsigned char * geom, size_t length);*/
|
|
||||||
|
|
||||||
/** Insert a new vertex before the given vertex number,
|
|
||||||
* ring and item (first number is index 0)
|
|
||||||
* Not meaningful for Point geometries
|
|
||||||
*/
|
|
||||||
// bool insertVertexBefore(double x, double y, int beforeVertex = 0, int atRing = 0, int atItem = 0);
|
|
||||||
|
|
||||||
/** Moves the vertex at the given position number,
|
|
||||||
* ring and item (first number is index 0)
|
|
||||||
* to the given coordinates
|
|
||||||
*/
|
|
||||||
/* bool moveVertexAt(double x, double y, int atVertex = 0, int atRing = 0, int atItem = 0);*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modifies x and y to indicate the location of
|
|
||||||
* the vertex at the given position number,
|
|
||||||
* ring and item (first number is index 0)
|
|
||||||
* to the given coordinates
|
|
||||||
*/
|
|
||||||
/* bool vertexAt(double &x, double &y, int atVertex = 0, int atRing = 0, int atItem = 0) const;*/
|
|
||||||
|
|
||||||
// /**Test for intersection with a rectangle (uses GEOS)*/
|
|
||||||
// bool intersects(QgsRect* r) const;
|
|
||||||
|
|
||||||
/**Returns the Vertex closest to a given point*/
|
|
||||||
// QgsPoint closestVertex(const QgsPoint& point) const;
|
|
||||||
|
|
||||||
/** Returns the line segment closest to the given point in beforeVertex, atRing and atItem
|
|
||||||
Returns the SQUARE of the closest distance in minDist.
|
|
||||||
Returns the closest point on the line segment to the given point
|
|
||||||
|
|
||||||
|
|
||||||
TODO: point handling
|
|
||||||
TODO: const correctness
|
|
||||||
*/
|
|
||||||
// QgsPoint closestSegment(QgsPoint& point,
|
|
||||||
// QgsPoint& segStart, QgsPoint& segStop,
|
|
||||||
// double& minSqrDist);
|
|
||||||
|
|
||||||
// QgsPoint QgsFeature::closestSegmentWithContext(QgsPoint& point,
|
|
||||||
// int& beforeVertex, int& atRing, int& atItem,
|
|
||||||
// double& minSqrDist);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/**Returns the bounding box of this feature*/
|
|
||||||
QgsRect boundingBox() const;
|
|
||||||
//
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! feature id
|
//! feature id
|
||||||
@ -237,41 +179,17 @@ class CORE_EXPORT QgsFeature {
|
|||||||
*/
|
*/
|
||||||
bool mOwnsGeometry;
|
bool mOwnsGeometry;
|
||||||
|
|
||||||
// /** pointer to modified (dirty / uncommitted) geometry in binary WKB format
|
|
||||||
// This is only valid if isDirty().
|
|
||||||
// */
|
|
||||||
// unsigned char * modifiedGeometry;
|
|
||||||
//
|
|
||||||
// /** size of geometry */
|
|
||||||
// size_t geometrySize;
|
|
||||||
//
|
|
||||||
// /** size of modified geometry */
|
|
||||||
// size_t modifiedGeometrySize;
|
|
||||||
|
|
||||||
//! Flag to indicate if this feature is valid
|
//! Flag to indicate if this feature is valid
|
||||||
|
// TODO: still applies? [MD]
|
||||||
bool mValid;
|
bool mValid;
|
||||||
|
|
||||||
//! Flag to indicate if this feature is dirty (e.g. geometry has been modified in-memory)
|
//! Flag to indicate if this feature is dirty (e.g. geometry has been modified in-memory)
|
||||||
|
// TODO: still applies? [MD]
|
||||||
bool mDirty;
|
bool mDirty;
|
||||||
|
|
||||||
/// feature type name
|
/// feature type name
|
||||||
QString mTypeName;
|
QString mTypeName;
|
||||||
|
|
||||||
// /**WKT representation of the geometry*/
|
|
||||||
// mutable QString mWKT;
|
|
||||||
//
|
|
||||||
// /**Exports the current WKB to mWKT
|
|
||||||
// @return true in case of success and false else*/
|
|
||||||
// bool exportToWKT(unsigned char * geom) const;
|
|
||||||
// bool exportToWKT() const;
|
|
||||||
//
|
|
||||||
// /** Squared distance from point to the given line segment
|
|
||||||
// * TODO: Perhaps move this to QgsPoint
|
|
||||||
// */
|
|
||||||
// double distanceSquaredPointToSegment(QgsPoint& point,
|
|
||||||
// double *x1, double *y1,
|
|
||||||
// double *x2, double *y2,
|
|
||||||
// QgsPoint& minDistPoint);
|
|
||||||
|
|
||||||
}; // class QgsFeature
|
}; // class QgsFeature
|
||||||
|
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
qgsfeatureattribute.cpp - description
|
|
||||||
-------------------
|
|
||||||
begin : Mon Sep 01 2003
|
|
||||||
copyright : (C) 2003 by Gary E.Sherman
|
|
||||||
email : sherman at mrcc.com
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
***************************************************************************/
|
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
|
|
||||||
QgsFeatureAttribute::QgsFeatureAttribute(QString const & fld, QString const & val, bool num)
|
|
||||||
: field(fld), value(val), numeric(num)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QgsFeatureAttribute::~QgsFeatureAttribute()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString const & QgsFeatureAttribute::fieldName() const
|
|
||||||
{
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString const & QgsFeatureAttribute::fieldValue() const
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QgsFeatureAttribute::isNumeric() const
|
|
||||||
{
|
|
||||||
return numeric;
|
|
||||||
}
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
qgsfeatureattribute.h - description
|
|
||||||
-------------------
|
|
||||||
begin : Mon Sep 01 2003
|
|
||||||
copyright : (C) 2003 by Gary E.Sherman
|
|
||||||
email : sherman at mrcc.com
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
***************************************************************************/
|
|
||||||
/* $Id$ */
|
|
||||||
#ifndef QGSFEATUREATTRIBUTE_H
|
|
||||||
#define QGSFEATUREATTRIBUTE_H
|
|
||||||
|
|
||||||
#include <qstring.h>
|
|
||||||
|
|
||||||
/** \class QgsFeatureAttribute - Feature attribute class.
|
|
||||||
* \brief Encapsulates a single feature attribute.
|
|
||||||
*@author Gary E.Sherman
|
|
||||||
*/
|
|
||||||
|
|
||||||
class CORE_EXPORT QgsFeatureAttribute
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
QgsFeatureAttribute(QString const & field = 0, QString const & value = 0, bool num = false);
|
|
||||||
|
|
||||||
//! Destructor
|
|
||||||
~QgsFeatureAttribute();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the field name for this feature attribute
|
|
||||||
* @return Field name
|
|
||||||
*/
|
|
||||||
QString const & fieldName() const;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the field value for this feature attribute
|
|
||||||
* @return Field value
|
|
||||||
*/
|
|
||||||
QString const & fieldValue() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether value is numeric or not
|
|
||||||
* @return Numeric flag
|
|
||||||
*/
|
|
||||||
bool isNumeric() const;
|
|
||||||
|
|
||||||
void setFieldName(QString name){field=name;}
|
|
||||||
|
|
||||||
void setFieldValue(QString thevalue){value=thevalue;}
|
|
||||||
|
|
||||||
void setNumeric(bool num = true) { numeric=num; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
//! attribute field name
|
|
||||||
QString field;
|
|
||||||
|
|
||||||
//! attribute field value
|
|
||||||
QString value;
|
|
||||||
|
|
||||||
//! flag whether field is numeric
|
|
||||||
bool numeric;
|
|
||||||
|
|
||||||
}; // class QgsFeatureAttribute
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -24,7 +24,7 @@
|
|||||||
static const char * const ident_ =
|
static const char * const ident_ =
|
||||||
"$Id$";
|
"$Id$";
|
||||||
|
|
||||||
|
/*
|
||||||
QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num,
|
QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num,
|
||||||
QString comment)
|
QString comment)
|
||||||
:mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num),
|
:mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num),
|
||||||
@ -35,33 +35,40 @@ QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num,
|
|||||||
// attribute actions getting confused between uppercase and
|
// attribute actions getting confused between uppercase and
|
||||||
// lowercase versions of the attribute names, so just leave the
|
// lowercase versions of the attribute names, so just leave the
|
||||||
// names how they are now.
|
// names how they are now.
|
||||||
|
}*/
|
||||||
|
|
||||||
|
QgsField::QgsField(QString name, QVariant::Type type, QString typeName, int len, int prec, QString comment)
|
||||||
|
: mName(name), mType(type), mTypeName(typeName),
|
||||||
|
mLength(len), mPrecision(prec), mComment(comment)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QgsField::~QgsField()
|
QgsField::~QgsField()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsField::operator==(const QgsField other) const
|
bool QgsField::operator==(const QgsField& other) const
|
||||||
{
|
{
|
||||||
return ((mName == other.mName) && (mType == other.mType)
|
return ((mName == other.mName) && (mType == other.mType) && (mTypeName == other.mTypeName)
|
||||||
&& (mLength == other.mLength) && (mPrecision == other.mPrecision));
|
&& (mLength == other.mLength) && (mPrecision == other.mPrecision));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsField::operator!=(const QgsField other) const
|
const QString & QgsField::name() const
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString const & QgsField::name() const
|
|
||||||
{
|
{
|
||||||
return mName;
|
return mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString const & QgsField::type() const
|
QVariant::Type QgsField::type() const
|
||||||
{
|
{
|
||||||
return mType;
|
return mType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString & QgsField::typeName() const
|
||||||
|
{
|
||||||
|
return mTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
int QgsField::length() const
|
int QgsField::length() const
|
||||||
{
|
{
|
||||||
return mLength;
|
return mLength;
|
||||||
@ -72,25 +79,26 @@ int QgsField::precision() const
|
|||||||
return mPrecision;
|
return mPrecision;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsField::isNumeric() const
|
const QString & QgsField::comment() const
|
||||||
{
|
|
||||||
return mNumeric;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString const & QgsField::comment() const
|
|
||||||
{
|
{
|
||||||
return mComment;
|
return mComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsField::setName(QString const & nam)
|
void QgsField::setName(const QString & nam)
|
||||||
{
|
{
|
||||||
mName = nam;
|
mName = nam;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsField::setType(QString const & typ)
|
void QgsField::setType(QVariant::Type type)
|
||||||
{
|
{
|
||||||
mType = typ;
|
mType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsField::setTypeName(const QString & typeName)
|
||||||
|
{
|
||||||
|
mTypeName = typeName;
|
||||||
|
}
|
||||||
|
|
||||||
void QgsField::setLength(int len)
|
void QgsField::setLength(int len)
|
||||||
{
|
{
|
||||||
mLength = len;
|
mLength = len;
|
||||||
@ -99,11 +107,8 @@ void QgsField::setPrecision(int prec)
|
|||||||
{
|
{
|
||||||
mPrecision = prec;
|
mPrecision = prec;
|
||||||
}
|
}
|
||||||
void QgsField::setNumeric(bool num)
|
|
||||||
{
|
void QgsField::setComment(const QString & comment)
|
||||||
mNumeric = num;
|
|
||||||
}
|
|
||||||
void QgsField::setComment(QString comment)
|
|
||||||
{
|
{
|
||||||
mComment = comment;
|
mComment = comment;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,8 @@
|
|||||||
#ifndef QGSFIELD_H
|
#ifndef QGSFIELD_H
|
||||||
#define QGSFIELD_H
|
#define QGSFIELD_H
|
||||||
|
|
||||||
#include <qstring.h>
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class QgsField
|
\class QgsField
|
||||||
@ -32,25 +33,33 @@ class CORE_EXPORT QgsField
|
|||||||
public:
|
public:
|
||||||
/** Constructor. Constructs a new QgsField object.
|
/** Constructor. Constructs a new QgsField object.
|
||||||
* @param nam Field name
|
* @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
|
Field types are usually unique to the source and are stored exactly
|
||||||
as returned from the data store.
|
as returned from the data store.
|
||||||
* @param len Field length
|
* @param len Field length
|
||||||
* @param prec Field precision. Usually decimal places but may also be
|
* @param prec Field precision. Usually decimal places but may also be
|
||||||
* used in conjunction with other fields types (eg. variable character fields)
|
* 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, QString comment = "");
|
|
||||||
|
QgsField(QString name = QString(),
|
||||||
|
QVariant::Type type = QVariant::Invalid,
|
||||||
|
QString typeName = QString(),
|
||||||
|
int len = 0,
|
||||||
|
int prec = 0,
|
||||||
|
QString comment = QString());
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~QgsField();
|
~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
|
//! Gets the name of the field
|
||||||
QString const & name() const;
|
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
|
Gets the field type. Field types vary depending on the data source. Examples
|
||||||
@ -58,7 +67,7 @@ public:
|
|||||||
the data store reports it, with no attenpt to standardize the value.
|
the data store reports it, with no attenpt to standardize the value.
|
||||||
@return QString containing the field type
|
@return QString containing the field type
|
||||||
*/
|
*/
|
||||||
QString const & type() const;
|
const QString & typeName() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,28 +83,27 @@ public:
|
|||||||
*/
|
*/
|
||||||
int precision() const;
|
int precision() const;
|
||||||
|
|
||||||
/**
|
|
||||||
Returns true if field contains numeric values. This information is set by provider.
|
|
||||||
*/
|
|
||||||
bool isNumeric() const;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the field comment
|
Returns the field comment
|
||||||
*/
|
*/
|
||||||
QString const & comment() const;
|
const QString & comment() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the field name.
|
Set the field name.
|
||||||
@param nam Name of the field
|
@param nam Name of the field
|
||||||
*/
|
*/
|
||||||
void setName(QString const & nam);
|
void setName(const QString & nam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set variant type.
|
||||||
|
*/
|
||||||
|
void setType(QVariant::Type type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the field type.
|
Set the field type.
|
||||||
@param typ Field type
|
@param typ Field type
|
||||||
*/
|
*/
|
||||||
void setType(QString const & typ);
|
void setTypeName(const QString & typ);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the field length.
|
Set the field length.
|
||||||
@ -109,23 +117,22 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setPrecision(int prec);
|
void setPrecision(int prec);
|
||||||
|
|
||||||
/**
|
|
||||||
Set whether field is numeric
|
|
||||||
*/
|
|
||||||
void setNumeric(bool num);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the field comment
|
Set the field comment
|
||||||
*/
|
*/
|
||||||
void setComment(QString comment);
|
void setComment(const QString & comment);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! Name
|
//! Name
|
||||||
QString mName;
|
QString mName;
|
||||||
|
|
||||||
//! Type
|
//! Variant type
|
||||||
QString mType;
|
QVariant::Type mType;
|
||||||
|
|
||||||
|
//! Type name from provider
|
||||||
|
QString mTypeName;
|
||||||
|
|
||||||
//! Length
|
//! Length
|
||||||
int mLength;
|
int mLength;
|
||||||
@ -133,9 +140,6 @@ private:
|
|||||||
//! Precision
|
//! Precision
|
||||||
int mPrecision;
|
int mPrecision;
|
||||||
|
|
||||||
//! Numeric
|
|
||||||
bool mNumeric;
|
|
||||||
|
|
||||||
//! Comment
|
//! Comment
|
||||||
QString mComment;
|
QString mComment;
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "qgis.h"
|
#include "qgis.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsrect.h"
|
#include "qgsrect.h"
|
||||||
@ -51,11 +50,9 @@ QgsLabel::QgsLabel( const QgsFieldMap & fields )
|
|||||||
{
|
{
|
||||||
|
|
||||||
mField = fields;
|
mField = fields;
|
||||||
mLabelField.resize ( LabelFieldCount );
|
|
||||||
mLabelFieldIdx.resize ( LabelFieldCount );
|
mLabelFieldIdx.resize ( LabelFieldCount );
|
||||||
for ( int i = 0; i < LabelFieldCount; i++ )
|
for ( int i = 0; i < LabelFieldCount; i++ )
|
||||||
{
|
{
|
||||||
mLabelField[i] = "";
|
|
||||||
mLabelFieldIdx[i] = -1;
|
mLabelFieldIdx[i] = -1;
|
||||||
}
|
}
|
||||||
mLabelAttributes = new QgsLabelAttributes ( true );
|
mLabelAttributes = new QgsLabelAttributes ( true );
|
||||||
@ -68,21 +65,22 @@ QgsLabel::~QgsLabel()
|
|||||||
|
|
||||||
QString QgsLabel::fieldValue ( int attr, QgsFeature &feature )
|
QString QgsLabel::fieldValue ( int attr, QgsFeature &feature )
|
||||||
{
|
{
|
||||||
if ( mLabelField[attr].isEmpty() )
|
if (mLabelFieldIdx[attr] == -1)
|
||||||
{
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QgsAttributeMap& attrs = feature.attributeMap();
|
|
||||||
QgsAttributeMap::const_iterator it;
|
|
||||||
|
|
||||||
for (it = attrs.begin(); it != attrs.end(); it++)
|
|
||||||
{
|
{
|
||||||
if (it.value().fieldName() == mLabelField[attr])
|
return QString();
|
||||||
return it.value().fieldValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString();
|
const QgsAttributeMap& attrs = feature.attributeMap();
|
||||||
|
QgsAttributeMap::const_iterator it = attrs.find(mLabelFieldIdx[attr]);
|
||||||
|
|
||||||
|
if (it != attrs.end())
|
||||||
|
{
|
||||||
|
return it->toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLabel::renderLabel( QPainter * painter, QgsRect &viewExtent,
|
void QgsLabel::renderLabel( QPainter * painter, QgsRect &viewExtent,
|
||||||
@ -426,22 +424,13 @@ QgsFieldMap & QgsLabel::fields ( void )
|
|||||||
return mField;
|
return mField;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLabel::setLabelField ( int attr, const QString str )
|
void QgsLabel::setLabelField ( int attr, int fieldIndex )
|
||||||
{
|
{
|
||||||
if ( attr >= LabelFieldCount )
|
if ( attr >= LabelFieldCount )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
mLabelFieldIdx[attr] = fieldIndex;
|
||||||
mLabelField[attr] = str;
|
std::cout << "setLabelField: " << attr << " -> " << fieldIndex << std::endl; // %%%
|
||||||
|
|
||||||
mLabelFieldIdx[attr] = -1;
|
|
||||||
for ( int i = 0; i < mField.size(); i++ )
|
|
||||||
{
|
|
||||||
if ( mField[i].name().compare(str) == 0 )
|
|
||||||
{
|
|
||||||
mLabelFieldIdx[attr] = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsLabel::labelField ( int attr )
|
QString QgsLabel::labelField ( int attr )
|
||||||
@ -449,7 +438,8 @@ QString QgsLabel::labelField ( int attr )
|
|||||||
if ( attr > LabelFieldCount )
|
if ( attr > LabelFieldCount )
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
return mLabelField[attr];
|
int fieldIndex = mLabelFieldIdx[attr];
|
||||||
|
return mField[fieldIndex].name();
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsLabelAttributes *QgsLabel::layerAttributes ( void )
|
QgsLabelAttributes *QgsLabel::layerAttributes ( void )
|
||||||
@ -677,7 +667,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
mLabelAttributes->setText ( el.attribute("text","") );
|
mLabelAttributes->setText ( el.attribute("text","") );
|
||||||
setLabelField ( Text, el.attribute("field","") );
|
setLabelField ( Text, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Family */
|
/* Family */
|
||||||
@ -691,7 +681,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
mLabelAttributes->setFamily ( el.attribute("name","") );
|
mLabelAttributes->setFamily ( el.attribute("name","") );
|
||||||
setLabelField ( Family, el.attribute("field","") );
|
setLabelField ( Family, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Size */
|
/* Size */
|
||||||
@ -706,7 +696,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
|
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
|
||||||
mLabelAttributes->setSize ( el.attribute("value", "0.0").toDouble(), type );
|
mLabelAttributes->setSize ( el.attribute("value", "0.0").toDouble(), type );
|
||||||
setLabelField ( Size, el.attribute("field","") );
|
setLabelField ( Size, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bold */
|
/* Bold */
|
||||||
@ -720,7 +710,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
mLabelAttributes->setBold ( (bool)el.attribute("on","0").toInt() );
|
mLabelAttributes->setBold ( (bool)el.attribute("on","0").toInt() );
|
||||||
setLabelField ( Bold, el.attribute("field","") );
|
setLabelField ( Bold, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Italic */
|
/* Italic */
|
||||||
@ -734,7 +724,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
mLabelAttributes->setItalic ( (bool)el.attribute("on","0").toInt() );
|
mLabelAttributes->setItalic ( (bool)el.attribute("on","0").toInt() );
|
||||||
setLabelField ( Italic, el.attribute("field","") );
|
setLabelField ( Italic, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Underline */
|
/* Underline */
|
||||||
@ -748,7 +738,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
mLabelAttributes->setUnderline ( (bool)el.attribute("on","0").toInt() );
|
mLabelAttributes->setUnderline ( (bool)el.attribute("on","0").toInt() );
|
||||||
setLabelField ( Underline, el.attribute("field","") );
|
setLabelField ( Underline, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Color */
|
/* Color */
|
||||||
@ -768,7 +758,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
|
|
||||||
mLabelAttributes->setColor( QColor(red, green, blue) );
|
mLabelAttributes->setColor( QColor(red, green, blue) );
|
||||||
|
|
||||||
setLabelField ( Color, el.attribute("field","") );
|
setLabelField ( Color, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* X */
|
/* X */
|
||||||
@ -781,7 +771,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
setLabelField ( XCoordinate, el.attribute("field","") );
|
setLabelField ( XCoordinate, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Y */
|
/* Y */
|
||||||
@ -794,7 +784,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
setLabelField ( YCoordinate, el.attribute("field","") );
|
setLabelField ( YCoordinate, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -816,8 +806,8 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
yoffset = el.attribute("y","0.0").toDouble();
|
yoffset = el.attribute("y","0.0").toDouble();
|
||||||
|
|
||||||
mLabelAttributes->setOffset ( xoffset, yoffset, type );
|
mLabelAttributes->setOffset ( xoffset, yoffset, type );
|
||||||
setLabelField ( XOffset, el.attribute("xfield","0") );
|
setLabelField ( XOffset, el.attribute("xfield","0").toInt() );
|
||||||
setLabelField ( YOffset, el.attribute("yfield","0") );
|
setLabelField ( YOffset, el.attribute("yfield","0").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Angle */
|
/* Angle */
|
||||||
@ -831,7 +821,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
mLabelAttributes->setAngle ( el.attribute("value","0.0").toDouble() );
|
mLabelAttributes->setAngle ( el.attribute("value","0.0").toDouble() );
|
||||||
setLabelField ( Angle, el.attribute("field","0.0") );
|
setLabelField ( Angle, el.attribute("field","0").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Alignment */
|
/* Alignment */
|
||||||
@ -845,7 +835,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
{
|
{
|
||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
mLabelAttributes->setAlignment ( QgsLabelAttributes::alignmentCode(el.attribute("value","")) );
|
mLabelAttributes->setAlignment ( QgsLabelAttributes::alignmentCode(el.attribute("value","")) );
|
||||||
setLabelField ( Alignment, el.attribute("field","") );
|
setLabelField ( Alignment, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -865,7 +855,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
blue = el.attribute("blue","0").toInt();
|
blue = el.attribute("blue","0").toInt();
|
||||||
|
|
||||||
mLabelAttributes->setBufferColor( QColor(red, green, blue) );
|
mLabelAttributes->setBufferColor( QColor(red, green, blue) );
|
||||||
setLabelField ( BufferColor, el.attribute("field","") );
|
setLabelField ( BufferColor, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
scratchNode = node.namedItem("buffersize");
|
scratchNode = node.namedItem("buffersize");
|
||||||
@ -880,7 +870,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
|
|
||||||
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
|
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
|
||||||
mLabelAttributes->setBufferSize ( el.attribute("value","0.0").toDouble(), type );
|
mLabelAttributes->setBufferSize ( el.attribute("value","0.0").toDouble(), type );
|
||||||
setLabelField ( BufferSize, el.attribute("field","") );
|
setLabelField ( BufferSize, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
scratchNode = node.namedItem("bufferenabled");
|
scratchNode = node.namedItem("bufferenabled");
|
||||||
@ -894,7 +884,7 @@ void QgsLabel::readXML( const QDomNode& node )
|
|||||||
el = scratchNode.toElement();
|
el = scratchNode.toElement();
|
||||||
|
|
||||||
mLabelAttributes->setBufferEnabled ( (bool)el.attribute("on","0").toInt() );
|
mLabelAttributes->setBufferEnabled ( (bool)el.attribute("on","0").toInt() );
|
||||||
setLabelField ( BufferEnabled, el.attribute("field","") );
|
setLabelField ( BufferEnabled, el.attribute("field","").toInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // QgsLabel::readXML()
|
} // QgsLabel::readXML()
|
||||||
@ -906,43 +896,60 @@ void QgsLabel::writeXML(std::ostream& xml)
|
|||||||
|
|
||||||
xml << "\t\t<labelattributes>\n";
|
xml << "\t\t<labelattributes>\n";
|
||||||
|
|
||||||
// else
|
// Text
|
||||||
if ( mLabelAttributes->textIsSet() && !mLabelField[Text].isEmpty() )
|
if (mLabelAttributes->textIsSet())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8()) << "\" field=\"" << (const char*)(mLabelField[Text].utf8()) << "\" />\n";
|
if (mLabelFieldIdx[Text] != -1)
|
||||||
}
|
{
|
||||||
else if ( mLabelAttributes->textIsSet() )
|
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8())
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[Text] << "\" />\n";
|
||||||
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8()) << "\" field=\"\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8())
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8()) << "\" field=\"" << (const char*)(mLabelField[Text].utf8()) << "\" />\n";
|
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8())
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mLabelAttributes->familyIsSet() && ! mLabelAttributes->family().isNull() && mLabelField[Family].isNull())
|
// Family
|
||||||
|
if (mLabelAttributes->familyIsSet() && !mLabelAttributes->family().isNull())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<family name=\"" << mLabelAttributes->family().utf8().data() << "\" field=\"" << (const char*)(mLabelField[Family].utf8().data()) << "\" />\n";
|
if (mLabelFieldIdx[Family] != -1)
|
||||||
}
|
{
|
||||||
else if ( mLabelAttributes->familyIsSet() && ! mLabelAttributes->family().isNull() )
|
xml << "\t\t\t<family name=\"" << mLabelAttributes->family().utf8().data()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[Family] << "\" />\n";
|
||||||
xml << "\t\t\t<family name=\"" << mLabelAttributes->family().utf8().data() << "\" field=\"\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<family name=\"" << mLabelAttributes->family().utf8().data()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<family name=\"Arial\" field=\"\" />\n";
|
xml << "\t\t\t<family name=\"Arial\" field=\"\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//size and units
|
// size and units
|
||||||
if ( mLabelAttributes->sizeIsSet() && !mLabelField[Size].isEmpty())
|
if (mLabelAttributes->sizeIsSet())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<size value=\"" << mLabelAttributes->size() << "\" units=\""
|
if (mLabelFieldIdx[Size] != -1)
|
||||||
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->sizeType()).utf8() << "\" field=\"" << (const char*)(mLabelField[Size].utf8()) << "\" />\n";
|
{
|
||||||
}
|
xml << "\t\t\t<size value=\"" << mLabelAttributes->size()
|
||||||
else if ( mLabelAttributes->sizeIsSet() )
|
<< "\" units=\"" << (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->sizeType()).utf8()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[Size] << "\" />\n";
|
||||||
xml << "\t\t\t<size value=\"" << mLabelAttributes->size() << "\" units=\""
|
}
|
||||||
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->sizeType()).utf8() << "\" field=\"\" />\n";
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<size value=\"" << mLabelAttributes->size()
|
||||||
|
<< "\" units=\"" << (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->sizeType()).utf8()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -950,57 +957,80 @@ void QgsLabel::writeXML(std::ostream& xml)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// bold
|
||||||
//bold
|
if (mLabelAttributes->boldIsSet())
|
||||||
if ( mLabelAttributes->boldIsSet() && !mLabelField[Bold].isEmpty() )
|
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<bold on=\"" << mLabelAttributes->bold() << "\" field=\"" << (const char*)(mLabelField[Bold].utf8()) << "\" />\n";
|
if (mLabelFieldIdx[Bold] != -1)
|
||||||
}
|
{
|
||||||
else if ( mLabelAttributes->boldIsSet() )
|
xml << "\t\t\t<bold on=\"" << mLabelAttributes->bold()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[Bold] << "\" />\n";
|
||||||
xml << "\t\t\t<bold on=\"" << mLabelAttributes->bold() << "\" field=\"\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<bold on=\"" << mLabelAttributes->bold()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<bold on=\"0\" field=\"0\" />\n";
|
xml << "\t\t\t<bold on=\"0\" field=\"0\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//italics
|
// italics
|
||||||
if ( mLabelAttributes->italicIsSet() && ! mLabelField[Italic].isEmpty())
|
if (mLabelAttributes->italicIsSet())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<italic on=\"" << mLabelAttributes->italic() << "\" field=\"" << (const char*)(mLabelField[Italic].utf8()) << "\" />\n";
|
if (mLabelFieldIdx[Italic] != -1)
|
||||||
}
|
{
|
||||||
else if ( mLabelAttributes->italicIsSet() )
|
xml << "\t\t\t<italic on=\"" << mLabelAttributes->italic()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[Italic] << "\" />\n";
|
||||||
xml << "\t\t\t<italic on=\"" << mLabelAttributes->italic() << "\" field=\"\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<italic on=\"" << mLabelAttributes->italic()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<italic on=\"0\" field=\"\" />\n";
|
xml << "\t\t\t<italic on=\"0\" field=\"\" />\n";
|
||||||
}
|
}
|
||||||
//underline
|
|
||||||
if ( mLabelAttributes->underlineIsSet() && !mLabelField[Underline].isEmpty())
|
// underline
|
||||||
|
if (mLabelAttributes->underlineIsSet())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<underline on=\"" << mLabelAttributes->underline() << "\" field=\"" << (const char*)(mLabelField[Underline].utf8()) << "\" />\n";
|
if (mLabelFieldIdx[Underline] != -1)
|
||||||
}
|
{
|
||||||
else if ( mLabelAttributes->underlineIsSet() )
|
xml << "\t\t\t<underline on=\"" << mLabelAttributes->underline()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[Underline] << "\" />\n";
|
||||||
xml << "\t\t\t<underline on=\"" << mLabelAttributes->underline() << "\" field=\"\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<underline on=\"" << mLabelAttributes->underline()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<underline on=\"0\" field=\"\" />\n";
|
xml << "\t\t\t<underline on=\"0\" field=\"\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mLabelAttributes->colorIsSet() && ! mLabelField[Color].isNull() )
|
// color
|
||||||
|
if (mLabelAttributes->colorIsSet())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<color red=\"" << mLabelAttributes->color().red() << "\" green=\"" << mLabelAttributes->color().green()
|
if (mLabelFieldIdx[Color] != -1)
|
||||||
<< "\" blue=\"" << mLabelAttributes->color().blue() << "\" field=\"" << (const char*)(mLabelField[Color].utf8()) << "\" />\n";
|
{
|
||||||
}
|
xml << "\t\t\t<color red=\"" << mLabelAttributes->color().red()
|
||||||
else if ( mLabelAttributes->colorIsSet() )
|
<< "\" green=\"" << mLabelAttributes->color().green()
|
||||||
{
|
<< "\" blue=\"" << mLabelAttributes->color().blue()
|
||||||
xml << "\t\t\t<color red=\"" << mLabelAttributes->color().red() << "\" green=\"" << mLabelAttributes->color().green()
|
<< "\" field=\"" << mLabelFieldIdx[Color] << "\" />\n";
|
||||||
<< "\" blue=\"" << mLabelAttributes->color().blue() << "\" field=\"\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<color red=\"" << mLabelAttributes->color().red()
|
||||||
|
<< "\" green=\"" << mLabelAttributes->color().green()
|
||||||
|
<< "\" blue=\"" << mLabelAttributes->color().blue()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1009,97 +1039,116 @@ void QgsLabel::writeXML(std::ostream& xml)
|
|||||||
|
|
||||||
|
|
||||||
/* X */
|
/* X */
|
||||||
if (! mLabelField[XCoordinate].isEmpty() )
|
if (mLabelFieldIdx[XCoordinate] != -1)
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<x field=\"" << (const char*)(mLabelField[XCoordinate].utf8()) << "\" />\n";
|
xml << "\t\t\t<x field=\"" << mLabelFieldIdx[XCoordinate] << "\" />\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<x field=\"" << "\" />\n";
|
xml << "\t\t\t<x field=\"\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Y */
|
/* Y */
|
||||||
if (! mLabelField[YCoordinate].isEmpty() )
|
if (mLabelFieldIdx[YCoordinate] != -1)
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<y field=\"" << (const char*)(mLabelField[YCoordinate].utf8()) << "\" />\n";
|
xml << "\t\t\t<y field=\"" << mLabelFieldIdx[YCoordinate] << "\" />\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<y field=\"" << "\" />\n";
|
xml << "\t\t\t<y field=\"\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// offset
|
// offset
|
||||||
if ( mLabelAttributes->offsetIsSet() )
|
if ( mLabelAttributes->offsetIsSet() )
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<offset units=\"" << QgsLabelAttributes::unitsName(mLabelAttributes->offsetType()).utf8().data()
|
xml << "\t\t\t<offset units=\"" << QgsLabelAttributes::unitsName(mLabelAttributes->offsetType()).utf8().data()
|
||||||
<< "\" x=\"" << mLabelAttributes->xOffset() << "\" xfield=\"" << (const char*)(mLabelField[XOffset].utf8().data())
|
<< "\" x=\"" << mLabelAttributes->xOffset() << "\" xfield=\"" << mLabelFieldIdx[XOffset]
|
||||||
<< "\" y=\"" << mLabelAttributes->yOffset() << "\" yfield=\"" << (const char*)(mLabelField[YOffset].utf8().data())
|
<< "\" y=\"" << mLabelAttributes->yOffset() << "\" yfield=\"" << mLabelFieldIdx[YOffset]
|
||||||
<< "\" />\n";
|
<< "\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Angle
|
// Angle
|
||||||
if ( mLabelAttributes->angleIsSet() )
|
if ( mLabelAttributes->angleIsSet() )
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<angle value=\"" << mLabelAttributes->angle() << "\" field=\"" << (const char*)(mLabelField[Angle].utf8()) << "\" />\n";
|
if (mLabelFieldIdx[Angle] != -1)
|
||||||
}
|
{
|
||||||
else if ( mLabelAttributes->angleIsSet() )
|
xml << "\t\t\t<angle value=\"" << mLabelAttributes->angle()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[Angle] << "\" />\n";
|
||||||
xml << "\t\t\t<angle value=\"" << mLabelAttributes->angle() << "\" field=\"" << "\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<angle value=\"" << mLabelAttributes->angle() << "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<angle value=\"" << "\" field=\"" << "\" />\n";
|
xml << "\t\t\t<angle value=\"\" field=\"\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// alignment
|
// alignment
|
||||||
if ( mLabelAttributes->alignmentIsSet() )
|
if ( mLabelAttributes->alignmentIsSet() )
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<alignment value=\"" << QgsLabelAttributes::alignmentName(mLabelAttributes->alignment()).utf8().data()
|
xml << "\t\t\t<alignment value=\"" << QgsLabelAttributes::alignmentName(mLabelAttributes->alignment()).utf8().data()
|
||||||
<< "\" field=\"" << (const char*)(mLabelField[Alignment].utf8().data()) << "\" />\n";
|
<< "\" field=\"" << mLabelFieldIdx[Alignment] << "\" />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buffer color
|
||||||
if ( mLabelAttributes->bufferColorIsSet() && ! mLabelField[BufferColor].isNull() )
|
if (mLabelAttributes->bufferColorIsSet())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<buffercolor red=\"" << mLabelAttributes->bufferColor().red() << "\" green=\"" << mLabelAttributes->bufferColor().green()
|
if (mLabelFieldIdx[BufferColor] != -1)
|
||||||
<< "\" blue=\"" << mLabelAttributes->bufferColor().blue() << "\" field=\"" << (const char*)(mLabelField[BufferColor].utf8()) << "\" />\n";
|
{
|
||||||
}
|
xml << "\t\t\t<buffercolor red=\"" << mLabelAttributes->bufferColor().red()
|
||||||
else if ( mLabelAttributes->bufferColorIsSet() )
|
<< "\" green=\"" << mLabelAttributes->bufferColor().green()
|
||||||
{
|
<< "\" blue=\"" << mLabelAttributes->bufferColor().blue()
|
||||||
xml << "\t\t\t<buffercolor red=\"" << mLabelAttributes->bufferColor().red() << "\" green=\"" << mLabelAttributes->bufferColor().green()
|
<< "\" field=\"" << mLabelFieldIdx[BufferColor] << "\" />\n";
|
||||||
<< "\" blue=\"" << mLabelAttributes->bufferColor().blue() << "\" field=\"" << "\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<buffercolor red=\"" << mLabelAttributes->bufferColor().red()
|
||||||
|
<< "\" green=\"" << mLabelAttributes->bufferColor().green()
|
||||||
|
<< "\" blue=\"" << mLabelAttributes->bufferColor().blue()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<buffercolor red=\"" << "\" green=\""
|
xml << "\t\t\t<buffercolor red=\"\" green=\"\" blue=\"\" field=\"\" />\n";
|
||||||
<< "\" blue=\"" << "\" field=\"" << "\" />\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buffer size
|
||||||
if ( mLabelAttributes->bufferSizeIsSet() && ! mLabelField[BufferSize].isNull() )
|
if (mLabelAttributes->bufferSizeIsSet())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<buffersize value=\"" << mLabelAttributes->bufferSize() << "\" units=\""
|
if (mLabelFieldIdx[BufferSize] != -1)
|
||||||
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->bufferSizeType()).utf8() << "\" field=\"" << (const char*)(mLabelField[BufferSize].utf8()) << "\" />\n";
|
{
|
||||||
}
|
xml << "\t\t\t<buffersize value=\"" << mLabelAttributes->bufferSize()
|
||||||
else if ( mLabelAttributes->bufferSizeIsSet() )
|
<< "\" units=\"" << (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->bufferSizeType()).utf8()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[BufferSize] << "\" />\n";
|
||||||
xml << "\t\t\t<buffersize value=\"" << mLabelAttributes->bufferSize() << "\" units=\""
|
}
|
||||||
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->bufferSizeType()).utf8() << "\" field=\"" << "\" />\n";
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<buffersize value=\"" << mLabelAttributes->bufferSize()
|
||||||
|
<< "\" units=\"" << (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->bufferSizeType()).utf8()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<buffersize value=\"" << "\" units=\""
|
xml << "\t\t\t<buffersize value=\"\" units=\"\" field=\"\" />\n";
|
||||||
<< "\" field=\"" << "\" />\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buffer enabled
|
||||||
if ( mLabelAttributes->bufferEnabled() && ! mLabelField[BufferEnabled].isNull() )
|
if (mLabelAttributes->bufferEnabled())
|
||||||
{
|
{
|
||||||
xml << "\t\t\t<bufferenabled on=\"" << mLabelAttributes->bufferEnabled() << "\" field=\"" << (const char*)(mLabelField[BufferEnabled].utf8()) << "\" />\n";
|
if (mLabelFieldIdx[BufferEnabled] != -1)
|
||||||
}
|
{
|
||||||
else if ( mLabelAttributes->bufferEnabled())
|
xml << "\t\t\t<bufferenabled on=\"" << mLabelAttributes->bufferEnabled()
|
||||||
{
|
<< "\" field=\"" << mLabelFieldIdx[BufferEnabled] << "\" />\n";
|
||||||
xml << "\t\t\t<bufferenabled on=\"" << mLabelAttributes->bufferEnabled() << "\" field=\"" << "\" />\n";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml << "\t\t\t<bufferenabled on=\"" << mLabelAttributes->bufferEnabled()
|
||||||
|
<< "\" field=\"\" />\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -104,7 +104,7 @@ public:
|
|||||||
QgsLabelAttributes *layerAttributes ( void );
|
QgsLabelAttributes *layerAttributes ( void );
|
||||||
|
|
||||||
//! Set label field
|
//! Set label field
|
||||||
void setLabelField ( int attr, const QString str );
|
void setLabelField ( int attr, int fieldIndex );
|
||||||
|
|
||||||
//! label field
|
//! label field
|
||||||
QString labelField ( int attr );
|
QString labelField ( int attr );
|
||||||
|
|||||||
@ -23,7 +23,6 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QSettings> // TODO: get rid of it [MD]
|
#include <QSettings> // TODO: get rid of it [MD]
|
||||||
|
|
||||||
#include "qgsfield.h"
|
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgsmaptopixel.h"
|
#include "qgsmaptopixel.h"
|
||||||
#include "qgsrect.h"
|
#include "qgsrect.h"
|
||||||
|
|||||||
@ -18,9 +18,10 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
|
#include "qgsfield.h"
|
||||||
#include "qgssearchtreenode.h"
|
#include "qgssearchtreenode.h"
|
||||||
#include <qregexp.h>
|
#include <QRegExp>
|
||||||
#include <qobject.h>
|
#include <QObject>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@ -180,7 +181,7 @@ QString QgsSearchTreeNode::makeSearchString()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QgsSearchTreeNode::checkAgainst(const QgsAttributeMap& attributes)
|
bool QgsSearchTreeNode::checkAgainst(const QgsFieldMap& fields, const QgsAttributeMap& attributes)
|
||||||
{
|
{
|
||||||
QgsDebugMsgLevel("checkAgainst: " + makeSearchString(), 2);
|
QgsDebugMsgLevel("checkAgainst: " + makeSearchString(), 2);
|
||||||
|
|
||||||
@ -199,17 +200,17 @@ bool QgsSearchTreeNode::checkAgainst(const QgsAttributeMap& attributes)
|
|||||||
switch (mOp)
|
switch (mOp)
|
||||||
{
|
{
|
||||||
case opNOT:
|
case opNOT:
|
||||||
return !mLeft->checkAgainst(attributes);
|
return !mLeft->checkAgainst(fields, attributes);
|
||||||
|
|
||||||
case opAND:
|
case opAND:
|
||||||
if (!mLeft->checkAgainst(attributes))
|
if (!mLeft->checkAgainst(fields, attributes))
|
||||||
return false;
|
return false;
|
||||||
return mRight->checkAgainst(attributes);
|
return mRight->checkAgainst(fields, attributes);
|
||||||
|
|
||||||
case opOR:
|
case opOR:
|
||||||
if (mLeft->checkAgainst(attributes))
|
if (mLeft->checkAgainst(fields, attributes))
|
||||||
return true;
|
return true;
|
||||||
return mRight->checkAgainst(attributes);
|
return mRight->checkAgainst(fields, attributes);
|
||||||
|
|
||||||
case opEQ:
|
case opEQ:
|
||||||
case opNE:
|
case opNE:
|
||||||
@ -218,7 +219,7 @@ bool QgsSearchTreeNode::checkAgainst(const QgsAttributeMap& attributes)
|
|||||||
case opGE:
|
case opGE:
|
||||||
case opLE:
|
case opLE:
|
||||||
|
|
||||||
if (!getValue(value1, mLeft, attributes) || !getValue(value2, mRight, attributes))
|
if (!getValue(value1, mLeft, fields, attributes) || !getValue(value2, mRight, fields, attributes))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
res = QgsSearchTreeValue::compare(value1, value2);
|
res = QgsSearchTreeValue::compare(value1, value2);
|
||||||
@ -239,7 +240,7 @@ bool QgsSearchTreeNode::checkAgainst(const QgsAttributeMap& attributes)
|
|||||||
case opRegexp:
|
case opRegexp:
|
||||||
case opLike:
|
case opLike:
|
||||||
{
|
{
|
||||||
if (!getValue(value1, mLeft, attributes) || !getValue(value2, mRight, attributes))
|
if (!getValue(value1, mLeft, fields, attributes) || !getValue(value2, mRight, fields, attributes))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// value1 is string to be matched
|
// value1 is string to be matched
|
||||||
@ -277,9 +278,9 @@ bool QgsSearchTreeNode::checkAgainst(const QgsAttributeMap& attributes)
|
|||||||
return false; // will never get there
|
return false; // will never get there
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsSearchTreeNode::getValue(QgsSearchTreeValue& value, QgsSearchTreeNode* node, const QgsAttributeMap& attributes)
|
bool QgsSearchTreeNode::getValue(QgsSearchTreeValue& value, QgsSearchTreeNode* node, const QgsFieldMap& fields, const QgsAttributeMap& attributes)
|
||||||
{
|
{
|
||||||
value = node->valueAgainst(attributes);
|
value = node->valueAgainst(fields, attributes);
|
||||||
if (value.isError())
|
if (value.isError())
|
||||||
{
|
{
|
||||||
switch ((int)value.number())
|
switch ((int)value.number())
|
||||||
@ -310,7 +311,7 @@ bool QgsSearchTreeNode::getValue(QgsSearchTreeValue& value, QgsSearchTreeNode* n
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsSearchTreeValue QgsSearchTreeNode::valueAgainst(const QgsAttributeMap& attributes)
|
QgsSearchTreeValue QgsSearchTreeNode::valueAgainst(const QgsFieldMap& fields, const QgsAttributeMap& attributes)
|
||||||
{
|
{
|
||||||
QgsDebugMsgLevel("valueAgainst: " + makeSearchString(), 2);
|
QgsDebugMsgLevel("valueAgainst: " + makeSearchString(), 2);
|
||||||
|
|
||||||
@ -328,37 +329,42 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst(const QgsAttributeMap& attrib
|
|||||||
case tColumnRef:
|
case tColumnRef:
|
||||||
{
|
{
|
||||||
QgsDebugMsgLevel("column (" + mText.lower() + "): ", 2);
|
QgsDebugMsgLevel("column (" + mText.lower() + "): ", 2);
|
||||||
// find value for the column
|
// find field index for the column
|
||||||
QgsAttributeMap::const_iterator it;
|
QgsFieldMap::const_iterator it;
|
||||||
for (it = attributes.begin(); it != attributes.end(); it++)
|
for (it = fields.begin(); it != fields.end(); it++)
|
||||||
{
|
{
|
||||||
if ( it->fieldName().lower() == mText.lower()) // TODO: optimize
|
if ( it->name().lower() == mText.lower()) // TODO: optimize
|
||||||
{
|
break;
|
||||||
QString value = it->fieldValue();
|
}
|
||||||
if (it->isNumeric())
|
|
||||||
{
|
if (it == fields.end())
|
||||||
QgsDebugMsgLevel(" number: " + QString::number(value.toDouble()), 2);
|
{
|
||||||
return QgsSearchTreeValue(value.toDouble());
|
// report missing column if not found
|
||||||
}
|
QgsDebugMsgLevel("ERROR!", 2);
|
||||||
else
|
return QgsSearchTreeValue(1, mText);
|
||||||
{
|
}
|
||||||
QgsDebugMsgLevel(" text: " + EVAL_STR(value), 2);
|
|
||||||
return QgsSearchTreeValue(value);
|
// get the value
|
||||||
}
|
QVariant val = attributes[it.key()];
|
||||||
}
|
if (val.type() == QVariant::Bool || val.type() == QVariant::Int || val.type() == QVariant::Double)
|
||||||
|
{
|
||||||
|
QgsDebugMsgLevel(" number: " + QString::number(val.toDouble()), 2);
|
||||||
|
return QgsSearchTreeValue(val.toDouble());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QgsDebugMsgLevel(" text: " + EVAL_STR(val.toString()), 2);
|
||||||
|
return QgsSearchTreeValue(val.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// else report missing column
|
|
||||||
QgsDebugMsgLevel("ERROR!", 2);
|
|
||||||
return QgsSearchTreeValue(1, mText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// arithmetic operators
|
// arithmetic operators
|
||||||
case tOperator:
|
case tOperator:
|
||||||
{
|
{
|
||||||
QgsSearchTreeValue value1, value2;
|
QgsSearchTreeValue value1, value2;
|
||||||
if (!getValue(value1, mLeft, attributes)) return value1;
|
if (!getValue(value1, mLeft, fields, attributes)) return value1;
|
||||||
if (!getValue(value2, mRight, attributes)) return value2;
|
if (!getValue(value2, mRight, fields, attributes)) return value2;
|
||||||
|
|
||||||
// convert to numbers if needed
|
// convert to numbers if needed
|
||||||
double val1, val2;
|
double val1, val2;
|
||||||
|
|||||||
@ -22,14 +22,13 @@
|
|||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "qgsfeatureattribute.h"
|
#include <QVariant>
|
||||||
|
|
||||||
// forward declaration due recursive declaration
|
|
||||||
class QgsFeatureAttribute;
|
|
||||||
|
|
||||||
class QgsSearchTreeValue;
|
class QgsSearchTreeValue;
|
||||||
|
class QgsField;
|
||||||
|
|
||||||
typedef QMap<int, QgsFeatureAttribute> QgsAttributeMap;
|
typedef QMap<int, QgsField> QgsFieldMap;
|
||||||
|
typedef QMap<int, QVariant> QgsAttributeMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QgsSearchTreeNode
|
* QgsSearchTreeNode
|
||||||
@ -112,7 +111,7 @@ public:
|
|||||||
QString makeSearchString();
|
QString makeSearchString();
|
||||||
|
|
||||||
//! checks whether the node tree is valid against supplied attributes
|
//! checks whether the node tree is valid against supplied attributes
|
||||||
bool checkAgainst(const QgsAttributeMap& attributes);
|
bool checkAgainst(const QgsFieldMap& fields, const QgsAttributeMap& attributes);
|
||||||
|
|
||||||
//! checks if there were errors during evaluation
|
//! checks if there were errors during evaluation
|
||||||
bool hasError() { return (!mError.isEmpty()); }
|
bool hasError() { return (!mError.isEmpty()); }
|
||||||
@ -123,11 +122,11 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
//! returns scalar value of node
|
//! returns scalar value of node
|
||||||
QgsSearchTreeValue valueAgainst(const QgsAttributeMap& attributes);
|
QgsSearchTreeValue valueAgainst(const QgsFieldMap& fields, const QgsAttributeMap& attributes);
|
||||||
|
|
||||||
//! wrapper around valueAgainst()
|
//! wrapper around valueAgainst()
|
||||||
bool getValue(QgsSearchTreeValue& value, QgsSearchTreeNode* node,
|
bool getValue(QgsSearchTreeValue& value, QgsSearchTreeNode* node,
|
||||||
const QgsAttributeMap& attributes);
|
const QgsFieldMap& fields, const QgsAttributeMap& attributes);
|
||||||
|
|
||||||
//! strips mText when node is of string type
|
//! strips mText when node is of string type
|
||||||
void stripText();
|
void stripText();
|
||||||
|
|||||||
@ -89,9 +89,9 @@ bool QgsVectorDataProvider::changeAttributeValues(const QgsChangedAttributesMap
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsVectorDataProvider::getDefaultValue(const QString& attr, QgsFeature* f)
|
QVariant QgsVectorDataProvider::getDefaultValue(int fieldId)
|
||||||
{
|
{
|
||||||
return "";
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsVectorDataProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
|
bool QgsVectorDataProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
|
||||||
@ -221,7 +221,7 @@ int QgsVectorDataProvider::indexFromFieldName(const QString& fieldName) const
|
|||||||
|
|
||||||
for (QgsFieldMap::const_iterator it = theFields.begin(); it != theFields.end(); ++it)
|
for (QgsFieldMap::const_iterator it = theFields.begin(); it != theFields.end(); ++it)
|
||||||
{
|
{
|
||||||
if(*it == fieldName)
|
if(it->name() == fieldName)
|
||||||
{
|
{
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -217,9 +217,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
|
|||||||
virtual bool changeAttributeValues(const QgsChangedAttributesMap & attr_map);
|
virtual bool changeAttributeValues(const QgsChangedAttributesMap & 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
|
* Changes geometries of existing features
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgsspatialrefsys.h"
|
#include "qgsspatialrefsys.h"
|
||||||
#include "qgsvectorfilewriter.h"
|
#include "qgsvectorfilewriter.h"
|
||||||
@ -483,7 +482,7 @@ QString QgsVectorFileWriter::writeVectorLayerAsShapefile(QString shapefileName,
|
|||||||
|
|
||||||
QgsDebugMsg("created layer");
|
QgsDebugMsg("created layer");
|
||||||
|
|
||||||
const QgsFieldMap & attributeFields = layer->fields();
|
const QgsFieldMap & attributeFields = layer->getDataProvider()->fields();
|
||||||
|
|
||||||
// TODO: calculate the field lengths
|
// TODO: calculate the field lengths
|
||||||
//int *lengths = getFieldLengths();
|
//int *lengths = getFieldLengths();
|
||||||
@ -536,7 +535,7 @@ QString QgsVectorFileWriter::writeVectorLayerAsShapefile(QString shapefileName,
|
|||||||
|
|
||||||
for (it = attributes.begin(); it != attributes.end(); it++)
|
for (it = attributes.begin(); it != attributes.end(); it++)
|
||||||
{
|
{
|
||||||
QString value = it.value().fieldValue();
|
QString value = it.value().toString();
|
||||||
uint i = it.key();
|
uint i = it.key();
|
||||||
if (!value.isNull())
|
if (!value.isNull())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -53,7 +53,6 @@
|
|||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgscoordinatetransform.h"
|
#include "qgscoordinatetransform.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgsgeometryvertexindex.h"
|
#include "qgsgeometryvertexindex.h"
|
||||||
@ -1063,7 +1062,7 @@ QgsRect QgsVectorLayer::boundingBoxOfSelected()
|
|||||||
{
|
{
|
||||||
if(fet.geometry())
|
if(fet.geometry())
|
||||||
{
|
{
|
||||||
r=fet.boundingBox();
|
r=fet.geometry()->boundingBox();
|
||||||
retval.combineExtentWith(&r);
|
retval.combineExtentWith(&r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1196,7 +1195,7 @@ void QgsVectorLayer::updateExtents()
|
|||||||
{
|
{
|
||||||
if (fet.geometry())
|
if (fet.geometry())
|
||||||
{
|
{
|
||||||
bb = fet.boundingBox();
|
bb = fet.geometry()->boundingBox();
|
||||||
mLayerExtent.combineExtentWith(&bb);
|
mLayerExtent.combineExtentWith(&bb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1211,7 +1210,7 @@ void QgsVectorLayer::updateExtents()
|
|||||||
// also consider the not commited features
|
// also consider the not commited features
|
||||||
for(QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
|
for(QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
|
||||||
{
|
{
|
||||||
QgsRect bb = (*iter).boundingBox();
|
QgsRect bb = iter->geometry()->boundingBox();
|
||||||
mLayerExtent.combineExtentWith(&bb);
|
mLayerExtent.combineExtentWith(&bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1250,29 +1249,6 @@ void QgsVectorLayer::setSubsetString(QString subset)
|
|||||||
emit recalculateExtents();
|
emit recalculateExtents();
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsVectorLayer::fieldCount() const
|
|
||||||
{
|
|
||||||
if ( ! mDataProvider )
|
|
||||||
{
|
|
||||||
QgsLogger::warning(" QgsVectorLayer::fieldCount() invoked with null mDataProvider");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mDataProvider->fieldCount();
|
|
||||||
} // QgsVectorLayer::fieldCount
|
|
||||||
|
|
||||||
|
|
||||||
const QgsFieldMap & QgsVectorLayer::fields() const
|
|
||||||
{
|
|
||||||
if ( ! mDataProvider )
|
|
||||||
{
|
|
||||||
QgsLogger::warning(" QgsVectorLayer::fields() invoked with null mDataProvider");
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mDataProvider->fields();
|
|
||||||
} // QgsVectorLayer::fields()
|
|
||||||
|
|
||||||
|
|
||||||
bool QgsVectorLayer::addFeature(QgsFeature& f, bool alsoUpdateExtent)
|
bool QgsVectorLayer::addFeature(QgsFeature& f, bool alsoUpdateExtent)
|
||||||
{
|
{
|
||||||
@ -1298,18 +1274,6 @@ bool QgsVectorLayer::addFeature(QgsFeature& f, bool alsoUpdateExtent)
|
|||||||
|
|
||||||
QgsDebugMsg("Assigned feature id " + QString::number(addedIdLowWaterMark));
|
QgsDebugMsg("Assigned feature id " + QString::number(addedIdLowWaterMark));
|
||||||
|
|
||||||
// Change the fields on the feature to suit the destination
|
|
||||||
// in the paste transformation transfer.
|
|
||||||
// TODO: Could be done more efficiently for large pastes
|
|
||||||
QgsFieldNameMap fields = f.fields();
|
|
||||||
|
|
||||||
QgsDebugMsg("QgsVectorLayer::addFeature: about to traverse fields.");
|
|
||||||
|
|
||||||
for (QgsFieldNameMap::iterator it = fields.begin(); it != fields.end(); ++it)
|
|
||||||
{
|
|
||||||
QgsDebugMsg("QgsVectorLayer::addFeature: inspecting field '" + *it + "'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force a feature ID (to keep other functions in QGIS happy,
|
// Force a feature ID (to keep other functions in QGIS happy,
|
||||||
// providers will use their own new feature ID when we commit the new feature)
|
// providers will use their own new feature ID when we commit the new feature)
|
||||||
// and add to the known added features.
|
// and add to the known added features.
|
||||||
@ -1417,12 +1381,6 @@ bool QgsVectorLayer::deleteVertexAt(int atFeatureId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString QgsVectorLayer::getDefaultValue(const QString& attr,
|
|
||||||
QgsFeature* f)
|
|
||||||
{
|
|
||||||
return mDataProvider->getDefaultValue(attr, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QgsVectorLayer::deleteSelectedFeatures()
|
bool QgsVectorLayer::deleteSelectedFeatures()
|
||||||
{
|
{
|
||||||
if(!(mDataProvider->capabilities() & QgsVectorDataProvider::DeleteFeatures))
|
if(!(mDataProvider->capabilities() & QgsVectorDataProvider::DeleteFeatures))
|
||||||
|
|||||||
@ -210,16 +210,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual QString subsetString();
|
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 QgsFieldMap & fields() const;
|
|
||||||
|
|
||||||
/** Adds a feature
|
/** Adds a feature
|
||||||
@param lastFeatureInBatch If True, will also go to the effort of e.g. updating the extents.
|
@param lastFeatureInBatch If True, will also go to the effort of e.g. updating the extents.
|
||||||
@ -253,8 +243,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool deleteSelectedFeatures();
|
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 */
|
/** Set labels on */
|
||||||
void setLabelOn( bool on );
|
void setLabelOn( bool on );
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
/* $Id: qgscontinuouscolorrenderer.cpp 5371 2006-04-25 01:52:13Z wonder $ */
|
/* $Id: qgscontinuouscolorrenderer.cpp 5371 2006-04-25 01:52:13Z wonder $ */
|
||||||
|
|
||||||
#include "qgscontinuouscolorrenderer.h"
|
#include "qgscontinuouscolorrenderer.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsmarkercatalogue.h"
|
#include "qgsmarkercatalogue.h"
|
||||||
#include "qgssymbol.h"
|
#include "qgssymbol.h"
|
||||||
#include "qgssymbologyutils.h"
|
#include "qgssymbologyutils.h"
|
||||||
@ -80,7 +79,7 @@ void QgsContinuousColorRenderer::renderFeature(QPainter * p, QgsFeature & f, QIm
|
|||||||
{
|
{
|
||||||
//first find out the value for the classification attribute
|
//first find out the value for the classification attribute
|
||||||
const QgsAttributeMap& attrs = f.attributeMap();
|
const QgsAttributeMap& attrs = f.attributeMap();
|
||||||
double fvalue = attrs[mClassificationField].fieldValue().toDouble();
|
double fvalue = attrs[mClassificationField].toDouble();
|
||||||
|
|
||||||
//double fvalue = vec[mClassificationField].fieldValue().toDouble();
|
//double fvalue = vec[mClassificationField].fieldValue().toDouble();
|
||||||
double minvalue = mMinimumSymbol->lowerValue().toDouble();
|
double minvalue = mMinimumSymbol->lowerValue().toDouble();
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
#include "qgis.h"
|
#include "qgis.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsgraduatedsymbolrenderer.h"
|
#include "qgsgraduatedsymbolrenderer.h"
|
||||||
#include "qgssymbol.h"
|
#include "qgssymbol.h"
|
||||||
#include "qgssymbologyutils.h"
|
#include "qgssymbologyutils.h"
|
||||||
@ -148,7 +147,7 @@ QgsSymbol* QgsGraduatedSymbolRenderer::symbolForFeature(const QgsFeature* f)
|
|||||||
{
|
{
|
||||||
//first find out the value for the classification attribute
|
//first find out the value for the classification attribute
|
||||||
const QgsAttributeMap& attrs = f->attributeMap();
|
const QgsAttributeMap& attrs = f->attributeMap();
|
||||||
double value = attrs[mClassificationField].fieldValue().toDouble();
|
double value = attrs[mClassificationField].toDouble();
|
||||||
|
|
||||||
std::list < QgsSymbol* >::iterator it;
|
std::list < QgsSymbol* >::iterator it;
|
||||||
//find the first render item which contains the feature
|
//find the first render item which contains the feature
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
/* $Id: qgsuniquevaluerenderer.cpp 5371 2006-04-25 01:52:13Z wonder $ */
|
/* $Id: qgsuniquevaluerenderer.cpp 5371 2006-04-25 01:52:13Z wonder $ */
|
||||||
|
|
||||||
#include "qgsuniquevaluerenderer.h"
|
#include "qgsuniquevaluerenderer.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
#include "qgssymbol.h"
|
#include "qgssymbol.h"
|
||||||
@ -154,7 +153,7 @@ QgsSymbol* QgsUniqueValueRenderer::symbolForFeature(const QgsFeature* f)
|
|||||||
{
|
{
|
||||||
//first find out the value
|
//first find out the value
|
||||||
const QgsAttributeMap& attrs = f->attributeMap();
|
const QgsAttributeMap& attrs = f->attributeMap();
|
||||||
QString value = attrs[mClassificationField].fieldValue();
|
QString value = attrs[mClassificationField].toString();
|
||||||
|
|
||||||
std::map<QString,QgsSymbol*>::iterator it=mSymbols.find(value);
|
std::map<QString,QgsSymbol*>::iterator it=mSymbols.find(value);
|
||||||
if(it == mSymbols.end())
|
if(it == mSymbols.end())
|
||||||
|
|||||||
@ -140,7 +140,7 @@ void QgsPgGeoprocessing::buffer()
|
|||||||
QgsFieldMap flds = dp->fields();
|
QgsFieldMap flds = dp->fields();
|
||||||
for (QgsFieldMap::iterator it = flds.begin(); it != flds.end(); ++it) {
|
for (QgsFieldMap::iterator it = flds.begin(); it != flds.end(); ++it) {
|
||||||
// check the field type -- if its int we can use it
|
// check the field type -- if its int we can use it
|
||||||
if (it->type().find("int") > -1) {
|
if (it->typeName().find("int") > -1) {
|
||||||
bb->addFieldItem(it->name());
|
bb->addFieldItem(it->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,6 @@
|
|||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsmaptopixel.h"
|
#include "qgsmaptopixel.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <grass/gis.h>
|
#include <grass/gis.h>
|
||||||
|
|||||||
@ -55,7 +55,6 @@
|
|||||||
#include "qgsmaptoolpan.h"
|
#include "qgsmaptoolpan.h"
|
||||||
#include "qgsmaptopixel.h"
|
#include "qgsmaptopixel.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsvertexmarker.h"
|
#include "qgsvertexmarker.h"
|
||||||
#include "qgsrubberband.h"
|
#include "qgsrubberband.h"
|
||||||
#include "qgsproject.h"
|
#include "qgsproject.h"
|
||||||
@ -576,7 +575,7 @@ void QgsGrassEdit::setAttributeTable ( int field )
|
|||||||
ti->setEnabled( false );
|
ti->setEnabled( false );
|
||||||
mAttributeTable->setItem ( c, 0, ti );
|
mAttributeTable->setItem ( c, 0, ti );
|
||||||
|
|
||||||
ti = new Q3TableItem( mAttributeTable, Q3TableItem::Never, col.type() );
|
ti = new Q3TableItem( mAttributeTable, Q3TableItem::Never, col.typeName() );
|
||||||
ti->setEnabled( false );
|
ti->setEnabled( false );
|
||||||
mAttributeTable->setItem ( c, 1, ti );
|
mAttributeTable->setItem ( c, 1, ti );
|
||||||
|
|
||||||
@ -1081,9 +1080,9 @@ int QgsGrassEdit::writeLine ( int type, struct line_pnts *Points )
|
|||||||
QString *key = mProvider->key ( field );
|
QString *key = mProvider->key ( field );
|
||||||
|
|
||||||
if ( !key->isEmpty() ) { // Database link defined
|
if ( !key->isEmpty() ) { // Database link defined
|
||||||
std::vector<QgsFeatureAttribute> *atts = mProvider->attributes ( field, cat );
|
QgsAttributeMap *atts = mProvider->attributes ( field, cat );
|
||||||
|
|
||||||
if ( atts->size() == 0 ) { // Nothing selected
|
if ( atts->count() == 0 ) { // Nothing selected
|
||||||
QString *error = mProvider->insertAttributes ( field, cat );
|
QString *error = mProvider->insertAttributes ( field, cat );
|
||||||
|
|
||||||
if ( !error->isEmpty() ) {
|
if ( !error->isEmpty() ) {
|
||||||
@ -1398,26 +1397,25 @@ void QgsGrassEdit::addAttributes ( int field, int cat )
|
|||||||
str.setNum( field );
|
str.setNum( field );
|
||||||
QMessageBox::warning( 0, tr("Warning"), tr("Cannot describe table for field ") + str );
|
QMessageBox::warning( 0, tr("Warning"), tr("Cannot describe table for field ") + str );
|
||||||
} else {
|
} else {
|
||||||
std::vector<QgsFeatureAttribute> *atts =
|
QgsAttributeMap *atts = mProvider->attributes ( field, cat );
|
||||||
mProvider->attributes ( field, cat );
|
|
||||||
|
|
||||||
if ( atts->size() == 0 ) { // cannot select attributes
|
if ( atts->size() == 0 ) { // cannot select attributes
|
||||||
mAttributes->addTextRow ( tab, "WARNING: ATTRIBUTES MISSING" );
|
mAttributes->addTextRow ( tab, "WARNING: ATTRIBUTES MISSING" );
|
||||||
} else {
|
} else {
|
||||||
int size;
|
int size;
|
||||||
if ( atts->size() < cols->size() )
|
if ( atts->size() < (int) cols->size() )
|
||||||
size = atts->size();
|
size = atts->size();
|
||||||
else
|
else
|
||||||
size = cols->size();
|
size = cols->size();
|
||||||
|
|
||||||
for ( unsigned int j = 0; j < cols->size(); j++ ) {
|
for ( unsigned int j = 0; j < cols->size(); j++ ) {
|
||||||
QgsField col = (*cols)[j];
|
QgsField col = (*cols)[j];
|
||||||
QgsFeatureAttribute att = (*atts)[j];
|
QVariant att = (*atts)[j];
|
||||||
std::cerr << " name = " << col.name().toLocal8Bit().data() << std::endl;
|
std::cerr << " name = " << col.name().toLocal8Bit().data() << std::endl;
|
||||||
|
|
||||||
if ( col.name() != *key ) {
|
if ( col.name() != *key ) {
|
||||||
std::cerr << " value = " << att.fieldValue().toLocal8Bit().data() << std::endl;
|
std::cerr << " value = " << att.toString().toLocal8Bit().data() << std::endl;
|
||||||
mAttributes->addAttribute ( tab, col.name(), att.fieldValue(), col.type() );
|
mAttributes->addAttribute ( tab, col.name(), att.toString(), col.typeName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1448,7 +1446,7 @@ void QgsGrassEdit::addCat ( int line )
|
|||||||
QString *key = mProvider->key ( field );
|
QString *key = mProvider->key ( field );
|
||||||
|
|
||||||
if ( !key->isEmpty() ) { // Database link defined
|
if ( !key->isEmpty() ) { // Database link defined
|
||||||
std::vector<QgsFeatureAttribute> *atts = mProvider->attributes ( field, cat );
|
QgsAttributeMap *atts = mProvider->attributes ( field, cat );
|
||||||
|
|
||||||
if ( atts->size() == 0 ) { // Nothing selected
|
if ( atts->size() == 0 ) { // Nothing selected
|
||||||
QString *error = mProvider->insertAttributes ( field, cat );
|
QString *error = mProvider->insertAttributes ( field, cat );
|
||||||
|
|||||||
@ -52,7 +52,6 @@
|
|||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <grass/gis.h>
|
#include <grass/gis.h>
|
||||||
|
|||||||
@ -35,7 +35,6 @@
|
|||||||
|
|
||||||
#include "qgis.h"
|
#include "qgis.h"
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsfeatureattribute.h" // TODO: remove - this is only for qgsgrassprovider.h
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <grass/gis.h>
|
#include <grass/gis.h>
|
||||||
|
|||||||
@ -78,7 +78,6 @@
|
|||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <grass/gis.h>
|
#include <grass/gis.h>
|
||||||
@ -2328,7 +2327,7 @@ void QgsGrassModuleInput::updateQgisLayers()
|
|||||||
mVectorLayerNames.push_back ( grassLayer );
|
mVectorLayerNames.push_back ( grassLayer );
|
||||||
|
|
||||||
// convert from QgsFieldMap to std::vector<QgsField>
|
// convert from QgsFieldMap to std::vector<QgsField>
|
||||||
QgsFieldMap flds = vector->fields();
|
QgsFieldMap flds = vector->getDataProvider()->fields();
|
||||||
std::vector<QgsField> fields;
|
std::vector<QgsField> fields;
|
||||||
for (QgsFieldMap::iterator it = flds.begin(); it != flds.end(); ++it)
|
for (QgsFieldMap::iterator it = flds.begin(); it != flds.end(); ++it)
|
||||||
fields.push_back(it.value());
|
fields.push_back(it.value());
|
||||||
@ -2915,7 +2914,7 @@ void QgsGrassModuleSelection::updateSelection()
|
|||||||
if ( attr.size() > keyField )
|
if ( attr.size() > keyField )
|
||||||
{
|
{
|
||||||
if ( i > 0 ) cats.append( "," );
|
if ( i > 0 ) cats.append( "," );
|
||||||
cats.append( attr[keyField].fieldValue() );
|
cats.append( attr[keyField].toString() );
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
delete feature;
|
delete feature;
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
#include "qgsmaplayer.h"
|
#include "qgsmaplayer.h"
|
||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsproviderregistry.h"
|
#include "qgsproviderregistry.h"
|
||||||
#include <qgsrasterlayer.h>
|
#include <qgsrasterlayer.h>
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,6 @@
|
|||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <grass/gis.h>
|
#include <grass/gis.h>
|
||||||
|
|||||||
@ -35,7 +35,6 @@
|
|||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsmessageoutput.h"
|
#include "qgsmessageoutput.h"
|
||||||
#include "qgsrect.h"
|
#include "qgsrect.h"
|
||||||
@ -145,7 +144,7 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString uri)
|
|||||||
QString field = *it;
|
QString field = *it;
|
||||||
if (field.length() > 0)
|
if (field.length() > 0)
|
||||||
{
|
{
|
||||||
attributeFields[fieldPos] = QgsField(*it, "Text");
|
attributeFields[fieldPos] = QgsField(*it, QVariant::String, "Text");
|
||||||
fieldPositions[*it] = fieldPos++;
|
fieldPositions[*it] = fieldPos++;
|
||||||
// check to see if this field matches either the x or y field
|
// check to see if this field matches either the x or y field
|
||||||
if (mXField == *it)
|
if (mXField == *it)
|
||||||
@ -426,7 +425,7 @@ QgsDelimitedTextProvider::getNextFeature_( QgsFeature & feature,
|
|||||||
i != desiredAttributes.end();
|
i != desiredAttributes.end();
|
||||||
++i )
|
++i )
|
||||||
{
|
{
|
||||||
feature.addAttribute(*i, QgsFeatureAttribute(attributeFields[*i].name(), tokens[*i]));
|
feature.addAttribute(*i, QVariant(tokens[*i]) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,7 +586,7 @@ void QgsDelimitedTextProvider::fillMinMaxCash()
|
|||||||
{
|
{
|
||||||
for (uint i = 0; i < fieldCount(); i++)
|
for (uint i = 0; i < fieldCount(); i++)
|
||||||
{
|
{
|
||||||
double value = (f.attributeMap())[i].fieldValue().toDouble();
|
double value = (f.attributeMap())[i].toDouble();
|
||||||
if (value < mMinMaxCache[i][0])
|
if (value < mMinMaxCache[i][0])
|
||||||
{
|
{
|
||||||
mMinMaxCache[i][0] = value;
|
mMinMaxCache[i][0] = value;
|
||||||
|
|||||||
@ -36,7 +36,6 @@
|
|||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgsspatialrefsys.h"
|
#include "qgsspatialrefsys.h"
|
||||||
@ -84,19 +83,19 @@ QgsGPXProvider::QgsGPXProvider(QString uri) :
|
|||||||
(typeStr == "route" ? RouteType : TrackType));
|
(typeStr == "route" ? RouteType : TrackType));
|
||||||
|
|
||||||
// set up the attributes and the geometry type depending on the feature type
|
// set up the attributes and the geometry type depending on the feature type
|
||||||
attributeFields[NameAttr] = QgsField(attr[NameAttr], "text");
|
attributeFields[NameAttr] = QgsField(attr[NameAttr], QVariant::String, "text");
|
||||||
if (mFeatureType == WaypointType) {
|
if (mFeatureType == WaypointType) {
|
||||||
attributeFields[EleAttr] = QgsField(attr[EleAttr], "text");
|
attributeFields[EleAttr] = QgsField(attr[EleAttr], QVariant::Double, "double");
|
||||||
attributeFields[SymAttr] = QgsField(attr[SymAttr], "text");
|
attributeFields[SymAttr] = QgsField(attr[SymAttr], QVariant::String, "text");
|
||||||
}
|
}
|
||||||
else if (mFeatureType == RouteType || mFeatureType == TrackType) {
|
else if (mFeatureType == RouteType || mFeatureType == TrackType) {
|
||||||
attributeFields[NumAttr] = QgsField(attr[NumAttr], "text");
|
attributeFields[NumAttr] = QgsField(attr[NumAttr], QVariant::Int, "int");
|
||||||
}
|
}
|
||||||
attributeFields[CmtAttr] = QgsField(attr[CmtAttr], "text");
|
attributeFields[CmtAttr] = QgsField(attr[CmtAttr], QVariant::String, "text");
|
||||||
attributeFields[DscAttr] = QgsField(attr[DscAttr], "text");
|
attributeFields[DscAttr] = QgsField(attr[DscAttr], QVariant::String, "text");
|
||||||
attributeFields[SrcAttr] = QgsField(attr[SrcAttr], "text");
|
attributeFields[SrcAttr] = QgsField(attr[SrcAttr], QVariant::String, "text");
|
||||||
attributeFields[URLAttr] = QgsField(attr[URLAttr], "text");
|
attributeFields[URLAttr] = QgsField(attr[URLAttr], QVariant::String, "text");
|
||||||
attributeFields[URLNameAttr] = QgsField(attr[URLNameAttr], "text");
|
attributeFields[URLNameAttr] = QgsField(attr[URLNameAttr], QVariant::String, "text");
|
||||||
mFileName = uri.left(fileNameEnd);
|
mFileName = uri.left(fileNameEnd);
|
||||||
|
|
||||||
// set the selection rectangle to null
|
// set the selection rectangle to null
|
||||||
@ -174,31 +173,31 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature,
|
|||||||
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
|
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
|
||||||
switch (*iter) {
|
switch (*iter) {
|
||||||
case 0:
|
case 0:
|
||||||
feature.addAttribute(0, QgsFeatureAttribute(attr[NameAttr], wpt->name));
|
feature.addAttribute(0, QVariant(wpt->name));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (wpt->ele == -std::numeric_limits<double>::max())
|
if (wpt->ele == -std::numeric_limits<double>::max())
|
||||||
feature.addAttribute(1, QgsFeatureAttribute(attr[EleAttr], ""));
|
feature.addAttribute(1, QVariant());
|
||||||
else
|
else
|
||||||
feature.addAttribute(1, QgsFeatureAttribute(attr[EleAttr], QString("%1").arg(wpt->ele)));
|
feature.addAttribute(1, QVariant(wpt->ele));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
feature.addAttribute(2, QgsFeatureAttribute(attr[SymAttr], wpt->sym));
|
feature.addAttribute(2, QVariant(wpt->sym));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
feature.addAttribute(3, QgsFeatureAttribute(attr[CmtAttr], wpt->cmt));
|
feature.addAttribute(3, QVariant(wpt->cmt));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
feature.addAttribute(4, QgsFeatureAttribute(attr[DscAttr], wpt->desc));
|
feature.addAttribute(4, QVariant(wpt->desc));
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
feature.addAttribute(5, QgsFeatureAttribute(attr[SrcAttr], wpt->src));
|
feature.addAttribute(5, QVariant(wpt->src));
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
feature.addAttribute(6, QgsFeatureAttribute(attr[URLAttr], wpt->url));
|
feature.addAttribute(6, QVariant(wpt->url));
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
feature.addAttribute(7, QgsFeatureAttribute(attr[URLNameAttr], wpt->urlname));
|
feature.addAttribute(7, QVariant(wpt->urlname));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,23 +240,23 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature,
|
|||||||
// add attributes if they are wanted
|
// add attributes if they are wanted
|
||||||
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
|
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
|
||||||
if (*iter == 0)
|
if (*iter == 0)
|
||||||
feature.addAttribute(0, QgsFeatureAttribute(attr[NameAttr], rte->name));
|
feature.addAttribute(0, QVariant(rte->name));
|
||||||
else if (*iter == 1) {
|
else if (*iter == 1) {
|
||||||
if (rte->number == std::numeric_limits<int>::max())
|
if (rte->number == std::numeric_limits<int>::max())
|
||||||
feature.addAttribute(1, QgsFeatureAttribute(attr[NumAttr], ""));
|
feature.addAttribute(1, QVariant());
|
||||||
else
|
else
|
||||||
feature.addAttribute(1, QgsFeatureAttribute(attr[NumAttr], QString("%1").arg(rte->number)));
|
feature.addAttribute(1, QVariant(rte->number));
|
||||||
}
|
}
|
||||||
else if (*iter == 2)
|
else if (*iter == 2)
|
||||||
feature.addAttribute(2, QgsFeatureAttribute(attr[CmtAttr], rte->cmt));
|
feature.addAttribute(2, QVariant(rte->cmt));
|
||||||
else if (*iter == 3)
|
else if (*iter == 3)
|
||||||
feature.addAttribute(3, QgsFeatureAttribute(attr[DscAttr], rte->desc));
|
feature.addAttribute(3, QVariant(rte->desc));
|
||||||
else if (*iter == 4)
|
else if (*iter == 4)
|
||||||
feature.addAttribute(4, QgsFeatureAttribute(attr[SrcAttr], rte->src));
|
feature.addAttribute(4, QVariant(rte->src));
|
||||||
else if (*iter == 5)
|
else if (*iter == 5)
|
||||||
feature.addAttribute(5, QgsFeatureAttribute(attr[URLAttr], rte->url));
|
feature.addAttribute(5, QVariant(rte->url));
|
||||||
else if (*iter == 6)
|
else if (*iter == 6)
|
||||||
feature.addAttribute(6, QgsFeatureAttribute(attr[URLNameAttr], rte->urlname));
|
feature.addAttribute(6, QVariant(rte->urlname));
|
||||||
}
|
}
|
||||||
|
|
||||||
++mRteIter;
|
++mRteIter;
|
||||||
@ -300,23 +299,23 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature,
|
|||||||
// add attributes if they are wanted
|
// add attributes if they are wanted
|
||||||
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
|
for (iter = attlist.begin(); iter != attlist.end(); ++iter) {
|
||||||
if (*iter == 0)
|
if (*iter == 0)
|
||||||
feature.addAttribute(0, QgsFeatureAttribute(attr[NameAttr], trk->name));
|
feature.addAttribute(0, QVariant(trk->name));
|
||||||
else if (*iter == 1) {
|
else if (*iter == 1) {
|
||||||
if (trk->number == std::numeric_limits<int>::max())
|
if (trk->number == std::numeric_limits<int>::max())
|
||||||
feature.addAttribute(1, QgsFeatureAttribute(attr[NumAttr], ""));
|
feature.addAttribute(1, QVariant());
|
||||||
else
|
else
|
||||||
feature.addAttribute(1, QgsFeatureAttribute(attr[NumAttr], QString("%1").arg(trk->number)));
|
feature.addAttribute(1, QVariant(trk->number));
|
||||||
}
|
}
|
||||||
else if (*iter == 2)
|
else if (*iter == 2)
|
||||||
feature.addAttribute(2, QgsFeatureAttribute(attr[CmtAttr], trk->cmt));
|
feature.addAttribute(2, QVariant(trk->cmt));
|
||||||
else if (*iter == 3)
|
else if (*iter == 3)
|
||||||
feature.addAttribute(3, QgsFeatureAttribute(attr[DscAttr], trk->desc));
|
feature.addAttribute(3, QVariant(trk->desc));
|
||||||
else if (*iter == 4)
|
else if (*iter == 4)
|
||||||
feature.addAttribute(4, QgsFeatureAttribute(attr[SrcAttr], trk->src));
|
feature.addAttribute(4, QVariant(trk->src));
|
||||||
else if (*iter == 5)
|
else if (*iter == 5)
|
||||||
feature.addAttribute(5, QgsFeatureAttribute(attr[URLAttr], trk->url));
|
feature.addAttribute(5, QVariant(trk->url));
|
||||||
else if (*iter == 6)
|
else if (*iter == 6)
|
||||||
feature.addAttribute(6, QgsFeatureAttribute(attr[URLNameAttr], trk->urlname));
|
feature.addAttribute(6, QVariant(trk->urlname));
|
||||||
}
|
}
|
||||||
|
|
||||||
++mTrkIter;
|
++mTrkIter;
|
||||||
@ -449,7 +448,7 @@ void QgsGPXProvider::fillMinMaxCash()
|
|||||||
getNextFeature(f, true);
|
getNextFeature(f, true);
|
||||||
do {
|
do {
|
||||||
for(uint i=0;i<fieldCount();i++) {
|
for(uint i=0;i<fieldCount();i++) {
|
||||||
double value=(f.attributeMap())[i].fieldValue().toDouble();
|
double value=(f.attributeMap())[i].toDouble();
|
||||||
if(value<mMinMaxCache[i][0]) {
|
if(value<mMinMaxCache[i][0]) {
|
||||||
mMinMaxCache[i][0]=value;
|
mMinMaxCache[i][0]=value;
|
||||||
}
|
}
|
||||||
@ -497,6 +496,7 @@ bool QgsGPXProvider::addFeature(QgsFeature& f)
|
|||||||
bool success = false;
|
bool success = false;
|
||||||
GPSObject* obj = NULL;
|
GPSObject* obj = NULL;
|
||||||
const QgsAttributeMap& attrs(f.attributeMap());
|
const QgsAttributeMap& attrs(f.attributeMap());
|
||||||
|
QgsAttributeMap::const_iterator it;
|
||||||
|
|
||||||
// is it a waypoint?
|
// is it a waypoint?
|
||||||
if (mFeatureType == WaypointType && geo != NULL && wkbType == QGis::WKBPoint) {
|
if (mFeatureType == WaypointType && geo != NULL && wkbType == QGis::WKBPoint) {
|
||||||
@ -507,15 +507,15 @@ bool QgsGPXProvider::addFeature(QgsFeature& f)
|
|||||||
std::memcpy(&wpt.lat, geo+13, sizeof(double));
|
std::memcpy(&wpt.lat, geo+13, sizeof(double));
|
||||||
|
|
||||||
// add waypoint-specific attributes
|
// add waypoint-specific attributes
|
||||||
for (int i = 0; i < attrs.size(); ++i) {
|
for (it = attrs.begin(); it != attrs.end(); ++it) {
|
||||||
if (attrs[i].fieldName() == attr[EleAttr]) {
|
if (attributeFields[it.key()].name() == attr[EleAttr]) {
|
||||||
bool eleIsOK;
|
bool eleIsOK;
|
||||||
double ele = attrs[i].fieldValue().toDouble(&eleIsOK);
|
double ele = it->toDouble(&eleIsOK);
|
||||||
if (eleIsOK)
|
if (eleIsOK)
|
||||||
wpt.ele = ele;
|
wpt.ele = ele;
|
||||||
}
|
}
|
||||||
else if (attrs[i].fieldName() == attr[SymAttr]) {
|
else if (attributeFields[it.key()].name() == attr[SymAttr]) {
|
||||||
wpt.sym = attrs[i].fieldValue();
|
wpt.sym = it->toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,10 +553,10 @@ bool QgsGPXProvider::addFeature(QgsFeature& f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add route-specific attributes
|
// add route-specific attributes
|
||||||
for (int i = 0; i < attrs.size(); ++i) {
|
for (it = attrs.begin(); it != attrs.end(); ++it) {
|
||||||
if (attrs[i].fieldName() == attr[NumAttr]) {
|
if (attributeFields[it.key()].name() == attr[NumAttr]) {
|
||||||
bool numIsOK;
|
bool numIsOK;
|
||||||
long num = attrs[i].fieldValue().toLong(&numIsOK);
|
long num = it->toInt(&numIsOK);
|
||||||
if (numIsOK)
|
if (numIsOK)
|
||||||
rte.number = num;
|
rte.number = num;
|
||||||
}
|
}
|
||||||
@ -597,10 +597,10 @@ bool QgsGPXProvider::addFeature(QgsFeature& f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add track-specific attributes
|
// add track-specific attributes
|
||||||
for (int i = 0; i < attrs.size(); ++i) {
|
for (it = attrs.begin(); it != attrs.end(); ++it) {
|
||||||
if (attrs[i].fieldName() == attr[NumAttr]) {
|
if (attributeFields[it.key()].name() == attr[NumAttr]) {
|
||||||
bool numIsOK;
|
bool numIsOK;
|
||||||
long num = attrs[i].fieldValue().toLong(&numIsOK);
|
long num = it->toInt(&numIsOK);
|
||||||
if (numIsOK)
|
if (numIsOK)
|
||||||
trk.number = num;
|
trk.number = num;
|
||||||
}
|
}
|
||||||
@ -615,24 +615,25 @@ bool QgsGPXProvider::addFeature(QgsFeature& f)
|
|||||||
|
|
||||||
// add common attributes
|
// add common attributes
|
||||||
if (obj) {
|
if (obj) {
|
||||||
for (int i = 0; i < attrs.size(); ++i) {
|
for (it = attrs.begin(); it != attrs.end(); ++it) {
|
||||||
if (attrs[i].fieldName() == attr[NameAttr]) {
|
QString fieldName = attributeFields[it.key()].name();
|
||||||
obj->name = attrs[i].fieldValue();
|
if (fieldName == attr[NameAttr]) {
|
||||||
|
obj->name = it->toString();
|
||||||
}
|
}
|
||||||
else if (attrs[i].fieldName() == attr[CmtAttr]) {
|
else if (fieldName == attr[CmtAttr]) {
|
||||||
obj->cmt = attrs[i].fieldValue();
|
obj->cmt = it->toString();
|
||||||
}
|
}
|
||||||
else if (attrs[i].fieldName() == attr[DscAttr]) {
|
else if (fieldName == attr[DscAttr]) {
|
||||||
obj->desc = attrs[i].fieldValue();
|
obj->desc = it->toString();
|
||||||
}
|
}
|
||||||
else if (attrs[i].fieldName() == attr[SrcAttr]) {
|
else if (fieldName == attr[SrcAttr]) {
|
||||||
obj->src = attrs[i].fieldValue();
|
obj->src = it->toString();
|
||||||
}
|
}
|
||||||
else if (attrs[i].fieldName() == attr[URLAttr]) {
|
else if (fieldName == attr[URLAttr]) {
|
||||||
obj->url = attrs[i].fieldValue();
|
obj->url = it->toString();
|
||||||
}
|
}
|
||||||
else if (attrs[i].fieldName() == attr[URLNameAttr]) {
|
else if (fieldName == attr[URLNameAttr]) {
|
||||||
obj->urlname = attrs[i].fieldValue();
|
obj->urlname = it->toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -707,27 +708,27 @@ void QgsGPXProvider::changeAttributeValues(GPSObject& obj, const QgsAttributeMap
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
if (attrs.contains(NameAttr))
|
if (attrs.contains(NameAttr))
|
||||||
obj.name = attrs[NameAttr].fieldValue();
|
obj.name = attrs[NameAttr].toString();
|
||||||
if (attrs.contains(CmtAttr))
|
if (attrs.contains(CmtAttr))
|
||||||
obj.cmt = attrs[CmtAttr].fieldValue();
|
obj.cmt = attrs[CmtAttr].toString();
|
||||||
if (attrs.contains(DscAttr))
|
if (attrs.contains(DscAttr))
|
||||||
obj.desc = attrs[DscAttr].fieldValue();
|
obj.desc = attrs[DscAttr].toString();
|
||||||
if (attrs.contains(SrcAttr))
|
if (attrs.contains(SrcAttr))
|
||||||
obj.src = attrs[SrcAttr].fieldValue();
|
obj.src = attrs[SrcAttr].toString();
|
||||||
if (attrs.contains(URLAttr))
|
if (attrs.contains(URLAttr))
|
||||||
obj.url = attrs[URLAttr].fieldValue();
|
obj.url = attrs[URLAttr].toString();
|
||||||
if (attrs.contains(URLNameAttr))
|
if (attrs.contains(URLNameAttr))
|
||||||
obj.urlname = attrs[URLNameAttr].fieldValue();
|
obj.urlname = attrs[URLNameAttr].toString();
|
||||||
|
|
||||||
// waypoint-specific attributes
|
// waypoint-specific attributes
|
||||||
Waypoint* wpt = dynamic_cast<Waypoint*>(&obj);
|
Waypoint* wpt = dynamic_cast<Waypoint*>(&obj);
|
||||||
if (wpt != NULL) {
|
if (wpt != NULL) {
|
||||||
if (attrs.contains(SymAttr))
|
if (attrs.contains(SymAttr))
|
||||||
wpt->sym = attrs[SymAttr].fieldValue();
|
wpt->sym = attrs[SymAttr].toString();
|
||||||
if (attrs.contains(EleAttr))
|
if (attrs.contains(EleAttr))
|
||||||
{
|
{
|
||||||
bool eleIsOK;
|
bool eleIsOK;
|
||||||
double ele = attrs[EleAttr].fieldValue().toDouble(&eleIsOK);
|
double ele = attrs[EleAttr].toDouble(&eleIsOK);
|
||||||
if (eleIsOK)
|
if (eleIsOK)
|
||||||
wpt->ele = ele;
|
wpt->ele = ele;
|
||||||
}
|
}
|
||||||
@ -739,7 +740,7 @@ void QgsGPXProvider::changeAttributeValues(GPSObject& obj, const QgsAttributeMap
|
|||||||
if (attrs.contains(NumAttr))
|
if (attrs.contains(NumAttr))
|
||||||
{
|
{
|
||||||
bool eleIsOK;
|
bool eleIsOK;
|
||||||
double ele = attrs[NumAttr].fieldValue().toDouble(&eleIsOK);
|
double ele = attrs[NumAttr].toDouble(&eleIsOK);
|
||||||
if (eleIsOK)
|
if (eleIsOK)
|
||||||
wpt->ele = ele;
|
wpt->ele = ele;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,10 +31,8 @@
|
|||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsrect.h"
|
#include "qgsrect.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsspatialrefsys.h"
|
#include "qgsspatialrefsys.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -739,6 +737,7 @@ void QgsGrassProvider::loadAttributes ( GLAYER &layer )
|
|||||||
dbColumn *column = db_get_table_column (databaseTable, i);
|
dbColumn *column = db_get_table_column (databaseTable, i);
|
||||||
|
|
||||||
int ctype = db_sqltype_to_Ctype ( db_get_column_sqltype(column) );
|
int ctype = db_sqltype_to_Ctype ( db_get_column_sqltype(column) );
|
||||||
|
QVariant::Type qtype;
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
std::cerr << "column = " << db_get_column_name(column)
|
std::cerr << "column = " << db_get_column_name(column)
|
||||||
<< " ctype = " << ctype << std::endl;
|
<< " ctype = " << ctype << std::endl;
|
||||||
@ -748,18 +747,22 @@ void QgsGrassProvider::loadAttributes ( GLAYER &layer )
|
|||||||
switch ( ctype ) {
|
switch ( ctype ) {
|
||||||
case DB_C_TYPE_INT:
|
case DB_C_TYPE_INT:
|
||||||
ctypeStr = "integer";
|
ctypeStr = "integer";
|
||||||
|
qtype = QVariant::Int;
|
||||||
break;
|
break;
|
||||||
case DB_C_TYPE_DOUBLE:
|
case DB_C_TYPE_DOUBLE:
|
||||||
ctypeStr = "double";
|
ctypeStr = "double";
|
||||||
|
qtype = QVariant::Double;
|
||||||
break;
|
break;
|
||||||
case DB_C_TYPE_STRING:
|
case DB_C_TYPE_STRING:
|
||||||
ctypeStr = "string";
|
ctypeStr = "string";
|
||||||
|
qtype = QVariant::String;
|
||||||
break;
|
break;
|
||||||
case DB_C_TYPE_DATETIME:
|
case DB_C_TYPE_DATETIME:
|
||||||
ctypeStr = "datetime";
|
ctypeStr = "datetime";
|
||||||
|
qtype = QVariant::String;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
layer.fields[i] = QgsField( db_get_column_name(column), ctypeStr,
|
layer.fields[i] = QgsField( db_get_column_name(column), qtype, ctypeStr,
|
||||||
db_get_column_length(column), db_get_column_precision(column) );
|
db_get_column_length(column), db_get_column_precision(column) );
|
||||||
|
|
||||||
if ( G_strcasecmp ( db_get_column_name(column), layer.fieldInfo->key) == 0 ) {
|
if ( G_strcasecmp ( db_get_column_name(column), layer.fieldInfo->key) == 0 ) {
|
||||||
@ -848,7 +851,7 @@ void QgsGrassProvider::loadAttributes ( GLAYER &layer )
|
|||||||
// Add cat if no attribute fields exist (otherwise qgis crashes)
|
// Add cat if no attribute fields exist (otherwise qgis crashes)
|
||||||
if ( layer.nColumns == 0 ) {
|
if ( layer.nColumns == 0 ) {
|
||||||
layer.keyColumn = 0;
|
layer.keyColumn = 0;
|
||||||
layer.fields[0] = ( QgsField( "cat", "integer", 10, 0) );
|
layer.fields[0] = ( QgsField( "cat", QVariant::Int, "integer") );
|
||||||
layer.minmax = new double[1][2];
|
layer.minmax = new double[1][2];
|
||||||
layer.minmax[0][0] = 0;
|
layer.minmax[0][0] = 0;
|
||||||
layer.minmax[0][1] = 0;
|
layer.minmax[0][1] = 0;
|
||||||
@ -1172,15 +1175,13 @@ void QgsGrassProvider::setFeatureAttributes ( int layerId, int cat, QgsFeature *
|
|||||||
for (int i = 0; i < mLayers[layerId].nColumns; i++) {
|
for (int i = 0; i < mLayers[layerId].nColumns; i++) {
|
||||||
if ( att != NULL ) {
|
if ( att != NULL ) {
|
||||||
Q3CString cstr( att->values[i] );
|
Q3CString cstr( att->values[i] );
|
||||||
feature->addAttribute (i, QgsFeatureAttribute( mLayers[layerId].fields[i].name(), mEncoding->toUnicode(cstr) ));
|
feature->addAttribute (i, QVariant(mEncoding->toUnicode(cstr)) );
|
||||||
} else { /* it may happen that attributes are missing -> set to empty string */
|
} else { /* it may happen that attributes are missing -> set to empty string */
|
||||||
feature->addAttribute (i, QgsFeatureAttribute( mLayers[layerId].fields[i].name(), ""));
|
feature->addAttribute (i, QVariant());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QString tmp;
|
feature->addAttribute (0, QVariant(cat));
|
||||||
tmp.sprintf("%d", cat );
|
|
||||||
feature->addAttribute (0, QgsFeatureAttribute("cat", tmp));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1199,15 +1200,13 @@ void QgsGrassProvider::setFeatureAttributes ( int layerId, int cat, QgsFeature *
|
|||||||
for (QgsAttributeList::const_iterator iter=attlist.begin(); iter!=attlist.end();++iter) {
|
for (QgsAttributeList::const_iterator iter=attlist.begin(); iter!=attlist.end();++iter) {
|
||||||
if ( att != NULL ) {
|
if ( att != NULL ) {
|
||||||
Q3CString cstr( att->values[*iter] );
|
Q3CString cstr( att->values[*iter] );
|
||||||
feature->addAttribute (*iter, QgsFeatureAttribute(mLayers[layerId].fields[*iter].name(), mEncoding->toUnicode(cstr) ));
|
feature->addAttribute (*iter, QVariant( mEncoding->toUnicode(cstr) ));
|
||||||
} else { /* it may happen that attributes are missing -> set to empty string */
|
} else { /* it may happen that attributes are missing -> set to empty string */
|
||||||
feature->addAttribute (*iter, QgsFeatureAttribute(mLayers[layerId].fields[*iter].name(), ""));
|
feature->addAttribute (*iter, QVariant());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QString tmp;
|
feature->addAttribute (0, QVariant(cat));
|
||||||
tmp.sprintf("%d", cat );
|
|
||||||
feature->addAttribute (0, QgsFeatureAttribute("cat", tmp));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1820,21 +1819,26 @@ std::vector<QgsField> *QgsGrassProvider::columns ( int field )
|
|||||||
|
|
||||||
int ctype = db_sqltype_to_Ctype( db_get_column_sqltype (column) );
|
int ctype = db_sqltype_to_Ctype( db_get_column_sqltype (column) );
|
||||||
QString type;
|
QString type;
|
||||||
|
QVariant::Type qtype;
|
||||||
switch ( ctype ) {
|
switch ( ctype ) {
|
||||||
case DB_C_TYPE_INT:
|
case DB_C_TYPE_INT:
|
||||||
type = "int";
|
type = "int";
|
||||||
|
qtype = QVariant::Int;
|
||||||
break;
|
break;
|
||||||
case DB_C_TYPE_DOUBLE:
|
case DB_C_TYPE_DOUBLE:
|
||||||
type = "double";
|
type = "double";
|
||||||
|
qtype = QVariant::Double;
|
||||||
break;
|
break;
|
||||||
case DB_C_TYPE_STRING:
|
case DB_C_TYPE_STRING:
|
||||||
type = "string";
|
type = "string";
|
||||||
|
qtype = QVariant::String;
|
||||||
break;
|
break;
|
||||||
case DB_C_TYPE_DATETIME:
|
case DB_C_TYPE_DATETIME:
|
||||||
type = "datetime";
|
type = "datetime";
|
||||||
|
qtype = QVariant::String;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
col->push_back ( QgsField( db_get_column_name (column), type, db_get_column_length(column), 0) );
|
col->push_back ( QgsField( db_get_column_name (column), qtype, type, db_get_column_length(column), 0) );
|
||||||
}
|
}
|
||||||
|
|
||||||
db_close_database_shutdown_driver ( driver );
|
db_close_database_shutdown_driver ( driver );
|
||||||
@ -1842,13 +1846,13 @@ std::vector<QgsField> *QgsGrassProvider::columns ( int field )
|
|||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<QgsFeatureAttribute> *QgsGrassProvider::attributes ( int field, int cat )
|
QgsAttributeMap *QgsGrassProvider::attributes ( int field, int cat )
|
||||||
{
|
{
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
std::cerr << "QgsGrassProvider::attributes() field = " << field << " cat = " << cat << std::endl;
|
std::cerr << "QgsGrassProvider::attributes() field = " << field << " cat = " << cat << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<QgsFeatureAttribute> *att = new std::vector<QgsFeatureAttribute>;
|
QgsAttributeMap *att = new QgsAttributeMap;
|
||||||
|
|
||||||
struct field_info *fi = Vect_get_field( mMap, field); // should work also with field = 0
|
struct field_info *fi = Vect_get_field( mMap, field); // should work also with field = 0
|
||||||
|
|
||||||
@ -1920,7 +1924,7 @@ std::vector<QgsFeatureAttribute> *QgsGrassProvider::attributes ( int field, int
|
|||||||
|
|
||||||
QString v = mEncoding->toUnicode(db_get_string(&dbstr));
|
QString v = mEncoding->toUnicode(db_get_string(&dbstr));
|
||||||
std::cerr << "Value: " << v.toLocal8Bit().data() << std::endl;
|
std::cerr << "Value: " << v.toLocal8Bit().data() << std::endl;
|
||||||
att->push_back ( QgsFeatureAttribute( db_get_column_name(column), v ) );
|
att->insert(i, QVariant( v ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
db_close_cursor (&databaseCursor);
|
db_close_cursor (&databaseCursor);
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
#define QGSGRASSPROVIDER_H
|
#define QGSGRASSPROVIDER_H
|
||||||
|
|
||||||
class QgsFeature;
|
class QgsFeature;
|
||||||
class QgsFeatureAttribute;
|
|
||||||
class QgsField;
|
class QgsField;
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@ -368,7 +367,7 @@ public:
|
|||||||
* @param cat
|
* @param cat
|
||||||
* @return vector of attributes
|
* @return vector of attributes
|
||||||
*/
|
*/
|
||||||
std::vector<QgsFeatureAttribute> *attributes ( int field, int cat );
|
QgsAttributeMap *attributes ( int field, int cat );
|
||||||
|
|
||||||
/** Key (cat) column name
|
/** Key (cat) column name
|
||||||
* @param field
|
* @param field
|
||||||
|
|||||||
@ -50,7 +50,6 @@ email : sherman at mrcc.com
|
|||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsdataprovider.h"
|
#include "qgsdataprovider.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
@ -213,14 +212,23 @@ void QgsOgrProvider::loadFields()
|
|||||||
for(int i=0;i<fdef->GetFieldCount();++i)
|
for(int i=0;i<fdef->GetFieldCount();++i)
|
||||||
{
|
{
|
||||||
OGRFieldDefn *fldDef = fdef->GetFieldDefn(i);
|
OGRFieldDefn *fldDef = fdef->GetFieldDefn(i);
|
||||||
OGRFieldType type = fldDef->GetType();
|
OGRFieldType ogrType = fldDef->GetType();
|
||||||
bool numeric = (type == OFTInteger || type == OFTReal);
|
QVariant::Type varType;
|
||||||
|
switch (ogrType)
|
||||||
|
{
|
||||||
|
case OFTInteger: varType = QVariant::Int; break;
|
||||||
|
case OFTReal: varType = QVariant::Double; break;
|
||||||
|
// unsupported in OGR 1.3
|
||||||
|
//case OFTDateTime: varType = QVariant::DateTime; break;
|
||||||
|
case OFTString: varType = QVariant::String; break;
|
||||||
|
default: varType = QVariant::String; // other unsupported, leave it as a string
|
||||||
|
}
|
||||||
|
|
||||||
mAttributeFields.insert(i, QgsField(
|
mAttributeFields.insert(i, QgsField(
|
||||||
mEncoding->toUnicode(fldDef->GetNameRef()),
|
mEncoding->toUnicode(fldDef->GetNameRef()), varType,
|
||||||
mEncoding->toUnicode(fldDef->GetFieldTypeName(type)),
|
mEncoding->toUnicode(fldDef->GetFieldTypeName(ogrType)),
|
||||||
fldDef->GetWidth(),
|
fldDef->GetWidth(),
|
||||||
fldDef->GetPrecision(),
|
fldDef->GetPrecision() ));
|
||||||
numeric));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -466,10 +474,21 @@ void QgsOgrProvider::getFeatureAttribute(OGRFeature * ogrFet, QgsFeature & f, in
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString fld = mEncoding->toUnicode(fldDef->GetNameRef());
|
//QString fld = mEncoding->toUnicode(fldDef->GetNameRef());
|
||||||
QByteArray cstr(ogrFet->GetFieldAsString(attindex));
|
QByteArray cstr(ogrFet->GetFieldAsString(attindex));
|
||||||
|
QString str = mEncoding->toUnicode(cstr);
|
||||||
|
QVariant value;
|
||||||
|
|
||||||
f.addAttribute(attindex, QgsFeatureAttribute(fld, mEncoding->toUnicode(cstr)));
|
switch (mAttributeFields[attindex].type())
|
||||||
|
{
|
||||||
|
case QVariant::String: value = QVariant(str); break;
|
||||||
|
case QVariant::Int: value = QVariant(str.toInt()); break;
|
||||||
|
case QVariant::Double: value = QVariant(str.toDouble()); break;
|
||||||
|
//case QVariant::DateTime: value = QVariant(QDateTime::fromString(str)); break;
|
||||||
|
default: assert(NULL && "unsupported field type");
|
||||||
|
}
|
||||||
|
|
||||||
|
f.addAttribute(attindex, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -581,13 +600,18 @@ void QgsOgrProvider::fillMinMaxCash()
|
|||||||
minmaxcache[i][1]=-DBL_MAX;
|
minmaxcache[i][1]=-DBL_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fetch only numeric columns
|
||||||
QgsFeature f;
|
QgsFeature f;
|
||||||
QgsAttributeList all = allAttributesList();
|
QgsAttributeList all = allAttributesList();
|
||||||
while (getNextFeature(f, false, all))
|
while (getNextFeature(f, false, all))
|
||||||
{
|
{
|
||||||
for(uint i = 0; i < fieldCount(); i++)
|
for(uint i = 0; i < fieldCount(); i++)
|
||||||
{
|
{
|
||||||
double value = (f.attributeMap())[i].fieldValue().toDouble();
|
const QVariant& varValue = (f.attributeMap())[i];
|
||||||
|
if (varValue.type() != QVariant::Double && varValue.type() != QVariant::Int)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
double value = varValue.toDouble();
|
||||||
if(value<minmaxcache[i][0])
|
if(value<minmaxcache[i][0])
|
||||||
{
|
{
|
||||||
minmaxcache[i][0]=value;
|
minmaxcache[i][0]=value;
|
||||||
@ -764,40 +788,33 @@ bool QgsOgrProvider::addFeature(QgsFeature& f)
|
|||||||
QgsAttributeMap attrs = f.attributeMap();
|
QgsAttributeMap attrs = f.attributeMap();
|
||||||
|
|
||||||
//add possible attribute information
|
//add possible attribute information
|
||||||
for(int i = 0; i < attrs.size(); ++i)
|
for(QgsAttributeMap::iterator it = attrs.begin(); it != attrs.end(); ++it)
|
||||||
{
|
{
|
||||||
QString s = attrs[i].fieldValue();
|
int targetAttributeId = it.key();
|
||||||
|
|
||||||
//find a matching field for the new attribute
|
//if(!s.isEmpty())
|
||||||
QString newAttribute = attrs[i].fieldName();
|
// continue;
|
||||||
int targetAttributeId = fdef->GetFieldIndex(mEncoding->fromUnicode(newAttribute).constData());
|
|
||||||
if(targetAttributeId == -1)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!s.isEmpty())
|
if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTInteger)
|
||||||
|
{
|
||||||
|
feature->SetField(targetAttributeId,it->toInt());
|
||||||
|
}
|
||||||
|
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTReal)
|
||||||
|
{
|
||||||
|
feature->SetField(targetAttributeId,it->toDouble());
|
||||||
|
}
|
||||||
|
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTString)
|
||||||
{
|
{
|
||||||
if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTInteger)
|
|
||||||
{
|
|
||||||
feature->SetField(targetAttributeId,s.toInt());
|
|
||||||
}
|
|
||||||
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTReal)
|
|
||||||
{
|
|
||||||
feature->SetField(targetAttributeId,s.toDouble());
|
|
||||||
}
|
|
||||||
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTString)
|
|
||||||
{
|
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
std::cerr << "Writing string attribute " << newAttribute.toLocal8Bit().data() <<
|
std::cerr << "Writing string attribute " << targetAttributeId
|
||||||
" with " << s.toLocal8Bit().data() << ", encoding " << mEncoding->name().data() << "\n";
|
<< " with " << it->toString().toLocal8Bit().data()
|
||||||
|
<< ", encoding " << mEncoding->name().data() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
feature->SetField(targetAttributeId,mEncoding->fromUnicode(s).constData());
|
feature->SetField(targetAttributeId,mEncoding->fromUnicode(it->toString()).constData());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QgsLogger::warning("QgsOgrProvider::addFeature, no type found");
|
QgsLogger::warning("QgsOgrProvider::addFeature, no type found");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -890,8 +907,6 @@ bool QgsOgrProvider::changeAttributeValues(const QgsChangedAttributesMap & attr_
|
|||||||
for( QgsAttributeMap::const_iterator it2 = attr.begin(); it2 != attr.end(); ++it2 )
|
for( QgsAttributeMap::const_iterator it2 = attr.begin(); it2 != attr.end(); ++it2 )
|
||||||
{
|
{
|
||||||
int f = it2.key();
|
int f = it2.key();
|
||||||
QString name = it2->fieldName();
|
|
||||||
QString value = it2->fieldValue();
|
|
||||||
|
|
||||||
OGRFieldDefn *fd = of->GetFieldDefnRef ( f );
|
OGRFieldDefn *fd = of->GetFieldDefnRef ( f );
|
||||||
if (fd == NULL)
|
if (fd == NULL)
|
||||||
@ -904,13 +919,13 @@ bool QgsOgrProvider::changeAttributeValues(const QgsChangedAttributesMap & attr_
|
|||||||
switch ( type )
|
switch ( type )
|
||||||
{
|
{
|
||||||
case OFTInteger:
|
case OFTInteger:
|
||||||
of->SetField ( f, value.toInt() );
|
of->SetField ( f, it2->toInt() );
|
||||||
break;
|
break;
|
||||||
case OFTReal:
|
case OFTReal:
|
||||||
of->SetField ( f, value.toDouble() );
|
of->SetField ( f, it2->toDouble() );
|
||||||
break;
|
break;
|
||||||
case OFTString:
|
case OFTString:
|
||||||
of->SetField ( f, mEncoding->fromUnicode(value).constData() );
|
of->SetField ( f, mEncoding->fromUnicode(it2->toString()).constData() );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
QgsLogger::warning("QgsOgrProvider::changeAttributeValues, Unknown field type, cannot change attribute");
|
QgsLogger::warning("QgsOgrProvider::changeAttributeValues, Unknown field type, cannot change attribute");
|
||||||
|
|||||||
@ -38,7 +38,6 @@
|
|||||||
#include <qgis.h>
|
#include <qgis.h>
|
||||||
#include <qgsapplication.h>
|
#include <qgsapplication.h>
|
||||||
#include <qgsfeature.h>
|
#include <qgsfeature.h>
|
||||||
#include <qgsfeatureattribute.h>
|
|
||||||
#include <qgsfield.h>
|
#include <qgsfield.h>
|
||||||
#include <qgsgeometry.h>
|
#include <qgsgeometry.h>
|
||||||
#include <qgsmessageoutput.h>
|
#include <qgsmessageoutput.h>
|
||||||
@ -207,7 +206,7 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
|
|||||||
"typelem = " + typOid + " AND typlen = -1)";
|
"typelem = " + typOid + " AND typlen = -1)";
|
||||||
|
|
||||||
PGresult* oidResult = PQexec(pd, (const char *) sql);
|
PGresult* oidResult = PQexec(pd, (const char *) sql);
|
||||||
QString fieldType = PQgetvalue(oidResult, 0, 0);
|
QString fieldTypeName = PQgetvalue(oidResult, 0, 0);
|
||||||
QString fieldSize = PQgetvalue(oidResult, 0, 1);
|
QString fieldSize = PQgetvalue(oidResult, 0, 1);
|
||||||
PQclear(oidResult);
|
PQclear(oidResult);
|
||||||
|
|
||||||
@ -225,13 +224,20 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
|
|||||||
PQclear(tresult);
|
PQclear(tresult);
|
||||||
|
|
||||||
QgsDebugMsg("Field: " + attnum + " maps to " + QString::number(i) + " " + fieldName + ", "
|
QgsDebugMsg("Field: " + attnum + " maps to " + QString::number(i) + " " + fieldName + ", "
|
||||||
+ fieldType + " (" + QString::number(fldtyp) + "), " + fieldSize + ", " + QString::number(fieldModifier));
|
+ fieldTypeName + " (" + QString::number(fldtyp) + "), " + fieldSize + ", " + QString::number(fieldModifier));
|
||||||
|
|
||||||
attributeFieldsIdMap[attnum.toInt()] = i;
|
attributeFieldsIdMap[attnum.toInt()] = i;
|
||||||
|
|
||||||
if(fieldName!=geometryColumn)
|
if(fieldName!=geometryColumn)
|
||||||
{
|
{
|
||||||
attributeFields.insert(i, QgsField(fieldName, fieldType, fieldSize.toInt(), fieldModifier, false, fieldComment));
|
QVariant::Type fieldType;
|
||||||
|
if (fieldTypeName.find("int") != -1 || fieldTypeName.find("serial") != -1)
|
||||||
|
fieldType = QVariant::Int;
|
||||||
|
else if (fieldTypeName == "real" || fieldTypeName == "double precision")
|
||||||
|
fieldType = QVariant::Double;
|
||||||
|
else
|
||||||
|
fieldType = QVariant::String;
|
||||||
|
attributeFields.insert(i, QgsField(fieldName, fieldType, fieldTypeName, fieldSize.toInt(), fieldModifier, fieldComment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
@ -577,8 +583,21 @@ void QgsPostgresProvider::getFeatureAttributes(int key, int &row, QgsFeature& f)
|
|||||||
if(fld != geometryColumn){
|
if(fld != geometryColumn){
|
||||||
// Add the attribute to the feature
|
// Add the attribute to the feature
|
||||||
//QString val = mEncoding->toUnicode(PQgetvalue(attr,0, i));
|
//QString val = mEncoding->toUnicode(PQgetvalue(attr,0, i));
|
||||||
QString val = QString::fromUtf8 (PQgetvalue(attr, row, i));
|
QString val = QString::fromUtf8 (PQgetvalue(attr, row, i));
|
||||||
f.addAttribute(i, QgsFeatureAttribute(fld, val));
|
switch (attributeFields[i].type())
|
||||||
|
{
|
||||||
|
case QVariant::Int:
|
||||||
|
f.addAttribute(i, val.toInt());
|
||||||
|
break;
|
||||||
|
case QVariant::Double:
|
||||||
|
f.addAttribute(i, val.toDouble());
|
||||||
|
break;
|
||||||
|
case QVariant::String:
|
||||||
|
f.addAttribute(i, val);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0 && "unsupported field type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PQclear(attr);
|
PQclear(attr);
|
||||||
@ -606,8 +625,21 @@ void QgsPostgresProvider::getFeatureAttributes(int key, int &row,
|
|||||||
if(fld != geometryColumn)
|
if(fld != geometryColumn)
|
||||||
{
|
{
|
||||||
// Add the attribute to the feature
|
// Add the attribute to the feature
|
||||||
QString val = QString::fromUtf8(PQgetvalue(attr, 0, 0));
|
QString val = QString::fromUtf8(PQgetvalue(attr, 0, 0));
|
||||||
f.addAttribute(*iter, QgsFeatureAttribute(fld, val));
|
switch (attributeFields[*iter].type())
|
||||||
|
{
|
||||||
|
case QVariant::Int:
|
||||||
|
f.addAttribute(*iter, val.toInt());
|
||||||
|
break;
|
||||||
|
case QVariant::Double:
|
||||||
|
f.addAttribute(*iter, val.toDouble());
|
||||||
|
break;
|
||||||
|
case QVariant::String:
|
||||||
|
f.addAttribute(*iter, val);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0 && "unsupported field type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PQclear(attr);
|
PQclear(attr);
|
||||||
}
|
}
|
||||||
@ -1473,31 +1505,18 @@ bool QgsPostgresProvider::addFeature(QgsFeature& f, int primaryKeyHighWater)
|
|||||||
|
|
||||||
for(QgsAttributeMap::const_iterator it = attributevec.begin(); it != attributevec.end(); ++it)
|
for(QgsAttributeMap::const_iterator it = attributevec.begin(); it != attributevec.end(); ++it)
|
||||||
{
|
{
|
||||||
QString fieldname=it->fieldName();
|
QString fieldname;
|
||||||
|
QgsFieldMap::const_iterator fit = attributeFields.find(it.key());
|
||||||
|
if (fit != attributeFields.end())
|
||||||
|
fieldname = fit->name();
|
||||||
|
|
||||||
QgsDebugMsg("Checking field against: " + fieldname);
|
QgsDebugMsg("Checking field against: " + fieldname);
|
||||||
|
|
||||||
//TODO: Check if field exists in this layer
|
|
||||||
// (Sometimes features will have fields that are not part of this layer since
|
|
||||||
// they have been pasted from other layers with a different field map)
|
|
||||||
bool fieldInLayer = FALSE;
|
|
||||||
|
|
||||||
for (QgsFieldMap::iterator iter = attributeFields.begin();
|
|
||||||
iter != attributeFields.end();
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
if ( iter->name() == it->fieldName() )
|
|
||||||
{
|
|
||||||
fieldInLayer = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
(fieldname != "") &&
|
||||||
(fieldname != geometryColumn) &&
|
(fieldname != geometryColumn) &&
|
||||||
(fieldname != primaryKey) &&
|
(fieldname != primaryKey) &&
|
||||||
(!(it->fieldValue().isEmpty())) &&
|
(!(it->isNull()))
|
||||||
(fieldInLayer)
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
insert+=",\"";
|
insert+=",\"";
|
||||||
@ -1562,34 +1581,21 @@ bool QgsPostgresProvider::addFeature(QgsFeature& f, int primaryKeyHighWater)
|
|||||||
//add the field values to the insert statement
|
//add the field values to the insert statement
|
||||||
for(QgsAttributeMap::const_iterator it=attributevec.begin();it!=attributevec.end();++it)
|
for(QgsAttributeMap::const_iterator it=attributevec.begin();it!=attributevec.end();++it)
|
||||||
{
|
{
|
||||||
QString fieldname=it->fieldName();
|
QString fieldname;
|
||||||
|
QgsFieldMap::const_iterator fit = attributeFields.find(it.key());
|
||||||
|
if (fit != attributeFields.end())
|
||||||
|
fieldname = fit->name();
|
||||||
|
|
||||||
QgsDebugMsg("Checking field name " + fieldname);
|
QgsDebugMsg("Checking field name " + fieldname);
|
||||||
|
|
||||||
//TODO: Check if field exists in this layer
|
|
||||||
// (Sometimes features will have fields that are not part of this layer since
|
|
||||||
// they have been pasted from other layers with a different field map)
|
|
||||||
bool fieldInLayer = FALSE;
|
|
||||||
|
|
||||||
for (QgsFieldMap::iterator iter = attributeFields.begin();
|
|
||||||
iter != attributeFields.end();
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
if ( iter->name() == it->fieldName() )
|
|
||||||
{
|
|
||||||
fieldInLayer = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
(fieldname != "") &&
|
||||||
(fieldname != geometryColumn) &&
|
(fieldname != geometryColumn) &&
|
||||||
(fieldname != primaryKey) &&
|
(fieldname != primaryKey) &&
|
||||||
(!(it->fieldValue().isEmpty())) &&
|
(!(it->isNull()))
|
||||||
(fieldInLayer)
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
QString fieldvalue = it->fieldValue();
|
QString fieldvalue = it->toString();
|
||||||
bool charactertype=false;
|
bool charactertype=false;
|
||||||
insert+=",";
|
insert+=",";
|
||||||
|
|
||||||
@ -1597,30 +1603,27 @@ bool QgsPostgresProvider::addFeature(QgsFeature& f, int primaryKeyHighWater)
|
|||||||
|
|
||||||
//add quotes if the field is a character or date type and not
|
//add quotes if the field is a character or date type and not
|
||||||
//the postgres provided default value
|
//the postgres provided default value
|
||||||
if(fieldvalue != "NULL" && fieldvalue != getDefaultValue(it->fieldName(), f))
|
if(fieldvalue != "NULL" && fieldvalue != getDefaultValue(it.key()).toString() )
|
||||||
{
|
{
|
||||||
for(QgsFieldMap::iterator iter=attributeFields.begin();iter!=attributeFields.end();++iter)
|
QString typeName = it->typeName();
|
||||||
|
if (
|
||||||
|
typeName.contains("char",false) > 0 ||
|
||||||
|
typeName == "text" ||
|
||||||
|
typeName == "date" ||
|
||||||
|
typeName == "interval" ||
|
||||||
|
typeName.contains("time",false) > 0 // includes time and timestamp
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if(iter->name()==it->fieldName())
|
charactertype=true;
|
||||||
{
|
break; // no need to continue with this loop
|
||||||
if (
|
|
||||||
iter->type().contains("char",false) > 0 ||
|
|
||||||
iter->type() == "text" ||
|
|
||||||
iter->type() == "date" ||
|
|
||||||
iter->type() == "interval" ||
|
|
||||||
iter->type().contains("time",false) > 0 // includes time and timestamp
|
|
||||||
)
|
|
||||||
{
|
|
||||||
charactertype=true;
|
|
||||||
break; // no need to continue with this loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// important: escape quotes in field value
|
// important: escape quotes in field value
|
||||||
fieldvalue.replace("'", "''");
|
fieldvalue.replace("'", "''");
|
||||||
|
|
||||||
|
// XXX isn't it better to always escape field value?
|
||||||
if(charactertype)
|
if(charactertype)
|
||||||
{
|
{
|
||||||
insert+="'";
|
insert+="'";
|
||||||
@ -1654,7 +1657,7 @@ bool QgsPostgresProvider::addFeature(QgsFeature& f, int primaryKeyHighWater)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsPostgresProvider::getDefaultValue(const QString& attr, QgsFeature& f)
|
QVariant QgsPostgresProvider::getDefaultValue(int fieldId)
|
||||||
{
|
{
|
||||||
// Get the default column value from the Postgres information
|
// Get the default column value from the Postgres information
|
||||||
// schema. If there is no default we return an empty string.
|
// schema. If there is no default we return an empty string.
|
||||||
@ -1662,12 +1665,14 @@ QString QgsPostgresProvider::getDefaultValue(const QString& attr, QgsFeature& f)
|
|||||||
// Maintaining a cache of the results of this query would be quite
|
// Maintaining a cache of the results of this query would be quite
|
||||||
// simple and if this query is called lots, could save some time.
|
// simple and if this query is called lots, could save some time.
|
||||||
|
|
||||||
|
QString fieldName = attributeFields[fieldId].name();
|
||||||
|
|
||||||
QString sql("SELECT column_default FROM "
|
QString sql("SELECT column_default FROM "
|
||||||
"information_schema.columns WHERE "
|
"information_schema.columns WHERE "
|
||||||
"column_default IS NOT NULL AND "
|
"column_default IS NOT NULL AND "
|
||||||
"table_schema = '" + mSchemaName + "' AND "
|
"table_schema = '" + mSchemaName + "' AND "
|
||||||
"table_name = '" + mTableName + "' AND "
|
"table_name = '" + mTableName + "' AND "
|
||||||
"column_name = '" + attr + "'");
|
"column_name = '" + fieldName + "'");
|
||||||
|
|
||||||
QString defaultValue("");
|
QString defaultValue("");
|
||||||
|
|
||||||
@ -1867,12 +1872,13 @@ bool QgsPostgresProvider::changeAttributeValues(const QgsChangedAttributesMap &
|
|||||||
// cycle through the changed attributes of the feature
|
// cycle through the changed attributes of the feature
|
||||||
for(QgsAttributeMap::const_iterator siter = attrs.begin(); siter != attrs.end(); ++siter)
|
for(QgsAttributeMap::const_iterator siter = attrs.begin(); siter != attrs.end(); ++siter)
|
||||||
{
|
{
|
||||||
QString val = siter->fieldValue();
|
QString val = siter->toString();
|
||||||
|
QString fieldName = attributeFields[siter.key()].name();
|
||||||
|
|
||||||
// escape quotes
|
// escape quotes
|
||||||
val.replace("'", "''");
|
val.replace("'", "''");
|
||||||
|
|
||||||
QString sql="UPDATE "+mSchemaTableName+" SET "+siter->fieldName()+"='"+val+"' WHERE \"" +primaryKey+"\"="+QString::number(fid);
|
QString sql="UPDATE "+mSchemaTableName+" SET "+fieldName+"='"+val+"' WHERE \"" +primaryKey+"\"="+QString::number(fid);
|
||||||
QgsDebugMsg(sql);
|
QgsDebugMsg(sql);
|
||||||
|
|
||||||
// s end sql statement and do error handling
|
// s end sql statement and do error handling
|
||||||
|
|||||||
@ -220,8 +220,8 @@ class QgsPostgresProvider:public QgsVectorDataProvider
|
|||||||
//! get status of PROJ4 capability
|
//! get status of PROJ4 capability
|
||||||
bool hasPROJ(PGconn *);
|
bool hasPROJ(PGconn *);
|
||||||
|
|
||||||
/**Returns the default value for attribute @c attr for feature @c f. */
|
/**Returns the default value for field specified by @c fieldId */
|
||||||
QString getDefaultValue(const QString& attr, QgsFeature& f);
|
QVariant getDefaultValue(int fieldId);
|
||||||
|
|
||||||
/**Adds a list of features
|
/**Adds a list of features
|
||||||
@return true in case of success and false in case of failure*/
|
@return true in case of success and false in case of failure*/
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
#include "qgswfsdata.h"
|
#include "qgswfsdata.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsrect.h"
|
#include "qgsrect.h"
|
||||||
#include "qgsspatialrefsys.h"
|
#include "qgsspatialrefsys.h"
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
@ -193,7 +192,7 @@ void QgsWFSData::endElement(const XML_Char* el)
|
|||||||
//qWarning(mAttributeName.toLocal8Bit().data());
|
//qWarning(mAttributeName.toLocal8Bit().data());
|
||||||
//qWarning(mStringCash.toLocal8Bit().data());
|
//qWarning(mStringCash.toLocal8Bit().data());
|
||||||
//mCurrentFeature->addAttribute(mAttributeName, mStringCash);
|
//mCurrentFeature->addAttribute(mAttributeName, mStringCash);
|
||||||
mCurrentFeature->addAttribute(mAttributeIndex, QgsFeatureAttribute(mAttributeName, mStringCash));
|
mCurrentFeature->addAttribute(mAttributeIndex, QVariant(mStringCash));
|
||||||
++mAttributeIndex;
|
++mAttributeIndex;
|
||||||
}
|
}
|
||||||
else if(localName == mGeometryAttribute)
|
else if(localName == mGeometryAttribute)
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsfeatureattribute.h"
|
|
||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgshttptransaction.h"
|
#include "qgshttptransaction.h"
|
||||||
@ -94,7 +93,7 @@ bool QgsWFSProvider::getNextFeature(QgsFeature& feature,
|
|||||||
const QgsAttributeMap& attributes = ((QgsFeature*)(*mFeatureIterator))->attributeMap();
|
const QgsAttributeMap& attributes = ((QgsFeature*)(*mFeatureIterator))->attributeMap();
|
||||||
for(QgsAttributeList::const_iterator it = attlist.begin(); it != attlist.end(); ++it)
|
for(QgsAttributeList::const_iterator it = attlist.begin(); it != attlist.end(); ++it)
|
||||||
{
|
{
|
||||||
feature.addAttribute(*it, QgsFeatureAttribute(attributes[*it].fieldName(), attributes[*it].fieldValue()));
|
feature.addAttribute(*it, attributes[*it]);
|
||||||
}
|
}
|
||||||
++mFeatureIterator;
|
++mFeatureIterator;
|
||||||
if(mUseIntersect)
|
if(mUseIntersect)
|
||||||
@ -189,7 +188,7 @@ void QgsWFSProvider::fillMinMaxCash()
|
|||||||
{
|
{
|
||||||
for(i = 0; i < fieldCount; ++i)
|
for(i = 0; i < fieldCount; ++i)
|
||||||
{
|
{
|
||||||
currentValue = (theFeature.attributeMap())[i].fieldValue().toDouble();
|
currentValue = (theFeature.attributeMap())[i].toDouble();
|
||||||
if(currentValue < tempMinMax[i].first)
|
if(currentValue < tempMinMax[i].first)
|
||||||
{
|
{
|
||||||
tempMinMax[i].first = currentValue;
|
tempMinMax[i].first = currentValue;
|
||||||
@ -366,7 +365,7 @@ int QgsWFSProvider::getFeatureGET(const QString& uri, const QString& geometryAtt
|
|||||||
GEOS_GEOM::Envelope* geosBBox;
|
GEOS_GEOM::Envelope* geosBBox;
|
||||||
for(std::list<QgsFeature*>::const_iterator it = dataFeatures.begin(); it != dataFeatures.end(); ++it)
|
for(std::list<QgsFeature*>::const_iterator it = dataFeatures.begin(); it != dataFeatures.end(); ++it)
|
||||||
{
|
{
|
||||||
featureBBox = (*it)->boundingBox();
|
featureBBox = (*it)->geometry()->boundingBox();
|
||||||
geosBBox = new GEOS_GEOM::Envelope(featureBBox.xMin(), featureBBox.xMax(), featureBBox.yMin(), featureBBox.yMax());
|
geosBBox = new GEOS_GEOM::Envelope(featureBBox.xMin(), featureBBox.xMax(), featureBBox.yMin(), featureBBox.yMax());
|
||||||
mSpatialIndex.insert(geosBBox, (void*)(*it));
|
mSpatialIndex.insert(geosBBox, (void*)(*it));
|
||||||
mEnvelopesAndFeatures.push_back(std::make_pair(geosBBox, (*it)));
|
mEnvelopesAndFeatures.push_back(std::make_pair(geosBBox, (*it)));
|
||||||
@ -489,7 +488,7 @@ int QgsWFSProvider::describeFeatureTypeFile(const QString& uri, QString& geometr
|
|||||||
for(std::list<QString>::const_iterator it = thematicAttributes.begin(); it != thematicAttributes.end(); ++it, ++i)
|
for(std::list<QString>::const_iterator it = thematicAttributes.begin(); it != thematicAttributes.end(); ++it, ++i)
|
||||||
{
|
{
|
||||||
// TODO: is this correct?
|
// TODO: is this correct?
|
||||||
fields[i] = QgsField(*it, "unknown");
|
fields[i] = QgsField(*it, QVariant::String, "unknown");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -573,7 +572,7 @@ int QgsWFSProvider::readAttributesFromSchema(QDomDocument& schemaDoc, QString& g
|
|||||||
}
|
}
|
||||||
else //todo: distinguish between numerical and non-numerical types
|
else //todo: distinguish between numerical and non-numerical types
|
||||||
{
|
{
|
||||||
fields[fields.size()] = QgsField(name, type);
|
fields[fields.size()] = QgsField(name, QVariant::String, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -823,7 +822,7 @@ int QgsWFSProvider::getFeaturesFromGML2(const QDomElement& wfsCollectionElement,
|
|||||||
{
|
{
|
||||||
if((currentAttributeElement.localName()) != geometryAttribute) //a normal attribute
|
if((currentAttributeElement.localName()) != geometryAttribute) //a normal attribute
|
||||||
{
|
{
|
||||||
f->addAttribute(attr++, QgsFeatureAttribute(currentAttributeElement.localName(), currentAttributeElement.text()));
|
f->addAttribute(attr++, QVariant(currentAttributeElement.text()));
|
||||||
}
|
}
|
||||||
else //a geometry attribute
|
else //a geometry attribute
|
||||||
{
|
{
|
||||||
@ -837,7 +836,7 @@ int QgsWFSProvider::getFeaturesFromGML2(const QDomElement& wfsCollectionElement,
|
|||||||
if(wkb && wkbSize > 0)
|
if(wkb && wkbSize > 0)
|
||||||
{
|
{
|
||||||
//insert bbox and pointer to feature into search tree
|
//insert bbox and pointer to feature into search tree
|
||||||
featureBBox = f->boundingBox();
|
featureBBox = f->geometry()->boundingBox();
|
||||||
geosBBox = new GEOS_GEOM::Envelope(featureBBox.xMin(), featureBBox.xMax(), featureBBox.yMin(), featureBBox.yMax());
|
geosBBox = new GEOS_GEOM::Envelope(featureBBox.xMin(), featureBBox.xMax(), featureBBox.yMin(), featureBBox.yMax());
|
||||||
mSpatialIndex.insert(geosBBox, (void*)f);
|
mSpatialIndex.insert(geosBBox, (void*)f);
|
||||||
mEnvelopesAndFeatures.push_back(std::make_pair(geosBBox, f));
|
mEnvelopesAndFeatures.push_back(std::make_pair(geosBBox, f));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user