Skip to content

Commit 14f861c

Browse files

File tree

1 file changed

+149
-149
lines changed

1 file changed

+149
-149
lines changed
 

‎src/app/qgsmaptoolidentify.cpp

Lines changed: 149 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)
4747
QPixmap myIdentifyQPixmap = QPixmap((const char **) identify_cursor);
4848
mCursor = QCursor(myIdentifyQPixmap, 1, 1);
4949
}
50-
50+
5151
QgsMapToolIdentify::~QgsMapToolIdentify()
5252
{
5353
if (mResults)
@@ -61,20 +61,20 @@ QgsMapToolIdentify::~QgsMapToolIdentify()
6161
void QgsMapToolIdentify::canvasMoveEvent(QMouseEvent * e)
6262
{
6363
}
64-
64+
6565
void QgsMapToolIdentify::canvasPressEvent(QMouseEvent * e)
6666
{
6767
}
6868

6969
void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)
7070
{
7171
if(!mCanvas || mCanvas->isDrawing())
72-
{
73-
return;
74-
}
72+
{
73+
return;
74+
}
7575

7676
QgsMapLayer* layer = mCanvas->currentLayer();
77-
77+
7878
// delete rubber band if there was any
7979
delete mRubberBand;
8080
mRubberBand = 0;
@@ -119,22 +119,22 @@ void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)
119119
else
120120
{
121121
QMessageBox::warning(mCanvas,
122-
QObject::tr("No active layer"),
123-
QObject::tr("To identify features, you must choose an active layer by clicking on its name in the legend"));
122+
QObject::tr("No active layer"),
123+
QObject::tr("To identify features, you must choose an active layer by clicking on its name in the legend"));
124124
}
125125

126-
126+
127127
}
128128

129129

