All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TL4ThemeSelectionWizardPage.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/plugins/terralib4/TL4ThemeSelectionWizardPage.cpp
22 
23  \brief A wizard page for selecting converted datasets to layers in TerraLib 5.
24 */
25 
26 // TerraLib
27 #include "../../../../common/StringUtils.h"
28 #include "../../../../terralib4/ThemeInfo.h"
29 #include "ui_TL4ThemeSelectionWizardPageForm.h"
31 
33 
34 
35 
37  : QWizardPage(parent),
38  m_ui(new Ui::TL4ThemeSelectionWizardPageForm)
39 {
40 // setup controls
41  m_ui->setupUi(this);
42 
43  connect(m_ui->m_selectAllPushButton, SIGNAL(clicked()), this, SLOT(onSelectAllPushButtonClicked()));
44  connect(m_ui->m_deselectAllPushButton, SIGNAL(clicked()), this, SLOT(onDeselectAllPushButtonClicked()));
45 }
46 
48 {
49 }
50 
52 {
53  for(int i = 0; i < m_ui->m_themeListWidget->count(); ++i)
54  {
55  Qt::CheckState state = m_ui->m_themeListWidget->item(i)->checkState();
56 
57  if(state != Qt::Checked)
58  m_ui->m_themeListWidget->item(i)->setCheckState(Qt::Checked);
59  }
60 }
61 
63 {
64  for(int i = 0; i < m_ui->m_themeListWidget->count(); ++i)
65  {
66  Qt::CheckState state = m_ui->m_themeListWidget->item(i)->checkState();
67 
68  if(state == Qt::Checked)
69  m_ui->m_themeListWidget->item(i)->setCheckState(Qt::Unchecked);
70  }
71 }
72 
73 void te::qt::plugins::terralib4::TL4ThemeSelectionWizardPage::setThemes(const std::vector<::terralib4::ThemeInfo>& themes)
74 {
75  for(std::size_t i = 0; i < themes.size(); ++i)
76  {
77  ::terralib4::ThemeInfo theme = themes[i];
78 
79  std::string names = "Layer: " + theme.m_layerName + " | View: " + theme.m_viewName + " | Theme: " + theme.m_name;
80 
81  QListWidgetItem* item = new QListWidgetItem(QIcon::fromTheme("tl4-theme"), QString::fromLatin1(names.c_str()), m_ui->m_themeListWidget, 1);
82 
83  item->setData(Qt::UserRole, QVariant::fromValue(theme));
84 
85  item->setCheckState(Qt::Checked);
86 
87  m_ui->m_themeListWidget->addItem(item);
88  }
89 }
90 
92 {
93  std::vector<::terralib4::ThemeInfo> themes;
94 
95  for(int i = 0; i < m_ui->m_themeListWidget->count(); ++i)
96  {
97  QListWidgetItem* item = m_ui->m_themeListWidget->item(i);
98 
99  if(item->type() != 1 || item->checkState() != Qt::Checked)
100  continue;
101 
102  std::string aux = m_ui->m_themeListWidget->item(i)->text().toLatin1();
103 
104  std::vector<std::string> names = getNames(aux);
105 
107  theme.m_layerName = names[0];
108  theme.m_viewName = names[1];
109  theme.m_name = names[2];
110 
111  themes.push_back(theme);
112  }
113 
114  return themes;
115 }
116 
117 std::vector<std::string> te::qt::plugins::terralib4::TL4ThemeSelectionWizardPage::getNames(const std::string& names)
118 {
119  std::vector<std::string> final;
120 
121  std::vector<std::string> tokens;
122  te::common::Tokenize(names, tokens, " | ");
123 
124  final.push_back(tokens[1]);
125  final.push_back(tokens[3]);
126  final.push_back(tokens[5]);
127 
128  return final;
129 }
std::string m_layerName
Definition: ThemeInfo.h:41
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Definition: StringUtils.h:216
Q_DECLARE_METATYPE(::terralib4::ThemeInfo)
std::string m_name
Definition: ThemeInfo.h:39
std::vector< std::string > getNames(const std::string &names)
void setThemes(const std::vector<::terralib4::ThemeInfo > &themes)
std::string m_viewName
Definition: ThemeInfo.h:40
std::auto_ptr< Ui::TL4ThemeSelectionWizardPageForm > m_ui