All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LayoutEditor.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of TerraView - A GIS Application.
4 
5  TerraView is free software: you can redistribute it and/or modify
6  it under the terms of the GNU 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  TerraView 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 General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with TerraLib Code Editor. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@dpi.inpe.br>.
18  */
19 
20 /*!
21  \file terralib/qt/af/connectors/LayoutEditor.cpp
22 
23  \brief A connector of the te::qt::widgets::MultiThreadMapDisplay used in te::qt::widgets::DataFrame class to the Application Framework.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/dataset/ObjectIdSet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../geometry/Geometry.h"
31 #include "../../../geometry/Envelope.h"
32 #include "../../../geometry/Utils.h"
33 #include "../../../maptools/Utils.h"
34 #include "../../../srs/Config.h"
35 #include "../../widgets/layout/LayoutEditor.h"
36 #include "../../widgets/layout/DataFrame.h"
37 #include "../../widgets/canvas/MultiThreadMapDisplay.h"
38 #include "../../widgets/tools/AbstractTool.h"
39 #include "../../widgets/tools/ZoomWheel.h"
40 #include "../../widgets/tools/CoordTracking.h"
41 #include "../../widgets/Utils.h"
42 #include "../events/LayerEvents.h"
43 #include "../events/MapEvents.h"
44 #include "../events/ProjectEvents.h"
45 #include "../events/ToolEvents.h"
46 #include "../ApplicationController.h"
47 #include "../Project.h"
48 #include "../Utils.h"
49 #include "LayoutEditor.h"
50 
51 // Qt
52 #include <QtGui/QContextMenuEvent>
53 #include <QtGui/QMessageBox>
54 
55 // STL
56 #include <cassert>
57 #include <utility>
58 
59 #define EXTENT_STACK_SIZE 5
60 
62  : QObject(),
63  m_layoutEditor(le),
64  m_tool(0)
65 {
66  //// Zoom Wheel tool
67  //m_mapDisplay->installEventFilter(new te::qt::widgets::ZoomWheel(m_mapDisplay, 2.0, this));
68 
69  // Signals & slots
70  //connect((QObject*)m_layoutEditor, SIGNAL(drawLayersFinished(const QMap<QString, QString>&)), SLOT(onDrawLayersFinished(const QMap<QString, QString>&)));
71 
73 }
74 
76 {
77  delete m_layoutEditor;
78  delete m_tool;
79 }
80 
82 {
83  return m_layoutEditor;
84 }
85 
87 {
88  //delete m_tool;
89  //m_tool = tool;
90 
91  //m_layoutEditor->installEventFilter(m_tool);
92 }
93 
95 {
96  switch(e->m_id)
97  {
99  {
101  m_layoutEditor->setSelectionColor(selColor);
102  m_layoutEditor->drawLayersSelection();
103  }
104  break;
105 
107  {
108  te::qt::af::evt::MapColorChanged* mapColorChanged = static_cast<te::qt::af::evt::MapColorChanged*>(e);
109 
110  m_layoutEditor->setDisplayBackgroundColor(mapColorChanged->m_color);
111  }
112  break;
113 
115  {
117  m_layoutEditor->setSelectionColor(selColor);
118  m_layoutEditor->drawButtonClicked();
119  }
120  break;
121 
123  {
124  m_layoutEditor->setMouseMode(1);
125  }
126  break;
127 
129  {
130  m_layoutEditor->setMouseMode(2);
131  }
132  break;
133 
135  {
136  m_layoutEditor->setMouseMode(3);
137  }
138  break;
139 
141  {
142  m_layoutEditor->setMouseMode(0);
143  }
144  break;
145 
146  default:
147  return;
148  }
149 }
150 
151 //void te::qt::af::LayoutEditor::drawLayerSelection(te::map::AbstractLayer* layer)
152 //{
153  //assert(layer);
154 
155  //if(layer->getVisibility() != te::map::VISIBLE)
156  // return;
157 
158  //const te::da::ObjectIdSet* oids = layer->getSelected();
159  //if(oids == 0 || oids->size() == 0)
160  //{
161  // m_mapDisplay->repaint();
162  // return;
163  //}
164 
165  //bool needRemap = false;
166 
167  //if((layer->getSRID() != TE_UNKNOWN_SRS) && (m_mapDisplay->getSRID() != TE_UNKNOWN_SRS) && (layer->getSRID() != m_mapDisplay->getSRID()))
168  // needRemap = true;
169 
170  //// Try retrieves the layer selection
171  //std::auto_ptr<te::da::DataSet> selected;
172  //try
173  //{
174  // selected = layer->getData(oids);
175  //}
176  //catch(std::exception& e)
177  //{
178  // QMessageBox::critical(m_mapDisplay, tr("Error"), QString(tr("The layer selection cannot be drawn. Details:") + " %1.").arg(e.what()));
179  // return;
180  //}
181 
182  //std::size_t gpos = te::da::GetFirstPropertyPos(selected.get(), te::dt::GEOMETRY_TYPE);
183 
184  //QPixmap* content = m_mapDisplay->getDisplayPixmap();
185 
186  //const te::gm::Envelope& displayExtent = m_mapDisplay->getExtent();
187 
188  //te::qt::widgets::Canvas canvas(content);
189  //canvas.setWindow(displayExtent.m_llx, displayExtent.m_lly, displayExtent.m_urx, displayExtent.m_ury);
190 
191  //te::gm::GeomType currentGeomType = te::gm::UnknownGeometryType;
192 
193  //while(selected->moveNext())
194  //{
195  // std::auto_ptr<te::gm::Geometry> g(selected->getGeometry(gpos));
196 
197  // if(needRemap)
198  // {
199  // g->setSRID(layer->getSRID());
200  // g->transform(m_mapDisplay->getSRID());
201  // }
202 
203  // if(currentGeomType != g->getGeomTypeId())
204  // {
205  // currentGeomType = g->getGeomTypeId();
206  // te::qt::widgets::Config2DrawLayerSelection(&canvas, ApplicationController::getInstance().getSelectionColor(), currentGeomType);
207  // }
208 
209  // canvas.draw(g.get());
210  //}
211 
212  //m_mapDisplay->repaint();
213 //}
214 
215 //void te::qt::af::LayoutEditor::onDrawLayersFinished(const QMap<QString, QString>& /*errors*/)
216 //{
217  //// Stores the clean pixmap!
218  //m_lastDisplayContent = QPixmap(*m_mapDisplay->getDisplayPixmap());
219 
220  //// TODO!!!
221  //drawLayerSelection((ApplicationController::getInstance().getProject()->getLayers().begin())->get());
222 //}
te::qt::widgets::LayoutEditor * getLayoutEditor()
void setCurrentTool(te::qt::widgets::AbstractTool *tool)
Updates the current tool being used on te::qt::widgets::MapDisplay.
QColor getSelectionColor() const
Returns the application selection color.
This event signals that the color of the map display changed.
Definition: MapEvents.h:73
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:62
LayoutEditor(te::qt::widgets::LayoutEditor *le)
Constructor.
static ApplicationController & getInstance()
It gives access to the controller singleton.
void onApplicationTriggered(te::qt::af::evt::Event *e)
Listener to the application framewrork events.
virtual ~LayoutEditor()
destructor.
int m_id
Identifier.
Definition: Event.h:70
void addListener(QObject *obj)
Insert an application item that will listen to framework events.
A base class for application events.
Definition: Event.h:59