Skip to content

Commit

Permalink
multiple features displayed when doing identify
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@252 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
gsherman committed Sep 1, 2003
1 parent a90cdcb commit c5cd293
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 55 deletions.
5 changes: 3 additions & 2 deletions src/qgisapp.cpp
Expand Up @@ -81,7 +81,7 @@ typedef QString name_t();
typedef QString description_t();

// version
static const char *qgisVersion = "0.0.12 pre 2 - August 15, 2003";
static const char *qgisVersion = "0.0.12 pre 3 - August 31, 2003";
static const int qgisVersionInt = 11;
// cursors
static unsigned char zoom_in_bits[] = {
Expand Down Expand Up @@ -227,7 +227,8 @@ void QgisApp::about()
abt->setURLs(urls);
QString watsNew = "Version ";
watsNew += qgisVersion;
watsNew += "\n**Preliminary Plugin Manager implementation\n"
watsNew += "\n**Multiple features displayed with the Identify tool\n"
"**Preliminary Plugin Manager implementation\n"
"**Version check under tools menu\n"
"**Version checking uses port 80 to prevent problems with firewalls\n"
"**Fix for PostGIS bug when srid != -1\n"
Expand Down
54 changes: 42 additions & 12 deletions src/qgsdatabaselayer.cpp
Expand Up @@ -23,6 +23,7 @@
#include <qpen.h>
#include <qpointarray.h>
#include <qbrush.h>
#include <qlistview.h>

#include "qgis.h"
#include "qgsrect.h"
Expand Down Expand Up @@ -478,6 +479,7 @@ void QgsDatabaseLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTra

}

//{{{ QgsDatabaseLayer::identify(QgsRect * r)
void QgsDatabaseLayer::identify(QgsRect * r)
{
// create a search filter for identifying records
Expand All @@ -500,18 +502,46 @@ void QgsDatabaseLayer::identify(QgsRect * r)
// std::cout << "Using following transform parameters:\n" << cXf->showParameters() << std::endl;
// create the results window
if (pgs.Tuples() > 0) {
int idxName = -1;
int idxId = -1;
// determine the field to use for the feature node label
for (int fi = 0; fi < pgs.Fields(); fi++) {
QString fldName = pgs.FieldName(fi);
if(fldName.contains("name", false)){
idxName = fi;
}
if(fldName.contains("id", false )){
idxId = fi;
}
}
int fieldIndex = 0;
if(idxName > -1){
fieldIndex = idxName;
}else{
if(idxId > -1){
fieldIndex = idxId;
}
}
QgsIdentifyResults *ir = new QgsIdentifyResults();
// just show one result - modify this later
int numFields = pgs.Fields();
for (int i = 0; i < numFields; i++) {
QString fld = pgs.FieldName(i);
int fldType = pgs.FieldType(i);
QString val;
if (fldType == 16604) // geometry
val = "(geometry column)";
else
val = pgs.GetValue(0, i);
ir->addAttribute(fld, val);
for(int j = 0; j < pgs.Tuples(); j++){
// display all features in the search area
int numFields = pgs.Fields();
QListViewItem *featureNode = ir->addNode("foo");
for (int i = 0; i < numFields; i++) {
QString fld = pgs.FieldName(i);
int fldType = pgs.FieldType(i);
QString val;
if (fldType == 16604) // geometry
val = "(geometry column)";
else
val = pgs.GetValue(j, i);

if(i == fieldIndex){
featureNode->setText(0,val);
std::cout << "Adding feature node: " << val << std::endl;
}
ir->addAttribute(featureNode, fld, val);
}
}
ir->setTitle(name());
ir->show();
Expand All @@ -520,7 +550,7 @@ void QgsDatabaseLayer::identify(QgsRect * r)
QMessageBox::information(0, "No features found", "No features were found in the active layer at the point you clicked");
}

}
} //}}}
void QgsDatabaseLayer::table()
{
// display the attribute table
Expand Down
10 changes: 8 additions & 2 deletions src/qgsidentifyresults.cpp
Expand Up @@ -15,6 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#include <qlistview.h>
#include "qgsidentifyresults.h"

Expand All @@ -27,9 +28,14 @@ QgsIdentifyResults::~QgsIdentifyResults()
}

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

/** Add a feature node to the list */
QListViewItem * QgsIdentifyResults::addNode(QString label){
return (new QListViewItem(lstResults,label));
}

void QgsIdentifyResults::setTitle(QString title)
Expand Down
9 changes: 6 additions & 3 deletions src/qgsidentifyresults.h
Expand Up @@ -15,7 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/

/* $Id$ */
#ifndef QGSIDENTIFYRESULTS_H
#define QGSIDENTIFYRESULTS_H

Expand All @@ -30,8 +30,11 @@ class QgsIdentifyResults:public QgsIdentifyResultsBase
public:
QgsIdentifyResults();
~QgsIdentifyResults();
/** No descriptions */
void addAttribute(QString field, QString value);
/** Add an attribute to the feature display node */
void addAttribute(QListViewItem *parent, QString field, QString value);
/** Add a feature node to the feature display */
QListViewItem * addNode(QString label);
/** Set the title for the identify results dialog */
void setTitle(QString title);
};

