All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SnapOptionsDialog.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/edit/qt/SnapOptionsWidget.cpp
22 
23  \brief A dialog used to configure geometry snap options.
24 */
25 
26 // TerraLib
27 #include "../../dataaccess/dataset/DataSet.h"
28 #include "../Snap.h"
29 #include "../SnapManager.h"
30 #include "SnapOptionsDialog.h"
31 #include "ui_SnapOptionsDialogForm.h"
32 
33 // Qt
34 #include <QCheckBox>
35 #include <QComboBox>
36 #include <QTableWidgetItem>
37 
38 // STL
39 #include <cassert>
40 
42 
43 te::edit::SnapOptionsDialog::SnapOptionsDialog(QWidget* parent, Qt::WindowFlags f)
44  : QDialog(parent, f),
45  m_ui(new Ui::SnapOptionsDialogForm)
46 {
47  m_ui->setupUi(this);
48 
49  // Signals & slots
50  connect(m_ui->m_okPushButton, SIGNAL(pressed()), this, SLOT(onOkPushButtonPressed()));
51 }
52 
54 {
55 }
56 
57 void te::edit::SnapOptionsDialog::setLayers(const std::list<te::map::AbstractLayerPtr>& layers)
58 {
59  m_layers = layers;
60 
61  buildOptions();
62 }
63 
65 {
66  for(std::list<te::map::AbstractLayerPtr>::const_iterator it = m_layers.begin(); it != m_layers.end(); ++it)
67  buildOptions(*it);
68 }
69 
71 {
72  for(std::size_t i = 0; i < layer->getChildrenCount(); ++i)
73  {
74  te::map::AbstractLayerPtr child(boost::dynamic_pointer_cast<te::map::AbstractLayer>(layer->getChild(i)));
75  buildOptions(child);
76  }
77 
78  if(layer->getType() == "FOLDER_LAYER")
79  return;
80 
81  int row = m_ui->m_tableOptionsWidget->rowCount() + 1;
82  m_ui->m_tableOptionsWidget->setRowCount(row);
83 
84  int currentRow = row - 1;
85  int currentCollumn = 0;
86 
87  // Enable
88  QCheckBox* enableCheckBox = new QCheckBox(m_ui->m_tableOptionsWidget);
89 
90  if(SnapManager::getInstance().hasSnap(layer->getId()))
91  enableCheckBox->setChecked(true);
92 
93  m_ui->m_tableOptionsWidget->setCellWidget(currentRow, currentCollumn++, enableCheckBox);
94 
95  // Layer
96  QTableWidgetItem* layerItem = new QTableWidgetItem(layer->getTitle().c_str());
97  layerItem->setTextAlignment(Qt::AlignCenter);
98  layerItem->setFlags(Qt::ItemIsEnabled);
99  layerItem->setData(Qt::UserRole, QVariant::fromValue(layer));
100  m_ui->m_tableOptionsWidget->setItem(currentRow, currentCollumn++, layerItem);
101 
102  // Snap Mode
103  QComboBox* modeComboBox = new QComboBox(m_ui->m_tableOptionsWidget);
104  modeComboBox->addItem(tr("vertex"));
105  m_ui->m_tableOptionsWidget->setCellWidget(currentRow, currentCollumn++, modeComboBox);
106 
107  // Tolerance
108  QTableWidgetItem* toleranceItem = new QTableWidgetItem("16");
109  toleranceItem->setTextAlignment( Qt::AlignCenter);
110 
111  if(SnapManager::getInstance().hasSnap(layer->getId()))
112  {
113  Snap* snap = SnapManager::getInstance().getSnap(layer->getId());
114  toleranceItem->setText(QString::number(snap->getTolerance()));
115  }
116 
117  m_ui->m_tableOptionsWidget->setItem(currentRow, currentCollumn++, toleranceItem);
118 
119  // Units
120  QComboBox* unitsComboBox = new QComboBox(m_ui->m_tableOptionsWidget);
121  unitsComboBox->addItem(tr("pixels"));
122  m_ui->m_tableOptionsWidget->setCellWidget(currentRow, currentCollumn++, unitsComboBox);
123 }
124 
126 {
127  for(int i = 0; i < m_ui->m_tableOptionsWidget->rowCount(); ++i) // for each option
128  {
129  QCheckBox* enableCheckBox = dynamic_cast<QCheckBox*>(m_ui->m_tableOptionsWidget->cellWidget(i, 0));
130 
131  // Get the layer
132  te::map::AbstractLayerPtr layer = m_ui->m_tableOptionsWidget->item(i, 1)->data(Qt::UserRole).value<te::map::AbstractLayerPtr>();
133 
134  // TODO: mode, tolerance and units
135 
136  if(enableCheckBox->isChecked())
137  {
138  if(SnapManager::getInstance().hasSnap(layer->getId()) == false)
139  {
140  // Build the snap
141  std::auto_ptr<te::da::DataSet> dataset(layer->getData());
142  SnapManager::getInstance().buildSnap(layer->getId(), layer->getSRID(), dataset.get());
143  }
144  }
145  else
146  {
147  // Remove the snap
148  SnapManager::getInstance().removeSnap(layer->getId());
149  }
150  }
151 
152  close();
153 }
This class implements geometry snap concept.
Definition: Snap.h:63
double getTolerance() const
Definition: Snap.cpp:75
void setLayers(const std::list< te::map::AbstractLayerPtr > &layers)
static T & getInstance()
It returns a reference to the singleton instance.
Definition: Singleton.h:120
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
A dialog used to configure geometry snap options.
SnapOptionsDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs the snap options dialog which is a child of parent, with widget flags set to f...
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::auto_ptr< Ui::SnapOptionsDialogForm > m_ui
Dialog form.