Skip to content

Commit c5cd293

Browse files
author
gsherman
committedSep 1, 2003
multiple features displayed when doing identify
git-svn-id: http://svn.osgeo.org/qgis/trunk@252 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a90cdcb commit c5cd293

File tree

6 files changed

+158
-55
lines changed

6 files changed

+158
-55
lines changed
 

‎src/qgisapp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ typedef QString name_t();
8181
typedef QString description_t();
8282

8383
// version
84-
static const char *qgisVersion = "0.0.12 pre 2 - August 15, 2003";
84+
static const char *qgisVersion = "0.0.12 pre 3 - August 31, 2003";
8585
static const int qgisVersionInt = 11;
8686
// cursors
8787
static unsigned char zoom_in_bits[] = {
@@ -227,7 +227,8 @@ void QgisApp::about()
227227
abt->setURLs(urls);
228228
QString watsNew = "Version ";
229229
watsNew += qgisVersion;
230-
watsNew += "\n**Preliminary Plugin Manager implementation\n"
230+
watsNew += "\n**Multiple features displayed with the Identify tool\n"
231+
"**Preliminary Plugin Manager implementation\n"
231232
"**Version check under tools menu\n"
232233
"**Version checking uses port 80 to prevent problems with firewalls\n"
233234
"**Fix for PostGIS bug when srid != -1\n"

‎src/qgsdatabaselayer.cpp

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <qpen.h>
2424
#include <qpointarray.h>
2525
#include <qbrush.h>
26+
#include <qlistview.h>
2627

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

479480
}
480481

482+
//{{{ QgsDatabaseLayer::identify(QgsRect * r)
481483
void QgsDatabaseLayer::identify(QgsRect * r)
482484
{
483485
// create a search filter for identifying records
@@ -500,18 +502,46 @@ void QgsDatabaseLayer::identify(QgsRect * r)
500502
// std::cout << "Using following transform parameters:\n" << cXf->showParameters() << std::endl;
501503
// create the results window
502504
if (pgs.Tuples() > 0) {
505+
int idxName = -1;
506+
int idxId = -1;
507+
// determine the field to use for the feature node label
508+
for (int fi = 0; fi < pgs.Fields(); fi++) {
509+
QString fldName = pgs.FieldName(fi);
510+
if(fldName.contains("name", false)){
511+
idxName = fi;
512+
}
513+
if(fldName.contains("id", false )){
514+
idxId = fi;
515+
}
516+
}
517+
int fieldIndex = 0;
518+
if(idxName > -1){
519+
fieldIndex = idxName;
520+
}else{
521+
if(idxId > -1){
522+
fieldIndex = idxId;
523+
}
524+
}
503525
QgsIdentifyResults *ir = new QgsIdentifyResults();
504-
// just show one result - modify this later
505-
int numFields = pgs.Fields();
506-
for (int i = 0; i < numFields; i++) {
507-
QString fld = pgs.FieldName(i);
508-
int fldType = pgs.FieldType(i);
509-
QString val;
510-
if (fldType == 16604) // geometry
511-
val = "(geometry column)";
512-
else
513-
val = pgs.GetValue(0, i);
514-
ir->addAttribute(fld, val);
526+
for(int j = 0; j < pgs.Tuples(); j++){
527+
// display all features in the search area
528+
int numFields = pgs.Fields();
529+
QListViewItem *featureNode = ir->addNode("foo");
530+
for (int i = 0; i < numFields; i++) {
531+
QString fld = pgs.FieldName(i);
532+
int fldType = pgs.FieldType(i);
533+
QString val;
534+
if (fldType == 16604) // geometry
535+
val = "(geometry column)";
536+
else
537+
val = pgs.GetValue(j, i);
538+
539+
if(i == fieldIndex){
540+
featureNode->setText(0,val);
541+
std::cout << "Adding feature node: " << val << std::endl;
542+
}
543+
ir->addAttribute(featureNode, fld, val);
544+
}
515545
}
516546
ir->setTitle(name());
517547
ir->show();
@@ -520,7 +550,7 @@ void QgsDatabaseLayer::identify(QgsRect * r)
520550
QMessageBox::information(0, "No features found", "No features were found in the active layer at the point you clicked");
521551
}
522552

523-
}
553+
} //}}}
524554
void QgsDatabaseLayer::table()
525555
{
526556
// display the attribute table

‎src/qgsidentifyresults.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* (at your option) any later version. *
1616
* *
1717
***************************************************************************/
18+
/* $Id$ */
1819
#include <qlistview.h>
1920
#include "qgsidentifyresults.h"
2021

@@ -27,9 +28,14 @@ QgsIdentifyResults::~QgsIdentifyResults()
2728
}
2829

