BaseApplication.cpp
Go to the documentation of this file.
1 #include "BaseApplication.h"
2 
3 #include "ui_BaseApplicationForm.h"
4 
5 // TerraLib
7 #include "SplashScreenManager.h"
11 #include "connectors/MapDisplay.h"
14 #include "events/LayerEvents.h"
15 #include "events/MapEvents.h"
16 #include "events/ToolEvents.h"
17 #include "InternalSettingsDialog.h"
18 #include "Utils.h"
19 
20 #include "../widgets/canvas/GridPropertyWidget.h"
21 #include "../widgets/canvas/ScalePropertyWidget.h"
22 
23 #include "../widgets/layer/explorer/FolderItem.h"
24 #include "../widgets/layer/explorer/LayerItem.h"
25 #include "../widgets/layer/explorer/StyleItem.h"
26 #include "../widgets/layer/explorer/LayerViewDelegate.h"
27 #include "../widgets/layer/explorer/RasterLayerDelegate.h"
28 
29 
30 #include "../widgets/layer/info/LayerPropertiesInfoWidget.h"
31 #include "../widgets/layer/utils/CharEncodingMenuWidget.h"
32 #include "../widgets/layer/utils/SaveSelectedObjectsDialog.h"
33 #include "../widgets/tools/Info.h"
34 #include "../widgets/tools/Measure.h"
35 #include "../widgets/tools/Pan.h"
36 #include "../widgets/tools/Selection.h"
37 #include "../widgets/tools/ZoomArea.h"
38 #include "../widgets/tools/ZoomClick.h"
39 #include "../widgets/srs/SRSManagerDialog.h"
40 #include "../widgets/Utils.h"
41 #include "../widgets/utils/ScopedCursor.h"
42 #include "../widgets/utils/InputCoordinateDialog.h"
43 
44 #include "../../Defines.h"
45 #include "../../common/TerraLib.h"
46 #include "../../common/progress/ProgressManager.h"
47 #include "../../common/progress/TaskProgress.h"
48 #include "../../dataaccess/dataset/ObjectIdSet.h"
49 #include "../../dataaccess/utils/Utils.h"
50 #include "../../geometry/GeometryProperty.h"
51 #include "../../maptools/Utils.h"
52 #include "../../raster/RasterProperty.h"
53 
54 // Qt
55 #include <QFileInfo>
56 #include <QInputDialog>
57 #include <QMessageBox>
58 #include <QToolBar>
59 #include <QToolButton>
60 #include <QStyledItemDelegate>
61 
62 
63 te::qt::af::DataSetTableDockWidget* GetLayerDock(const te::map::AbstractLayer* layer, const std::vector<te::qt::af::DataSetTableDockWidget*>& docs)
64 {
65  std::vector<te::qt::af::DataSetTableDockWidget*>::const_iterator it;
66 
67  for(it = docs.begin(); it != docs.end(); ++it)
68  if((*it)->getLayer() == layer)
69  return *it;
70 
71  return nullptr;
72 }
73 
74 
76  QMainWindow(parent)
77 {
78  m_ui = nullptr;
79  m_layerExplorer = nullptr;
80  m_display = nullptr;
81  m_styleExplorer = nullptr;
82  m_internalSettingsDlg = nullptr;
83  m_encodingMenu = nullptr;
84  m_app = nullptr;
85  m_mapCursorSize = QSize(20, 20);
86 
87  te::qt::af::AppCtrlSingleton::getInstance().setMsgBoxParentWidget(this);
88 }
89 
90 
92 {
94 
95  while(!m_tables.empty())
96  delete *m_tables.begin();
97 
98  if(m_app)
100 
101  delete m_layerExplorer;
102 
103  delete m_display;
104  delete m_styleExplorer;
105 
106  if(m_app)
107  m_app->finalize();
108 
109  delete m_ui;
110 }
111 
112 void te::qt::af::BaseApplication::init(const QString& cfgFile)
113 {
114  initFramework(cfgFile);
115 
116  m_ui = new Ui::BaseApplicationForm;
117  m_ui->setupUi(this);
118 
119  try
120  {
121  makeDialog();
122 
124 
125  te::qt::widgets::LayerViewDelegate* ld = new te::qt::widgets::LayerViewDelegate((QStyledItemDelegate*)view->itemDelegate(), this);
126 
127  view->setItemDelegate(ld);
128 
129  //register menubar and load plugins
131  }
132  catch(te::common::Exception& e)
133  {
134  QMessageBox::warning(this, "Error", e.what());
135  }
136 }
137 
139 {
140  return m_ui->m_layerExplorer;
141 }
142 
144 {
145  return m_ui->m_display;
146 }
147 
148 te::qt::af::DataSetTableDockWidget* te::qt::af::BaseApplication::getLayerDock(const te::map::AbstractLayer* layer, const std::vector<te::qt::af::DataSetTableDockWidget*>& docs)
149 {
150  std::vector<te::qt::af::DataSetTableDockWidget*>::const_iterator it;
151 
152  for (it = docs.begin(); it != docs.end(); ++it)
153  if ((*it)->getLayer() == layer)
154  return *it;
155 
156  return nullptr;
157 }
158 
160 {
161  return m_ui->m_layerExplorerDockWidget;
162 }
163 
164 void te::qt::af::BaseApplication::prepareQtEnvironment(const QString& cfgFile, const QString& splashImg)
165 {
166  AppCtrlSingleton::prepareQtEnvironment(cfgFile, splashImg);
167 }
168 
170 {
171  switch (e->m_id)
172  {
174  {
176  QString text = "(" + QString::number(ctE->m_x, 'f', 5) + " , " + QString::number(ctE->m_y, 'f', 5) + ")";
177  m_coordinateLineEdit->setText(text);
178  }
179  break;
180 
182  {
184 
185  std::pair<int, std::string> srid = mEvt->m_srid;
186 
187  setMapSRIDLineEdit(srid.first);
188  }
189  break;
190 
192  {
194  if (lEvt->m_layer == nullptr || lEvt->m_layer->getSelected() == nullptr)
195  return;
196 
197  m_selected->setText(tr("Selected rows: ") + QString::number(lEvt->m_layer->getSelected()->size()));
198  }
199  break;
200 
201  default:
202  break;
203  }
204 }
205 
207 {
208 // QApplication::setOverrideCursor(Qt::WaitCursor);
209 
211  emit triggered(&drawClicked);
212 
213  std::list<te::map::AbstractLayerPtr> ls;
214 
215  te::qt::widgets::GetValidLayers(getLayerExplorer()->model(), QModelIndex(), ls);
216 
217  m_display->draw(ls);
218 
219 // QApplication::restoreOverrideCursor();
220 }
221 
223 {
224  if (!checked)
225  return;
226 
227  QCursor zoomAreaCursor(QIcon::fromTheme("zoom-in").pixmap(m_mapCursorSize));
228 
229  te::qt::widgets::ZoomArea* zoomArea = new te::qt::widgets::ZoomArea(m_display->getDisplay(), zoomAreaCursor);
230  m_display->getDisplay()->setCurrentTool(zoomArea);
231 
233  m_app->trigger(&ezoom);
234 }
235 
237 {
238  if (!checked)
239  return;
240 
241  QCursor zoomOutCursor(QIcon::fromTheme("zoom-out").pixmap(m_mapCursorSize));
242 
244  m_display->getDisplay()->setCurrentTool(zoomOut);
245 
247  m_app->trigger(&ezoom);
248 }
249 
251 {
253 }
254 
256 {
258 }
259 
261 {
262  if (!checked)
263  return;
264 
265  te::qt::widgets::Pan* pan = new te::qt::widgets::Pan(m_display->getDisplay(), Qt::OpenHandCursor, Qt::ClosedHandCursor);
267 
269  m_app->trigger(&epan);
270 }
271 
273 {
274  std::list<te::map::AbstractLayerPtr> ls;
275 
276  te::qt::widgets::GetValidLayers(getLayerExplorer()->model(), QModelIndex(), ls);
277 
278  if(ls.empty())
279  return;
280 
281  //m_display->fit(m_layerExplorer->getExplorer()->getAllLayers());
282  // TODO: Change to get only visible single layers, not selected.
283  m_display->fit(ls);
284 
285 }
286 
288 {
289  if (!checked)
290  return;
291 
292  QPixmap pxmap = QIcon::fromTheme("pointer-info").pixmap(m_mapCursorSize);
293  QCursor infoCursor(pxmap, 0, 0);
294 
297 
298  connect(m_layerExplorer->getExplorer(), SIGNAL(selectedLayersChanged(const std::list<te::map::AbstractLayerPtr>&)), info, SLOT(setLayers(const std::list<te::map::AbstractLayerPtr>&)));
299 }
300 
302 {
303  std::list<te::map::AbstractLayerPtr> layers;
304 
305  te::qt::widgets::GetValidLayers(getLayerExplorer()->model(), QModelIndex(), layers);
306 
307  std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
308 
309  while (it != layers.end())
310  {
311  te::map::AbstractLayerPtr layer = (*it);
312 
313  layer->clearSelected();
314 
315  ++it;
316 
318  m_app->trigger(&e);
319  }
320 }
321 
323 {
324  if (!checked)
325  return;
326 
328  m_display->getDisplay()->setCurrentTool(selection);
329 
330  connect(m_layerExplorer->getExplorer(), SIGNAL(selectedLayersChanged(const std::list<te::map::AbstractLayerPtr>&)), selection, SLOT(setLayers(const std::list<te::map::AbstractLayerPtr>&)));
331  connect(selection, SIGNAL(layerSelectedObjectsChanged(const te::map::AbstractLayerPtr&)), SLOT(onLayerSelectedObjectsChanged(const te::map::AbstractLayerPtr&)));
332 
334  m_app->trigger(&esel);
335 }
336 
338 {
339  te::qt::widgets::SRSManagerDialog srsDialog(this);
340  srsDialog.setWindowTitle(tr("Choose the SRS"));
341 
342  if (srsDialog.exec() == QDialog::Rejected)
343  return;
344 
345  std::pair<int, std::string> srid = srsDialog.getSelectedSRS();
346 
347  te::qt::af::evt::MapSRIDChanged mapSRIDChagned(srid);
348  m_app->trigger(&mapSRIDChagned);
349 
350  m_display->getDisplay()->setSRID(srid.first);
351 }
352 
354 {
355  std::pair<int, std::string> srid = std::make_pair(TE_UNKNOWN_SRS, "");
356  te::qt::af::evt::MapSRIDChanged mapSRIDChagned(srid);
357  m_app->trigger(&mapSRIDChagned);
358 
360 }
361 
363 {
364  m_display->getDisplay()->showGrid(check);
365 
366  m_mapEditGrid->setEnabled(check);
367  m_mapShowGeographicGrid->setChecked(check);
368 }
369 
371 {
372  if (!checked)
373  return;
374 
375  QCursor measureDistanceCursor(QIcon::fromTheme("distance-measure-cursor").pixmap(m_mapCursorSize), 0, 0);
376 
378  m_display->getDisplay()->setCurrentTool(distance);
379 }
380 
382 {
383  if (!checked)
384  return;
385 
386  QCursor measureAreaCursor(QIcon::fromTheme("area-measure-cursor").pixmap(m_mapCursorSize), 0, 0);
387 
390 }
391 
393 {
394  if (!checked)
395  return;
396 
397  QCursor measureAngleCursor(QIcon::fromTheme("angle-measure-cursor").pixmap(m_mapCursorSize), 0, 0);
398 
401 }
402 
404 {
405  std::string coord("0, 0");
407 
408  wid->move(width() / 2, height() / 2);
409 
410 // wid->setMapDisplay(m_display->getDisplay());
411 
412  wid->show();
413 }
414 
416 {
418 }
419 
421 {
422  bool ok = false;
423 
424  double scale = m_scaleCmbBox->currentText().toDouble(&ok);
425 
426  if (ok)
427  {
428  m_display->getDisplay()->setScale(scale);
429  m_display->getDisplay()->refresh(true);
430  }
431  else
432  {
433  QVariant var = m_scaleCmbBox->itemData(m_scaleCmbBox->currentIndex());
434 
435  if (var.isValid())
436  {
437  double scale = var.toDouble();
438 
439  m_display->getDisplay()->setScale(scale);
440  m_display->getDisplay()->refresh(true);
441  }
442  }
443 }
444 
446 {
447  double scale = m_display->getDisplay()->getScale();
448 
449  m_scaleCmbBox->setItemText(m_scaleCmbBox->currentIndex(), QString::number(scale, 'f', 0));
450 }
451 
453 {
454  if (m_internalSettingsDlg == nullptr)
456 
457  connect(m_internalSettingsDlg, SIGNAL(destroyed(QObject*)), this,
459 
460  m_internalSettingsDlg->show();
461 }
462 
464 {
465  m_internalSettingsDlg = nullptr;
466 }
467 
469 {
470  QModelIndexList ls = getLayerExplorer()->selectionModel()->selectedIndexes();
471 
472  if(ls.isEmpty())
473  {
474  QString msg = tr("Select at least one item to be removed!");
475  QMessageBox::warning(this, tr("Remove item"), msg);
476 
477  return;
478  }
479 
480  QString msg;
481  QString questionTitle;
482 
483  if(ls.size() == 1)
484  {
485  msg = tr("Do you really want to remove the selected item?");
486  questionTitle = tr("Remove Item");
487  }
488  else
489  {
490  msg = tr("Do you really want to remove the selected items?");
491  questionTitle = tr("Remove Items");
492  }
493 
494  int reply = QMessageBox::question(this, questionTitle, msg, QMessageBox::No, QMessageBox::Yes);
495 
496  if(reply == QMessageBox::No)
497  return;
498 
499  //check the selected item type
500  std::list<te::qt::widgets::TreeItem*> items = getLayerExplorer()->getSelectedItems();
501 
502  if (items.size() == 1 && (*items.begin())->getType() == "STYLE")
503  {
504  //get layer from tree
505  te::qt::widgets::TreeItem* item = *items.begin();
506 
508 
510 
511  te::map::AbstractLayerPtr layer = layerItem->getLayer();
512 
513  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
514 
515  //remove style item
517 
518  //remove grouping if exists
519  if (layer->getGrouping())
520  layer->setGrouping(nullptr);
521 
522  //create new style
523  te::se::Style* newStyle = nullptr;
524 
525  if (dsType->hasGeom())
526  {
528 
530  }
531  else if (dsType->hasRaster())
532  {
534 
536  }
537 
538  layer->setStyle(newStyle);
539 
540  layerItem->updateLegend();
541 
542  te::qt::af::evt::LayerChanged e2(layer.get());
543  emit triggered(&e2);
544 
545  getMapDisplay()->refresh();
546  }
547  else
548  {
549  //get selected layers
550  std::list<te::map::AbstractLayerPtr> lays = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
551  std::list<te::map::AbstractLayerPtr> lays2;
552 
554 
555  //remove items from tree
557 
558  //refresh application
559  bool needRefresh = !lays2.empty();
560 
561  for (std::list<te::map::AbstractLayerPtr>::iterator it = lays2.begin(); it != lays2.end(); ++it)
562  {
563  te::qt::af::evt::LayerChanged e2((*it).get());
564  emit triggered(&e2);
565  }
566 
567  for (std::list<te::map::AbstractLayerPtr>::iterator it = lays.begin(); it != lays.end() && !needRefresh; ++it)
568  if ((*it)->getVisibility() == te::map::VISIBLE)
569  needRefresh = true;
570 
572  emit triggered(&e);
573 
574  if (needRefresh)
575  {
576  lays.clear();
577  te::qt::widgets::GetValidLayers(getLayerExplorer()->model(), QModelIndex(), lays);
578  getMapDisplay()->setLayerList(lays);
579  getMapDisplay()->refresh();
580  }
581  }
582 }
583 
585 {
586  std::list<te::qt::widgets::TreeItem*> selectedLayerItems = getLayerExplorer()->getSelectedItems();
587 
588  if (selectedLayerItems.empty())
589  return;
590 
591  bool renameAllowed = (selectedLayerItems.size() == 1 && (selectedLayerItems.front()->getType() == "LAYER" || selectedLayerItems.front()->getType() == "FOLDER"));
592 
593  if(!renameAllowed)
594  {
595  QString msg = tr("Select only one layer to be renamed!");
596  QMessageBox::warning(this, tr("Rename Layer"), msg);
597 
598  return;
599  }
600 
601  te::qt::widgets::TreeItem* item = selectedLayerItems.front();
602 
603  bool ok;
604  QString text = QInputDialog::getText(this, m_app->getAppTitle(),
605  tr("Rename Layer:"), QLineEdit::Normal,
606  item->getAsString().c_str(), &ok);
607 
608  if(!ok)
609  return;
610 
611  if(text.isEmpty())
612  {
613  QMessageBox::warning(this, m_app->getAppTitle(), tr("Enter the new name!"));
614  return;
615  }
616 
617  if(item->getType() == "LAYER")
618  ((te::qt::widgets::LayerItem*)item)->getLayer()->setTitle(text.toUtf8().data());
619  else if(item->getType() == "FOLDER")
620  ((te::qt::widgets::FolderItem*)item)->setTitle(text.toUtf8().data());
621 
622  std::list<te::map::AbstractLayerPtr> ls;
623 
625 // e.
626  emit triggered(&e);
627 }
628 
630 {
631  std::list<te::qt::widgets::TreeItem*> selectedLayerItems = getLayerExplorer()->getSelectedItems();
632 
633  if(selectedLayerItems.empty())
634  return;
635 
636  for(std::list<te::qt::widgets::TreeItem*>::iterator it = selectedLayerItems.begin(); it != selectedLayerItems.end(); ++it)
637  {
638  te::qt::widgets::TreeItem* item = *it;
639 
641  }
642 }
643 
645 {
646  std::list<te::qt::widgets::TreeItem*> selectedLayerItems = getLayerExplorer()->getSelectedItems();
647 
648  if(selectedLayerItems.empty())
649  return;
650 
651  for(std::list<te::qt::widgets::TreeItem*>::iterator it = selectedLayerItems.begin(); it != selectedLayerItems.end(); ++it)
652  {
653  te::qt::widgets::TreeItem* item = *it;
654 
656  }
657 }
658 
660 {
661  //std::list<te::qt::widgets::AbstractTreeItem*> selectedItems = m_layerExplorer->getExplorer()->getSelectedItems();
662 
663  //std::list<te::qt::widgets::AbstractTreeItem*>::const_iterator it;
664  //for (it = selectedItems.begin(); it != selectedItems.end(); ++it)
665  //{
666  // te::qt::af::evt::ItemOfLayerRemoved evt((*it));
667  // m_app->trigger(&evt);
668  //}
669 }
670 
672 {
673  std::list<te::map::AbstractLayerPtr> layers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
674 
675  if(layers.empty())
676  {
677  QMessageBox::warning(this, m_app->getAppTitle(), tr("There's no selected layer."));
678  return;
679  }
680 
681  // Docking
682  QDockWidget* doc = new QDockWidget(this, Qt::Dialog);
683 
684  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
685 
686  te::map::AbstractLayerPtr l = *layers.begin();
688 
689  doc->setWidget(info);
690  doc->setWindowTitle(info->windowTitle());
691  doc->setAttribute(Qt::WA_DeleteOnClose, true);
692 
693  doc->show();
694 }
695 
697 {
698  std::list<te::map::AbstractLayerPtr> layers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
699 
700  if(layers.empty())
701  {
702  QMessageBox::warning(this, m_app->getAppTitle(), tr("There's no selected layer."));
703  return;
704  }
705 
706  std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
707 
708  while(it != layers.end())
709  {
710  te::map::AbstractLayerPtr layer = (*it);
711 
712  if(!layer->isValid())
713  {
714  ++it;
715  continue;
716  }
717 
718  layer->clearSelected();
719 
720  ++it;
721 
723  emit triggered(&e);
724  }
725 }
726 
728 {
729  std::list<te::map::AbstractLayerPtr> layers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
730 
731  if (layers.empty())
732  {
733  QMessageBox::warning(this, m_app->getAppTitle(), tr("There's no selected layer."));
734  return;
735  }
736 
737  std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
738 
739  while (it != layers.end())
740  {
741  te::map::AbstractLayerPtr layer = (*it);
742 
743  if (!layer->isValid() || !layer->getSchema()->hasGeom())
744  {
745  ++it;
746  continue;
747  }
748 
749  std::unique_ptr<te::da::DataSetType> dt = layer->getSchema();
750  std::unique_ptr<te::da::DataSet> ds = layer->getData();
751 
752  te::da::ObjectIdSet* allObjects = te::da::GenerateOIDSet(ds.get(), dt.get());
753 
754  const te::da::ObjectIdSet* selected = layer->getSelected();
755 
756  if(selected && (selected->size() > 0))
757  allObjects->difference(selected);
758 
759  layer->clearSelected();
760 
761  layer->select(allObjects);
762 
763  ++it;
764 
766  emit triggered(&e);
767  }
768 }
769 
771 {
772  std::list<te::map::AbstractLayerPtr> layers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
773 
774  if(layers.empty())
775  {
776  QMessageBox::warning(this, m_app->getAppTitle(), tr("There's no selected layer."));
777  return;
778  }
779  te::qt::widgets::SRSManagerDialog srsDialog(this);
780  srsDialog.setWindowTitle(tr("Choose the SRS"));
781 
782  if(srsDialog.exec() == QDialog::Rejected)
783  return;
784 
785  std::pair<int, std::string> srid = srsDialog.getSelectedSRS();
786 
787  for (std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin(); it != layers.end(); ++it)
788  {
789  te::map::AbstractLayerPtr lay = *it;
790 
791  lay->setSRID(srid.first);
792  }
793 }
794 
796 {
797  try
798  {
799  std::list<te::map::AbstractLayerPtr> selectedLayers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
800 
801  if(selectedLayers.empty())
802  {
803  QMessageBox::warning(this, m_app->getAppTitle(),
804  tr("Select a layer in the layer explorer!"));
805  return;
806  }
807  else
808  {
809  std::list<te::map::AbstractLayerPtr>::iterator it = selectedLayers.begin();
810 
811  while(it != selectedLayers.end())
812  {
813  if(!it->get()->isValid())
814  {
815  QMessageBox::warning(this, m_app->getAppTitle(),
816  tr("There are invalid layers selected!"));
817 
818  return;
819  }
820 
821  ++it;
822  }
823  }
824 
825  // The layer fitting will be accomplished only on the first layer selected
826  te::map::AbstractLayerPtr selectedLayer = *(selectedLayers.begin());
827 
828  te::gm::Envelope env = selectedLayer->getExtent();
829 
831 
832  if(display->getLayerList().empty())
833  {
834  std::list<te::map::AbstractLayerPtr> ls;
835  te::qt::widgets::GetValidLayers(getLayerExplorer()->model(), QModelIndex(), ls);
836 
837  display->setLayerList(ls);
838  }
839 
840  if((display->getSRID() == TE_UNKNOWN_SRS && selectedLayer->getSRID() == TE_UNKNOWN_SRS) || (display->getSRID() == selectedLayer->getSRID()))
841  {
842  display->setExtent(env, true);
843  return;
844  }
845 
846  if(display->getSRID() == TE_UNKNOWN_SRS && selectedLayer->getSRID() != TE_UNKNOWN_SRS)
847  {
848  te::qt::af::evt::MapSRIDChanged mapSRIDChagned(std::pair<int, std::string>(selectedLayer->getSRID(), "EPSG"));
849  m_app->trigger(&mapSRIDChagned);
850 
851  display->setSRID(selectedLayer->getSRID());
852  display->setExtent(env, true);
853  return;
854  }
855 
856  if(display->getSRID() == TE_UNKNOWN_SRS || selectedLayer->getSRID() == TE_UNKNOWN_SRS)
857  {
858  QMessageBox::warning(this, m_app->getAppTitle(), tr("The spatial reference system of the map display and the layer are not compatible!"));
859  return;
860  }
861 
862  if(display->getSRID() != selectedLayer->getSRID())
863  env.transform(selectedLayer->getSRID(), display->getSRID());
864 
865  display->setExtent(env, true);
866  }
867  catch(const std::exception& e)
868  {
869  QMessageBox::warning(this, m_app->getAppTitle(), e.what());
870  }
871 
872 }
873 
875 {
876  std::list<te::map::AbstractLayerPtr> selectedLayers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
877  if(selectedLayers.empty())
878  {
879  QString msg = tr("Select at least a layer to accomplish this operation!");
880  QMessageBox::warning(this, m_app->getAppTitle(), msg);
881  return;
882  }
883  else
884  {
885  std::list<te::map::AbstractLayerPtr>::iterator it = selectedLayers.begin();
886 
887  while(it != selectedLayers.end())
888  {
889  if(!it->get()->isValid())
890  {
891  QMessageBox::warning(this, m_app->getAppTitle(),
892  tr("There are invalid layers selected!"));
893  return;
894  }
895 
896  ++it;
897  }
898  }
899 
900  te::gm::Envelope finalEnv = te::map::GetSelectedExtent(selectedLayers, m_display->getDisplay()->getSRID(), false);
901 
902  if(!finalEnv.isValid())
903  {
904  QString msg = tr("Select object(s) in the selected layer(s) to accomplish this operation!");
905  QMessageBox::warning(this, m_app->getAppTitle(), msg);
906  return;
907  }
908 
909  m_display->getDisplay()->setExtent(finalEnv, true);
910 }
911 
913 {
914  std::list<te::map::AbstractLayerPtr> selectedLayers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
915  if(selectedLayers.empty())
916  {
917  QString msg = tr("Select at least a layer to accomplish this operation!");
918  QMessageBox::warning(this, m_app->getAppTitle(), msg);
919  return;
920  }
921  else
922  {
923  std::list<te::map::AbstractLayerPtr>::iterator it = selectedLayers.begin();
924 
925  while(it != selectedLayers.end())
926  {
927  if(!it->get()->isValid())
928  {
929  QMessageBox::warning(this, m_app->getAppTitle(),
930  tr("There are invalid layers selected!"));
931  return;
932  }
933 
934  ++it;
935  }
936  }
937 
939 
940  te::gm::Envelope selectedExtent = te::map::GetSelectedExtent(selectedLayers, display->getSRID(), true);
941 
942  te::gm::Coord2D centerOfSelectedExtent = selectedExtent.getCenter();
943 
944  te::gm::Envelope displayExtent = display->getExtent();
945 
946  double halfWidth = displayExtent.getWidth() * 0.5;
947  double halfHeight = displayExtent.getHeight() * 0.5;
948 
949  te::gm::Envelope newExtent;
950 
951  newExtent.m_llx = centerOfSelectedExtent.x - halfWidth;
952  newExtent.m_lly = centerOfSelectedExtent.y - halfHeight;
953 
954  newExtent.m_urx = centerOfSelectedExtent.x + halfWidth;
955  newExtent.m_ury = centerOfSelectedExtent.y + halfHeight;
956 
957  display->setExtent(newExtent);
958 }
959 
961 {
962  try
963  {
964  std::list<te::map::AbstractLayerPtr> selectedLayers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
965 
966  if (selectedLayers.empty())
967  {
968  QString msg = tr("Select one layer to accomplish this operation!");
969  QMessageBox::warning(this, m_app->getAppTitle(), msg);
970  return;
971  }
972  else
973  {
974  std::list<te::map::AbstractLayerPtr>::iterator it = selectedLayers.begin();
975 
976  if (!it->get()->isValid())
977  {
978  QMessageBox::warning(this, m_app->getAppTitle(),
979  tr("This is a invalid layer selected!"));
980  return;
981  }
982  }
983 
984  te::map::AbstractLayerPtr selectedLayer = *selectedLayers.begin();
985 
987 
988  dlg.setWindowTitle(dlg.windowTitle() + " (" + tr("Layer") + ":" + selectedLayer->getTitle().c_str() + ")");
989 
990  dlg.setParameters(selectedLayer);
991 
992  if (dlg.exec() != QDialog::Accepted)
993  return;
994 
995  te::map::AbstractLayerPtr layer = dlg.getLayer();
996 
997  if (!layer)
998  return;
999 
1000  te::qt::af::evt::LayerAdded evt(layer.get());
1001  emit triggered(&evt);
1002 
1003  }
1004  catch(const std::exception& e)
1005  {
1006  QMessageBox::warning(this, m_app->getAppTitle(), e.what());
1007  }
1008 
1009 }
1010 
1012 {
1013  std::list<te::map::AbstractLayerPtr> selectedLayers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
1014 
1015  if (!selectedLayers.empty())
1016  {
1017  std::list<te::map::AbstractLayerPtr>::iterator it = selectedLayers.begin();
1018 
1019  m_encodingMenu->setLayer(*it);
1020  }
1021 }
1022 
1023 
1025 {
1026  checked ? showFullScreen() : showMaximized();
1027 }
1028 
1030 {
1031  m_viewLayerExplorer->blockSignals(true);
1032  m_viewLayerExplorer->setChecked(visible);
1033  m_viewLayerExplorer->blockSignals(false);
1034 }
1035 
1037 {
1038  if (m_tables.empty())
1039  return;
1040 
1041  for (std::size_t i = 0; i < m_tables.size(); ++i)
1042  {
1043  if (visible)
1044  m_tables[i]->show();
1045  else
1046  m_tables[i]->hide();
1047  }
1048 
1049  m_viewDataTable->setChecked(visible);
1050 }
1051 
1053 {
1054  m_viewStyleExplorer->blockSignals(true);
1055  m_viewStyleExplorer->setChecked(visible);
1056  m_viewStyleExplorer->blockSignals(false);
1057 }
1058 
1060 {
1061  std::list<te::map::AbstractLayerPtr> layers = te::qt::widgets::GetSelectedLayersOnly(getLayerExplorer());
1062 
1063  if(layers.empty())
1064  {
1065  QMessageBox::warning(this, m_app->getAppTitle(), tr("There's no selected layer."));
1066  return;
1067  }
1068  else
1069  {
1070  for(std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin(); it != layers.end(); ++it)
1071  {
1072  if(!(*it)->isValid())
1073  {
1074  QMessageBox::warning(this, m_app->getAppTitle(), tr("There are invalid layers selected!"));
1075  return;
1076  }
1077  }
1078  }
1079 
1080 
1081  te::map::AbstractLayerPtr lay = *layers.begin();
1082 
1083  if(lay->getSchema()->hasRaster())
1084  return;
1085 
1087 
1088  if(doc == nullptr)
1089  {
1090  doc = new te::qt::af::DataSetTableDockWidget(this);
1091  doc->setLayer(lay.get());
1093  addDockWidget(Qt::BottomDockWidgetArea, doc);
1094 
1097 
1098  if(!m_tables.empty())
1099  tabifyDockWidget(m_tables[m_tables.size() - 1], doc);
1100 
1101  m_tables.push_back(doc);
1102 
1103  m_app->addListener(doc);
1104  }
1105 
1106  doc->show();
1107  doc->raise();
1108 
1109  m_viewDataTable->setChecked(true);
1110 
1111  m_viewDataTable->setEnabled(true);
1112 }
1113 
1115 {
1116  std::vector<te::qt::af::DataSetTableDockWidget*>::iterator it;
1117 
1118  for (it = m_tables.begin(); it != m_tables.end(); ++it)
1119  if (*it == wid)
1120  break;
1121 
1122  if (it != m_tables.end())
1123  {
1124  m_app->removeListener(*it);
1125  m_tables.erase(it);
1126  }
1127 }
1128 
1130 {
1131  try
1132  {
1135  doc->setWindowTitle("Histogram");
1136  doc->setWindowIcon(QIcon::fromTheme("chart-bar"));
1137  doc->setLayer(layer);
1138  doc->setAppController(m_app);
1139 
1140  m_app->addListener(doc);
1141  addDockWidget(Qt::RightDockWidgetArea, doc, Qt::Horizontal);
1142  doc->show();
1143  }
1144  catch (const std::exception& e)
1145  {
1146  QMessageBox::warning(this, m_app->getAppTitle(), e.what());
1147  }
1148 }
1149 
1151 {
1152  m_mapEditGraphicScale->setEnabled(checked);
1153 }
1154 
1156 {
1158 
1159  QMainWindow::addDockWidget(Qt::RightDockWidgetArea, wid);
1160 }
1161 
1163 {
1165 
1166  QMainWindow::addDockWidget(Qt::RightDockWidgetArea, wid);
1167 }
1168 
1170 {
1172  emit triggered(&e);
1173 }
1174 
1176 {
1177  assert(layer.get());
1178 
1180  m_app->trigger(&e);
1181 }
1182 
1184 {
1185  QMainWindow::setCentralWidget(m_ui->m_display);
1186 
1187  //start menu
1188  initMenus();
1189 
1190  //start actions
1191  initActions();
1192 
1193  //start main components
1194  m_layerExplorer = new LayerExplorer(m_ui->m_layerExplorer);
1195  m_display = new MapDisplay(m_ui->m_display, m_app);
1196  m_styleExplorer = new StyleExplorer(m_ui->m_styleExplorer, m_app);
1197 
1198  m_ui->m_styleExplorer->setMapDisplay(m_display->getDisplay());
1199 
1201 
1202  initStatusBar();
1203 
1204  initToolbars();
1205 
1206  m_viewLayerExplorer->setChecked(true);
1208  m_viewStyleExplorer->setChecked(false);
1209  m_styleExplorer->getExplorer()->setVisible(false);
1210 
1211  //define startup tool
1212  onSelectionToggled(true);
1213  m_mapSelection->setChecked(true);
1214 
1215  //connect components
1219  m_app->addListener(this);
1220 
1221  m_display->getDisplay()->connect(m_mapStopDrawing, SIGNAL(triggered()), SLOT(onDrawCanceled()));
1222 
1223  //char encoding
1226 
1227  //set app info
1228  setWindowTitle(m_app->getAppTitle());
1229  setWindowIcon(QIcon(m_app->getAppIconName()));
1230  setWindowIconText(m_app->getAppTitle());
1231 }
1232 
1234 {
1236  m_app->setConfigFile(cfgFile.toUtf8().data());
1237  m_app->initialize();
1238 
1239  //check user settings file
1240  QSettings user_settings(QSettings::IniFormat,
1241  QSettings::UserScope,
1242  QApplication::instance()->organizationName(),
1243  QApplication::instance()->applicationName());
1244 
1245  QFileInfo info(user_settings.fileName());
1246 
1247  if (!info.exists())
1249 }
1250 
1252 {
1253  // Status Bar
1254  m_statusbar = new QStatusBar(this);
1255  m_statusbar->setObjectName("StatusBar");
1256  setStatusBar(m_statusbar);
1257 
1258  // Selected status
1259  m_selected = new QLabel(m_statusbar);
1260  m_selected->setText(tr("Selected rows: 0"));
1261  m_statusbar->addPermanentWidget(m_selected);
1262 
1263  // Map SRID reset action
1264  QToolButton* mapUnknownSRIDToolButton = new QToolButton(m_statusbar);
1265  mapUnknownSRIDToolButton->setDefaultAction(m_mapUnknownSRID);
1266  m_statusbar->addPermanentWidget(mapUnknownSRIDToolButton);
1267 
1268  // Map SRID action
1269  QToolButton* mapSRIDToolButton = new QToolButton(m_statusbar);
1270  mapSRIDToolButton->setDefaultAction(m_mapSRID);
1271  m_statusbar->addPermanentWidget(mapSRIDToolButton);
1272 
1273  // Coordinate Line Edit
1274  m_coordinateLineEdit = new QLineEdit(m_statusbar);
1275  m_coordinateLineEdit->setFixedWidth(220);
1276  m_coordinateLineEdit->setAlignment(Qt::AlignHCenter);
1277  m_coordinateLineEdit->setReadOnly(true);
1278  m_coordinateLineEdit->setFocusPolicy(Qt::NoFocus);
1279  m_coordinateLineEdit->setText(tr("Coordinates"));
1280 
1281  // Map SRID information
1282  m_mapSRIDLineEdit = new QLineEdit(m_statusbar);
1283  m_mapSRIDLineEdit->setFixedWidth(120);
1284  m_mapSRIDLineEdit->setAlignment(Qt::AlignHCenter);
1285  m_mapSRIDLineEdit->setReadOnly(true);
1286  int srid = m_display->getDisplay()->getSRID();
1287  setMapSRIDLineEdit(srid);
1288  m_statusbar->addPermanentWidget(m_mapSRIDLineEdit);
1289 
1290  m_statusbar->addPermanentWidget(m_coordinateLineEdit);
1291 
1292  // Stop draw action
1293  QToolButton* stopDrawToolButton = new QToolButton(m_statusbar);
1294  stopDrawToolButton->setDefaultAction(m_mapStopDrawing);
1295  m_statusbar->addPermanentWidget(stopDrawToolButton);
1296 
1297  // Scale Combo Box
1298  m_scaleCmbBox = new QComboBox(m_statusbar);
1299  m_scaleCmbBox->setToolTip(tr("Scale Information"));
1300  m_scaleCmbBox->setEditable(true);
1301  m_scaleCmbBox->setInsertPolicy(QComboBox::NoInsert);
1302  m_scaleCmbBox->setMinimumWidth(100);
1303  m_statusbar->addPermanentWidget(m_scaleCmbBox);
1304 
1305  m_scaleCmbBox->addItem("Scale");
1306  m_scaleCmbBox->addItem("1 000", QVariant((double)1000));
1307  m_scaleCmbBox->addItem("1 500", QVariant((double)1500));
1308  m_scaleCmbBox->addItem("2 000", QVariant((double)2000));
1309  m_scaleCmbBox->addItem("2 500", QVariant((double)2500));
1310  m_scaleCmbBox->addItem("5 000", QVariant((double)5000));
1311  m_scaleCmbBox->addItem("7 500", QVariant((double)7500));
1312  m_scaleCmbBox->addItem("10 000", QVariant((double)10000));
1313  m_scaleCmbBox->addItem("12 500", QVariant((double)12500));
1314  m_scaleCmbBox->addItem("15 000", QVariant((double)15000));
1315  m_scaleCmbBox->addItem("20 000", QVariant((double)20000));
1316  m_scaleCmbBox->addItem("25 000", QVariant((double)25000));
1317  m_scaleCmbBox->addItem("50 000", QVariant((double)50000));
1318  m_scaleCmbBox->addItem("100 000", QVariant((double)100000));
1319  m_scaleCmbBox->addItem("125 000", QVariant((double)125000));
1320  m_scaleCmbBox->addItem("150 000", QVariant((double)150000));
1321  m_scaleCmbBox->addItem("175 000", QVariant((double)175000));
1322  m_scaleCmbBox->addItem("200 000", QVariant((double)200000));
1323  m_scaleCmbBox->addItem("250 000", QVariant((double)250000));
1324  m_scaleCmbBox->addItem("500 000", QVariant((double)500000));
1325  m_scaleCmbBox->addItem("750 000", QVariant((double)750000));
1326  m_scaleCmbBox->addItem("1 000 000", QVariant((double)1000000));
1327  m_scaleCmbBox->addItem("1 250 000", QVariant((double)1250000));
1328  m_scaleCmbBox->addItem("1 500 000", QVariant((double)1500000));
1329  m_scaleCmbBox->addItem("1 750 000", QVariant((double)1750000));
1330  m_scaleCmbBox->addItem("2 000 000", QVariant((double)2000000));
1331 
1332  connect(m_scaleCmbBox, SIGNAL(activated(int)), this, SLOT(onScaleComboBoxActivated()));
1333  connect(m_scaleCmbBox->lineEdit(), SIGNAL(returnPressed()), this, SLOT(onScaleComboBoxActivated()));
1334 
1335  if (m_display->getDisplay())
1336  connect(m_display->getDisplay(), SIGNAL(extentChanged()), SLOT(onScaleDisplayChanged()));
1337 
1338  //internal settings
1339  QToolButton* internalSettingsToolButton = new QToolButton(m_statusbar);
1340  internalSettingsToolButton->setDefaultAction(m_internalSettings);
1341  m_statusbar->addPermanentWidget(internalSettingsToolButton);
1342 }
1343 
1345 {
1346  initAction(m_viewLayerExplorer, "view-layer-explorer", "View.Layer Explorer", tr("&Layer Explorer"), tr("Show or hide the layer explorer"), true, true, true, m_menubar);
1347  initAction(m_viewDataTable, "view-data-table", "View.Data Table", tr("&Data Table"), tr("Show or hide the data table"), true, true, true, m_menubar);
1348  initAction(m_viewStyleExplorer, "style", "View.Style Explorer", tr("&Style Explorer"), tr("Show or hide the style explorer"), true, true, true, m_menubar);
1349  initAction(m_viewFullScreen, "view-fullscreen", "View.Full Screen", tr("F&ull Screen"), tr(""), true, true, true, m_menubar);
1350 
1351  initAction(m_layerShowTable, "view-data-table", "Layer.Show Table", tr("S&how Table"), tr(""), true, false, true, m_menubar);
1352  initAction(m_layerRemove, "layer-remove", "Project.Remove Layer", tr("&Remove Item(s)"), tr("Remove items(s) from the project"), true, false, true, this);
1353  initAction(m_layerRename, "layer-rename", "Project.Rename Layer", tr("Rename Layer..."), tr("Rename layer"), true, false, true, this);
1354  initAction(m_layerCheckSelectedLayer, "check", "Project.Check Selected Layer", tr("Check Selected Layer"), tr("Check selected layer"), true, false, true, m_menubar);
1355  initAction(m_layerClearSelectedLayer, "edit-deletetool", "Project.Clear Selected Layer", tr("Clear Selected Layer"), tr("Clear selected layer"), true, false, true, m_menubar);
1356  initAction(m_layerRemoveObjectSelection, "pointer-remove-selection", "Layer.Remove Selection", tr("&Remove Selection"), tr(""), true, false, true, m_menubar);
1357  initAction(m_layerInvertObjectSelection, "pointer-invert-selection", "Layer.Invert Selection", tr("&Invert Selection"), tr(""), true, false, true, m_menubar);
1358  initAction(m_layerRemoveItem, "item-remove", "Layer.Remove Item", tr("&Remove Item"), tr(""), true, false, true, m_menubar);
1359  initAction(m_layerProperties, "layer-info", "Layer.Properties", tr("&Properties..."), tr(""), true, false, true, m_menubar);
1360  initAction(m_layerSRS, "layer-srs", "Layer.SRS", tr("&Inform SRS..."), tr(""), true, false, true, m_menubar);
1361  initAction(m_layerFitOnMapDisplay, "layer-fit", "Layer.Fit Layer on the Map Display", tr("Fit Layer"), tr("Fit the current layer on the Map Display"), true, false, true, m_menubar);
1362  initAction(m_layerFitSelectedOnMapDisplay, "zoom-selected-extent", "Layer.Fit Selected Features on the Map Display", tr("Fit Selected Features"), tr("Fit the selected features on the Map Display"), true, false, true, m_menubar);
1363  initAction(m_layerPanToSelectedOnMapDisplay, "pan-selected", "Layer.Pan to Selected Features on Map Display", tr("Pan to Selected Features"), tr("Pan to the selected features on the Map Display"), true, false, true, m_menubar);
1364  initAction(m_layerSaveSelectedObjects, "layer-save-selected-obj", "Layer.Save Selected Objects", tr("Save Selected Objects..."), tr("Save a new layer based on the selected objects from this layer"), true, false, true, this);
1365  initAction(m_layerCharEncoding, "char-encoding", "Layer.Encoding", tr("&Encoding..."), tr("Set the encoding to load data from selected layer"), true, false, true, m_menubar);
1366 
1367  initAction(m_mapDraw, "map-draw", "Map.Draw", tr("&Draw"), tr("Draw the visible layers"), true, false, true, m_menubar);
1368  initAction(m_mapZoomIn, "zoom-in", "Map.Zoom In", tr("Zoom &In"), tr(""), true, true, true, m_menubar);
1369  initAction(m_mapZoomOut, "zoom-out", "Map.Zoom Out", tr("Zoom &Out"), tr(""), true, true, true, m_menubar);
1370  initAction(m_mapPan, "pan", "Map.Pan", tr("&Pan"), tr(""), true, true, true, m_menubar);
1371  initAction(m_mapZoomExtent, "zoom-extent", "Map.Zoom Extent", tr("Zoom &Extent"), tr(""), true, false, true, m_menubar);
1372  initAction(m_mapPreviousExtent, "edit-undo", "Map.Previous Extent", tr("&Previous Extent"), tr(""), true, false, false, m_menubar);
1373  initAction(m_mapNextExtent, "edit-redo", "Map.Next Extent", tr("&Next Extent"), tr(""), true, false, false, m_menubar);
1374  initAction(m_mapInfo, "pointer-info", "Map.Info", tr("&Info"), tr(""), true, true, true, m_menubar);
1375  initAction(m_mapRemoveSelection, "pointer-remove-selection", "Map.Remove Selection", tr("&Remove Selection"), tr(""), true, false, true, m_menubar);
1376  initAction(m_mapSelection, "pointer-selection", "Map.Selection", tr("&Selection"), tr(""), true, true, true, m_menubar);
1377  initAction(m_mapShowGraphicScale, "", "Map.Show graphic scale", tr("S&how graphic scale"), tr(""), false, true, true, m_menubar);
1378  initAction(m_mapEditGraphicScale, "", "Map.Edit graphic scale", tr("&Edit graphic scale"), tr(""), false, false, false, m_menubar);
1379  initAction(m_mapEditGrid, "", "Map.Edit grid", tr("E&dit grid"), tr(""), false, false, false, m_menubar);
1380  initAction(m_mapMeasureDistance, "distance-measure", "Map.Measure Distance", tr("Measure &Distance"), tr(""), true, true, true, m_menubar);
1381  initAction(m_mapMeasureArea, "area-measure", "Map.Measure Area", tr("Measure &Area"), tr(""), true, true, true, m_menubar);
1382  initAction(m_mapMeasureAngle, "angle-measure", "Map.Measure Angle", tr("Measure &Angle"), tr(""), true, true, true, m_menubar);
1383 
1384  initAction(m_mapSRID, "srs", "Map.SRID", tr("&SRS..."), tr("Config the Map SRS"), true, false, true, m_menubar);
1385  initAction(m_mapUnknownSRID, "srs-unknown", "Map.UnknownSRID", tr("&Set Unknown SRS"), tr("Set the Map SRS to unknown"), true, false, true, m_menubar);
1386  initAction(m_mapStopDrawing, "map-draw-cancel", "Map.Stop Drawing", tr("&Stop Drawing"), tr("Stop all drawing tasks"), true, false, true, m_menubar);
1387  initAction(m_mapShowGeographicGrid, "", "Map.Show geographic grid", tr("S&how geographic grid"), tr("Shows the geographic grid over the map."), true, false, true, m_menubar);
1388  initAction(m_mapPanToCoordinateTool, "", "Map.Find coordinate tool", tr("&Find coordinate tool"), tr("Makes a pan centralizing the input coordinate."), true, true, true, m_menubar);
1389 
1390  initAction(m_internalSettings, "gear", "Map.Internal Settings", tr("&Internal Settings"), tr("Application Internal Settings"), true, false, true, m_menubar);
1391 
1392  m_layerRename->setShortcut(QKeySequence(Qt::Key_F2));
1393 
1394  // Group the map tools
1395  QActionGroup* mapToolsGroup = new QActionGroup(this->menuBar());
1396  mapToolsGroup->setObjectName("Map.ToolsGroup");
1397  mapToolsGroup->addAction(m_mapZoomIn);
1398  mapToolsGroup->addAction(m_mapZoomOut);
1399  mapToolsGroup->addAction(m_mapPan);
1400  mapToolsGroup->addAction(m_mapInfo);
1401  mapToolsGroup->addAction(m_mapSelection);
1402  mapToolsGroup->addAction(m_mapRemoveSelection);
1403  mapToolsGroup->addAction(m_mapMeasureDistance);
1404  mapToolsGroup->addAction(m_mapMeasureArea);
1405  mapToolsGroup->addAction(m_mapMeasureAngle);
1406  mapToolsGroup->addAction(m_mapPanToCoordinateTool);
1407 }
1408 
1410 {
1411  m_menubar = new QMenuBar(this);
1412  m_menubar->setObjectName("menubar");
1413  m_menubar->setGeometry(QRect(0, 0, 640, 21));
1414 
1415  setMenuBar(m_menubar);
1416 
1418 }
1419 
1421 {
1422  std::vector<QToolBar*> bars = te::qt::af::ReadToolBarsFromSettings(m_app, this);
1423  std::vector<QToolBar*>::iterator it;
1424 
1425  for (it = bars.begin(); it != bars.end(); ++it)
1426  {
1427  QToolBar* bar = *it;
1428  addToolBar(Qt::TopToolBarArea, bar);
1429  m_app->registerToolBar(bar->objectName(), bar);
1430  }
1431 }
1432 
1434 {
1435  connect(m_mapDraw, SIGNAL(triggered()), SLOT(onDrawTriggered()));
1436  connect(m_mapZoomIn, SIGNAL(toggled(bool)), SLOT(onZoomInToggled(bool)));
1437  connect(m_mapZoomOut, SIGNAL(toggled(bool)), SLOT(onZoomOutToggled(bool)));
1438  connect(m_mapPreviousExtent, SIGNAL(triggered()), SLOT(onPreviousExtentTriggered()));
1439  connect(m_mapNextExtent, SIGNAL(triggered()), SLOT(onNextExtentTriggered()));
1440  connect(m_mapPan, SIGNAL(toggled(bool)), SLOT(onPanToggled(bool)));
1441  connect(m_mapZoomExtent, SIGNAL(triggered()), SLOT(onZoomExtentTriggered()));
1442  connect(m_mapInfo, SIGNAL(toggled(bool)), SLOT(onInfoToggled(bool)));
1443  connect(m_mapRemoveSelection, SIGNAL(triggered()), SLOT(onMapRemoveSelectionTriggered()));
1444  connect(m_mapSelection, SIGNAL(toggled(bool)), SLOT(onSelectionToggled(bool)));
1445  connect(m_mapMeasureDistance, SIGNAL(toggled(bool)), SLOT(onMeasureDistanceToggled(bool)));
1446  connect(m_mapMeasureArea, SIGNAL(toggled(bool)), SLOT(onMeasureAreaToggled(bool)));
1447  connect(m_mapMeasureAngle, SIGNAL(toggled(bool)), SLOT(onMeasureAngleToggled(bool)));
1448 
1449  connect(m_layerRemove, SIGNAL(triggered()), SLOT(onLayerRemoveTriggered()));
1450  connect(m_layerRename, SIGNAL(triggered()), SLOT(onLayerRenameTriggered()));
1451  connect(m_layerProperties, SIGNAL(triggered()), SLOT(onLayerPropertiesTriggered()));
1454  connect(m_layerRemoveItem, SIGNAL(triggered()), SLOT(onLayerRemoveItemTriggered()));
1455  connect(m_layerSRS, SIGNAL(triggered()), SLOT(onLayerSRSTriggered()));
1459  connect(m_layerShowTable, SIGNAL(triggered()), SLOT(onLayerShowTableTriggered()));
1461  connect(m_layerCharEncoding, SIGNAL(hovered()), SLOT(onLayerCharEncodingHovered()));
1462  connect(m_layerCheckSelectedLayer, SIGNAL(triggered(bool)), SLOT(onCheckSelectedLayerTriggered()));
1463  connect(m_layerClearSelectedLayer, SIGNAL(triggered(bool)), SLOT(onClearSelectedLayerTriggered()));
1464 
1465  connect(m_mapSRID, SIGNAL(triggered()), SLOT(onMapSRIDTriggered()));
1466  connect(m_mapUnknownSRID, SIGNAL(triggered()), SLOT(onMapSetUnknwonSRIDTriggered()));
1467  connect(m_mapStopDrawing, SIGNAL(triggered()), SLOT(onStopDrawTriggered()));
1468  connect(m_mapShowGeographicGrid, SIGNAL(toggled(bool)), SLOT(onMapShowGeographicGridToggled(bool)));
1470  connect(m_internalSettings, SIGNAL(triggered()), SLOT(onInternalSettingsTriggered()));
1471 
1472  connect(m_viewFullScreen, SIGNAL(toggled(bool)), SLOT(onFullScreenToggled(bool)));
1473 
1474  connect(m_viewLayerExplorer, SIGNAL(toggled(bool)), m_ui->m_layerExplorerDockWidget, SLOT(setVisible(bool)));
1475 
1476  connect(m_display, SIGNAL(hasPreviousExtent(bool)), m_mapPreviousExtent, SLOT(setEnabled(bool)));
1477  connect(m_display, SIGNAL(hasNextExtent(bool)), m_mapNextExtent, SLOT(setEnabled(bool)));
1478 
1479  connect(m_viewStyleExplorer, SIGNAL(toggled(bool)), m_styleExplorer->getExplorer(), SLOT(setVisible(bool)));
1480  connect(m_styleExplorer->getExplorer(), SIGNAL(visibilityChanged(bool)), this, SLOT(onStyleExplorerVisibilityChanged(bool)));
1481  connect(m_styleExplorer->getExplorer(), SIGNAL(repaintMapDisplay()), this, SLOT(onDrawTriggered()));
1482 
1483  connect(m_viewDataTable, SIGNAL(toggled(bool)), this, SLOT(onDisplayDataTableChanged(bool)));
1484 
1485  connect(m_mapEditGraphicScale, SIGNAL(triggered()), SLOT(onEditGraphicScaleTriggered()));
1486  connect(m_mapShowGraphicScale, SIGNAL(toggled(bool)), SLOT(onShowGraphicScaleTriggered(bool)));
1487  connect(m_mapEditGrid, SIGNAL(triggered()), SLOT(onEditGridTriggered()));
1488  m_display->getDisplay()->connect(m_mapShowGraphicScale, SIGNAL(toggled(bool)), SLOT(showGraphicScale(bool)));
1489 }
1490 
1491 void te::qt::af::BaseApplication::initAction(QAction*& act, const QString& icon, const QString& name,
1492  const QString& text, const QString& tooltip,
1493  bool iconVisibleInMenu, bool isCheckable,
1494  bool enabled, QObject* parent)
1495 {
1496  act = new QAction(parent);
1497 
1498  if (!icon.isEmpty())
1499  act->setIcon(QIcon::fromTheme(icon));
1500 
1501  act->setObjectName(name);
1502  act->setText(text);
1503  act->setIconVisibleInMenu(iconVisibleInMenu);
1504  act->setCheckable(isCheckable);
1505  act->setEnabled(enabled);
1506 
1507 #ifndef QT_NO_TOOLTIP
1508  act->setToolTip(tooltip);
1509 #endif
1510 }
1511 
1513 {
1514  if (srid != TE_UNKNOWN_SRS)
1515  {
1516  m_mapSRIDLineEdit->setPalette(QPalette());
1517  m_mapSRIDLineEdit->setFont(QFont());
1518  QString sridText("EPSG:" + QString::number(srid));
1519  m_mapSRIDLineEdit->setText(sridText);
1520  }
1521  else
1522  {
1523  QPalette palette;
1524  palette.setColor(QPalette::Text, Qt::red);
1525  m_mapSRIDLineEdit->setPalette(palette);
1526  QFont newFont(m_mapSRIDLineEdit->font());
1527  newFont.setBold(true);
1528  m_mapSRIDLineEdit->setFont(newFont);
1529  m_mapSRIDLineEdit->setText("Unknown SRS");
1530  m_coordinateLineEdit->setText("Coordinates");
1531  }
1532 }
virtual void initFramework(const QString &cfgFile)
A class for rendering icons for layer and folder itens.
void setLayer(te::map::AbstractLayerPtr layer)
Set the layer that can be used.
This event signals that a new layer was created.
Definition: LayerEvents.h:71
virtual void setCurrentTool(te::qt::widgets::AbstractTool *tool, const bool &delPrevious=true)
Updates the current tool being used on te::qt::widgets::MapDisplay.
ApplicationController * m_app
virtual void refresh(bool redraw=false)
It updates the contents in the map display.
void onLayerSelectionChanged(const te::map::AbstractLayerPtr &layer)
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
A dock widget for table view objects.
Geometric property.
virtual void setConfigFile(const std::string &configFileName)
Tells wich configuration file to be used by the controller during its initialization.
A dialog that gets a coordinate ad centralize the area of visualization at it.
void onZoomInToggled(bool checked)
double m_x
The x coordinate value.
Definition: ToolEvents.h:93
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
A dock widget for ChartDisplayWidget objects.
This is the base class for layers.
Definition: AbstractLayer.h:77
te::map::AbstractLayerPtr m_layer
Layer whose selected objects were changed.
Definition: LayerEvents.h:218
a QDockWidget that contains a property browser object with graphic scale properties.
te::qt::af::DataSetTableDockWidget * GetLayerDock(const te::map::AbstractLayer *layer, const std::vector< te::qt::af::DataSetTableDockWidget * > &docs)
void onPanToggled(bool checked)
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
void fit(const std::list< te::map::AbstractLayerPtr > &layers)
virtual void initializePlugins()
Load the plugin list and initialize the plugins enabled by the user.
const QString & getAppTitle() const
Returns the application title.
QDockWidget * getLayerExplorerDock()
void onLayerSelectedObjectsChanged(const te::map::AbstractLayerPtr &layer)
static void prepareQtEnvironment(const QString &configFileName, const QString &splashFileName)
void MapDisplay()
It retrieves data from a data source, create a set of layer and show map display. ...
virtual std::list< AbstractLayerPtr > getLayerList() const
This class implements a concrete tool to geographic zoom in operation using a boundary rectangle...
Definition: ZoomArea.h:49
A base class for application events.
virtual const char * what() const
It outputs the exception message.
This class is widget that provides a menu for char encoding selection.
void registerMenuBar(QMenuBar *bar)
Register the bar.
te::map::AbstractLayerPtr getLayer() const
Returns the layer contained in the item.
Definition: LayerItem.cpp:140
const QString & getAppIconName() const
Returns the application icon.
void setSelectionColor(QColor selColor)
color used to hgihlight selected objects on this display.
virtual std::string getAsString() const =0
Returns the label of the item to be presented in a Qt view.
void onChartDisplayCreated(te::qt::widgets::ChartDisplayWidget *chartDisplay, te::map::AbstractLayer *layer)
A connector for the te::qt::widgets::StyleDockWidget class to the Application Framework.
A connector for the te::qt::widgets::LayerExplorer class to the Application Framework.
Definition: LayerExplorer.h:75
This event signals that the srid of the map display changed.
Definition: MapEvents.h:54
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
A connector for the te::qt::widgets::StyleDockWidget class to the Application Framework.
Contains a list of the map display events.
double m_urx
Upper right corner x-coordinate.
virtual double getScale() const
Calculates and return the current scale.
int updateLegend()
updateLegend
Definition: LayerItem.cpp:155
A singleton for holding he application splash screen.
double getWidth() const
It returns the envelope width.
te::qt::widgets::StyleDockWidget * getExplorer() const
double m_y
The y coordinate value.
Definition: ToolEvents.h:94
void onStyleExplorerVisibilityChanged(bool visible)
A widget to control the display of a set of layers.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
static te::dt::Date ds(2010, 01, 01)
virtual void onApplicationTriggered(te::qt::af::evt::Event *e)
TEQTAFEXPORT void UpdateUserSettings()
Reads and return a te::qt::af::Project from the file.
This class implements a concrete tool to select layer features using an extent.
Definition: Selection.h:65
void onInfoToggled(bool checked)
This event indicates that the selected objects of the layer were changed.
Definition: LayerEvents.h:204
A dock widget for DataSetTableView objects.
void onShowGraphicScaleTriggered(bool checked)
Raster property.
ScaleWidget * getGraphicScale() const
Returns the pointer for the graphic scale object;.
Defines a hierarchical structure.
Represents a folder item that contains layers and / or other folders.
Definition: FolderItem.h:48
virtual void createDefaultSettings()=0
virtual void init(const QString &cfgFile)
A Dialog to be used to inform about internal settings.
te::qt::widgets::LayerItemView * getExplorer() const
virtual void initAction(QAction *&act, const QString &icon, const QString &name, const QString &text, const QString &tooltip, bool iconVisibleInMenu, bool isCheckable, bool enabled, QObject *parent)
static void prepareQtEnvironment(const QString &cfgFile, const QString &splashImg)
te::qt::af::DataSetTableDockWidget * getLayerDock(const te::map::AbstractLayer *layer, const std::vector< te::qt::af::DataSetTableDockWidget * > &docs)
virtual void initialize()
Initializes the application framework.
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
TEQTWIDGETSEXPORT void GetValidLayers(QAbstractItemModel *model, const QModelIndex &parent, std::vector< te::map::AbstractLayerPtr > &layers)
TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const std::list< te::map::AbstractLayerPtr > layers, int srid, bool onlyVisibles)
It calculates the extent of selected objects of the given layers in the given SRID.
Coord2D getCenter() const
It returns the rectangle&#39;s center coordinate.
This class implements a concrete tool to get informations about a specified feature using pointing op...
Definition: Info.h:76
virtual void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the layer list to be showed in the Map Display.
This class implements a concrete tool to geographic pan operation.
Definition: Pan.h:49
double m_llx
Lower left corner x-coordinate.
virtual void setResizePolicy(const ResizePolicy &policy)
Sets the resize policy to this map display.
QColor getSelectionColor() const
Returns the application selection color.
A connector of the te::qt::widgets::MapDisplay class to the Application Framework.
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
void onMeasureAngleToggled(bool checked)
void setHighlightColor(QColor color)
Defines the color to be used as Highlight.
An Envelope defines a 2D rectangular region.
A connector for the te::qt::widgets::LayerExplorer class to the Application Framework.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
void onMeasureDistanceToggled(bool checked)
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
void onSelectionToggled(bool checked)
This class controls how a set of layers are displayed.
Contains a list of the layer events.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void setLayer(te::map::AbstractLayer *layer)
Sets the layer to be showed on view. This DOES NOT takes the ownership of layer.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
void onMeasureAreaToggled(bool checked)
te::qt::widgets::LayerItemView * getLayerExplorer()
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:78
void onMapShowGeographicGridToggled(bool check)
void onFullScreenToggled(bool checked)
void draw(const std::list< te::map::AbstractLayerPtr > &layers)
It draws the given layer list.
void cancelTasks(unsigned int type)
Cancels the task with the given task type and inform all viewers that a task was canceled.
This class implements a concrete tool to geographic zoom operation using the mouse click...
Definition: ZoomClick.h:49
void onLayerExplorerVisibilityChanged(bool visible)
TEDATAACCESSEXPORT ObjectIdSet * GenerateOIDSet(DataSet *dataset, const DataSetType *type)
Utility functions for the data access module.
Ui::BaseApplicationForm * m_ui
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
te::qt::widgets::CharEncodingMenuWidget * m_encodingMenu
A dock widget for chart display objects.
virtual void onLayerShowTableTriggered()
BaseApplication(QWidget *parent=0)
double m_lly
Lower left corner y-coordinate.
void triggered(te::qt::af::evt::Event *e)
Signals a mouse moved over the current display.
Definition: ToolEvents.h:78
void addListener(QObject *obj, const ListenerType &type=BOTH)
Insert an application item that will listen to framework events.
std::list< te::qt::widgets::TreeItem * > getSelectedItems() const
Returns a list of TreeItem that are selected.
void setAppController(ApplicationController *app)
Sets the app controller to emit signal to app. This DOES NOT takes the ownership of app controller...
A wdiget used to display a chart.
std::vector< te::qt::af::DataSetTableDockWidget * > m_tables
void trigger(te::qt::af::evt::Event *)
TEQTWIDGETSEXPORT std::list< te::map::AbstractLayerPtr > GetSelectedLayersOnly(te::qt::widgets::LayerItemView *view, const bool getFolder=false)
double m_ury
Upper right corner y-coordinate.
te::qt::widgets::MapDisplay * getMapDisplay()
void onDisplayDataTableChanged(bool visible)
void setParameters(te::map::AbstractLayerPtr layer)
Set a layer.
TreeItem * getParent() const
Returns the item parent.
void removeListener(QObject *obj)
Remove the obj from the list of event listeners.
void setMapSRIDLineEdit(const int srid)
void onZoomOutToggled(bool checked)
a QDockWidget that contains a property browser object with grid properties.
std::vector< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions.
std::list< te::map::AbstractLayerPtr > GetSelectedLayersOnly(te::qt::widgets::LayerItemView *view)
virtual void onInternalSettingsTriggered()
This class implements a concrete tool to measure operation (distance, area, and angle).
Definition: Measure.h:66
A dialog used to build a SRSManagerDialog element.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEQTWIDGETSEXPORT void GetChangedAndVisibleLayers(const QModelIndexList &idxs, std::list< te::map::AbstractLayerPtr > &layers)
virtual void setSRID(const int &srid, bool doRefresh=true)
It sets a new Spatial Reference System to be used by the Map Display.
A class that represents a style of a layer in a LayerTreeModel.
Definition: StyleItem.h:50
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
Contains the list of the application events.
A QMainWindow to be used as the basis for TerraLib applications.
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
double getHeight() const
It returns the envelope height.
The base API for controllers of TerraLib applications.
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
void setLayer(te::map::AbstractLayer *layer, const bool &editable=true)
Sets the layer to be showed on view. This DOES NOT takes the ownership of layer.
bool isValid() const
It tells if the rectangle is valid or not.
virtual bool setScale(const double &scale)
Defines the scale and calculates envelope based on the requested scale.
virtual void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
void registerToolBar(const QString &id, QToolBar *bar)
Register the toolbar in the list of the known toolbars.
void difference(const ObjectIdSet *rhs)
It performs the difference operation between this ObjectIdSet and the given ObjectIdSet.
void removeSelectedItems()
Removes the items that are selected.
std::string getType() const
Returns the type of the item.
TEQTAFEXPORT std::vector< QToolBar * > ReadToolBarsFromSettings(te::qt::af::ApplicationController *appController, QWidget *barsParent=0)
Returns a vector of tool bars registered in the QSettings.
virtual void finalize()
Finalize the application framework.
std::pair< int, std::string > m_srid
Definition: MapEvents.h:67
void onLayerTableClose(te::qt::af::DataSetTableDockWidget *wid)
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
InternalSettingsDialog * m_internalSettingsDlg