Skip to content

Commit

Permalink
In the Identify results window, derived attributes such as Length or …
Browse files Browse the repository at this point in the history
…Area are now placed in a subtree of the attributes list called "(Derived)". This distinguishes them from explicit attributes that are a part of the user's layer.

If programmers wish to add more derived attributes in future, they can use the new QgsIdentifyResults::addDerivedAttribute() function.

This commit should address trac ticket #100.



git-svn-id: http://svn.osgeo.org/qgis/trunk@5592 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Jul 14, 2006
1 parent 4a6923a commit 8c38434
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
29 changes: 28 additions & 1 deletion src/gui/qgsidentifyresults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
QgsIdentifyResults::QgsIdentifyResults(const QgsAttributeAction& actions,
QWidget *parent, Qt::WFlags f)
: QDialog(parent, f),
mActions(actions), mClickedOnValue(0), mActionPopup(0)
mActions(actions),
mClickedOnValue(0),
mActionPopup(0)
{
setupUi(this);
lstResults->setResizeMode(Q3ListView::AllColumns);
Expand Down Expand Up @@ -157,16 +159,41 @@ void QgsIdentifyResults::saveWindowLocation()
settings.writeEntry("/Windows/Identify/w", s.width());
settings.writeEntry("/Windows/Identify/h", s.height());
}

/** add an attribute and its value to the list */
void QgsIdentifyResults::addAttribute(Q3ListViewItem * fnode, QString field, QString value)
{
new Q3ListViewItem(fnode, field, value);
}

void QgsIdentifyResults::addAttribute(QString field, QString value)
{
new Q3ListViewItem(lstResults, field, value);
}

void QgsIdentifyResults::addDerivedAttribute(Q3ListViewItem * fnode, QString field, QString value)
{
// TODO: When we migrate this to a Qt4 QTreeViewWidget,
// this should be added as italic text instead

Q3ListViewItem * daRootNode;

// Determine if this is the first derived attribute for this
// feature or not
if (mDerivedAttributeRootNodes.find(fnode) != mDerivedAttributeRootNodes.end())
{
// Reuse existing derived-attribute root node
daRootNode = mDerivedAttributeRootNodes[fnode];
}
else
{
// Create new derived-attribute root node
daRootNode = new Q3ListViewItem(fnode, tr("(Derived)"));
}

new Q3ListViewItem(daRootNode, field, value);
}

void QgsIdentifyResults::addAction(Q3ListViewItem * fnode, int id, QString field, QString value)
{
Q3ListViewItem *item = new Q3ListViewItem(fnode, field, value, "action", QString::number(id) );
Expand Down
15 changes: 15 additions & 0 deletions src/gui/qgsidentifyresults.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgsattributeaction.h"
#include <QWidget>
#include <vector>
#include <map>

class QCloseEvent;
class Q3ListViewItem;
Expand All @@ -43,11 +44,16 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
QgsIdentifyResults(const QgsAttributeAction& actions, QWidget *parent = 0, Qt::WFlags f = 0);

~QgsIdentifyResults();

/** Add an attribute to the feature display node */
void addAttribute(Q3ListViewItem *parent, QString field, QString value);

/** Add an attribute */
void addAttribute(QString field, QString value);

/** Add a derived attribute (e.g. Length, Area) to the feature display node */
void addDerivedAttribute(Q3ListViewItem *parent, QString field, QString value);

/** Add an action to the feature display node */
void addAction(Q3ListViewItem *parent, int id, QString field, QString value);

Expand Down Expand Up @@ -90,6 +96,15 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
int mClickedOnValue;
QMenu* mActionPopup;
std::vector<std::pair<QString, QString> > mValues;

/**
Keeps track of what derived-attribute (e.g. Length, Area)
root nodes have been generated for each feature in this widget.
First item: Feature root node
Second item: Derived-attribute root node for that feature
*/
std::map<Q3ListViewItem *, Q3ListViewItem *> mDerivedAttributeRootNodes;
};

#endif
9 changes: 5 additions & 4 deletions src/gui/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,21 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
mResults->addAttribute(featureNode, attr[i].fieldName(), attr[i].fieldValue());
}

// measure distance or area
// Calculate derived attributes and insert:
// measure distance or area depending on geometry type
if (layer->vectorType() == QGis::Line)
{
double dist = calc.measure(fet->geometry());
QString str = QString::number(dist/1000, 'f', 3);
str += " km";
mResults->addAttribute(featureNode, ".Length", str);
mResults->addDerivedAttribute(featureNode, QObject::tr("Length"), str);
}
else if (layer->vectorType() == QGis::Polygon)
{
double area = calc.measure(fet->geometry());
QString str = QString::number(area/1000000, 'f', 3);
str += " km2";
mResults->addAttribute(featureNode, ".Area", str);
str += " km^2";
mResults->addDerivedAttribute(featureNode, QObject::tr("Area"), str);
}

// Add actions
Expand Down

0 comments on commit 8c38434

Please sign in to comment.