Skip to content

Commit 34431bf

Browse files
author
g_j_m
committed
Provide for a layer comment to be made available for vector layers
For postgres provider, get the layer comment from the table comment (if it exists). Resolves ticket #244 git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6726 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9c5303e commit 34431bf

7 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/app/qgsvectorlayerproperties.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,15 @@ QString QgsVectorLayerProperties::getMetadata()
380380
myMetadataQString += tr("General:");
381381
myMetadataQString += "</td></tr>";
382382

383+
// data comment
384+
if (!(layer->dataComment().isEmpty()))
385+
{
386+
myMetadataQString += "<tr><td bgcolor=\"white\">";
387+
myMetadataQString += tr("Layer comment: ") +
388+
layer->dataComment();
389+
myMetadataQString += "</td></tr>";
390+
}
391+
383392
//storage type
384393
myMetadataQString += "<tr><td bgcolor=\"white\">";
385394
myMetadataQString += tr("Storage type of this layer : ") +

src/core/qgsvectordataprovider.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ void QgsVectorDataProvider::getFeatureGeometry(int key, QgsFeature *f)
5959
{
6060
}
6161

62+
QString QgsVectorDataProvider::dataComment() const
63+
{
64+
return QString();
65+
}
6266

6367
bool QgsVectorDataProvider::addFeatures(QgsFeatureList & flist)
6468
{

src/core/qgsvectordataprovider.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
155155
*/
156156
virtual const QgsFieldMap & fields() const = 0;
157157

158+
/**
159+
* Return a short comment for the data that this provider is
160+
* providing access to (e.g. the comment for postgres table).
161+
*/
162+
virtual QString dataComment() const;
163+
158164
/**
159165
* Reset the layer to clear any spatial filtering or other contstraints that
160166
* would prevent the entire record set from being traversed by call to

src/core/qgsvectorlayer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ QString QgsVectorLayer::capabilitiesString() const
165165
return 0;
166166
}
167167

168+
QString QgsVectorLayer::dataComment() const
169+
{
170+
if (mDataProvider)
171+
{
172+
return mDataProvider->dataComment();
173+
}
174+
return QString();
175+
}
176+
168177

169178
QString QgsVectorLayer::providerType() const
170179
{

src/core/qgsvectorlayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
8282
/** Capabilities for this layer in a friendly format. */
8383
QString capabilitiesString() const;
8484

85+
/** Returns a comment for the data in the layer */
86+
QString dataComment() const;
87+
8588
/** Set the primary display field to be used in the identify results dialog */
8689
void setDisplayField(QString fldName=0);
8790

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,13 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
176176
QString tableoid = PQgetvalue(tresult, 0, 0);
177177
PQclear(tresult);
178178

179-
/* Code to extrac the table description. Needs a way to make is accesssible
180-
to the rest of qgis...
181-
182179
// Get the table description
183180
sql = "SELECT description FROM pg_description WHERE "
184-
"classoid = " + tableoid + " AND objsubid = 0";
181+
"objoid = " + tableoid + " AND objsubid = 0";
185182
tresult = PQexec(pd, (const char*) sql.utf8());
186183
if (PQntuples(tresult) > 0)
187-
mDescription = PQgetvalue(tresult, 0, 0);
184+
mDataComment = PQgetvalue(tresult, 0, 0);
188185
PQclear(tresult);
189-
*/
190186

191187
// Populate the field vector for this layer. The field vector contains
192188
// field name, type, length, and precision (if numeric)
@@ -685,6 +681,11 @@ const QgsFieldMap & QgsPostgresProvider::fields() const
685681
return attributeFields;
686682
}
687683

684+
QString QgsPostgresProvider::dataComment() const
685+
{
686+
return mDataComment;
687+
}
688+
688689
void QgsPostgresProvider::reset()
689690
{
690691
// reset the cursor to the first record

src/providers/postgres/qgspostgresprovider.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ class QgsPostgresProvider:public QgsVectorDataProvider
185185
*/
186186
const QgsFieldMap & fields() const;
187187

188+
/**
189+
* Return a short comment for the data that this provider is
190+
* providing access to (e.g. the comment for postgres table).
191+
*/
192+
QString dataComment() const;
193+
188194
/** Reset the layer - for a PostgreSQL layer, this means clearing the PQresult
189195
* pointer and setting it to 0
190196
*/
@@ -335,6 +341,7 @@ class QgsPostgresProvider:public QgsVectorDataProvider
335341
std::vector < QgsFeature > features;
336342
QgsFieldMap attributeFields;
337343
std::map < int, int > attributeFieldsIdMap;
344+
QString mDataComment;
338345

339346
//! Data source URI struct for this layer
340347
QgsDataSourceURI mUri;

0 commit comments

Comments
 (0)