ProgressViewerWidget.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/progress/ProgressViewerWidget.cpp
22 
23  \brief A class that defines the interface of a qt widget to group a set of ProgressWidgetItem.
24 */
25 
26 // Terralib
28 #include "ProgressViewerWidget.h"
29 #include "ProgressWidgetItem.h"
31 
32 // Qt
33 #include <QtCore/QCoreApplication>
34 #include <QApplication>
35 #include <QCloseEvent>
36 #include <QScrollBar>
37 
39  : QDialog(parent, Qt::Tool),
40  AbstractProgressViewer()
41 {
42  //create custom widget
43  m_MainLayout = new QGridLayout(this);
44  m_MainLayout->setContentsMargins(1, 1, 1, 1);
45 
46  m_scroll = new QScrollArea(this);
47  m_scroll->setBackgroundRole(QPalette::Light);
48  m_MainLayout->addWidget(m_scroll);
49  m_scroll->setWidgetResizable(true);
50 
51  m_widget = new QWidget(m_scroll);
52  m_scroll->setWidget(m_widget);
53 
54  m_widgetLayout = new QGridLayout(m_widget);
55  m_widgetLayout->setContentsMargins(1, 1, 1, 1);
56  m_widgetLayout->setVerticalSpacing(1);
57  m_widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
58 }
59 
61 {
62 }
63 
65 {
66  m_tasks.insert(std::map<int, te::common::TaskProgress*>::value_type(id, t));
67 
68  QCoreApplication::postEvent(this, new CreateProgressWidgetItemEvent(t->getMessage().c_str(), id, t->getTotalSteps()));
69  QCoreApplication::processEvents();
70 }
71 
73 {
74  std::map<int, te::common::TaskProgress*>::iterator it = m_tasks.find(taskId);
75 
76  if(it != m_tasks.end())
77  m_tasks.erase(it);
78 
79  QCoreApplication::postEvent(this, new RemoveProgressWidgetItemEvent(taskId));
80 
81  QCoreApplication::processEvents();
82 }
83 
85 {
86  removeTask(taskId);
87 }
88 
90 {
91 }
92 
94 {
95  std::map<int, te::common::TaskProgress*>::iterator it = m_tasks.find(taskId);
96 
97  if(it != m_tasks.end())
98  {
99  std::map<int, te::qt::widgets::ProgressWidgetItem*>::iterator itItem = m_items.find(taskId);
100 
101  if(itItem != m_items.end())
102  {
103  itItem->second->setValue(it->second->getProportionalValue());
104  }
105  }
106 }
107 
109 {
110  std::map<int, te::common::TaskProgress*>::iterator it = m_tasks.find(taskId);
111 
112  if(it != m_tasks.end())
113  {
114  std::map<int, te::qt::widgets::ProgressWidgetItem*>::iterator itItem = m_items.find(taskId);
115 
116  if(itItem != m_items.end())
117  {
118  itItem->second->setLabel(it->second->getMessage());
119  }
120  }
121 }
122 
124 {
125  if(e->type() == CreateProgressWidgetItemEvent::type())
126  {
127  CreateProgressWidgetItemEvent* createEvent = static_cast<CreateProgressWidgetItemEvent*>(e);
128 
129  ProgressWidgetItem* item = new ProgressWidgetItem(m_widget, createEvent->m_taskId, createEvent->m_totalSteps);
130 
131  item->setLabel(createEvent->m_label.toStdString());
132 
133  m_items.insert(std::map<int, ProgressWidgetItem*>::value_type(createEvent->m_taskId, item));
134 
135  connect(item, SIGNAL(taskCanceled(int)), this, SLOT(cancel(int)));
136 
137  m_widgetLayout->addWidget(item);
138 
139  item->show();
140 
141  return;
142  }
143 
144  if(e->type() == RemoveProgressWidgetItemEvent::type())
145  {
146  RemoveProgressWidgetItemEvent* removeEvent = static_cast<RemoveProgressWidgetItemEvent*>(e);
147 
148  std::map<int, te::qt::widgets::ProgressWidgetItem*>::iterator itItem = m_items.find(removeEvent->m_taskId);
149  if(itItem == m_items.end())
150  return;
151 
152  delete itItem->second;
153  m_items.erase(itItem);
154  }
155 }
156 
158 {
159  std::map<int, te::common::TaskProgress*>::iterator itTask = m_tasks.find(id);
160 
161  if(itTask != m_tasks.end())
162  {
163  itTask->second->cancel();
164  }
165 }
166 
virtual void cancelTask(int taskId)
Cancel a task.
virtual void updateMessage(int taskId)
Update the progress message.
The CreateProgressWidgetItemEvent is a custom event used to create a progress widget item...
The RemoveProgressWidgetItemEvent is a custom event used to remove a progress widget item...
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
virtual void removeTask(int taskId)
Removes a task from progress viewer container.
const std::string & getMessage() const
Get the task message.
virtual void updateValue(int taskId)
Update the progress evaluation.
A class that defines the interface of a qt widget to group a set of ProgressWidgetItem.
Custom widget used to represent a single task.
The CreateProgressWidgetItemEvent is a custom event used to create a progress widget item...
static QEvent::Type type()
Get the custom event type.
ProgressViewerWidget(QWidget *parent)
Default constructor.
int m_totalSteps
The total steps of progress widget that will be created.
int m_taskId
The task id associated with the progress widget that will be removed.
static QEvent::Type type()
Get the custom event type.
virtual void addTask(te::common::TaskProgress *t, int id)
Insert a new taks to progress viewer container.
The RemoveProgressWidgetItem is a custom event used to remove a progress widget item.
void cancel(int id)
This slot is connect to all cancel buttons of each progress items.
virtual void setLabel(const std::string &message)
Set the progress label information.
QGridLayout * m_widgetLayout
GUI Objects used to build the custom widget.
QGridLayout * m_MainLayout
GUI Objects used to build the custom widget.
int m_taskId
The task id associated with the progress widget that will be created.
QWidget * m_widget
GUI Objects used to build the custom widget.
QScrollArea * m_scroll
GUI Objects used to build the custom widget.
void customEvent(QEvent *e)
Used to receive custom progress events.
virtual void setTotalValues(int taskId)
Set task total steps.
virtual ~ProgressViewerWidget()
Virtual destructor.
int getTotalSteps() const
Get the task total stepes.
Custom widget used to represent a single task.