All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ListWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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/utils/DoubleListWidget.cpp
22 
23  \brief ...
24 */
25 
26 // TerraLib
27 #include "../../../common/Translator.h"
28 #include "ui_ListWidgetForm.h"
29 #include "ListWidget.h"
30 
31 // Qt
32 #include <QIcon>
33 #include <QInputDialog>
34 
35 
36 te::qt::widgets::ListWidget::ListWidget(QWidget* parent, Qt::WindowFlags f)
37  : QWidget(parent, f),
38  m_ui(new Ui::ListWidgetForm)
39 {
40  m_ui->setupUi(this);
41 
42 // set icons
43  m_ui->m_addToolButton->setIcon(QIcon::fromTheme(""));
44  m_ui->m_removeToolButton->setIcon(QIcon::fromTheme(""));
45  m_ui->m_editToolButton->setIcon(QIcon::fromTheme(""));
46  m_ui->m_upToolButton->setIcon(QIcon::fromTheme(""));
47  m_ui->m_downToolButton->setIcon(QIcon::fromTheme(""));
48 
49 // set selection mode
50  m_ui->m_listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
51 
52 // connect signals and slots
53  connect(m_ui->m_addToolButton, SIGNAL(pressed()), this, SLOT(onAddToolButtonPressed()));
54  connect(m_ui->m_removeToolButton, SIGNAL(pressed()), this, SLOT(onRemoveToolButtonPressed()));
55  connect(m_ui->m_editToolButton, SIGNAL(pressed()), this, SLOT(onEditToolButtonPressed()));
56  connect(m_ui->m_upToolButton, SIGNAL(pressed()), this, SLOT(onUpToolButtonPressed()));
57  connect(m_ui->m_downToolButton, SIGNAL(pressed()), this, SLOT(onDownToolButtonPressed()));
58  connect(m_ui->m_listWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(onListPressed(QListWidgetItem*)));
59 
60 }
61 
63 {
64 }
65 
66 Ui::ListWidgetForm* te::qt::widgets::ListWidget::getForm() const
67 {
68  return m_ui.get();
69 }
70 
72 {
73  m_ui->m_label->setText(value.c_str());
74 }
75 
76 std::vector<std::string> te::qt::widgets::ListWidget::getValues()
77 {
78  std::vector<std::string> vec;
79 
80  int count = m_ui->m_listWidget->count();
81 
82  for(int i = 0; i < count; ++i)
83  {
84  vec.push_back(m_ui->m_listWidget->item(i)->text().toLatin1().data());
85  }
86 
87  return vec;
88 }
89 
91 {
92  bool ok;
93 
94  QString text = QInputDialog::getText(this, TE_TR("Add Value"), TE_TR("Value:"), QLineEdit::Normal, "", &ok);
95 
96  if(ok && !text.isEmpty())
97  {
98  m_ui->m_listWidget->addItem(text);
99  }
100 }
101 
103 {
104  if(m_ui->m_listWidget->currentItem())
105  {
106  int row = m_ui->m_listWidget->row(m_ui->m_listWidget->currentItem());
107 
108  QListWidgetItem* item = m_ui->m_listWidget->takeItem(row);
109 
110  delete item;
111  }
112 }
113 
115 {
116  if(m_ui->m_listWidget->currentItem())
117  {
118  bool ok;
119 
120  QString text = QInputDialog::getText(this, TE_TR("Add Value"), TE_TR("Value:"), QLineEdit::Normal, m_ui->m_listWidget->currentItem()->text(), &ok);
121 
122  if(ok && !text.isEmpty())
123  {
124  m_ui->m_listWidget->currentItem()->setText(text);
125  }
126  }
127 }
128 
130 {
131  if(m_ui->m_listWidget->currentItem())
132  {
133  int row = m_ui->m_listWidget->row(m_ui->m_listWidget->currentItem());
134 
135  if(row != 0)
136  {
137  QListWidgetItem* item = m_ui->m_listWidget->takeItem(row);
138 
139  m_ui->m_listWidget->insertItem(row - 1, item);
140 
141  m_ui->m_listWidget->setCurrentItem(item);
142  }
143  }
144 }
145 
147 {
148  if(m_ui->m_listWidget->currentItem())
149  {
150  int row = m_ui->m_listWidget->row(m_ui->m_listWidget->currentItem());
151 
152  int count = m_ui->m_listWidget->count();
153 
154  if(row != count - 1)
155  {
156  QListWidgetItem* item = m_ui->m_listWidget->takeItem(row);
157 
158  m_ui->m_listWidget->insertItem(row + 1, item);
159 
160  m_ui->m_listWidget->setCurrentItem(item);
161  }
162  }
163 }
165 {
166 }
ListWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: ListWidget.cpp:36
Ui::ListWidgetForm * getForm() const
Definition: ListWidget.cpp:66
void setLabel(std::string value)
Definition: ListWidget.cpp:71
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:345
std::auto_ptr< Ui::ListWidgetForm > m_ui
Definition: ListWidget.h:85
std::vector< std::string > getValues()
Definition: ListWidget.cpp:76
void onListPressed(QListWidgetItem *item)
Definition: ListWidget.cpp:164