RpToolsWidget.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/rp/RpToolsWidget.cpp
22 
23  \brief This file has the RpToolsWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Coord2D.h"
28 #include "../../../geometry/Geometry.h"
29 #include "../../../geometry/Point.h"
30 #include "../../../geometry/Utils.h"
31 #include "../../../maptools/Utils.h"
32 #include "../../widgets/tools/AbstractTool.h"
33 #include "../../widgets/tools/ExtentAcquire.h"
34 #include "../../widgets/tools/PolygonAcquire.h"
35 #include "../../widgets/tools/PointPicker.h"
36 #include "../canvas/Canvas.h"
37 #include "../canvas/MultiThreadMapDisplay.h"
38 #include "RpToolsWidget.h"
39 #include "ui_RpToolsWidgetForm.h"
40 
41 //QT
42 #include <QActionGroup>
43 
44 //STL
45 #include <memory>
46 
47 
49  : QWidget(parent, f),
50  m_ui(new Ui::RpToolsWidgetForm),
51  m_mapDisplay(nullptr),
52  m_actionGroup(nullptr),
53  m_pickerAction(nullptr),
54  m_geomAction(nullptr),
55  m_boxAction(nullptr)
56 {
57  m_ui->setupUi(this);
58  m_pointCursor = Qt::CrossCursor;
59 
60 //signals & slots
61 
62  connect(m_ui->m_geomActionToolButton, SIGNAL(toggled(bool)), this, SLOT(onGeomToggled(bool)));
63  connect(m_ui->m_extentActionToolButton, SIGNAL(toggled(bool)), this, SLOT(onBoxToggled(bool)));
64  connect(m_ui->m_pointActionToolButton, SIGNAL(toggled(bool)), this, SLOT(onPointPickerToggled(bool)));
65 
66 //pixmap
67 
68  m_ui->m_geomActionToolButton->setIcon(QIcon::fromTheme("edit-polygon"));
69  m_ui->m_extentActionToolButton->setIcon(QIcon::fromTheme("edit-box"));
70  m_ui->m_pointActionToolButton->setIcon(QIcon::fromTheme("placemark"));
71 
72  hideEditionTools(true);
73 }
74 
76 {
78 
79  delete m_pickerAction;
80  delete m_geomAction;
81  delete m_boxAction;
82 }
83 
85 {
86  m_mapDisplay = mapDisplay;
87 }
88 
89 void te::qt::widgets::RpToolsWidget::setActionGroup(QActionGroup* actionGroup)
90 {
91  m_actionGroup = actionGroup;
92 }
93 
95 {
96  m_ui->m_pointActionToolButton->setVisible(!hide);
97  m_ui->m_geomActionToolButton->setVisible(!hide);
98  m_ui->m_extentActionToolButton->setVisible(!hide);
99 }
100 
102 {
103  if(!checked)
104  {
106  return;
107  }
108 
109  m_ui->m_pointActionToolButton->setChecked(checked);
110  m_pickerAction->setChecked(checked);
111 }
112 
114 {
115  if(!checked)
116  {
118  return;
119  }
120 
121  m_ui->m_geomActionToolButton->setChecked(checked);
122  m_geomAction->setChecked(checked);
123 }
124 
126 {
127  if(!checked)
128  {
130  return;
131  }
132 
133  m_ui->m_extentActionToolButton->setChecked(checked);
134  m_boxAction->setChecked(checked);
135 }
136 
138 {
139  if(mode)
140  {
141  m_ui->m_pointActionToolButton->setIcon(QIcon::fromTheme("pointer-selection"));
142  m_pointCursor = Qt::ArrowCursor;
143  }
144  else
145  {
146  m_ui->m_pointActionToolButton->setIcon(QIcon::fromTheme("placemark"));
147  m_pointCursor = Qt::CrossCursor;
148  }
149 }
150 
152 {
153  //emit signal
154  emit envelopeAcquired(env);
155 }
156 
158 {
159  //emit signal
160  emit geomAquired(poly);
161 }
162 
164 {
165  //emit signal
166  emit pointPicked(point.x(), point.y());
167 }
168 
170 {
171  //emit signal
172  emit pointPickerMoving(point.x(), point.y());
173 }
174 
176 {
177  if (!checked)
178  return;
179 
180  if(!m_actionGroup->actions().contains(m_pickerAction))
181  m_actionGroup->addAction(m_ui->m_pointActionToolButton->defaultAction());
182 
185 
186  connect(pp, SIGNAL(pointPicked(QPointF&)), this, SLOT(onPointPicked(QPointF&)));
187  connect(pp, SIGNAL(pointPickerMoving(QPointF&)), this, SLOT(onPointPickerMoving(QPointF&)));
188 }
189 
191 {
192  if (!checked)
193  return;
194 
195  if(!m_actionGroup->actions().contains(m_geomAction))
196  m_actionGroup->addAction(m_ui->m_geomActionToolButton->defaultAction());
197 
200 
201  connect(pa, SIGNAL(polygonAquired(te::gm::Polygon*)), this, SLOT(onGeomAquired(te::gm::Polygon*)));
202 }
203 
205 {
206  if (!checked)
207  return;
208 
209  if(!m_actionGroup->actions().contains(m_boxAction))
210  m_actionGroup->addAction(m_ui->m_extentActionToolButton->defaultAction());
211 
214 
215  connect(ea, SIGNAL(extentAcquired(te::gm::Envelope)), this, SLOT(onEnvelopeAcquired(te::gm::Envelope)));
216 }
217 
219 {
220  m_pickerAction = new QAction(this);
221  m_pickerAction->setIcon(QIcon::fromTheme("placemark"));
222  m_pickerAction->setToolTip(tr("Create by Point"));
223  m_pickerAction->setCheckable(true);
224  m_pickerAction->setEnabled(true);
225 
226  m_ui->m_pointActionToolButton->setDefaultAction(m_pickerAction);
227 
228  m_ui->m_pointActionToolButton->setVisible(true);
229 
230  m_actionGroup->addAction(m_ui->m_pointActionToolButton->defaultAction());
231 }
232 
234 {
235  m_geomAction = new QAction(this);
236  m_geomAction->setIcon(QIcon::fromTheme("edit-polygon"));
237  m_geomAction->setToolTip(tr("Create by Polygon"));
238  m_geomAction->setCheckable(true);
239  m_geomAction->setEnabled(true);
240 
241  m_ui->m_geomActionToolButton->setDefaultAction(m_geomAction);
242 
243  m_ui->m_geomActionToolButton->setVisible(true);
244 
245  m_actionGroup->addAction(m_ui->m_geomActionToolButton->defaultAction());
246 }
247 
249 {
250  m_boxAction = new QAction(this);
251  m_boxAction->setIcon(QIcon::fromTheme("edit-box"));
252  m_boxAction->setToolTip(tr("Create by Extent"));
253  m_boxAction->setCheckable(true);
254  m_boxAction->setEnabled(true);
255 
256  m_ui->m_extentActionToolButton->setDefaultAction(m_boxAction);
257 
258  m_ui->m_extentActionToolButton->setVisible(true);
259 
260  m_actionGroup->addAction(m_ui->m_extentActionToolButton->defaultAction());
261 }
262 
264 {
265  if(m_pickerAction != nullptr && m_pickerAction->isChecked())
266  {
267  m_pickerAction->setChecked(false);
268  m_mapDisplay->setCursor(Qt::ArrowCursor);
269  m_mapDisplay->setCurrentTool(nullptr, false);
270  }
271  else if(m_geomAction != nullptr && m_geomAction->isChecked())
272  {
273  m_geomAction->setChecked(false);
274  m_mapDisplay->setCursor(Qt::ArrowCursor);
275  m_mapDisplay->setCurrentTool(nullptr, false);
276  }
277  else if(m_boxAction != nullptr && m_boxAction->isChecked())
278  {
279  m_boxAction->setChecked(false);
280  m_mapDisplay->setCursor(Qt::ArrowCursor);
281  m_mapDisplay->setCurrentTool(nullptr, false);
282  }
283 }
virtual void setCurrentTool(te::qt::widgets::AbstractTool *tool, const bool &delPrevious=true)
Updates the current tool being used on te::qt::widgets::MapDisplay.
void onGeomAquired(te::gm::Polygon *poly)
void onGeomToggled(bool checked)
void pointPickerMoving(double x, double y)
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
te::qt::widgets::MapDisplay * m_mapDisplay
A widget to control the display of a set of layers.
void geomAquired(te::gm::Polygon *poly)
This class implements a concrete tool to acquire a polygon geometry.
void setPickerTool(bool checked)
This class implements a concrete tool to define a boundary rectangle.
Definition: ExtentAcquire.h:50
void onPointPickerToggled(bool checked)
void pointPicked(double x, double y)
std::unique_ptr< Ui::RpToolsWidgetForm > m_ui
void setEnvelopeTool(bool checked)
void onPointPickerMoving(QPointF &point)
An Envelope defines a 2D rectangular region.
void onPointPicked(QPointF &point)
RpToolsWidget(QWidget *parent=0, Qt::WindowFlags f=0)
void envelopeAcquired(te::gm::Envelope env)
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
This class implements a concrete tool to geographic coordinate picker on mouse click operation...
Definition: PointPicker.h:50
This file has the RpToolsWidget class.
void onEnvelopeAcquired(te::gm::Envelope env)
void setActionGroup(QActionGroup *actionGroup)