2930
/** add an attribute and its value to the list */
30-
void QgsIdentifyResults::addAttribute(QString field, QString value)
31+
void QgsIdentifyResults::addAttribute(QListViewItem *fnode, QString field, QString value)
3132
{
32-
QListViewItem *lvi = new QListViewItem(lstResults, field, value);
33+
new QListViewItem(fnode, field, value);
34+
}
35+
36+
/** Add a feature node to the list */
37+
QListViewItem * QgsIdentifyResults::addNode(QString label){
38+
return (new QListViewItem(lstResults,label));
3339
}
3440

3541
void QgsIdentifyResults::setTitle(QString title)

‎src/qgsidentifyresults.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (at your option) any later version. *
1616
* *
1717
***************************************************************************/
18-
18+
/* $Id$ */
1919
#ifndef QGSIDENTIFYRESULTS_H
2020
#define QGSIDENTIFYRESULTS_H
2121

@@ -30,8 +30,11 @@ class QgsIdentifyResults:public QgsIdentifyResultsBase
3030
public:
3131
QgsIdentifyResults();
3232
~QgsIdentifyResults();
33-
/** No descriptions */
34-
void addAttribute(QString field, QString value);
33+
/** Add an attribute to the feature display node */
34+
void addAttribute(QListViewItem *parent, QString field, QString value);
35+
/** Add a feature node to the feature display */
36+
QListViewItem * addNode(QString label);
37+
/** Set the title for the identify results dialog */
3538
void setTitle(QString title);
3639
};
3740

‎src/qgsidentifyresultsbase.ui

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE UI><UI version="3.0" stdsetdef="1">
1+
<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
22
<class>QgsIdentifyResultsBase</class>
33
<widget class="QDialog">
44
<property name="name">
@@ -8,7 +8,7 @@
88
<rect>
99
<x>0</x>
1010
<y>0</y>
11-
<width>275</width>
11+
<width>281</width>
1212
<height>316</height>
1313
</rect>
1414
</property>
@@ -50,7 +50,7 @@
5050
<string>Help</string>
5151
</property>
5252
<property name="accel">
53-
<number>4144</number>
53+
<string>F1</string>
5454
</property>
5555
<property name="autoDefault">
5656
<bool>true</bool>
@@ -81,7 +81,7 @@
8181
<string>OK</string>
8282
</property>
8383
<property name="accel">
84-
<number>0</number>
84+
<string></string>
8585
</property>
8686
<property name="autoDefault">
8787
<bool>true</bool>
@@ -98,40 +98,54 @@
9898
<string>Cancel</string>
9999
</property>
100100
<property name="accel">
101-
<number>0</number>
101+
<string></string>
102102
</property>
103103
<property name="autoDefault">
104104
<bool>true</bool>
105105
</property>
106106
</widget>
107107
</hbox>
108108
</widget>
109-
<widget class="QListView" row="0" column="0">
110-
<column>
111-
<property name="text">
112-
<string>Field</string>
113-
</property>
114-
<property name="clickable">
115-
<bool>true</bool>
116-
</property>
117-
<property name="resizeable">
118-
<bool>true</bool>
119-
</property>
120-
</column>
121-
<column>
122-
<property name="text">
123-
<string>Value</string>
109+
<widget class="QSplitter" row="0" column="0">
110+
<property name="name">
111+
<cstring>splitter1</cstring>
112+
</property>
113+
<property name="orientation">
114+
<enum>Horizontal</enum>
115+
</property>
116+
<widget class="QListView">
117+
<column>
118+
<property name="text">
119+
<string>Feature</string>
120+
</property>
121+
<property name="clickable">
122+
<bool>true</bool>
123+
</property>
124+
<property name="resizable">
125+
<bool>true</bool>
126+
</property>
127+
</column>
128+
<column>
129+
<property name="text">
130+
<string>Value</string>
131+
</property>
132+
<property name="clickable">
133+
<bool>true</bool>
134+
</property>
135+
<property name="resizable">
136+
<bool>true</bool>
137+
</property>
138+
</column>
139+
<property name="name">
140+
<cstring>lstResults</cstring>
124141
</property>
125-
<property name="clickable">
142+
<property name="showSortIndicator">
126143
<bool>true</bool>
127144
</property>
128-
<property name="resizeable">
145+
<property name="rootIsDecorated">
129146
<bool>true</bool>
130147
</property>
131-
</column>
132-
<property name="name">
133-
<cstring>lstResults</cstring>
134-
</property>
148+
</widget>
135149
</widget>
136150
</grid>
137151
</widget>

