[QGIS Commit] r9031 - trunk/qgis/src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Aug 8 04:42:16 EDT 2008
Author: gjm
Date: 2008-08-08 04:42:16 -0400 (Fri, 08 Aug 2008)
New Revision: 9031
Modified:
trunk/qgis/src/app/qgsidentifyresults.cpp
trunk/qgis/src/app/qgsidentifyresults.h
trunk/qgis/src/app/qgsmaptoolidentify.cpp
Log:
Actions now provide access to the coordinates for points and the
start/end points for linestrings. Also includes some
raionalisation of, and subtle bug fies for, the action code.
Modified: trunk/qgis/src/app/qgsidentifyresults.cpp
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.cpp 2008-08-08 07:01:02 UTC (rev 9030)
+++ trunk/qgis/src/app/qgsidentifyresults.cpp 2008-08-08 08:42:16 UTC (rev 9031)
@@ -54,6 +54,9 @@
connect( lstResults, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
this, SLOT(handleCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
+
+ // The label to use for the Derived node in the identify results
+ mDerivedLabel = tr("(Derived)");
}
QgsIdentifyResults::~QgsIdentifyResults()
@@ -121,31 +124,8 @@
}
// Save the attribute values as these are needed for substituting into
// the action.
- // A little bit complicated because the user could of right-clicked
- // on a parent or a child in the dialog box. We also want to keep
- // track of which row in the identify results table was actually
- // clicked on. This is stored as an index into the mValues vector.
+ extractAllItemData(item);
- QTreeWidgetItem* parent = item->parent();
- if (parent == 0)
- parent = item;
-
- mValues.clear();
- for (int j = 0; j < parent->childCount(); ++j)
- {
- if ( parent->child(j)->text(0) != "action" ) {
- mValues.push_back(std::make_pair(parent->child(j)->text(0),
- parent->child(j)->text(1)));
- // Need to do the comparison on the text strings rather than the
- // pointers because if the user clicked on the parent, we need
- // to pick up which child that actually is (the parent in the
- // identify results dialog box is just one of the children
- // that has been chosen by some method).
- if (parent->child(j)->text(0) == item->text(0))
- mClickedOnValue = j;
- }
- }
-
if (mActions.size() > 0)
mActionPopup->popup(event->globalPos());
}
@@ -194,7 +174,7 @@
else
{
// Create new derived-attribute root node
- daRootNode = new QTreeWidgetItem(fnode, QStringList(tr("(Derived)")));
+ daRootNode = new QTreeWidgetItem(fnode, QStringList(mDerivedLabel));
QFont font = daRootNode->font(0);
font.setItalic(true);
daRootNode->setFont(0, font);
@@ -277,22 +257,8 @@
int id = item->text(3).toInt();
- QTreeWidgetItem* parent = item->parent();
- if (parent == 0)
- parent = item;
+ extractAllItemData(item);
- mValues.clear();
-
- for (int j = 0; j < parent->childCount(); ++j)
- {
- if ( parent->child(j)->text(0) != "action" ) {
- mValues.push_back(std::make_pair(parent->child(j)->text(0),
- parent->child(j)->text(1)));
- if (parent->child(j)->text(0) == item->text(0))
- mClickedOnValue = j;
- }
- }
-
mActions.doAction(id, mValues, mClickedOnValue);
}
void QgsIdentifyResults::on_buttonHelp_clicked()
@@ -337,3 +303,53 @@
mCurrentFeatureId = fid2;
emit selectedFeatureChanged(mCurrentFeatureId);
}
+
+void QgsIdentifyResults::extractAllItemData(QTreeWidgetItem* item)
+{
+ // Extracts the name/value pairs from the given item. This includes data
+ // under the (Derived) item.
+
+ // A little bit complicated because the user could of right-clicked
+ // on any item in the dialog box. We want a toplevel item, so walk upwards
+ // as far as possible.
+ // We also want to keep track of which row in the identify results table was
+ // actually clicked on. This is stored as an index into the mValues vector.
+
+ QTreeWidgetItem* child = item;
+ QTreeWidgetItem* parent = child->parent();
+ while (parent != 0)
+ {
+ child = parent;
+ parent = parent->parent();
+ }
+ parent = child;
+
+ mValues.clear();
+
+ // For the code below we
+ // need to do the comparison on the text strings rather than the
+ // pointers because if the user clicked on the parent, we need
+ // to pick up which child that actually is (the parent in the
+ // identify results dialog box is just one of the children
+ // that has been chosen by some method).
+
+ for (int j = 0; j < parent->childCount(); ++j)
+ {
+ if ( parent->child(j)->text(0) != "action" ) {
+ // For derived attributes, build up a virtual name
+ if (parent->child(j)->text(0) == mDerivedLabel ) {
+ for (int k = 0; k < parent->child(j)->childCount(); ++k)
+ mValues.push_back(
+ std::make_pair(mDerivedLabel + "."
+ + parent->child(j)->child(k)->text(0),
+ parent->child(j)->child(k)->text(1)));
+ }
+ else // do the actual feature attributes
+ mValues.push_back(std::make_pair(parent->child(j)->text(0),
+ parent->child(j)->text(1)));
+
+ if (parent->child(j)->text(0) == item->text(0))
+ mClickedOnValue = j;
+ }
+ }
+}
Modified: trunk/qgis/src/app/qgsidentifyresults.h
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.h 2008-08-08 07:01:02 UTC (rev 9030)
+++ trunk/qgis/src/app/qgsidentifyresults.h 2008-08-08 08:42:16 UTC (rev 9031)
@@ -116,6 +116,7 @@
std::vector<std::pair<QString, QString> > mValues;
static const int context_id = 689216579;
int mCurrentFeatureId;
+ QString mDerivedLabel;
/**
Keeps track of what derived-attribute (e.g. Length, Area)
@@ -125,6 +126,10 @@
Second item: Derived-attribute root node for that feature
*/
std::map<QTreeWidgetItem *, QTreeWidgetItem *> mDerivedAttributeRootNodes;
+
+ // Convenience function to populate mValues with all of the item names and
+ // values for a item, including the derived ones.
+ void extractAllItemData(QTreeWidgetItem* item);
};
#endif
Modified: trunk/qgis/src/app/qgsmaptoolidentify.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolidentify.cpp 2008-08-08 07:01:02 UTC (rev 9030)
+++ trunk/qgis/src/app/qgsmaptoolidentify.cpp 2008-08-08 08:42:16 UTC (rev 9031)
@@ -314,6 +314,15 @@
double dist = calc.measure(f_it->geometry());
QString str = calc.textUnit(dist, 3, mCanvas->mapUnits(), false);
mResults->addDerivedAttribute(featureNode, QObject::tr("Length"), str);
+ // Add the start and end points in as derived attributes
+ str.setNum(f_it->geometry()->asPolyline().first().x(), 'g', 10);
+ mResults->addDerivedAttribute(featureNode, "startX", str);
+ str.setNum(f_it->geometry()->asPolyline().first().y(), 'g', 10);
+ mResults->addDerivedAttribute(featureNode, "startY", str);
+ str.setNum(f_it->geometry()->asPolyline().last().x(), 'g', 10);
+ mResults->addDerivedAttribute(featureNode, "endX", str);
+ str.setNum(f_it->geometry()->asPolyline().last().y(), 'g', 10);
+ mResults->addDerivedAttribute(featureNode, "endY", str);
}
else if (layer->vectorType() == QGis::Polygon)
{
@@ -321,6 +330,15 @@
QString str = calc.textUnit(area, 3, mCanvas->mapUnits(), true);
mResults->addDerivedAttribute(featureNode, QObject::tr("Area"), str);
}
+ else if (layer->vectorType() == QGis::Point)
+ {
+ // Include the x and y coordinates of the point as a derived attribute
+ QString str;
+ str.setNum(f_it->geometry()->asPoint().x(), 'g', 10);
+ mResults->addDerivedAttribute(featureNode, "X", str);
+ str.setNum(f_it->geometry()->asPoint().y(), 'g', 10);
+ mResults->addDerivedAttribute(featureNode, "Y", str);
+ }
// Add actions
QgsAttributeAction::aIter iter = actions.begin();
More information about the QGIS-commit
mailing list