All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GraphicSelectorWidget.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/GraphicSelectorWidget.cpp
22 
23  \brief A widget used to select a graphic element.
24 */
25 
26 // TerraLib
27 #include "AbstractGraphicWidget.h"
29 #include "GraphicSelectorWidget.h"
30 #include "ui_GraphicSelectorWidgetForm.h"
31 
32 // Qt
33 #include <QStackedWidget>
34 
36  : QWidget(parent, f),
37  m_ui(new Ui::GraphicSelectorWidgetForm)
38 {
39  m_ui->setupUi(this);
40 
41  // Graphic Widgets
42  m_graphicWidgets = new QStackedWidget(this);
43 
44  // Gets registered graphic widgets
45  std::vector<std::string> keys;
47  std::vector<std::string>::reverse_iterator it;
48  for(it = keys.rbegin(); it != keys.rend(); ++it)
49  {
51  m_ui->m_graphicTypeComboBox->addItem(gw->getGraphicType());
52  connect(gw, SIGNAL(graphicChanged()), SLOT(onGraphicChanged()));
53  m_graphicWidgets->addWidget(gw);
54  }
55 
56  // Adjusting...
57  QGridLayout* layout = new QGridLayout(m_ui->m_graphicWidgetFrame);
58  layout->setSizeConstraint(QLayout::SetFixedSize);
59  layout->addWidget(m_graphicWidgets);
60 
61  // Signals & slots
62  connect(m_ui->m_graphicTypeComboBox, SIGNAL(activated(int)), SLOT(onGraphicTypeComboBoxCurrentIndexChanged(int)));
63 }
64 
66 {
67 }
68 
70 {
71  int i;
72  for(i = 0; i < m_graphicWidgets->count(); ++i)
73  {
74  te::qt::widgets::AbstractGraphicWidget* gw = static_cast<te::qt::widgets::AbstractGraphicWidget*>(m_graphicWidgets->widget(i));
75  if(gw->setGraphic(graphic))
76  break;
77  }
78 
79  if(i == m_graphicWidgets->count())
80  return; // TODO: Exception! The given graphic cannot be dealt by any registered graphic widgets.
81 
82  // Updating Ui
83  m_ui->m_graphicTypeComboBox->setCurrentIndex(i);
84  m_graphicWidgets->setCurrentIndex(i);
85 }
86 
88 {
89  te::qt::widgets::AbstractGraphicWidget* g = static_cast<te::qt::widgets::AbstractGraphicWidget*>(m_graphicWidgets->currentWidget());
90  return g->getGraphic();
91 }
92 
94 {
95  te::qt::widgets::AbstractGraphicWidget* g = static_cast<te::qt::widgets::AbstractGraphicWidget*>(m_graphicWidgets->currentWidget());
96  return g->getGraphicIcon(size);
97 }
98 
100 {
101  m_graphicWidgets->setCurrentIndex(index);
102  emit graphicChanged();
103 }
104 
106 {
107  // Propagates the signal
108  emit graphicChanged();
109 }
virtual QString getGraphicType() const =0
Pure virtual method that should return a "user friendly" string that informs the graphic type that ca...
QIcon getGraphicIcon(const QSize &size)
Gets the current graphic icon.
void setGraphic(const te::se::Graphic *graphic)
Sets the graphic element.
A widget used to select a graphic element.
te::se::Graphic * getGraphic() const
Gets the configured graphic element.
te::se::Graphic * getGraphic() const
Gets the configured graphic element.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
Abstract class that represents a widget that can be used to build a graphic element.
static AbstractGraphicWidget * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
static void RegisteredWidgets(std::vector< std::string > &keys)
It informs the key of each registered graphic widget factory.
The abstract factory of widgets used to configure Symbology Enconding Graphic element.
virtual QIcon getGraphicIcon(const QSize &size) const =0
Pure virtual method that should return a QIcon that represents the graphic. i.e. a simple preview...
std::auto_ptr< Ui::GraphicSelectorWidgetForm > m_ui
Widget form.
QStackedWidget * m_graphicWidgets
Set of Graphic Widgets that can be used to configure the graphic element.
Abstract class that represents a widget that can be used to build a graphic element.
virtual bool setGraphic(const te::se::Graphic *graphic)=0
Sets a graphic element to this widget.
GraphicSelectorWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a graphic selector widget dialog which is a child of parent, with widget flags set to f...