All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WellKnownMarkWidget.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/se/WellKnownMarkWidget.cpp
22 
23  \brief A widget used to build a well known mark element.
24 */
25 
26 // TerraLib
27 #include "../../../maptools/MarkRendererManager.h"
28 #include "../../../se/Mark.h"
29 #include "BasicFillWidget.h"
30 #include "BasicStrokeWidget.h"
31 #include "ui_WellKnownMarkWidgetForm.h"
32 #include "WellKnownMarkWidget.h"
33 
34 // STL
35 #include <cassert>
36 
38  : QWidget(parent, f),
39  m_ui(new Ui::WellKnownMarkWidgetForm),
40  m_mark(new te::se::Mark)
41 {
42  m_ui->setupUi(this);
43 
44  // Fill Widget
46 
47  // Adjusting...
48  QGridLayout* fillLayout = new QGridLayout(m_ui->m_fillGroupBox);
49  fillLayout->addWidget(m_fillWidget);
50 
51  // Stroke Widget
53 
54  // Adjusting...
55  QGridLayout* strokeLayout = new QGridLayout(m_ui->m_strokeGroupBox);
56  strokeLayout->addWidget(m_strokeWidget);
57 
58  // Gets supported marks
60  for(std::size_t i = 0; i < m_supportedMarks.size(); ++i)
61  m_ui->m_markTypeComboBox->addItem(m_supportedMarks[i].c_str());
62 
63  // Setups initial mark
64  m_mark->setWellKnownName(new std::string(m_supportedMarks[0]));
67 
68  // Signals & slots
69  connect(m_ui->m_markTypeComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onMarkTypeComboBoxCurrentIndexChanged(const QString&)));
70  connect(m_fillWidget, SIGNAL(fillChanged()), SLOT(onFillChanged()));
71  connect(m_ui->m_fillGroupBox, SIGNAL(toggled(bool)), this, SLOT(onFillGroupBoxToggled(bool)));
72  connect(m_strokeWidget, SIGNAL(strokeChanged()), SLOT(onStrokeChanged()));
73  connect(m_ui->m_strokeGroupBox, SIGNAL(toggled(bool)), this, SLOT(onStrokeGroupBoxToggled(bool)));
74 }
75 
77 {
78  delete m_mark;
79 }
80 
82 {
83  assert(mark);
84 
85  delete m_mark;
86 
87  m_mark = mark->clone();
88 
89  updateUi();
90 }
91 
93 {
94  return m_mark->clone();
95 }
96 
98 {
99  const std::string* name = m_mark->getWellKnownName();
100  assert(name); // TODO: Exception?
101 
102  QString qName(name->c_str());
103  int index = m_ui->m_markTypeComboBox->findText(qName, Qt::MatchFixedString);
104  assert(index != -1); // TODO: Exception?
105  m_ui->m_markTypeComboBox->setCurrentIndex(index);
106 
107  const te::se::Stroke* stroke = m_mark->getStroke();
108  if(stroke)
109  {
110  m_strokeWidget->setStroke(stroke);
111  m_ui->m_strokeGroupBox->setChecked(true);
112  }
113  else
114  m_ui->m_strokeGroupBox->setChecked(false);
115 
116  const te::se::Fill* fill = m_mark->getFill();
117  if(fill)
118  {
119  m_fillWidget->setFill(fill);
120  m_ui->m_fillGroupBox->setChecked(true);
121  }
122  else
123  m_ui->m_fillGroupBox->setChecked(false);
124 }
125 
127 {
128  m_mark->setWellKnownName(new std::string(currentText.toStdString()));
129  emit markChanged();
130 }
131 
133 {
134  m_mark->setStroke(m_strokeWidget->getStroke());
135  emit markChanged();
136 }
137 
139 {
140  if(on == false)
141  m_mark->setStroke(0);
142  else
143  m_mark->setStroke(m_strokeWidget->getStroke());
144  emit markChanged();
145 }
146 
148 {
149  m_mark->setFill(m_fillWidget->getFill());
150  emit markChanged();
151 }
152 
154 {
155  if(on == false)
156  m_mark->setFill(0);
157  else
158  m_mark->setFill(m_fillWidget->getFill());
159  emit markChanged();
160 }
A widget used to build a well known mark element.
A widget used to build a basic fill element.
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
void onMarkTypeComboBoxCurrentIndexChanged(const QString &currentText)
te::se::Mark * getMark() const
Gets the configured mark element.
te::qt::widgets::BasicStrokeWidget * m_strokeWidget
Basic Stroke Widget used to configure the mark stroke element.
void setFill(Fill *f)
Definition: Mark.cpp:108
std::auto_ptr< Ui::WellKnownMarkWidgetForm > m_ui
Widget form.
A widget used to build a basic fill element.
A widget used to build a basic stroke element.
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
std::vector< std::string > m_supportedMarks
Names of supported marks.
WellKnownMarkWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a well known mark widget which is a child of parent, with widget flags set to f...
void updateUi()
Updates the widget form based on internal mark element.
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
void setStroke(Stroke *s)
Definition: Mark.cpp:119
Mark * clone() const
It creates a new copy of this object.
Definition: Mark.cpp:130
A widget used to build a basic stroke element.
te::qt::widgets::BasicFillWidget * m_fillWidget
Basic Fill Widget used to configure the mark fill element.
void setWellKnownName(std::string *name)
The WellKnownName element gives the well-known name of the shape of the mark.
Definition: Mark.cpp:54
te::se::Stroke * getStroke() const
Gets the configured stroke element.
te::se::Fill * getFill() const
Gets the configured fill element.
te::se::Mark * m_mark
Mark element that will be configured by this widget.