‎src/qgsshapefilelayer.cpp

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "qgsshapefilelayer.h"
3232
#include "qgsidentifyresults.h"
3333
#include "qgsattributetable.h"
34+
#include <qlistview.h>
3435
#include <ogrsf_frmts.h>
3536
#include <ogr_geometry.h>
3637

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

354355
ogrLayer->SetSpatialFilter(filter);
355356
int featureCount = 0;
356-
// just id the first feature for now
357-
//while (OGRFeature * fet = ogrLayer->GetNextFeature()) {
357+
// display features falling within the search radius
358+
QgsIdentifyResults *ir = 0;
359+
while (OGRFeature * fet = ogrLayer->GetNextFeature()) {
358360
//}
359361

360-
OGRFeature *fet = ogrLayer->GetNextFeature();
361362
if (fet) {
362-
// found feature - show it in the identify box
363-
QgsIdentifyResults *ir = new QgsIdentifyResults();
364-
// just show one result - modify this later
363+
featureCount++;
364+
// found at least one feature - show it in the identify box
365+
if(ir == 0){
366+
// create the identify results dialog if it doesn't already
367+
// exist
368+
ir = new QgsIdentifyResults();
369+
}
370+
365371
int numFields = fet->GetFieldCount();
372+
// Determine the field index for the feature column of the identify
373+
// dialog. We look for fields containing "name" first and second for
374+
// fields containing "id". If neither are found, the first field
375+
// is used as the node.
376+
int idxName = -1;
377+
int idxId = -1;
378+
for(int j = 0; j < numFields; j++){
379+
OGRFieldDefn *def = fet->GetFieldDefnRef(j);
380+
QString fldName = def->GetNameRef();
381+
std::cout << "Checking field " << fldName << std::endl;
382+
if(fldName.contains("name", false)){
383+
idxName = j;
384+
break;
385+
}
386+
if(fldName.contains("id", false )){
387+
idxId = j;
388+
break;
389+
}
390+
}
391+
int fieldIndex = 0;
392+
if(idxName > -1){
393+
fieldIndex = idxName;
394+
}else{
395+
if(idxId > -1){
396+
fieldIndex = idxId;
397+
}
398+
}
399+
std::cout << "Field index for feature label is " << fieldIndex << std::endl;
400+
QListViewItem *featureNode = ir->addNode("foo");
366401
for (int i = 0; i < numFields; i++) {
367-
// get the field definition
402+
403+
// add the feature attributes to the tree
368404
OGRFieldDefn *fldDef = fet->GetFieldDefnRef(i);
369405
QString fld = fldDef->GetNameRef();
370406
OGRFieldType fldType = fldDef->GetType();
371407
QString val;
408+
372409
//if(fldType == 16604 ) // geometry
373410
val = "(geometry column)";
374411
// else
375412
val = fet->GetFieldAsString(i);
376-
ir->addAttribute(fld, val);
413+
// Create a node for this feature
414+
std::cout << "i / fieldIndex " << i << " / " << fieldIndex << std::endl;
415+
if(i == fieldIndex){
416+
featureNode->setText(0,val);
417+
std::cout << "Adding feature node: " << val << std::endl;
418+
}
419+
std::cout << "Adding attribute " << fld << " = " << val << std::endl;
420+
ir->addAttribute(featureNode, fld, val);
377421
}
422+
}
423+
424+
}
425+
std::cout << "Feature count on identify: " << featureCount << std::endl;
426+
if(ir){
378427
ir->setTitle(name());
379428
ir->show();
380-
381-
} else {
429+
}
430+
if(featureCount == 0){
382431
QMessageBox::information(0, "No features found", "No features were found in the active layer at the point you clicked");
383432
}
384433
ogrLayer->ResetReading();

0 commit comments

Comments
 (0)
Please sign in to comment.