Info.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/tools/Info.cpp
22 
23  \brief This class implements a concrete tool to get informations about a specified feature using pointing operation.
24 */
25 
26 // TerraLib
27 #include "../../../common/STLUtils.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../geometry/Coord2D.h"
32 #include "../../../geometry/Envelope.h"
33 #include "../../../geometry/Geometry.h"
34 #include "../../../geometry/GeometryProperty.h"
35 #include "../../../geometry/Point.h"
36 #include "../../../geometry/Utils.h"
37 #include "../../../maptools/MarkRendererManager.h"
38 #include "../../../raster/Raster.h"
39 #include "../../../raster/RasterProperty.h"
40 #include "../../../raster/Utils.h"
41 #include "../../../se/Fill.h"
42 #include "../../../se/Stroke.h"
43 #include "../../../se/Mark.h"
44 #include "../../../se/Utils.h"
45 #include "../../../srs/Config.h"
46 #include "../canvas/Canvas.h"
47 #include "../canvas/MapDisplay.h"
48 #include "../Utils.h"
49 #include "../layer/info/FeatureInfoMakerFactory.h"
50 #include "../layer/info/AbstractFeatureInfoMaker.h"
51 #include "Info.h"
52 
53 // Qt
54 #include <QtCore/QPointF>
55 #include <QtCore/QString>
56 #include <QtCore/QStringList>
57 #include <QMessageBox>
58 #include <QMouseEvent>
59 
60 // STL
61 #include <cassert>
62 #include <memory>
63 
64 te::qt::widgets::Info::Info(te::qt::widgets::MapDisplay* display, const QCursor& cursor, const std::list<te::map::AbstractLayerPtr>& layers, QObject* parent)
65  : AbstractTool(display, parent),
66  m_layers(layers),
67  m_infoWidget(new QTreeWidget(display))
68 {
69  setCursor(cursor);
70 
71  // Setup the widget that will be used to show the informations
72  m_infoWidget->setWindowTitle(tr("Information"));
73  m_infoWidget->setWindowFlags(Qt::Tool);
74  m_infoWidget->setAlternatingRowColors(true);
75  m_infoWidget->setMinimumSize(300, 300);
76  m_infoWidget->setColumnCount(2);
77 
78  QStringList labels;
79  labels << tr("Property") << tr("Value");
80  m_infoWidget->setHeaderLabels(labels);
81 }
82 
84 {
85  QPixmap* draft = m_display->getDraftPixmap();
86 
87  draft->fill(Qt::transparent);
88 
89  m_infoWidget->close();
90 
91  delete m_infoWidget;
92 }
93 
95 {
96  if(e->button() != Qt::LeftButton)
97  return false;
98 
99  Qt::KeyboardModifiers keys = e->modifiers();
100 
101  if(keys & Qt::ShiftModifier)
103 
104  if(m_layers.empty())
105  return false;
106 
107  QPointF pixelOffset(4.0, 4.0);
108 #if (QT_VERSION >= 0x050000)
109  QRectF rect = QRectF(e->localPos() - pixelOffset, e->localPos() + pixelOffset);
110 #else
111  QRectF rect = QRectF(e->posF() - pixelOffset, e->posF() + pixelOffset);
112 #endif
113 
114  // Converts rect boundary to world coordinates
115  QPointF ll(rect.left(), rect.bottom());
116  QPointF ur(rect.right(), rect.top());
117  ll = m_display->transform(ll);
118  ur = m_display->transform(ur);
119 
120  // Bulding the query box
121  te::gm::Envelope envelope(ll.x(), ll.y(), ur.x(), ur.y());
122 
123  // Clear draft!
124  QPixmap* draft = m_display->getDraftPixmap();
125  draft->fill(Qt::transparent);
126 
127  // Clear info widget!
128  m_infoWidget->clear();
129 
130  // For each layer, get info!
131  std::list<te::map::AbstractLayerPtr>::const_iterator it;
132  for(it = m_layers.begin(); it != m_layers.end(); ++it)
133  {
134  te::map::AbstractLayerPtr layer = *it;
135 
136  // The Layer item
137  QTreeWidgetItem* layerItem = new QTreeWidgetItem;
138  layerItem->setIcon(0, QIcon::fromTheme("layer"));
139  layerItem->setText(0, tr("Layer"));
140  layerItem->setText(1, layer->getTitle().c_str());
141 
142  m_infoWidget->addTopLevelItem(layerItem);
143 
144  std::unique_ptr<AbstractFeatureInfoMaker> featureInfoMaker;
145 
146  featureInfoMaker.reset(te::qt::widgets::FeatureInfoMakerFactory::make(layer->getType()));
147 
148  featureInfoMaker->getInfo(layerItem, m_display, layer, envelope);
149 
150  if(layerItem->childCount() == 0)
151  delete layerItem;
152  }
153 
154  if(m_infoWidget->topLevelItemCount() > 0)
155  {
156  m_infoWidget->expandAll();
157  m_infoWidget->resizeColumnToContents(0);
158  m_infoWidget->show();
159  }
160  else
161  m_infoWidget->hide();
162 
163  m_display->repaint();
164 
165  return true;
166 }
167 
168 void te::qt::widgets::Info::setLayers(const std::list<te::map::AbstractLayerPtr>& layers)
169 {
170  m_layers = layers;
171 }
void setLayers(const std::list< te::map::AbstractLayerPtr > &layers)
Definition: Info.cpp:168
virtual std::list< AbstractLayerPtr > getLayerList() const
static AbstractFeatureInfoMaker * make()
It creates and returns the default AbstractFeatureInfoMaker.
std::list< te::map::AbstractLayerPtr > m_layers
The layer list that will be queried.
Definition: Info.h:119
~Info()
Destructor.
Definition: Info.cpp:83
A widget to control the display of a set of layers.
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:63
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: Info.cpp:94
virtual QPointF transform(const QPointF &p)
Transforms the given point, in screen coordinates, to a point in world coordinates.
An Envelope defines a 2D rectangular region.
virtual void setCursor(const QCursor &cursor)
It sets the tool cursor.
QTreeWidget * m_infoWidget
Widget used to show the informations.
Definition: Info.h:120
Info(MapDisplay *display, const QCursor &cursor, const std::list< te::map::AbstractLayerPtr > &layers, QObject *parent=0)
It constructs a info tool associated with the given map display.
Definition: Info.cpp:64
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
This class implements a concrete tool to get informations about a specified feature using pointing op...
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr