All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
67 }
68 
70 {
71  return m_colorBar;
72 }
73 
75 {
76  m_ui->m_catalogComboBox->clear();
77 
78  std::pair<std::vector<te::color::ColorSchemeCatalog*>::const_iterator, std::vector<te::color::ColorSchemeCatalog*>::const_iterator> cscPairIt = te::color::ColorSchemeCatalogManager::getInstance().getIterator();
79 
80  while(cscPairIt.first != cscPairIt.second)
81  {
82  te::color::ColorSchemeCatalog* csc = *cscPairIt.first;
83 
84  m_ui->m_catalogComboBox->addItem(csc->getName().c_str());
85 
86  ++cscPairIt.first;
87  }
88 
89  if(m_ui->m_catalogComboBox->count() != 0)
90  onCatalogComboBoxActivated(0);
91 }
92 
94 {
95  std::string name = m_ui->m_catalogComboBox->itemText(index).toStdString();
96 
98 
99  if(!csc)
100  return;
101 
102  m_ui->m_groupComboBox->clear();
103 
104  std::vector<te::color::ColorSchemeGroup*> csgVec = csc->getColorSchemeGroups();
105 
106  for(std::size_t t = 0; t < csgVec.size(); ++t)
107  {
108  te::color::ColorSchemeGroup* csg = csgVec[t];
109 
110  m_ui->m_groupComboBox->addItem(csg->getName().c_str());
111  }
112 
113  if(m_ui->m_groupComboBox->count() != 0)
114  onGroupComboBoxActivated(0);
115 }
116 
118 {
119  std::string catalog = m_ui->m_catalogComboBox->currentText().toStdString();
120 
121  std::string group = m_ui->m_groupComboBox->itemText(index).toStdString();
122 
124 
125  m_ui->m_schemaComboBox->clear();
126 
127  if(csc)
128  {
129  std::vector<te::color::ColorSchemeGroup*> csgVec = csc->getColorSchemeGroups();
130 
131  for(std::size_t t = 0; t < csgVec.size(); ++t)
132  {
133  te::color::ColorSchemeGroup* csg = csgVec[t];
134 
135  if(csg->getName() == group)
136  {
137  std::vector<te::color::ColorScheme*> csVec = csg->getColorSchemes();
138 
139  for(std::size_t p = 0; p < csVec.size(); ++p)
140  {
141  te::color::ColorScheme* cs = csVec[p];
142 
143  m_ui->m_schemaComboBox->addItem(cs->getName().c_str());
144  }
145  }
146  }
147  }
148 
149  if(m_ui->m_schemaComboBox->count() != 0)
150  onSchemaComboBoxActivated(0);
151 }
152 
154 {
155  std::string catalog = m_ui->m_catalogComboBox->currentText().toStdString();
156 
157  std::string group = m_ui->m_groupComboBox->currentText().toStdString();
158 
159  std::string schema = m_ui->m_schemaComboBox->itemText(index).toStdString();
160 
162 
163  if(csc)
164  {
165  std::vector<te::color::ColorSchemeGroup*> csgVec = csc->getColorSchemeGroups();
166 
167  for(std::size_t t = 0; t < csgVec.size(); ++t)
168  {
169  te::color::ColorSchemeGroup* csg = csgVec[t];
170 
171  if(csg->getName() == group)
172  {
173  std::vector<te::color::ColorScheme*> csVec = csg->getColorSchemes();
174 
175  for(std::size_t p = 0; p < csVec.size(); ++p)
176  {
177  te::color::ColorScheme* cs = csVec[p];
178 
179  if(cs->getName() == schema)
180  {
181  std::vector<te::color::RGBAColor>* colors = cs->getColors()[0]; //WARNING... Always getting the first position
182 
183  std::vector<te::color::RGBAColor>::iterator it = colors->begin();
184 
185  // create color bar
186  te::color::ColorBar* cb = new te::color::ColorBar(*(colors->begin()), *(colors->end() - 1), 256);
187 
188  int count = 0;
189 
190  //fill color bar
191  while(it != colors->end())
192  {
193  if(count != 0 && count != colors->size() - 1)
194  {
195  double pos = (1. / (colors->size() - 1)) * count;
196 
197  cb->addColor(*it, pos);
198  }
199 
200  ++count;
201  ++it;
202  }
203 
204  //set color bar
205  m_colorBar->setColorBar(cb);
206  }
207  }
208  }
209  }
210  }
211 }
212 
214 {
215  if(flag) //start catalog
216  loadDefaultColorCatalog();
217  else //create default color bar
218  {
219  te::color::ColorBar* cb = new te::color::ColorBar(te::color::RGBAColor(0, 0, 0, 255), te::color::RGBAColor(255, 0, 0, 255), 256);
220  m_colorBar->setColorBar(cb);
221  }
222 }
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.
const std::string & getName() const
It returns the group name.
It models the concept of color scheme.
Definition: ColorScheme.h:58
void addColor(const RGBAColor &color, const double &pos)
It adds a color in the color bar.
Definition: ColorBar.cpp:264
const std::vector< std::vector< RGBAColor > * > & getColors() const
It returns all color lists.
Definition: ColorScheme.cpp:68
std::auto_ptr< Ui::ColorCatalogWidgetForm > m_ui
static T & getInstance()
It returns a reference to the singleton instance.
Definition: Singleton.h:120
const std::string & getName() const
It returns the catalog name.
It QWidget implementation of color bar.
Definition: ColorBar.h:67
ColorCatalogWidget(QWidget *parent=0, Qt::WindowFlags f=0)
const std::string & getName() const
It returns the color schema name.
Definition: ColorScheme.cpp:42
This class represents a group of color schemes.
The concept of color bar.
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.
Definition: ColorBar.h:49
te::qt::widgets::colorbar::ColorBar * getColorBar()