Expand Down
66 changes: 40 additions & 26 deletions src/qgsidentifyresultsbase.ui
@@ -1,4 +1,4 @@
<!DOCTYPE UI><UI version="3.0" stdsetdef="1">
<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<class>QgsIdentifyResultsBase</class>
<widget class="QDialog">
<property name="name">
Expand All @@ -8,7 +8,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<width>281</width>
<height>316</height>
</rect>
</property>
Expand Down Expand Up @@ -50,7 +50,7 @@
<string>Help</string>
</property>
<property name="accel">
<number>4144</number>
<string>F1</string>
</property>
<property name="autoDefault">
<bool>true</bool>
Expand Down Expand Up @@ -81,7 +81,7 @@
<string>OK</string>
</property>
<property name="accel">
<number>0</number>
<string></string>
</property>
<property name="autoDefault">
<bool>true</bool>
Expand All @@ -98,40 +98,54 @@
<string>Cancel</string>
</property>
<property name="accel">
<number>0</number>
<string></string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</hbox>
</widget>
<widget class="QListView" row="0" column="0">
<column>
<property name="text">
<string>Field</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizeable">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
<widget class="QSplitter" row="0" column="0">
<property name="name">
<cstring>splitter1</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<widget class="QListView">
<column>
<property name="text">
<string>Feature</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<property name="name">
<cstring>lstResults</cstring>
</property>
<property name="clickable">
<property name="showSortIndicator">
<bool>true</bool>
</property>
<property name="resizeable">
<property name="rootIsDecorated">
<bool>true</bool>
</property>
</column>
<property name="name">
<cstring>lstResults</cstring>
</property>
</widget>
</widget>
</grid>
</widget>
Expand Down
69 changes: 59 additions & 10 deletions src/qgsshapefilelayer.cpp
Expand Up @@ -31,6 +31,7 @@
#include "qgsshapefilelayer.h"
#include "qgsidentifyresults.h"
#include "qgsattributetable.h"
#include <qlistview.h>
#include <ogrsf_frmts.h>
#include <ogr_geometry.h>

Expand Down Expand Up @@ -353,32 +354,80 @@ void QgsShapeFileLayer::identify(QgsRect * r)

ogrLayer->SetSpatialFilter(filter);
int featureCount = 0;
// just id the first feature for now
//while (OGRFeature * fet = ogrLayer->GetNextFeature()) {
// display features falling within the search radius
QgsIdentifyResults *ir = 0;
while (OGRFeature * fet = ogrLayer->GetNextFeature()) {
//}

OGRFeature *fet = ogrLayer->GetNextFeature();
if (fet) {
// found feature - show it in the identify box
QgsIdentifyResults *ir = new QgsIdentifyResults();
// just show one result - modify this later
featureCount++;
// found at least one feature - show it in the identify box
if(ir == 0){
// create the identify results dialog if it doesn't already
// exist
ir = new QgsIdentifyResults();
}

int numFields = fet->GetFieldCount();
// Determine the field index for the feature column of the identify
// dialog. We look for fields containing "name" first and second for
// fields containing "id". If neither are found, the first field
// is used as the node.
int idxName = -1;
int idxId = -1;
for(int j = 0; j < numFields; j++){
OGRFieldDefn *def = fet->GetFieldDefnRef(j);
QString fldName = def->GetNameRef();
std::cout << "Checking field " << fldName << std::endl;
if(fldName.contains("name", false)){
idxName = j;
break;
}
if(fldName.contains("id", false )){
idxId = j;
break;
}
}
int fieldIndex = 0;
if(idxName > -1){
fieldIndex = idxName;
}else{
if(idxId > -1){
fieldIndex = idxId;
}
}
std::cout << "Field index for feature label is " << fieldIndex << std::endl;
QListViewItem *featureNode = ir->addNode("foo");
for (int i = 0; i < numFields; i++) {
// get the field definition

// add the feature attributes to the tree
OGRFieldDefn *fldDef = fet->GetFieldDefnRef(i);
QString fld = fldDef->GetNameRef();
OGRFieldType fldType = fldDef->GetType();
QString val;

//if(fldType == 16604 ) // geometry
val = "(geometry column)";
// else
val = fet->GetFieldAsString(i);
ir->addAttribute(fld, val);
// Create a node for this feature
std::cout << "i / fieldIndex " << i << " / " << fieldIndex << std::endl;
if(i == fieldIndex){
featureNode->setText(0,val);
std::cout << "Adding feature node: " << val << std::endl;
}
std::cout << "Adding attribute " << fld << " = " << val << std::endl;
ir->addAttribute(featureNode, fld, val);
}
}

}
std::cout << "Feature count on identify: " << featureCount << std::endl;
if(ir){
ir->setTitle(name());
ir->show();

} else {
}
if(featureCount == 0){
QMessageBox::information(0, "No features found", "No features were found in the active layer at the point you clicked");
}
ogrLayer->ResetReading();
Expand Down

0 comments on commit c5cd293

Please sign in to comment.