Skip to content

Commit c3decb7

Browse files
author
g_j_m
committed
Changes to support a comment for each attribute in vector data. Now
requires support in providers. Addresses ticket #244. git-svn-id: http://svn.osgeo.org/qgis/trunk@6612 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5d03090 commit c3decb7

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

src/app/qgsvectorlayerproperties.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ QString QgsVectorLayerProperties::getMetadata()
523523
myMetadataQString += "<th bgcolor=\"black\">";
524524
myMetadataQString += "<font color=\"white\">" + tr("Precision") + "</font>";
525525
myMetadataQString += "</th>";
526+
myMetadataQString += "<th bgcolor=\"black\">";
527+
myMetadataQString += "<font color=\"white\">" + tr("Comment") + "</font>";
528+
myMetadataQString += "</th>";
526529
myMetadataQString += "<tr>";
527530

528531
//get info for each field by looping through them
@@ -543,6 +546,9 @@ QString QgsVectorLayerProperties::getMetadata()
543546
myMetadataQString += "</td>";
544547
myMetadataQString += "<td bgcolor=\"white\">";
545548
myMetadataQString += QString("%1").arg(myField.precision());
549+
myMetadataQString += "</td>";
550+
myMetadataQString += "<td bgcolor=\"white\">";
551+
myMetadataQString += QString("%1").arg(myField.comment());
546552
myMetadataQString += "</td></tr>";
547553
}
548554

src/core/qgsfield.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ static const char * const ident_ =
2525
"$Id$";
2626

2727

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

80+
QString const & QgsField::comment() const
81+
{
82+
return mComment;
83+
}
84+
7885
void QgsField::setName(QString const & nam)
7986
{
8087
mName = nam;
@@ -96,3 +103,7 @@ void QgsField::setNumeric(bool num)
96103
{
97104
mNumeric = num;
98105
}
106+
void QgsField::setComment(QString comment)
107+
{
108+
mComment = comment;
109+
}

src/core/qgsfield.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CORE_EXPORT QgsField
4040
* used in conjunction with other fields types (eg. variable character fields)
4141
* @param num Has to be true if field contains numeric values.
4242
*/
43-
QgsField(QString nam = "", QString typ = "", int len = 0, int prec = 0, bool num = false);
43+
QgsField(QString nam = "", QString typ = "", int len = 0, int prec = 0, bool num = false, QString comment = "");
4444

4545
//! Destructor
4646
~QgsField();
@@ -80,6 +80,11 @@ class CORE_EXPORT QgsField
8080
bool isNumeric() const;
8181

8282

83+
/**
84+
Returns the field comment
85+
*/
86+
QString const & comment() const;
87+
8388
/**
8489
Set the field name.
8590
@param nam Name of the field
@@ -109,6 +114,11 @@ class CORE_EXPORT QgsField
109114
*/
110115
void setNumeric(bool num);
111116

117+
/**
118+
Set the field comment
119+
*/
120+
void setComment(QString comment);
121+
112122
private:
113123

114124
//! Name
@@ -126,6 +136,9 @@ class CORE_EXPORT QgsField
126136
//! Numeric
127137
bool mNumeric;
128138

139+
//! Comment
140+
QString mComment;
141+
129142
}; // class QgsField
130143

131144
#endif

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
181181
int fldtyp = PQftype(result, i);
182182
QString typOid = QString().setNum(fldtyp);
183183
int fieldModifier = PQfmod(result, i);
184+
QString fieldComment = "";
184185

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

215216
if(fieldName!=geometryColumn)
216217
{
217-
attributeFields.insert(i, QgsField(fieldName, fieldType, fieldSize.toInt(), fieldModifier));
218+
attributeFields.insert(i, QgsField(fieldName, fieldType, fieldSize.toInt(), fieldModifier, false, fieldComment));
218219
}
219220
}
220221
PQclear(result);

0 commit comments

Comments
 (0)