All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ProgressViewerBar.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/ProgressViewerBar.cpp
22 
23  \brief A class that defines the interface of a qt bar progress viewer.
24 */
25 
26 // Terralib
27 #include "../../../common/Translator.h"
29 #include "ProgressSetValueEvent.h"
30 #include "ProgressResetEvent.h"
31 #include "ProgressViewerBar.h"
32 
33 // Qt
34 #include <QtCore/QCoreApplication>
35 #include <QApplication>
36 
38  : QWidget(parent),
39  AbstractProgressViewer(),
40  m_totalSteps(0),
41  m_currentStep(0),
42  m_propStep(0)
43 {
44  m_progressBar = new QProgressBar(this);
45  m_progressBar->setRange(0, 100);
46  m_progressBar->setTextVisible(false);
47  m_progressBar->setFixedHeight(16);
48 
49  m_button = new QPushButton(this);
50  m_button->setText("...");
51  m_button->setFixedSize(24, 18);
52 
53  m_layout = new QGridLayout(this);
54 
55  m_layout->setContentsMargins(0, 0, 0, 0);
56  m_layout->setHorizontalSpacing(1);
57  m_layout->addWidget(m_progressBar, 0, 0);
58  m_layout->addWidget(m_button, 0, 1);
59 
60  connect(m_button, SIGNAL(released()), this, SLOT(onReleased()));
61 }
62 
64 {
65 }
66 
68 {
69  m_tasks.insert(std::map<int, te::common::TaskProgress*>::value_type(id, t));
70 }
71 
73 {
74  std::map<int, te::common::TaskProgress*>::iterator it = m_tasks.find(taskId);
75 
76  if(it != m_tasks.end())
77  {
78  m_tasks.erase(it);
79  }
80 
81  if(m_tasks.empty())
82  {
83  m_totalSteps = 0;
84  m_currentStep = 0;
85  m_propStep = 0;
86 
87  QCoreApplication::postEvent(this, new ProgressResetEvent);
88  QCoreApplication::processEvents();
89  }
90 }
91 
93 {
94  std::map<int, te::common::TaskProgress*>::iterator it = m_tasks.find(taskId);
95 
96  if(it != m_tasks.end())
97  {
98  // update total and current values
99  m_totalSteps -= it->second->getTotalSteps();
100  m_currentStep -= it->second->getCurrentStep();
101 
102  double aux = static_cast<double>(m_currentStep) / static_cast<double>(m_totalSteps);
103 
104  m_propStep = static_cast<int>(100.0 * aux);
105  }
106 }
107 
109 {
110  m_totalSteps += m_tasks[taskId]->getTotalSteps();
111 }
112 
114 {
115  m_currentStep++;
116 
117  double aux = static_cast<double>(m_currentStep) / static_cast<double>(m_totalSteps);
118 
119  int val = static_cast<int>(100.0 * aux);
120 
121  if(val != m_propStep && val >= 0.0)
122  {
123  m_propStep = val;
124 
125  QCoreApplication::postEvent(this, new ProgressSetValueEvent(m_propStep));
126  QCoreApplication::processEvents();
127  }
128 }
129 
131 {
132 }
133 
135 {
136  m_button->setText(value.c_str());
137 }
138 
140 {
141  if(e->type() == ProgressSetValueEvent::type())
142  {
143  m_progressBar->setValue(static_cast<ProgressSetValueEvent*>(e)->m_value);
144  return;
145  }
146 
147  if(e->type() == ProgressResetEvent::type())
148  m_progressBar->reset();
149 }
150 
152 {
153  emit clicked();
154 }
QPushButton * m_button
GUI Objects used to build the custom widget.
void cancelTask(int taskId)
Cancel a task.
QGridLayout * m_layout
GUI Objects used to build the custom widget.
The ProgressSetValueEvent is a custom event used to set a new value into a progress bar...
virtual void onReleased()
Used to get the button clicked (internal function).
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
A custom event used to set a new message into a progress bar.
The ProgressResetEvent is a custom event used to reset a progress bar.
void addTask(te::common::TaskProgress *t, int id)
Insert a new taks to progress viewer container.
static QEvent::Type type()
Get the custom event type.
~ProgressViewerBar()
Virtual destructor.
void updateMessage(int taskId)
Update the progress message.
void setButtonText(const std::string &value)
static QEvent::Type type()
Get the custom event type.
void setTotalValues(int taskId)
Set task total steps.
The ProgressResetEvent is a custom event used to reset a progress bar.
ProgressViewerBar(QWidget *parent)
Default constructor.
void removeTask(int taskId)
Removes a task from progress viewer container.
A class that defines the interface of a qt bar progress viewer.
virtual void customEvent(QEvent *e)
Used to receive custom progress events.
QProgressBar * m_progressBar
GUI Objects used to build the custom widget.
The ProgressSetValueEvent is a custom event used to set a new value into a progress bar...
void updateValue(int taskId)
Update the progress evaluation.