Skip to content

Commit

Permalink
Changes to support a comment for each attribute in vector data. Now
Browse files Browse the repository at this point in the history
requires support in providers. Addresses ticket #244.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6612 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Feb 17, 2007
1 parent 879a45e commit 9bbbd97
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -523,6 +523,9 @@ QString QgsVectorLayerProperties::getMetadata()
myMetadataQString += "<th bgcolor=\"black\">";
myMetadataQString += "<font color=\"white\">" + tr("Precision") + "</font>";
myMetadataQString += "</th>";
myMetadataQString += "<th bgcolor=\"black\">";
myMetadataQString += "<font color=\"white\">" + tr("Comment") + "</font>";
myMetadataQString += "</th>";
myMetadataQString += "<tr>";

//get info for each field by looping through them
Expand All @@ -543,6 +546,9 @@ QString QgsVectorLayerProperties::getMetadata()
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"white\">";
myMetadataQString += QString("%1").arg(myField.precision());
myMetadataQString += "</td>";
myMetadataQString += "<td bgcolor=\"white\">";
myMetadataQString += QString("%1").arg(myField.comment());
myMetadataQString += "</td></tr>";
}

Expand Down
15 changes: 13 additions & 2 deletions src/core/qgsfield.cpp
Expand Up @@ -25,8 +25,10 @@ static const char * const ident_ =
"$Id$";


QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num)
:mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num)
QgsField::QgsField(QString nam, QString typ, int len, int prec, bool num,
QString comment)
:mName(nam), mType(typ), mLength(len), mPrecision(prec), mNumeric(num),
mComment(comment)
{
// This function used to lower case the field name since some stores
// use upper case (eg. shapefiles), but that caused problems with
Expand Down Expand Up @@ -75,6 +77,11 @@ bool QgsField::isNumeric() const
return mNumeric;
}

QString const & QgsField::comment() const
{
return mComment;
}

void QgsField::setName(QString const & nam)
{
mName = nam;
Expand All @@ -96,3 +103,7 @@ void QgsField::setNumeric(bool num)
{
mNumeric = num;
}
void QgsField::setComment(QString comment)
{
mComment = comment;
}
15 changes: 14 additions & 1 deletion src/core/qgsfield.h
Expand Up @@ -40,7 +40,7 @@ class CORE_EXPORT QgsField
* used in conjunction with other fields types (eg. variable character fields)
* @param num Has to be true if field contains numeric values.
*/
QgsField(QString nam = "", QString typ = "", int len = 0, int prec = 0, bool num = false);
QgsField(QString nam = "", QString typ = "", int len = 0, int prec = 0, bool num = false, QString comment = "");

//! Destructor
~QgsField();
Expand Down Expand Up @@ -80,6 +80,11 @@ class CORE_EXPORT QgsField
bool isNumeric() const;


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

/**
Set the field name.
@param nam Name of the field
Expand Down Expand Up @@ -109,6 +114,11 @@ class CORE_EXPORT QgsField
*/
void setNumeric(bool num);

/**
Set the field comment
*/
void setComment(QString comment);

private:

//! Name
Expand All @@ -126,6 +136,9 @@ class CORE_EXPORT QgsField
//! Numeric
bool mNumeric;

//! Comment
QString mComment;

}; // class QgsField

#endif
3 changes: 2 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -181,6 +181,7 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
int fldtyp = PQftype(result, i);
QString typOid = QString().setNum(fldtyp);
int fieldModifier = PQfmod(result, i);
QString fieldComment = "";

sql = "select typelem from pg_type where typelem = " + typOid + " and typlen = -1";
// //--std::cout << sql << std::endl;
Expand Down Expand Up @@ -214,7 +215,7 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)

if(fieldName!=geometryColumn)
{
attributeFields.insert(i, QgsField(fieldName, fieldType, fieldSize.toInt(), fieldModifier));
attributeFields.insert(i, QgsField(fieldName, fieldType, fieldSize.toInt(), fieldModifier, false, fieldComment));
}
}
PQclear(result);
Expand Down

0 comments on commit 9bbbd97

Please sign in to comment.