All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ProgressWidgetItem.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/ProgressWidgetItem.cpp
22 
23  \brief Custom widget used to represent a single task.
24 */
25 
26 // TerraLib
27 #include "ProgressResetEvent.h"
29 #include "ProgressSetValueEvent.h"
30 #include "ProgressWidgetItem.h"
31 
32 // Qt
33 #include <QtCore/QCoreApplication>
34 #include <QSizePolicy>
35 #include <QStyle>
36 
37 te::qt::widgets::ProgressWidgetItem::ProgressWidgetItem(QWidget* parent, int taskId, int totalSteps)
38  : QWidget(parent),
39  m_taskId(taskId)
40 {
41  // build custom widget
42  m_mainGridLayout = new QGridLayout(this);
43  m_mainGridLayout->setContentsMargins(1, 1, 1, 1);
44  m_mainGridLayout->setHorizontalSpacing(2);
45 
46  m_frame = new QFrame(this);
47  m_frame->setFrameShape(QFrame::StyledPanel);
48  m_frame->setFrameShadow(QFrame::Sunken);
49 
50  m_mainGridLayout->addWidget(m_frame);
51 
52  m_frameGridLayout = new QGridLayout(m_frame);
53  m_frameGridLayout->setContentsMargins(1, 1, 1, 1);
54  m_frameGridLayout->setVerticalSpacing(1);
55 
56  m_label = new QLabel(m_frame);
57  m_label->setText("");
58 
59  m_progressBar = new QProgressBar(m_frame);
60 
61  m_button = new QCommandLinkButton(m_frame);
62  m_button->setIcon(m_button->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
63  m_button->setFixedHeight(23);
64  m_button->setFixedWidth(23);
65 
66  m_frameGridLayout->addWidget(m_label, 0, 0, 1, 2);
67  m_frameGridLayout->addWidget(m_progressBar, 1, 1);
68  m_frameGridLayout->addWidget(m_button, 1, 0);
69 
70  // set default range
71  totalSteps == 0 ? m_progressBar->setRange(0, 0) : m_progressBar->setRange(0, 100);
72 
73  // connect signal cancel
74  connect(m_button, SIGNAL(released()), this, SLOT(cancel()));
75 
76  this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
77 }
78 
80 {
81 }
82 
84 {
85  QCoreApplication::postEvent(this, new te::qt::widgets::ProgressSetValueEvent(step));
86 
87  QCoreApplication::processEvents();
88 }
89 
90 void te::qt::widgets::ProgressWidgetItem::setLabel(const std::string& message)
91 {
92  QCoreApplication::postEvent(this, new ProgressSetMessageEvent(message));
93 }
94 
96 {
97  QCoreApplication::postEvent(this, new ProgressResetEvent);
98 
99  QCoreApplication::processEvents();
100 }
101 
103 {
104  emit taskCanceled(m_taskId);
105 }
106 
108 {
110  {
111  if(m_progressBar->minimum() == 0 && m_progressBar->maximum() == 0)
112  return;
113 
114  m_progressBar->setValue(static_cast<te::qt::widgets::ProgressSetValueEvent*>(e)->m_value);
115 
116  return;
117  }
118 
119  if(e->type() == ProgressSetMessageEvent::type())
120  {
121  m_label->setText(static_cast<ProgressSetMessageEvent*>(e)->m_value.c_str());
122  return;
123  }
124 
125  if(e->type() == ProgressResetEvent::type())
126  m_progressBar->reset();
127 }
virtual void customEvent(QEvent *e)
Used to receive custom progress events.
QProgressBar * m_progressBar
GUI Objects used to build the custom widget.
QGridLayout * m_frameGridLayout
GUI Objects used to build the custom widget.
QCommandLinkButton * m_button
GUI Objects used to build the custom widget.
The ProgressSetValueEvent is a custom event used to set a new value into a progress bar...
QFrame * m_frame
GUI Objects used to build the custom widget.
A custom event used to set a new message into a progress bar.
virtual void setValue(int step)
Set the current value in progress bar.
The ProgressResetEvent is a custom event used to reset a progress bar.
QLabel * m_label
GUI Objects used to build the custom widget.
static QEvent::Type type()
Get the custom event type.
QGridLayout * m_mainGridLayout
GUI Objects used to build the custom widget.
virtual void reset()
Reset the progress bar.
ProgressWidgetItem(QWidget *parent, int taskId, int totalSteps)
Default constructor.
static QEvent::Type type()
Get the custom event type.
virtual void setLabel(const std::string &message)
Set the progress label information.
The ProgressResetEvent is a custom event used to reset a progress bar.
virtual void cancel()
Get the button clicked and cancel ALL tasks.
The ProgressSetMessageEvent is a custom event used to set a new message into a progress bar...
The ProgressSetValueEvent is a custom event used to set a new value into a progress bar...
Custom widget used to represent a single task.
static QEvent::Type type()
Get the custom event type.