ListWidget.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/utils/DoubleListWidget.cpp
22 
23  \brief ...
24 */
25 
26 // TerraLib
27 #include "../../../core/translator/Translator.h"
28 #include "ui_ListWidgetForm.h"
29 #include "ListWidget.h"
30 
31 // Qt
32 #include <QIcon>
33 #include <QInputDialog>
34 
35 
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 Ui::ListWidgetForm* te::qt::widgets::ListWidget::getForm() const
65 {
66  return m_ui.get();
67 }
68 
70 {
71  m_ui->m_label->setText(value.c_str());
72 }
73 
74 std::vector<std::string> te::qt::widgets::ListWidget::getValues()
75 {
76  std::vector<std::string> vec;
77 
78  int count = m_ui->m_listWidget->count();
79 
80  for(int i = 0; i < count; ++i)
81  {
82  vec.push_back(m_ui->m_listWidget->item(i)->text().toUtf8().data());
83  }
84 
85  return vec;
86 }
87 
89 {
90  bool ok;
91 
92  QString text = QInputDialog::getText(this, TE_TR("Add Value"), TE_TR("Value:"), QLineEdit::Normal, "", &ok);
93 
94  if(ok && !text.isEmpty())
95  {
96  m_ui->m_listWidget->addItem(text);
97  }
98 }
99 
101 {
102  if(m_ui->m_listWidget->currentItem())
103  {
104  int row = m_ui->m_listWidget->row(m_ui->m_listWidget->currentItem());
105 
106  QListWidgetItem* item = m_ui->m_listWidget->takeItem(row);
107 
108  delete item;
109  }
110 }
111 
113 {
114  if(m_ui->m_listWidget->currentItem())
115  {
116  bool ok;
117 
118  QString text = QInputDialog::getText(this, TE_TR("Add Value"), TE_TR("Value:"), QLineEdit::Normal, m_ui->m_listWidget->currentItem()->text(), &ok);
119 
120  if(ok && !text.isEmpty())
121  {
122  m_ui->m_listWidget->currentItem()->setText(text);
123  }
124  }
125 }
126 
128 {
129  if(m_ui->m_listWidget->currentItem())
130  {
131  int row = m_ui->m_listWidget->row(m_ui->m_listWidget->currentItem());
132 
133  if(row != 0)
134  {
135  QListWidgetItem* item = m_ui->m_listWidget->takeItem(row);
136 
137  m_ui->m_listWidget->insertItem(row - 1, item);
138 
139  m_ui->m_listWidget->setCurrentItem(item);
140  }
141  }
142 }
143 
145 {
146  if(m_ui->m_listWidget->currentItem())
147  {
148  int row = m_ui->m_listWidget->row(m_ui->m_listWidget->currentItem());
149 
150  int count = m_ui->m_listWidget->count();
151 
152  if(row != count - 1)
153  {
154  QListWidgetItem* item = m_ui->m_listWidget->takeItem(row);
155 
156  m_ui->m_listWidget->insertItem(row + 1, item);
157 
158  m_ui->m_listWidget->setCurrentItem(item);
159  }
160  }
161 }
162 void te::qt::widgets::ListWidget::onListPressed(QListWidgetItem* /*item*/)
163 {
164 }
ListWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: ListWidget.cpp:36
Ui::ListWidgetForm * getForm() const
Definition: ListWidget.cpp:64
void setLabel(std::string value)
Definition: ListWidget.cpp:69
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::unique_ptr< Ui::ListWidgetForm > m_ui
Definition: ListWidget.h:85
std::vector< std::string > getValues()
Definition: ListWidget.cpp:74
void onListPressed(QListWidgetItem *item)
Definition: ListWidget.cpp:162