@@ -54,6 +54,9 @@ QgsIdentifyResults::QgsIdentifyResults(const QgsAttributeAction& actions,
5454
5555 connect ( lstResults, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
5656 this , SLOT (handleCurrentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)));
57+
58+ // The label to use for the Derived node in the identify results
59+ mDerivedLabel = tr (" (Derived)" );
5760}
5861
5962QgsIdentifyResults::~QgsIdentifyResults ()
@@ -121,30 +124,7 @@ void QgsIdentifyResults::contextMenuEvent(QContextMenuEvent* event)
121124 }
122125 // Save the attribute values as these are needed for substituting into
123126 // the action.
124- // A little bit complicated because the user could of right-clicked
125- // on a parent or a child in the dialog box. We also want to keep
126- // track of which row in the identify results table was actually
127- // clicked on. This is stored as an index into the mValues vector.
128-
129- QTreeWidgetItem* parent = item->parent ();
130- if (parent == 0 )
131- parent = item;
132-
133- mValues .clear ();
134- for (int j = 0 ; j < parent->childCount (); ++j)
135- {
136- if ( parent->child (j)->text (0 ) != " action" ) {
137- mValues .push_back (std::make_pair (parent->child (j)->text (0 ),
138- parent->child (j)->text (1 )));
139- // Need to do the comparison on the text strings rather than the
140- // pointers because if the user clicked on the parent, we need
141- // to pick up which child that actually is (the parent in the
142- // identify results dialog box is just one of the children
143- // that has been chosen by some method).
144- if (parent->child (j)->text (0 ) == item->text (0 ))
145- mClickedOnValue = j;
146- }
147- }
127+ extractAllItemData (item);
148128
149129 if (mActions .size () > 0 )
150130 mActionPopup ->popup (event->globalPos ());
@@ -194,7 +174,7 @@ void QgsIdentifyResults::addDerivedAttribute(QTreeWidgetItem * fnode, QString fi
194174 else
195175 {
196176 // Create new derived-attribute root node
197- daRootNode = new QTreeWidgetItem (fnode, QStringList (tr ( " (Derived) " ) ));
177+ daRootNode = new QTreeWidgetItem (fnode, QStringList (mDerivedLabel ));
198178 QFont font = daRootNode->font (0 );
199179 font.setItalic (true );
200180 daRootNode->setFont (0 , font);
@@ -277,21 +257,7 @@ void QgsIdentifyResults::clicked ( QTreeWidgetItem *item )
277257
278258 int id = item->text (3 ).toInt ();
279259
280- QTreeWidgetItem* parent = item->parent ();
281- if (parent == 0 )
282- parent = item;
283-
284- mValues .clear ();
285-
286- for (int j = 0 ; j < parent->childCount (); ++j)
287- {
288- if ( parent->child (j)->text (0 ) != " action" ) {
289- mValues .push_back (std::make_pair (parent->child (j)->text (0 ),
290- parent->child (j)->text (1 )));
291- if (parent->child (j)->text (0 ) == item->text (0 ))
292- mClickedOnValue = j;
293- }
294- }
260+ extractAllItemData (item);
295261
296262 mActions .doAction (id, mValues , mClickedOnValue );
297263}
@@ -337,3 +303,53 @@ void QgsIdentifyResults::handleCurrentItemChanged(QTreeWidgetItem* current, QTre
337303 mCurrentFeatureId = fid2;
338304 emit selectedFeatureChanged (mCurrentFeatureId );
339305}
306+
307+ void QgsIdentifyResults::extractAllItemData (QTreeWidgetItem* item)
308+ {
309+ // Extracts the name/value pairs from the given item. This includes data
310+ // under the (Derived) item.
311+
312+ // A little bit complicated because the user could of right-clicked
313+ // on any item in the dialog box. We want a toplevel item, so walk upwards
314+ // as far as possible.
315+ // We also want to keep track of which row in the identify results table was
316+ // actually clicked on. This is stored as an index into the mValues vector.
317+
318+ QTreeWidgetItem* child = item;
319+ QTreeWidgetItem* parent = child->parent ();
320+ while (parent != 0 )
321+ {
322+ child = parent;
323+ parent = parent->parent ();
324+ }
325+ parent = child;
326+
327+ mValues .clear ();
328+
329+ // For the code below we
330+ // need to do the comparison on the text strings rather than the
331+ // pointers because if the user clicked on the parent, we need
332+ // to pick up which child that actually is (the parent in the
333+ // identify results dialog box is just one of the children
334+ // that has been chosen by some method).
335+
336+ for (int j = 0 ; j < parent->childCount (); ++j)
337+ {
338+ if ( parent->child (j)->text (0 ) != " action" ) {
339+ // For derived attributes, build up a virtual name
340+ if (parent->child (j)->text (0 ) == mDerivedLabel ) {
341+ for (int k = 0 ; k < parent->child (j)->childCount (); ++k)
342+ mValues .push_back (
343+ std::make_pair (mDerivedLabel + " ."
344+ + parent->child (j)->child (k)->text (0 ),
345+ parent->child (j)->child (k)->text (1 )));
346+ }
347+ else // do the actual feature attributes
348+ mValues .push_back (std::make_pair (parent->child (j)->text (0 ),
349+ parent->child (j)->text (1 )));
350+
351+ if (parent->child (j)->text (0 ) == item->text (0 ))
352+ mClickedOnValue = j;
353+ }
354+ }
355+ }
0 commit comments