OutsideArea.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 OutsideArea.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "OutsideArea.h"
30 #include "PropertiesDock.h"
31 #include "ObjectInspectorDock.h"
32 #include "EditTemplateDock.h"
33 #include "../../../layout/core/pattern/singleton/Context.h"
34 #include "../../../layout/qt/outside/PropertiesOutside.h"
35 #include "../../../layout/qt/outside/ObjectInspectorOutside.h"
36 #include "../../../layout/core/enum/Enums.h"
37 #include "../../../layout/core/pattern/mvc/OutsideObserver.h"
38 #include "../../../layout/qt/core/BuildGraphicsItem.h"
39 #include "../../../layout/qt/core/BuildGraphicsOutside.h"
40 
41 // STL
42 #include <string>
43 
44 // Qt
45 #include <QMainWindow>
46 #include <QMenu>
47 #include <QAction>
48 #include <QStatusBar>
49 
50 te::qt::plugins::layout::OutsideArea::OutsideArea( te::layout::View* view, QWidget* dockParent, QMenu* mnuLayout, QStatusBar* status) :
51  m_dockParent(dockParent),
52  m_dockProperties(0),
53  m_dockInspector(0),
54  m_dockEditTemplate(0),
55  m_parentMenu(mnuLayout),
56  m_view(view),
57  m_toolbar(0),
58  m_statusBar(status),
59  m_optionNew("mnu_main_new"),
60  m_optionUpdate("mnu_main_update"),
61  m_optionImportJSON("mnu_main_import_json"),
62  m_optionExportJSON("mnu_main_export_json"),
63  m_optionPageConfig("mnu_main_page_config"),
64  m_optionPrint("mnu_main_print"),
65  m_optionExit("mnu_main_exit"),
66  m_optionDockInspector("mnu_dock_inspector"),
67  m_optionDockProperties("mnu_dock_properties"),
68  m_optionDockToolbar("mnu_dock_toolbar"),
69  m_optionDockEditTemplate("mnu_dock_edit_template")
70 {
71  init();
72 }
73 
75 {
76  QMainWindow* win = (QMainWindow*)m_dockParent;
77 
78  if(!win)
79  return;
80 
81  if(m_dockProperties)
82  {
83  win->removeDockWidget(m_dockProperties);
84  m_dockProperties->close();
85  m_dockProperties->setParent(0);
86  delete m_dockProperties;
87  m_dockProperties = 0;
88  }
89 
90  if(m_dockInspector)
91  {
92  win->removeDockWidget(m_dockInspector);
93  m_dockInspector->close();
94  m_dockInspector->setParent(0);
95  delete m_dockInspector;
96  m_dockInspector = 0;
97  }
98 
99  if(m_toolbar)
100  {
101  win->removeToolBar(m_toolbar);
102  m_toolbar->close();
103  m_toolbar->setParent(0);
104  delete m_toolbar;
105  m_toolbar = 0;
106  }
107 
108  if(m_dockEditTemplate)
109  {
110  win->removeDockWidget(m_dockEditTemplate);
111  m_dockEditTemplate->close();
112  m_dockEditTemplate->setParent(0);
113  delete m_dockEditTemplate;
114  m_dockEditTemplate = 0;
115  }
116 }
117 
119 {
120  if(m_view)
121  {
122  connect(m_view, SIGNAL(reloadProperties()), this, SLOT(onSelectionChanged()));
123  connect(m_view->scene(), SIGNAL(addItemFinalized()), this, SLOT(onAddItemFinalized()));
124  connect(m_view, SIGNAL(hideView()), this, SLOT(onHideView()));
125  connect(m_view, SIGNAL(closeView()), this, SLOT(onCloseView()));
126  connect(m_view, SIGNAL(showView()), this, SLOT(onShowView()));
127  connect(this, SIGNAL(changeMenuContext(bool)), m_view, SLOT(onMainMenuChangeContext(bool)));
128  connect(m_view, SIGNAL(changeContext()), this, SLOT(onRefreshStatusBar()));
129  }
130 
131  te::layout::AbstractBuildGraphicsItem* abstractBuildItem = te::layout::Context::getInstance().getAbstractBuildGraphicsItem();
132  if(abstractBuildItem)
133  {
134  te::layout::BuildGraphicsItem* buildItem = dynamic_cast<te::layout::BuildGraphicsItem*>(abstractBuildItem);
135  if(buildItem)
136  {
137  connect(buildItem, SIGNAL(addChildFinalized(QGraphicsItem*, QGraphicsItem*)), this, SLOT(onAddChildFinalized(QGraphicsItem*, QGraphicsItem*)));
138  }
139  }
140 
141  createPropertiesDock();
142 
143  createInspectorDock();
144 
145  createToolbar();
146 
147  createMainMenu();
148 
149  createEditTemplateDock();
150 
151  if(m_toolbar)
152  {
153  connect(m_toolbar, SIGNAL(changeContext(bool)), m_view, SLOT(onToolbarChangeContext(bool)));
154  connect(m_view, SIGNAL(changeZoom(double)), m_toolbar, SLOT(onChangeZoom(double)));
155  }
156 
157  if(m_dockInspector)
158  {
159  connect(m_view->scene(), SIGNAL(deleteFinalized(std::vector<std::string>)),
160  m_dockInspector->getObjectInspectorOutside(), SLOT(onRemoveProperties(std::vector<std::string>)));
161  }
162 
163  if(m_dockProperties)
164  {
165  connect(m_view->scene(), SIGNAL(deleteFinalized(std::vector<std::string>)),
166  m_dockProperties->getPropertiesOutside(), SLOT(onClear(std::vector<std::string>)));
167  }
168 }
169 
171 {
172  m_dockProperties = new PropertiesDock;
173  m_dockProperties->setFeatures(QDockWidget::DockWidgetMovable |
174  QDockWidget::DockWidgetFloatable);
175 }
176 
178 {
179  m_dockInspector = new ObjectInspectorDock;
180  m_dockInspector->setFeatures(QDockWidget::DockWidgetMovable |
181  QDockWidget::DockWidgetFloatable);
182 }
183 
185 {
186  QMainWindow* win = (QMainWindow*)m_dockParent;
187 
188  if(!win)
189  return;
190 
191  te::layout::AbstractBuildGraphicsOutside* abstractBuildOutside = te::layout::Context::getInstance().getAbstractBuildGraphicsOutside();
192  if(!abstractBuildOutside)
193  {
194  return;
195  }
196 
197  te::layout::BuildGraphicsOutside* buildOutside = dynamic_cast<te::layout::BuildGraphicsOutside*>(abstractBuildOutside);
198  if(!buildOutside)
199  {
200  return;
201  }
202 
203  te::layout::EnumObjectType* objectType = te::layout::Enums::getInstance().getEnumObjectType();
204  if(!objectType)
205  {
206  return;
207  }
208 
209  QWidget* widget = buildOutside->createOuside(objectType->getToolbar());
210  if(!widget)
211  {
212  return;
213  }
214 
215  m_toolbar = dynamic_cast<te::layout::ToolbarOutside*>(widget);
216  win->addToolBar(m_toolbar);
217 }
218 
220 {
221  m_dockEditTemplate = new EditTemplateDock;
222  m_dockEditTemplate->setFeatures(QDockWidget::NoDockWidgetFeatures);
223  m_dockEditTemplate->setVisible(false);
224 }
225 
227 {
228  connect(m_parentMenu, SIGNAL(triggered(QAction*)), this, SLOT(onMainMenuTriggered(QAction*)));
229 
230  QAction* actionNew = createAction("New", m_optionNew, "layout-new");
231  m_parentMenu->addAction(actionNew);
232 
233  QAction* actionSave = createAction("Update Template", m_optionUpdate, "layout-save");
234  m_parentMenu->addAction(actionSave);
235 
236  m_parentMenu->addSeparator();
237 
238  QMenu* mnuImport = m_parentMenu->addMenu("Import Template");
239  QMenu* mnuExport = m_parentMenu->addMenu("Export Template");
240 
241  QAction* actionImportJSON = createAction("Import JSON Template", m_optionImportJSON, "layout-import");
242  mnuImport->addAction(actionImportJSON);
243 
244  QAction* actionExportJSON = createAction("Export JSON Template", m_optionExportJSON, "layout-export");
245  mnuExport->addAction(actionExportJSON);
246 
247  m_parentMenu->addSeparator();
248 
249  QAction* actionDockInspector = createAction("Dock Inspector", m_optionDockInspector, "");
250  actionDockInspector->setCheckable(true);
251  actionDockInspector->setChecked(true);
252  m_parentMenu->addAction(actionDockInspector);
253 
254  QAction* actionDockProperties = createAction("Dock Properties", m_optionDockProperties, "");
255  actionDockProperties->setCheckable(true);
256  actionDockProperties->setChecked(true);
257  m_parentMenu->addAction(actionDockProperties);
258 
259  m_parentMenu->addSeparator();
260 
261  QAction* actionPageConfig = createAction("Page Config...", m_optionPageConfig, "layout-page-setup");
262  m_parentMenu->addAction(actionPageConfig);
263 
264  QAction* actionPrint = createAction("Print...", m_optionPrint, "layout-printer");
265  m_parentMenu->addAction(actionPrint);
266 
267  m_parentMenu->addSeparator();
268 
269  QAction* actionExit = createAction("Exit", m_optionExit, "layout-close");
270  m_parentMenu->addAction(actionExit);
271 }
272 
274 {
275  te::layout::EnumModeType* type = te::layout::Enums::getInstance().getEnumModeType();
276 
277  if(action->objectName().compare(m_optionNew.c_str()) == 0)
278  {
279  changeAction(type->getModeNewTemplate());
280  }
281  else if(action->objectName().compare(m_optionUpdate.c_str()) == 0)
282  {
283  //changeAction(TypeSaveCurrentTemplate);
284  }
285  else if(action->objectName().compare(m_optionImportJSON.c_str()) == 0)
286  {
287  changeAction(type->getModeImportJSONProps());
288  }
289  else if(action->objectName().compare(m_optionExportJSON.c_str()) == 0)
290  {
291  changeAction(type->getModeExportPropsJSON());
292  }
293  else if(action->objectName().compare(m_optionPageConfig.c_str()) == 0)
294  {
295  changeAction(type->getModePageConfig());
296  }
297  else if(action->objectName().compare(m_optionPrint.c_str()) == 0)
298  {
299  changeAction(type->getModePrinter());
300  }
301  else if(action->objectName().compare(m_optionExit.c_str()) == 0)
302  {
303  changeAction(type->getModeExit());
304  emit exit();
305  }
306  else if(action->objectName().compare(m_optionDockInspector.c_str()) == 0)
307  {
308  if(m_dockInspector->isVisible())
309  {
310  m_dockInspector->setVisible(false);
311  }
312  else
313  {
314  m_dockInspector->setVisible(true);
315  }
316  }
317  else if(action->objectName().compare(m_optionDockProperties.c_str()) == 0)
318  {
319  if(m_dockProperties->isVisible())
320  {
321  m_dockProperties->setVisible(false);
322  }
323  else
324  {
325  m_dockProperties->setVisible(true);
326  }
327  }
328  else if(action->objectName().compare(m_optionDockEditTemplate.c_str()) == 0)
329  {
330  if(m_dockEditTemplate->isVisible())
331  {
332  m_dockEditTemplate->setVisible(false);
333  }
334  else
335  {
336  m_dockEditTemplate->setVisible(true);
337  }
338  }
339 }
340 
341 QAction* te::qt::plugins::layout::OutsideArea::createAction( std::string text, std::string objName, std::string icon, std::string tooltip )
342 {
343  QAction *actionMenu = new QAction(text.c_str(), m_parentMenu);
344  actionMenu->setObjectName(objName.c_str());
345 
346  actionMenu->setIcon(QIcon::fromTheme(icon.c_str()));
347  actionMenu->setToolTip(tooltip.c_str());
348 
349  return actionMenu;
350 }
351 
353 {
354  bool result = true;
355  te::layout::EnumType* layoutMode = te::layout::Context::getInstance().getMode();
356 
357  if(mode != layoutMode)
358  {
359  te::layout::Context::getInstance().setMode(mode);
360  }
361  else
362  {
363  result = false;
364  }
365 
366  emit changeMenuContext(result);
367 }
368 
370 {
371  return m_dockProperties;
372 }
373 
375 {
376  return m_dockInspector;
377 }
378 
380 {
381  return m_toolbar;
382 }
383 
385 {
386  QMainWindow* win = (QMainWindow*)m_dockParent;
387 
388  if(!win)
389  return;
390 
391  if(m_dockProperties)
392  {
393  m_dockProperties->setParent(m_dockParent);
394  win->addDockWidget(Qt::LeftDockWidgetArea, m_dockProperties);
395  m_dockProperties->setVisible(true);
396  }
397  if(m_dockInspector)
398  {
399  m_dockInspector->setParent(m_dockParent);
400  win->addDockWidget(Qt::LeftDockWidgetArea, m_dockInspector);
401  m_dockInspector->setVisible(true);
402  }
403  if(m_toolbar)
404  {
405  m_toolbar->setParent(m_dockParent);
406  win->addToolBar(m_toolbar);
407  m_toolbar->setVisible(true);
408  }
409  if(m_dockEditTemplate)
410  {
411  m_dockEditTemplate->setParent(m_dockParent);
412  win->addDockWidget(Qt::RightDockWidgetArea, m_dockEditTemplate);
413  bool visible = m_dockEditTemplate->isVisible();
414  m_dockEditTemplate->setVisible(visible);
415  }
416 }
417 
419 {
420  QMainWindow* win = (QMainWindow*)m_dockParent;
421 
422  if(!win)
423  return;
424 
425  if(m_dockProperties)
426  {
427  win->removeDockWidget(m_dockProperties);
428  m_dockProperties->close();
429  }
430  if(m_dockInspector)
431  {
432  win->removeDockWidget(m_dockInspector);
433  m_dockInspector->close();
434  }
435  if(m_toolbar)
436  {
437  win->removeToolBar(m_toolbar);
438  m_toolbar->close();
439  }
440  if(m_dockEditTemplate)
441  {
442  win->removeDockWidget(m_dockEditTemplate);
443  m_dockEditTemplate->close();
444  }
445 }
446 
448 {
449  if(!m_parentMenu)
450  return;
451 
452  QList<QAction*> acts = m_parentMenu->actions();
453 
454  foreach(QAction* act, acts)
455  {
456  act->setVisible(true);
457  }
458 
459  if(!acts.empty())
460  {
461  //m_parentMenu: The first QAction of the QMenu is to open the layout
462  QAction* firstOption = acts.first();
463  firstOption->setVisible(false);
464  }
465 }
466 
468 {
469  if(!m_parentMenu)
470  return;
471 
472  QList<QAction*> acts = m_parentMenu->actions();
473  foreach(QAction* act, acts)
474  {
475  act->setVisible(false);
476  }
477 
478  if(!acts.empty())
479  {
480  //m_parentMenu: The first QAction of the QMenu is to open the layout
481  QAction* firstOption = acts.first();
482  firstOption->setVisible(true);
483  }
484 
485  m_view->closeOutsideWindows();
486 }
487 
489 {
490  QList<QGraphicsItem*> graphicsItems = m_view->scene()->selectedItems();
491  QList<QGraphicsItem*> allItems = m_view->scene()->items();
492 
493  //Refresh Property window
494  if(m_dockProperties)
495  m_dockProperties->getPropertiesOutside()->itemsSelected(graphicsItems, allItems);
496 
497  if(m_dockInspector)
498  m_dockInspector->getObjectInspectorOutside()->selectItems(graphicsItems);
499 }
500 
502 {
503  QList<QGraphicsItem*> allItems = m_view->scene()->items();
504  //Refresh Inspector Object window
505  if(m_dockInspector)
506  m_dockInspector->getObjectInspectorOutside()->itemsInspector(allItems);
507 }
508 
510 {
511  openAllDocks();
512  openMainMenu();
513 }
514 
516 {
517  closeAllDocks();
518  closeMainMenu();
519  m_view->closeOutsideWindows();
520 }
521 
523 {
524  closeAllDocks();
525  closeMainMenu();
526  m_view->closeOutsideWindows();
527  emit exit();
528 }
529 
531 {
532  if(!m_statusBar)
533  {
534  return;
535  }
536 
538 
539  std::string msg;
540 
541  if(mode == te::layout::Enums::getInstance().getEnumModeType()->getModeNone())
542  {
543  msg = "Map Layout - TerraLib 5";
544  m_statusBar->showMessage(msg.c_str());
545  return;
546  }
547 
548  msg = "Map Layout - TerraLib 5 | Context: ";
549 
550  std::string s_mode = mode->getLabel();
551  if(s_mode.compare("") == 0)
552  {
553  s_mode = mode->getName();
554  }
555  msg += s_mode;
556  m_statusBar->showMessage(msg.c_str());
557 }
558 
559 void te::qt::plugins::layout::OutsideArea::onAddChildFinalized( QGraphicsItem* parent, QGraphicsItem* child )
560 {
561  QList<QGraphicsItem*> allItems = m_view->scene()->items();
562  //Refresh Inspector Object window
563  if(m_dockInspector)
564  m_dockInspector->getObjectInspectorOutside()->itemsInspector(allItems);
565 }
566 
567 
568 
569 
virtual void changeAction(te::layout::EnumType *mode)
Class to represent a graphic object (MVC component) and widget object (MVC widget) type enumeration...
QWidget * createOuside(te::layout::EnumType *type)
Method to create a widget from the type.
std::string getName()
Returns name.
Definition: EnumType.cpp:54
ObjectInspectorDock * getObjectInspectorDock()
std::string getLabel()
Returns label.
Definition: EnumType.cpp:64
virtual void onAddChildFinalized(QGraphicsItem *parent, QGraphicsItem *child)
virtual EnumType * getModeExportPropsJSON() const
Returns value that represents export properties to json mode type belonging to enumeration.
virtual EnumType * getModeExit() const
Returns value that represents exit mode type belonging to enumeration.
Abstract class for build MVC widgets.
Class responsible for creating or building graphics objects. All objects are children of QGraphicsIte...
virtual EnumType * getModeNewTemplate() const
Returns value that represents new template mode type belonging to enumeration.
static Context & getInstance()
It returns a reference to the singleton instance.
Class to represent a mode type enumeration. Ex.: select, pan, create text, etc. The type of mode is u...
Definition: EnumModeType.h:50
Class responsible for creating or building widgets. All objects are children of Qwidget and OutsideOb...
Class representing the view. This view is child of QGraphicsView, part of Graphics View Framework...
Definition: View.h:89
virtual EnumType * getToolbar() const
Returns value that represents toolbar widget (MVC widget) type belonging to enumeration.
OutsideArea(te::layout::View *view, QWidget *dockParent=0, QMenu *mnuLayout=0, QStatusBar *status=0)
Definition: OutsideArea.cpp:50
virtual QAction * createAction(std::string text, std::string objName, std::string icon, std::string tooltip="")
virtual void onMainMenuTriggered(QAction *action)
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
Definition: EnumType.h:48
Standard Toolbar for Layout. Includes Qt components for interaction between the user and the plugin/a...
virtual EnumType * getModePrinter() const
Returns value that represents printer mode type belonging to enumeration.
te::layout::ToolbarOutside * getToolbar()
virtual EnumType * getModeImportJSONProps() const
Returns value that represents import properties from json mode type belonging to enumeration.
Abstract class for build graphics MVC components.
virtual EnumType * getModePageConfig() const
Returns value that represents page configuration mode type belonging to enumeration.