@@ -47,7 +47,7 @@ QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)
47
47
QPixmap myIdentifyQPixmap = QPixmap ((const char **) identify_cursor);
48
48
mCursor = QCursor (myIdentifyQPixmap, 1 , 1 );
49
49
}
50
-
50
+
51
51
QgsMapToolIdentify::~QgsMapToolIdentify ()
52
52
{
53
53
if (mResults )
@@ -61,20 +61,20 @@ QgsMapToolIdentify::~QgsMapToolIdentify()
61
61
void QgsMapToolIdentify::canvasMoveEvent (QMouseEvent * e)
62
62
{
63
63
}
64
-
64
+
65
65
void QgsMapToolIdentify::canvasPressEvent (QMouseEvent * e)
66
66
{
67
67
}
68
68
69
69
void QgsMapToolIdentify::canvasReleaseEvent (QMouseEvent * e)
70
70
{
71
71
if (!mCanvas || mCanvas ->isDrawing ())
72
- {
73
- return ;
74
- }
72
+ {
73
+ return ;
74
+ }
75
75
76
76
QgsMapLayer* layer = mCanvas ->currentLayer ();
77
-
77
+
78
78
// delete rubber band if there was any
79
79
delete mRubberBand ;
80
80
mRubberBand = 0 ;
@@ -119,22 +119,22 @@ void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)
119
119
else
120
120
{
121
121
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" ));
124
124
}
125
125
126
-
126
+
127
127
}
128
128
129
129
130
130
void QgsMapToolIdentify::identifyRasterLayer (QgsRasterLayer* layer, const QgsPoint& point)
131
131
{
132
132
if (!layer)
133
133
return ;
134
-
134
+
135
135
QMap<QString, QString> attributes;
136
136
layer->identify (point, attributes);
137
-
137
+
138
138
if (!mResults )
139
139
{
140
140
QgsAttributeAction aa;
@@ -179,9 +179,9 @@ void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const Qgs
179
179
QgsRect viewExtent = mCanvas ->extent ();
180
180
double mupp = mCanvas ->mupp ();
181
181
if (mupp == 0 )
182
- {
183
- return ;
184
- }
182
+ {
183
+ return ;
184
+ }
185
185
double xMinView = viewExtent.xMin ();
186
186
double yMaxView = viewExtent.yMax ();
187
187
@@ -192,26 +192,26 @@ void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const Qgs
192
192
double i, j;
193
193
194
194
if (xMinView < xMinLayer)
195
- {
196
- i = (int )(point.x () - (xMinLayer - xMinView) / mupp);
197
- }
195
+ {
196
+ i = (int )(point.x () - (xMinLayer - xMinView) / mupp);
197
+ }
198
198
else
199
- {
200
- i = point.x ();
201
- }
199
+ {
200
+ i = point.x ();
201
+ }
202
202
203
203
if (yMaxView > yMaxLayer)
204
- {
205
- j = (int )(point.y () - (yMaxView - yMaxLayer) / mupp);
206
- }
204
+ {
205
+ j = (int )(point.y () - (yMaxView - yMaxLayer) / mupp);
206
+ }
207
207
else
208
- {
209
- j = point.y ();
210
- }
211
-
208
+ {
209
+ j = point.y ();
210
+ }
211
+
212
212
213
213
QString text = layer->identifyAsText (QgsPoint (i, j));
214
-
214
+
215
215
if (text.isEmpty ())
216
216
{
217
217
showError (layer);
@@ -229,21 +229,21 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
229
229
{
230
230
if (!layer)
231
231
return ;
232
-
232
+
233
233
// load identify radius from settings
234
234
QSettings settings;
235
235
double identifyValue = settings.value (" /Map/identifyRadius" , QGis::DEFAULT_IDENTIFY_RADIUS).toDouble ();
236
236
QString ellipsoid = settings.value (" /qgis/measure/ellipsoid" , " WGS84" ).toString ();
237
237
238
238
// create the search rectangle
239
239
double searchRadius = mCanvas ->extent ().width () * (identifyValue/100.0 );
240
-
240
+
241
241
QgsRect r;
242
242
r.setXmin (point.x () - searchRadius);
243
243
r.setXmax (point.x () + searchRadius);
244
244
r.setYmin (point.y () - searchRadius);
245
245
r.setYmax (point.y () + searchRadius);
246
-
246
+
247
247
r = toLayerCoords (layer, r);
248
248
249
249
int featureCount = 0 ;
@@ -258,126 +258,126 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
258
258
calc.setProjectionsEnabled (mCanvas ->projectionsEnabled ()); // project?
259
259
calc.setEllipsoid (ellipsoid);
260
260
calc.setSourceSRS (layer->srs ().srsid ());
261
-
261
+
262
262
// display features falling within the search radius
263
263
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
+ }
274
274
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
+
281
281
QApplication::setOverrideCursor (Qt::WaitCursor);
282
-
282
+
283
283
int lastFeatureId = 0 ;
284
-
284
+
285
285
QList<QgsFeature> featureList;
286
286
layer->featuresInRectangle (r, featureList, true , true );
287
287
QList<QgsFeature>::iterator f_it = featureList.begin ();
288
-
288
+
289
289
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)
290
304
{
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 ());
355
306
}
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 ();
359
359
}
360
360
361
361
#if 0 //MH: old state of the function
362
362
void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoint& point)
363
363
{
364
364
if (!layer)
365
365
return;
366
-
366
+
367
367
// load identify radius from settings
368
368
QSettings settings;
369
369
double identifyValue = settings.value("/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS).toDouble();
370
370
QString ellipsoid = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
371
371
372
372
// create the search rectangle
373
373
double searchRadius = mCanvas->extent().width() * (identifyValue/100.0);
374
-
374
+
375
375
QgsRect r;
376
376
r.setXmin(point.x() - searchRadius);
377
377
r.setXmax(point.x() + searchRadius);
378
378
r.setYmin(point.y() - searchRadius);
379
379
r.setYmax(point.y() + searchRadius);
380
-
380
+
381
381
r = toLayerCoords(layer, r);
382
382
383
383
int featureCount = 0;
@@ -387,15 +387,15 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
387
387
QgsVectorDataProvider* dataProvider = layer->getDataProvider();
388
388
QgsAttributeList allAttributes = dataProvider->allAttributesList();
389
389
const QgsFieldMap& fields = dataProvider->fields();
390
-
390
+
391
391
dataProvider->select(allAttributes, r, true, true);
392
392
393
393
// init distance/area calculator
394
394
QgsDistanceArea calc;
395
395
calc.setProjectionsEnabled(mCanvas->projectionsEnabled()); // project?
396
396
calc.setEllipsoid(ellipsoid);
397
397
calc.setSourceSRS(layer->srs().srsid());
398
-
398
+
399
399
if ( !layer->isEditable() )
400
400
{
401
401
// display features falling within the search radius
@@ -418,7 +418,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
418
418
}
419
419
420
420
QApplication::setOverrideCursor(Qt::WaitCursor);
421
-
421
+
422
422
int lastFeatureId = 0;
423
423
424
424
QTreeWidgetItem *click = mResults->addNode(tr("(clicked coordinate)"));
@@ -433,11 +433,11 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
433
433
lastFeatureId = feat.featureId();
434
434
featureNode->setText(0, fieldIndex);
435
435
const QgsAttributeMap& attr = feat.attributeMap();
436
-
436
+
437
437
for (QgsAttributeMap::const_iterator it = attr.begin(); it != attr.end(); ++it)
438
438
{
439
439
//QgsDebugMsg(it->fieldName() + " == " + fieldIndex);
440
-
440
+
441
441
if (fields[it.key()].name() == fieldIndex)
442
442
{
443
443
featureNode->setText(1, it->toString());
@@ -500,7 +500,7 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
500
500
// Edit attributes
501
501
// TODO: what to do if more features were selected? - nearest?
502
502
QgsChangedAttributesMap& changedAttributes = layer->changedAttributes();
503
-
503
+
504
504
QApplication::setOverrideCursor(Qt::WaitCursor);
505
505
506
506
if (dataProvider->getNextFeature(feat))
@@ -563,9 +563,9 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
563
563
{
564
564
QApplication::restoreOverrideCursor();
565
565
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>"));
569
569
}
570
570
}
571
571
}
@@ -574,26 +574,26 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
574
574
575
575
void QgsMapToolIdentify::showError (QgsMapLayer * mapLayer)
576
576
{
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
+ // );
583
583
584
584
QgsMessageViewer * mv = new QgsMessageViewer ();
585
585
mv->setWindowTitle ( mapLayer->errorCaptionString () );
586
586
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
+ );
590
590
mv->exec (); // deletes itself on close
591
591
}
592
592
593
593
void QgsMapToolIdentify::resultsDialogGone ()
594
594
{
595
595
mResults = 0 ;
596
-
596
+
597
597
delete mRubberBand ;
598
598
mRubberBand = 0 ;
599
599
}
@@ -610,23 +610,23 @@ void QgsMapToolIdentify::highlightFeature(int featureId)
610
610
QgsVectorLayer* layer = dynamic_cast <QgsVectorLayer*>(mCanvas ->currentLayer ());
611
611
if (!layer)
612
612
return ;
613
-
613
+
614
614
delete mRubberBand ;
615
615
mRubberBand = 0 ;
616
616
617
617
QgsFeature feat;
618
618
if (layer->getFeatureAtId (featureId, feat, true , false ) != 0 )
619
- {
620
- return ;
621
- }
619
+ {
620
+ return ;
621
+ }
622
622
623
623
if (!feat.geometry ())
624
- {
625
- return ;
626
- }
627
-
624
+ {
625
+ return ;
626
+ }
627
+
628
628
mRubberBand = new QgsRubberBand (mCanvas , feat.geometry ()->vectorType () == QGis::Polygon);
629
-
629
+
630
630
if (mRubberBand )
631
631
{
632
632
mRubberBand ->setToGeometry (feat.geometry (), *layer);
0 commit comments