ColorCatalogWidget.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/colorbar/ColorCatalogWidget.cpp
22 
23  \brief ...
24 */
25 
26 // TerraLib
27 #include "../../../color/ColorBar.h"
28 #include "../../../color/ColorScheme.h"
29 #include "../../../color/ColorSchemeCatalog.h"
30 #include "../../../color/ColorSchemeCatalogManager.h"
31 #include "../../../color/ColorSchemeGroup.h"
32 #include "../../../color/RGBAColor.h"
33 #include "ColorBar.h"
34 #include "ColorCatalogWidget.h"
35 #include "ui_ColorCatalogWidgetForm.h"
36 
37 // QT
38 #include <QGridLayout>
39 
40 
42  : QWidget(parent, f),
43  m_ui(new Ui::ColorCatalogWidgetForm)
44 {
45  m_ui->setupUi(this);
46 
47  //build form
48  QGridLayout* l = new QGridLayout(m_ui->m_widget);
49  l->setContentsMargins(0,0,0,0);
50 
52  l->addWidget(m_colorBar);
53 
54  //connects
55  connect(m_ui->m_catalogComboBox, SIGNAL(activated(int)), this, SLOT(onCatalogComboBoxActivated(int)));
56  connect(m_ui->m_groupComboBox, SIGNAL(activated(int)), this, SLOT(onGroupComboBoxActivated(int)));
57  connect(m_ui->m_schemaComboBox, SIGNAL(activated(int)), this, SLOT(onSchemaComboBoxActivated(int)));
58  connect(m_ui->m_catalogGroupBox, SIGNAL(clicked(bool)), this, SLOT(onUseCatalogGroupBoxClicked(bool)));
59 
60  connect(m_colorBar, SIGNAL(colorBarChanged()), this, SIGNAL(colorBarChanged()));
61 
63 }
64 
66 
68 {
69  return m_colorBar;
70 }
71 
73 {
74  return m_ui->m_catalogComboBox->currentText().toUtf8().data();
75 }
76 
78 {
79  return m_ui->m_groupComboBox->currentText().toUtf8().data();
80 }
81 
83 {
84  return m_ui->m_schemaComboBox->currentText().toUtf8().data();
85 }
86 
87 void te::qt::widgets::ColorCatalogWidget::setCatalog(const std::string& catalog)
88 {
89  int index = m_ui->m_catalogComboBox->findText(catalog.c_str());
90 
92 }
93 
94 void te::qt::widgets::ColorCatalogWidget::setGroup(const std::string& group)
95 {
96  int index = m_ui->m_groupComboBox->findText(group.c_str());
97 
99 }
100 
101 void te::qt::widgets::ColorCatalogWidget::setSchema(const std::string& schema)
102 {
103  int index = m_ui->m_schemaComboBox->findText(schema.c_str());
104 
106 }
107 
109 {
110  m_ui->m_catalogComboBox->clear();
111 
112  std::pair<std::vector<te::color::ColorSchemeCatalog*>::const_iterator, std::vector<te::color::ColorSchemeCatalog*>::const_iterator> cscPairIt = te::color::ColorSchemeCatalogManager::getInstance().getIterator();
113 
114  while(cscPairIt.first != cscPairIt.second)
115  {
116  te::color::ColorSchemeCatalog* csc = *cscPairIt.first;
117 
118  m_ui->m_catalogComboBox->addItem(csc->getName().c_str());
119 
120  ++cscPairIt.first;
121  }
122 
123  if(m_ui->m_catalogComboBox->count() != 0)
125 }
126 
128 {
129  std::string name = m_ui->m_catalogComboBox->itemText(index).toUtf8().data();
130 
131  m_ui->m_catalogComboBox->setCurrentIndex(index);
132 
134 
135  if(!csc)
136  return;
137 
138  m_ui->m_groupComboBox->clear();
139 
140  std::vector<te::color::ColorSchemeGroup*> csgVec = csc->getColorSchemeGroups();
141 
142  for(std::size_t t = 0; t < csgVec.size(); ++t)
143  {
144  te::color::ColorSchemeGroup* csg = csgVec[t];
145 
146  m_ui->m_groupComboBox->addItem(csg->getName().c_str());
147  }
148 
149  if(m_ui->m_groupComboBox->count() != 0)
151 }
152 
154 {
155  std::string catalog = m_ui->m_catalogComboBox->currentText().toUtf8().data();
156 
157  m_ui->m_groupComboBox->setCurrentIndex(index);
158 
159  std::string group = m_ui->m_groupComboBox->itemText(index).toUtf8().data();
160 
162 
163  m_ui->m_schemaComboBox->clear();
164 
165  if(csc)
166  {
167  std::vector<te::color::ColorSchemeGroup*> csgVec = csc->getColorSchemeGroups();
168 
169  for(std::size_t t = 0; t < csgVec.size(); ++t)
170  {
171  te::color::ColorSchemeGroup* csg = csgVec[t];
172 
173  if(csg->getName() == group)
174  {
175  std::vector<te::color::ColorScheme*> csVec = csg->getColorSchemes();
176 
177  for(std::size_t p = 0; p < csVec.size(); ++p)
178  {
179  te::color::ColorScheme* cs = csVec[p];
180 
181  m_ui->m_schemaComboBox->addItem(cs->getName().c_str());
182  }
183  }
184  }
185  }
186 
187  if(m_ui->m_schemaComboBox->count() != 0)
189 }
190 
192 {
193  std::string catalog = m_ui->m_catalogComboBox->currentText().toUtf8().data();
194 
195  std::string group = m_ui->m_groupComboBox->currentText().toUtf8().data();
196 
197  m_ui->m_schemaComboBox->setCurrentIndex(index);
198 
199  std::string schema = m_ui->m_schemaComboBox->itemText(index).toUtf8().data();
200 
202 
203  if(csc)
204  {
205  std::vector<te::color::ColorSchemeGroup*> csgVec = csc->getColorSchemeGroups();
206 
207  for(std::size_t t = 0; t < csgVec.size(); ++t)
208  {
209  te::color::ColorSchemeGroup* csg = csgVec[t];
210 
211  if(csg->getName() == group)
212  {
213  std::vector<te::color::ColorScheme*> csVec = csg->getColorSchemes();
214 
215  for(std::size_t p = 0; p < csVec.size(); ++p)
216  {
217  te::color::ColorScheme* cs = csVec[p];
218 
219  if(cs->getName() == schema)
220  {
221  std::vector<te::color::RGBAColor>* colors = cs->getColors()[0]; //WARNING... Always getting the first position
222 
223  std::vector<te::color::RGBAColor>::iterator it = colors->begin();
224 
225  // create color bar
226  te::color::ColorBar* cb = new te::color::ColorBar(*(colors->begin()), *(colors->end() - 1), 256);
227 
228  int count = 0;
229 
230  //fill color bar
231  while(it != colors->end())
232  {
233  if(count != 0 && count != static_cast<int>(colors->size()) - 1)
234  {
235  double pos = (1. / (colors->size() - 1)) * count;
236 
237  cb->addColor(*it, pos);
238  }
239 
240  ++count;
241  ++it;
242  }
243 
244  //set color bar
245  m_colorBar->setColorBar(cb);
246  }
247  }
248  }
249  }
250  }
251 }
252 
254 {
255  if(flag) //start catalog
257  else //create default color bar
258  {
259  te::color::ColorBar* cb = new te::color::ColorBar(te::color::RGBAColor(0, 0, 0, 255), te::color::RGBAColor(255, 0, 0, 255), 256);
260  m_colorBar->setColorBar(cb);
261  }
262 }
const std::vector< ColorScheme * > & getColorSchemes() const
It returns a reference to the list of color schemes belonging to this group.
const std::vector< ColorSchemeGroup * > & getColorSchemeGroups() const
It returns the list of color scheme groups in the catalog.
std::unique_ptr< Ui::ColorCatalogWidgetForm > m_ui
const std::string & getName() const
It returns the group name.
It models the concept of color scheme.
Definition: ColorScheme.h:58
const std::vector< std::vector< RGBAColor > * > & getColors() const
It returns all color lists.
Definition: ColorScheme.cpp:68
void setCatalog(const std::string &catalog)
static T & getInstance()
It returns a reference to the singleton instance.
Definition: Singleton.h:126
const std::string & getName() const
It returns the catalog name.
te::gm::Polygon * p
The concept of color bar.
ColorCatalogWidget(QWidget *parent=0, Qt::WindowFlags f=0)
const std::string & getName() const
It returns the color schema name.
Definition: ColorScheme.cpp:42
void addColor(const RGBAColor &color, const double &pos)
It adds a color in the color bar.
void setSchema(const std::string &schema)
This class represents a group of color schemes.
te::qt::widgets::colorbar::ColorBar * m_colorBar
Widget used to represent a color bar.
A catalog for color schemes.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
It models the concept of color bar.
te::qt::widgets::colorbar::ColorBar * getColorBar()
void setColorBar(te::color::ColorBar *cb)
It sets the color bar.
void setGroup(const std::string &group)