Skip to content

Commit a343e6f

Browse files
author
morb_au
committedJul 14, 2006
In the Identify results window, derived attributes such as Length or 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/qgis@5592 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed
 

‎src/gui/qgsidentifyresults.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
QgsIdentifyResults::QgsIdentifyResults(const QgsAttributeAction& actions,
3232
QWidget *parent, Qt::WFlags f)
3333
: QDialog(parent, f),
34-
mActions(actions), mClickedOnValue(0), mActionPopup(0)
34+
mActions(actions),
35+
mClickedOnValue(0),
36+
mActionPopup(0)
3537
{
3638
setupUi(this);
3739
lstResults->setResizeMode(Q3ListView::AllColumns);
@@ -157,16 +159,41 @@ void QgsIdentifyResults::saveWindowLocation()
157159
settings.writeEntry("/Windows/Identify/w", s.width());
158160
settings.writeEntry("/Windows/Identify/h", s.height());
159161
}
162+
160163
/** add an attribute and its value to the list */
161164
void QgsIdentifyResults::addAttribute(Q3ListViewItem * fnode, QString field, QString value)
162165
{
163166
new Q3ListViewItem(fnode, field, value);
164167
}
168+
165169
void QgsIdentifyResults::addAttribute(QString field, QString value)
166170
{
167171
new Q3ListViewItem(lstResults, field, value);
168172
}
169173

174+
void QgsIdentifyResults::addDerivedAttribute(Q3ListViewItem * fnode, QString field, QString value)
175+
{
176+
// TODO: When we migrate this to a Qt4 QTreeViewWidget,
177+
// this should be added as italic text instead
178+
179+
Q3ListViewItem * daRootNode;
180+
181+
// Determine if this is the first derived attribute for this
182+
// feature or not
183+
if (mDerivedAttributeRootNodes.find(fnode) != mDerivedAttributeRootNodes.end())
184+
{
185+
// Reuse existing derived-attribute root node
186+
daRootNode = mDerivedAttributeRootNodes[fnode];
187+
}
188+
else
189+
{
190+
// Create new derived-attribute root node
191+
daRootNode = new Q3ListViewItem(fnode, tr("(Derived)"));
192+
}
193+
194+
new Q3ListViewItem(daRootNode, field, value);
195+
}
196+
170197
void QgsIdentifyResults::addAction(Q3ListViewItem * fnode, int id, QString field, QString value)
171198
{
172199
Q3ListViewItem *item = new Q3ListViewItem(fnode, field, value, "action", QString::number(id) );

‎src/gui/qgsidentifyresults.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgsattributeaction.h"
2424
#include <QWidget>
2525
#include <vector>
26+
#include <map>
2627

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

4546
~QgsIdentifyResults();
47+
4648
/** Add an attribute to the feature display node */
4749
void addAttribute(Q3ListViewItem *parent, QString field, QString value);
50+
4851
/** Add an attribute */
4952
void addAttribute(QString field, QString value);
5053

54+
/** Add a derived attribute (e.g. Length, Area) to the feature display node */
55+
void addDerivedAttribute(Q3ListViewItem *parent, QString field, QString value);
56+
5157
/** Add an action to the feature display node */
5258
void addAction(Q3ListViewItem *parent, int id, QString field, QString value);
5359

@@ -90,6 +96,15 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
9096
int mClickedOnValue;
9197
QMenu* mActionPopup;
9298
std::vector<std::pair<QString, QString> > mValues;
99+
100+
/**
101+
Keeps track of what derived-attribute (e.g. Length, Area)
102+
root nodes have been generated for each feature in this widget.
103+
104+
First item: Feature root node
105+
Second item: Derived-attribute root node for that feature
106+
*/
107+
std::map<Q3ListViewItem *, Q3ListViewItem *> mDerivedAttributeRootNodes;
93108
};
94109

95110
#endif

‎src/gui/qgsmaptoolidentify.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,21 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
260260
mResults->addAttribute(featureNode, attr[i].fieldName(), attr[i].fieldValue());
261261
}
262262

263-
// measure distance or area
263+
// Calculate derived attributes and insert:
264+
// measure distance or area depending on geometry type
264265
if (layer->vectorType() == QGis::Line)
265266
{
266267
double dist = calc.measure(fet->geometry());
267268
QString str = QString::number(dist/1000, 'f', 3);
268269
str += " km";
269-
mResults->addAttribute(featureNode, ".Length", str);
270+
mResults->addDerivedAttribute(featureNode, QObject::tr("Length"), str);
270271
}
271272
else if (layer->vectorType() == QGis::Polygon)
272273
{
273274
double area = calc.measure(fet->geometry());
274275
QString str = QString::number(area/1000000, 'f', 3);
275-
str += " km2";
276-
mResults->addAttribute(featureNode, ".Area", str);
276+
str += " km^2";
277+
mResults->addDerivedAttribute(featureNode, QObject::tr("Area"), str);
277278
}
278279

279280
// Add actions

0 commit comments

Comments
 (0)
Please sign in to comment.