Skip to content
Permalink
Browse files
multiple features displayed when doing identify
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 c5cd29303d41de3359b57b0ce6612ead44efc3c9
Showing with 158 additions and 55 deletions.
  1. +3 −2 src/qgisapp.cpp
  2. +42 −12 src/qgsdatabaselayer.cpp
  3. +8 −2 src/qgsidentifyresults.cpp
  4. +6 −3 src/qgsidentifyresults.h
  5. +40 −26 src/qgsidentifyresultsbase.ui
  6. +59 −10 src/qgsshapefilelayer.cpp
@@ -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[] = {
@@ -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"
@@ -23,6 +23,7 @@
#include <qpen.h>
#include <qpointarray.h>
#include <qbrush.h>
#include <qlistview.h>

#include "qgis.h"
#include "qgsrect.h"
@@ -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
@@ -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();
@@ -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
@@ -15,6 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#include <qlistview.h>
#include "qgsidentifyresults.h"

@@ -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)
@@ -15,7 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/

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

@@ -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);
};

@@ -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">
@@ -8,7 +8,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<width>281</width>
<height>316</height>
</rect>
</property>
@@ -50,7 +50,7 @@
<string>Help</string>
</property>
<property name="accel">
<number>4144</number>
<string>F1</string>
</property>
<property name="autoDefault">
<bool>true</bool>
@@ -81,7 +81,7 @@
<string>OK</string>
</property>
<property name="accel">
<number>0</number>
<string></string>
</property>
<property name="autoDefault">
<bool>true</bool>
@@ -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>
@@ -31,6 +31,7 @@
#include "qgsshapefilelayer.h"
#include "qgsidentifyresults.h"
#include "qgsattributetable.h"
#include <qlistview.h>
#include <ogrsf_frmts.h>
#include <ogr_geometry.h>

@@ -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();

0 comments on commit c5cd293

Please sign in to comment.