130130
void QgsMapToolIdentify::identifyRasterLayer(QgsRasterLayer* layer, const QgsPoint& point)
131131
{
132132
if (!layer)
133133
return;
134-
134+
135135
QMap<QString, QString> attributes;
136136
layer->identify(point, attributes);
137-
137+
138138
if(!mResults)
139139
{
140140
QgsAttributeAction aa;
@@ -179,9 +179,9 @@ void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const Qgs
179179
QgsRect viewExtent = mCanvas->extent();
180180
double mupp = mCanvas->mupp();
181181
if(mupp == 0)
182-
{
183-
return;
184-
}
182+
{
183+
return;
184+
}
185185
double xMinView = viewExtent.xMin();
186186
double yMaxView = viewExtent.yMax();
187187

@@ -192,26 +192,26 @@ void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const Qgs
192192
double i, j;
193193

194194
if(xMinView < xMinLayer)
195-
{
196-
i = (int)(point.x() - (xMinLayer - xMinView) / mupp);
197-
}
195+
{
196+
i = (int)(point.x() - (xMinLayer - xMinView) / mupp);
197+
}
198198
else
199-
{
200-
i = point.x();
201-
}
199+
{
200+
i = point.x();
201+
}
202202

203203
if(yMaxView > yMaxLayer)
204-
{
205-
j = (int)(point.y() - (yMaxView - yMaxLayer) / mupp);
206-
}
204+
{
205+
j = (int)(point.y() - (yMaxView - yMaxLayer) / mupp);
206+
}
207207
else
208-
{
209-
j = point.y();
210-
}
211-
208+
{
209+
j = point.y();
210+
}
211+
212212

213213
QString text = layer->identifyAsText(QgsPoint(i, j));
214-
214+
215215
if (text.isEmpty())
216216
{
217217
showError(layer);
@@ -229,21 +229,21 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
229229
{
230230
if (!layer)
231231
return;
232-
232+
233233
// load identify radius from settings
234234
QSettings settings;
235235
double identifyValue = settings.value("/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS).toDouble();
236236
QString ellipsoid = settings.value("/qgis/measure/ellipsoid", "WGS84").toString();
237237

238238
// create the search rectangle
239239
double searchRadius = mCanvas->extent().width() * (identifyValue/100.0);
240-
240+
241241
QgsRect r;
242242
r.setXmin(point.x() - searchRadius);
243243
r.setXmax(point.x() + searchRadius);
244244
r.setYmin(point.y() - searchRadius);
245245
r.setYmax(point.y() + searchRadius);
246-
246+
247247
r = toLayerCoords(layer, r);
248248

249249
int featureCount = 0;
@@ -258,126 +258,126 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
258258
calc.setProjectionsEnabled(mCanvas->projectionsEnabled()); // project?
259259
calc.setEllipsoid(ellipsoid);
260260
calc.setSourceSRS(layer->srs().srsid());
261-
261+
262262
// display features falling within the search radius
263263
if(!mResults)
264-
{
265-
mResults = new QgsIdentifyResults(actions, mCanvas->window());
266-
mResults->setAttribute(Qt::WA_DeleteOnClose);
267-
// Be informed when the dialog box is closed so that we can stop using it.
268-
connect(mResults, SIGNAL(accepted()), this, SLOT(resultsDialogGone()));
269-
connect(mResults, SIGNAL(rejected()), this, SLOT(resultsDialogGone()));
270-
connect(mResults, SIGNAL(selectedFeatureChanged(int)), this, SLOT(highlightFeature(int)));
271-
// restore the identify window position and show it
272-
mResults->restorePosition();
273-
}
264+
{
265+
mResults = new QgsIdentifyResults(actions, mCanvas->window());
266+
mResults->setAttribute(Qt::WA_DeleteOnClose);
267+
// Be informed when the dialog box is closed so that we can stop using it.
268+
connect(mResults, SIGNAL(accepted()), this, SLOT(resultsDialogGone()));
269+
connect(mResults, SIGNAL(rejected()), this, SLOT(resultsDialogGone()));
270+
connect(mResults, SIGNAL(selectedFeatureChanged(int)), this, SLOT(highlightFeature(int)));
271+
// restore the identify window position and show it
272+
mResults->restorePosition();
273+
}
274274
else
275-
{
276-
mResults->raise();
277-
mResults->clear();
278-
mResults->setActions(actions);
279-
}
280-
275+
{
276+
mResults->raise();
277+
mResults->clear();
278+
mResults->setActions(actions);
279+
}
280+
281281
QApplication::setOverrideCursor(Qt::WaitCursor);
282-
282+
283283
int lastFeatureId = 0;
284-
284+
285285
QList<QgsFeature> featureList;
286286
layer->featuresInRectangle(r, featureList, true, true);
287287
QList<QgsFeature>::iterator f_it = featureList.begin();
288-
288+
289289
for(; f_it != featureList.end(); ++f_it)
290+
{
291+
featureCount++;
292+
293+
QTreeWidgetItem* featureNode = mResults->addNode("foo");
294+
featureNode->setData(0, Qt::UserRole, QVariant(f_it->featureId())); // save feature id
295+
lastFeatureId = f_it->featureId();
296+
featureNode->setText(0, fieldIndex);
297+
const QgsAttributeMap& attr = f_it->attributeMap();
298+
299+
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
300+
{
301+
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
302+
303+
if (fields[it.key()].name() == fieldIndex)
290304
{
291-
featureCount++;
292-
293-
QTreeWidgetItem* featureNode = mResults->addNode("foo");
294-
featureNode->setData(0, Qt::UserRole, QVariant(f_it->featureId())); // save feature id
295-
lastFeatureId = f_it->featureId();
296-
featureNode->setText(0, fieldIndex);
297-
const QgsAttributeMap& attr = f_it->attributeMap();
298-
299-
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
300-
{
301-
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
302-
303-
if (fields[it.key()].name() == fieldIndex)
304-
{
305-
featureNode->setText(1, it->toString());
306-
}
307-
mResults->addAttribute(featureNode, fields[it.key()].name(), it->isNull() ? "NULL" : it->toString());
308-
}
309-
310-
// Calculate derived attributes and insert:
311-
// measure distance or area depending on geometry type
312-
if (layer->vectorType() == QGis::Line)
313-
{
314-
double dist = calc.measure(f_it->geometry());
315-
QString str = calc.textUnit(dist, 3, mCanvas->mapUnits(), false);
316-
mResults->addDerivedAttribute(featureNode, QObject::tr("Length"), str);
317-
}
318-
else if (layer->vectorType() == QGis::Polygon)
319-
{
320-
double area = calc.measure(f_it->geometry());
321-
QString str = calc.textUnit(area, 3, mCanvas->mapUnits(), true);
322-
mResults->addDerivedAttribute(featureNode, QObject::tr("Area"), str);
323-
}
324-
325-
// Add actions
326-
QgsAttributeAction::aIter iter = actions.begin();
327-
for (register int i = 0; iter != actions.end(); ++iter, ++i)
328-
{
329-
mResults->addAction( featureNode, i, QObject::tr("action"), iter->name() );
330-
}
331-
332-
}
333-
334-
QgsDebugMsg("Feature count on identify: " + QString::number(featureCount));
335-
336-
//also test the not commited features //todo: eliminate copy past code
337-
338-
mResults->setTitle(layer->name() + " - " + QString::number(featureCount) + QObject::tr(" features found"));
339-
if (featureCount == 1)
340-
{
341-
mResults->showAllAttributes();
342-
mResults->setTitle(layer->name() + " - " + QObject::tr(" 1 feature found") );
343-
highlightFeature(lastFeatureId);
344-
}
345-
else if (featureCount == 0)
346-
{
347-
mResults->setTitle(layer->name() + " - " + QObject::tr("No features found") );
348-
mResults->setMessage ( QObject::tr("No features found"), QObject::tr("No features were found in the active layer at the point you clicked") );
349-
}
350-
else
351-
{
352-
QString title = layer->name();
353-
title += QString( tr("- %1 features found","Identify results window title",featureCount) ).arg(featureCount);
354-
mResults->setTitle(title);
305+
featureNode->setText(1, it->toString());
355306
}
356-
QApplication::restoreOverrideCursor();
357-
358-
mResults->show();
307+
mResults->addAttribute(featureNode, fields[it.key()].name(), it->isNull() ? "NULL" : it->toString());
308+
}
309+
310+
// Calculate derived attributes and insert:
311+
// measure distance or area depending on geometry type
312+
if (layer->vectorType() == QGis::Line)
313+
{
314+
double dist = calc.measure(f_it->geometry());
315+
QString str = calc.textUnit(dist, 3, mCanvas->mapUnits(), false);
316+
mResults->addDerivedAttribute(featureNode, QObject::tr("Length"), str);
317+
}
318+
else if (layer->vectorType() == QGis::Polygon)
319+
{
320+
double area = calc.measure(f_it->geometry());
321+
QString str = calc.textUnit(area, 3, mCanvas->mapUnits(), true);
322+
mResults->addDerivedAttribute(featureNode, QObject::tr("Area"), str);
323+
}
324+
325+
// Add actions
326+
QgsAttributeAction::aIter iter = actions.begin();
327+
for (register int i = 0; iter != actions.end(); ++iter, ++i)
328+
{
329+
mResults->addAction( featureNode, i, QObject::tr("action"), iter->name() );
330+
}
331+
332+
}
333+
334+
QgsDebugMsg("Feature count on identify: " + QString::number(featureCount));
335+
336+
//also test the not commited features //todo: eliminate copy past code
337+
338+
mResults->setTitle(layer->name() + " - " + QString::number(featureCount) + QObject::tr(" features found"));
339+
if (featureCount == 1)
340+
{
341+
mResults->showAllAttributes();
342+
mResults->setTitle(layer->name() + " - " + QObject::tr(" 1 feature found") );
343+
highlightFeature(lastFeatureId);
344+
}
345+
else if (featureCount == 0)
346+
{
347+
mResults->setTitle(layer->name() + " - " + QObject::tr("No features found") );
348+
mResults->setMessage ( QObject::tr("No features found"), QObject::tr("No features were found in the active layer at the point you clicked") );
349+
}
350+
else
351+
{
352+
QString title = layer->name();
353+
title += QString( tr("- %1 features found","Identify results window title",featureCount) ).arg(featureCount);
354+
mResults->setTitle(title);
355+
}
356+
QApplication::restoreOverrideCursor();
357+
358+
mResults->show();
359359
}
360360

361361
#if 0 //MH: old state of the function
362362
void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoint& point)
363363
{
364364
if (!layer)
365365
return;
366-
366+
367367
// load identify radius from settings
368368
QSettings settings;
369369
double identifyValue = settings.value("/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS).toDouble();
370370
QString ellipsoid = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
371371

372372
// create the search rectangle
373373
double searchRadius = mCanvas->extent().width() * (identifyValue/100.0);
374-
374+
375375
QgsRect r;
376376
r.setXmin(point.x() - searchRadius);
377377
r.setXmax(point.x() + searchRadius);
378378
r.setYmin(point.y() - searchRadius);
379379
r.setYmax(point.y() + searchRadius);
380-
380+
381381
r = toLayerCoords(layer, r);
382382

383383
int featureCount = 0;
@@ -387,15 +387,15 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
387387
QgsVectorDataProvider* dataProvider = layer->getDataProvider();
388388
QgsAttributeList allAttributes = dataProvider->allAttributesList();
389389
const QgsFieldMap& fields = dataProvider->fields();
390-
390+
391391
dataProvider->select(allAttributes, r, true, true);
392392

393393
// init distance/area calculator
394394
QgsDistanceArea calc;
395395
calc.setProjectionsEnabled(mCanvas->projectionsEnabled()); // project?
396396
calc.setEllipsoid(ellipsoid);
397397
calc.setSourceSRS(layer->srs().srsid());
398-
398+
399399
if ( !layer->isEditable() )
400400
{
401401
// display features falling within the search radius
@@ -418,7 +418,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
418418
}
419419

420420
QApplication::setOverrideCursor(Qt::WaitCursor);
421-
421+
422422
int lastFeatureId = 0;
423423

424424
QTreeWidgetItem *click = mResults->addNode(tr("(clicked coordinate)"));
@@ -433,11 +433,11 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
433433
lastFeatureId = feat.featureId();
434434
featureNode->setText(0, fieldIndex);
435435
const QgsAttributeMap& attr = feat.attributeMap();
436-
436+
437437
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
438438
{
439439
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
440-
440+
441441
if (fields[it.key()].name() == fieldIndex)
442442
{
443443
featureNode->setText(1, it->toString());
@@ -500,7 +500,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
500500
// Edit attributes
501501
// TODO: what to do if more features were selected? - nearest?
502502
QgsChangedAttributesMap& changedAttributes = layer->changedAttributes();
503-
503+
504504
QApplication::setOverrideCursor(Qt::WaitCursor);
505505

506506
if (dataProvider->getNextFeature(feat))
@@ -563,9 +563,9 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
563563
{
564564
QApplication::restoreOverrideCursor();
565565
QMessageBox::information(0, tr("No features found"),
566-
tr("<p>No features were found within the search radius. "
567-
"Note that it is currently not possible to use the "
568-
"identify tool on unsaved features.</p>"));
566+
tr("<p>No features were found within the search radius. "
567+
"Note that it is currently not possible to use the "
568+
"identify tool on unsaved features.</p>"));
569569
}
570570
}
571571
}
@@ -574,26 +574,26 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
574574

575575
void QgsMapToolIdentify::showError(QgsMapLayer * mapLayer)
576576
{
577-
// QMessageBox::warning(
578-
// this,
579-
// mapLayer->errorCaptionString(),
580-
// tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
581-
// mapLayer->errorString()
582-
// );
577+
// QMessageBox::warning(
578+
// this,
579+
// mapLayer->errorCaptionString(),
580+
// tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
581+
// mapLayer->errorString()
582+
// );
583583

584584
QgsMessageViewer * mv = new QgsMessageViewer();
585585
mv->setWindowTitle( mapLayer->errorCaptionString() );
586586
mv->setMessageAsPlainText(
587-
QObject::tr("Could not identify objects on") + " " + mapLayer->name() + " " + QObject::tr("because") + ":\n" +
588-
mapLayer->errorString()
589-
);
587+
QObject::tr("Could not identify objects on") + " " + mapLayer->name() + " " + QObject::tr("because") + ":\n" +
588+
mapLayer->errorString()
589+
);
590590
mv->exec(); // deletes itself on close
591591
}
592592

593593
void QgsMapToolIdentify::resultsDialogGone()
594594
{
595595
mResults = 0;
596-
596+
597597
delete mRubberBand;
598598
mRubberBand = 0;
599599
}
@@ -610,23 +610,23 @@ void QgsMapToolIdentify::highlightFeature(int featureId)
610610
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>(mCanvas->currentLayer());
611611
if (!layer)
612612
return;
613-
613+
614614
delete mRubberBand;
615615
mRubberBand = 0;
616616

617617
QgsFeature feat;
618618
if(layer->getFeatureAtId(featureId, feat, true, false) != 0)
619-
{
620-
return;
621-
}
619+
{
620+
return;
621+
}
622622

623623
if(!feat.geometry())
624-
{
625-
return;
626-
}
627-
624+
{
625+
return;
626+
}
627+
628628
mRubberBand = new QgsRubberBand(mCanvas, feat.geometry()->vectorType() == QGis::Polygon);
629-
629+
630630
if (mRubberBand)
631631
{
632632
mRubberBand->setToGeometry(feat.geometry(), *layer);

0 commit comments

Comments
 (0)
Please sign in to comment.