14
14
***************************************************************************/
15
15
/* $Id$ */
16
16
17
+ #include " qgsmessageviewer.h"
17
18
#include " qgsmaptoolidentify.h"
18
19
#include " qgsmapcanvas.h"
19
20
#include " qgsvectordataprovider.h"
30
31
#include < QMessageBox>
31
32
#include < QCursor>
32
33
#include < QPixmap>
34
+ #include < QObject>
33
35
34
36
35
37
QgsMapToolIdentify::QgsMapToolIdentify (QgsMapCanvas* canvas)
36
- : QgsMapTool(canvas), mResults(NULL )
38
+ : QgsMapTool(canvas),
39
+ mResults(0 ),
40
+ mViewer(0 )
37
41
{
38
42
// set cursor
39
43
QPixmap myIdentifyQPixmap = QPixmap ((const char **) identify_cursor);
@@ -42,7 +46,15 @@ QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)
42
46
43
47
QgsMapToolIdentify::~QgsMapToolIdentify ()
44
48
{
45
- delete mResults ;
49
+ if (mResults )
50
+ {
51
+ delete mResults ;
52
+ }
53
+
54
+ if (mViewer )
55
+ {
56
+ delete mViewer ;
57
+ }
46
58
}
47
59
48
60
void QgsMapToolIdentify::canvasMoveEvent (QMouseEvent * e)
@@ -61,24 +73,38 @@ void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)
61
73
62
74
if (layer)
63
75
{
64
- // convert screen coordinates to map coordinates
65
- QgsPoint idPoint = mCanvas ->getCoordinateTransform ()->toMapCoordinates (e->x (), e->y ());
66
-
67
- if (layer->type () == QgsMapLayer::VECTOR)
76
+ // In the special case of the WMS provider,
77
+ // coordinates are sent back to the server as pixel coordinates
78
+ // not the layer's native CRS. So identify on screen coordinates!
79
+ if (
80
+ (layer->type () == QgsMapLayer::RASTER)
81
+ &&
82
+ (dynamic_cast <QgsRasterLayer*>(layer)->providerKey () == " wms" )
83
+ )
68
84
{
69
- identifyVectorLayer (dynamic_cast <QgsVectorLayer*>(layer), idPoint);
70
- }
71
- else if (layer->type () == QgsMapLayer::RASTER)
72
- {
73
- identifyRasterLayer (dynamic_cast <QgsRasterLayer*>(layer), idPoint);
85
+ identifyRasterWmsLayer (dynamic_cast <QgsRasterLayer*>(layer), QgsPoint (e->x (), e->y ()) );
74
86
}
75
87
else
76
88
{
89
+ // convert screen coordinates to map coordinates
90
+ QgsPoint idPoint = mCanvas ->getCoordinateTransform ()->toMapCoordinates (e->x (), e->y ());
91
+
92
+ if (layer->type () == QgsMapLayer::VECTOR)
93
+ {
94
+ identifyVectorLayer (dynamic_cast <QgsVectorLayer*>(layer), idPoint);
95
+ }
96
+ else if (layer->type () == QgsMapLayer::RASTER)
97
+ {
98
+ identifyRasterLayer (dynamic_cast <QgsRasterLayer*>(layer), idPoint);
99
+ }
100
+ else
101
+ {
77
102
#ifdef QGISDEBUG
78
- std::cout << " identify : unknown layer type!" << std::endl;
103
+ std::cout << " QgsMapToolIdentify::canvasReleaseEvent : unknown layer type!" << std::endl;
79
104
#endif
105
+ }
80
106
}
81
-
107
+
82
108
}
83
109
else
84
110
{
@@ -124,6 +150,34 @@ void QgsMapToolIdentify::identifyRasterLayer(QgsRasterLayer* layer, const QgsPoi
124
150
}
125
151
126
152
153
+ void QgsMapToolIdentify::identifyRasterWmsLayer (QgsRasterLayer* layer, const QgsPoint& point)
154
+ {
155
+ if (!layer)
156
+ {
157
+ return ;
158
+ }
159
+
160
+ QString html = layer->identifyAsHtml (point);
161
+
162
+ if (html.isEmpty ())
163
+ {
164
+ showError (layer);
165
+ return ;
166
+ }
167
+
168
+ if (!mViewer )
169
+ {
170
+ mViewer = new QgsMessageViewer ();
171
+ }
172
+
173
+ mViewer ->setCaption ( layer->name () );
174
+ mViewer ->setMessageAsPlainText ( html );
175
+ // mViewer->setMessageAsHtml( html );
176
+
177
+ // mViewer->exec();
178
+ mViewer ->show ();
179
+ }
180
+
127
181
128
182
void QgsMapToolIdentify::identifyVectorLayer (QgsVectorLayer* layer, const QgsPoint& point)
129
183
{
@@ -313,3 +367,26 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
313
367
}
314
368
dataProvider->reset ();
315
369
}
370
+
371
+
372
+ void QgsMapToolIdentify::showError (QgsMapLayer * mapLayer)
373
+ {
374
+ // QMessageBox::warning(
375
+ // this,
376
+ // mapLayer->errorCaptionString(),
377
+ // tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
378
+ // mapLayer->errorString()
379
+ // );
380
+
381
+ QgsMessageViewer * mv = new QgsMessageViewer ();
382
+ mv->setCaption ( mapLayer->errorCaptionString () );
383
+ mv->setMessageAsPlainText (
384
+ QObject::tr (" Could not identify objects on" ) + " " + mapLayer->name () + " " + QObject::tr (" because" ) + " :\n " +
385
+ mapLayer->errorString ()
386
+ );
387
+ mv->exec ();
388
+ delete mv;
389
+
390
+ }
391
+
392
+ // ENDS
0 commit comments