Skip to content

Commit

Permalink
Provide for a layer comment to be made available for vector layers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
g_j_m committed Feb 28, 2007
1 parent 9c5303e commit 34431bf
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ QString QgsVectorLayerProperties::getMetadata()
myMetadataQString += tr("General:");
myMetadataQString += "</td></tr>";

// data comment
if (!(layer->dataComment().isEmpty()))
{
myMetadataQString += "<tr><td bgcolor=\"white\">";
myMetadataQString += tr("Layer comment: ") +
layer->dataComment();
myMetadataQString += "</td></tr>";
}

//storage type
myMetadataQString += "<tr><td bgcolor=\"white\">";
myMetadataQString += tr("Storage type of this layer : ") +
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectordataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ void QgsVectorDataProvider::getFeatureGeometry(int key, QgsFeature *f)
{
}

QString QgsVectorDataProvider::dataComment() const
{
return QString();
}

bool QgsVectorDataProvider::addFeatures(QgsFeatureList & flist)
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectordataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
*/
virtual const QgsFieldMap & fields() const = 0;

/**
* Return a short comment for the data that this provider is
* providing access to (e.g. the comment for postgres table).
*/
virtual QString dataComment() const;

/**
* Reset the layer to clear any spatial filtering or other contstraints that
* would prevent the entire record set from being traversed by call to
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ QString QgsVectorLayer::capabilitiesString() const
return 0;
}

QString QgsVectorLayer::dataComment() const
{
if (mDataProvider)
{
return mDataProvider->dataComment();
}
return QString();
}


QString QgsVectorLayer::providerType() const
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Capabilities for this layer in a friendly format. */
QString capabilitiesString() const;

/** Returns a comment for the data in the layer */
QString dataComment() const;

/** Set the primary display field to be used in the identify results dialog */
void setDisplayField(QString fldName=0);

Expand Down
13 changes: 7 additions & 6 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,13 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
QString tableoid = PQgetvalue(tresult, 0, 0);
PQclear(tresult);

/* Code to extrac the table description. Needs a way to make is accesssible
to the rest of qgis...
// Get the table description
sql = "SELECT description FROM pg_description WHERE "
"classoid = " + tableoid + " AND objsubid = 0";
"objoid = " + tableoid + " AND objsubid = 0";
tresult = PQexec(pd, (const char*) sql.utf8());
if (PQntuples(tresult) > 0)
mDescription = PQgetvalue(tresult, 0, 0);
mDataComment = PQgetvalue(tresult, 0, 0);
PQclear(tresult);
*/

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

QString QgsPostgresProvider::dataComment() const
{
return mDataComment;
}

void QgsPostgresProvider::reset()
{
// reset the cursor to the first record
Expand Down
7 changes: 7 additions & 0 deletions src/providers/postgres/qgspostgresprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ class QgsPostgresProvider:public QgsVectorDataProvider
*/
const QgsFieldMap & fields() const;

/**
* Return a short comment for the data that this provider is
* providing access to (e.g. the comment for postgres table).
*/
QString dataComment() const;

/** Reset the layer - for a PostgreSQL layer, this means clearing the PQresult
* pointer and setting it to 0
*/
Expand Down Expand Up @@ -335,6 +341,7 @@ class QgsPostgresProvider:public QgsVectorDataProvider
std::vector < QgsFeature > features;
QgsFieldMap attributeFields;
std::map < int, int > attributeFieldsIdMap;
QString mDataComment;

//! Data source URI struct for this layer
QgsDataSourceURI mUri;
Expand Down

0 comments on commit 34431bf

Please sign in to comment.