DummyWindow.cpp
Go to the documentation of this file.
1 #include "DummyWindow.h"
2 
3 // Terralib
4 #include "../../src/terralib/Defines.h"
7 
8 // Qt
9 #include <QSpacerItem>
10 
11 // System
12 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
13  #include <windows.h>
14 #endif
15 
16 // OpenMP
17 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
18  #include <omp.h>
19 #endif
20 
21 #define TOTAL_STEPS 3000
22 #define PART_1 1000
23 #define PART_2 2000
24 
25 #define TOTAL_STEPS_INTERNAL 500
26 
27 #include <iostream>
28 
30 {
31  this->setWindowTitle("Qt Progress Bar Test");
32 
33  m_mainLayout = new QGridLayout(this);
34  m_progressPushButton = new QPushButton("Progress Bar...", this);
35  m_progressThreadPushButton = new QPushButton("Progress Bar (Thread)...", this);
36  m_statusBar = new QStatusBar(this);
37  m_statusBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
38 
39  QSpacerItem* spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
40 
42 
44 
45  m_statusBar->addPermanentWidget(m_barViewer);
46 
47  m_mainLayout->addWidget(m_progressPushButton, 0, 0);
48  m_mainLayout->addWidget(m_progressThreadPushButton, 1, 0);
49  m_mainLayout->addItem(spacer, 2, 0);
50  m_mainLayout->addWidget(m_statusBar, 3, 0);
51 
52  connect(m_progressPushButton, SIGNAL(clicked()), this, SLOT(showProgressBar()));
53  connect(m_progressThreadPushButton, SIGNAL(clicked()), this, SLOT(showThreadProgressBar()));
54  connect(m_barViewer, SIGNAL(clicked()), this, SLOT(showWidgetViewer()));
55 
56  m_widgetViewer = 0;
57 
58 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
59  omp_set_num_threads(omp_get_num_procs());
60 #endif
61 }
62 
64 {
65  delete m_dlgViewer;
66 
67  delete m_widgetViewer;
68 
69  delete m_barViewer;
70 }
71 
73 {
76  task.setMessage("Qt Progress Test");
77  task.useTimer(true);
78 
79  for(unsigned int i = 0; i < TOTAL_STEPS; ++i)
80  {
81  if(!task.isActive())
82  {
83  break;
84  }
85 
86  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
87  Sleep(5);
88  #endif
89 
90  task.pulse();
91  }
92 }
93 
95 {
96  te::common::TaskProgress task("Qt Progress Test", 0, TOTAL_STEPS);
97  task.useTimer(true);
98 
99 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
100 #pragma omp parallel for
101 #endif
102  for (int i = 0; i < TOTAL_STEPS; ++i)
103  {
104  if (task.isActive())
105  {
106 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
107  Sleep(5);
108  std::cout << "Thread: " << omp_get_thread_num() << " i: " << i << " total: " << TOTAL_STEPS << std::endl;
109 #endif
110 
111  task.pulse();
112  }
113 
114  if (i == PART_1 || i == PART_2)
115  {
116  te::common::TaskProgress taskInternal("Qt Progress Internal Task", 0, TOTAL_STEPS_INTERNAL);
117 
118  for (int j = 0; j < TOTAL_STEPS_INTERNAL; ++j)
119  {
120  if (taskInternal.isActive())
121  {
122 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
123  Sleep(5);
124  std::cout << "Thread: " << omp_get_thread_num() << " j: " << j << " total: " << TOTAL_STEPS_INTERNAL << std::endl;
125 #endif
126 
127  taskInternal.pulse();
128  }
129  }
130  }
131  }
132  return;
133 }
134 
136 {
137  if(m_widgetViewer == 0)
138  {
140  }
141 
142  if(m_widgetViewer->isVisible())
143  {
144  m_widgetViewer->hide();
145  }
146  else
147  {
148  m_widgetViewer->show();
149  }
150 }
te::qt::widgets::ProgressViewerDialog * m_dlgViewer
Definition: DummyWindow.h:37
void setMessage(const std::string &message)
Set the task message.
This class can be used to inform the progress of a task.
A class that defines the interface of a qt widget to group a set of ProgressWidgetItem.
A singleton class used to manage tasks progresses and their viewers.
void useTimer(bool flag)
Used to define if task use progress timer information.
QPushButton * m_progressThreadPushButton
Definition: DummyWindow.h:34
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
QPushButton * m_progressPushButton
Definition: DummyWindow.h:33
#define PART_2
Definition: DummyWindow.cpp:23
void showWidgetViewer()
void showProgressBar()
Definition: DummyWindow.cpp:72
QGridLayout * m_mainLayout
Definition: DummyWindow.h:32
bool isActive() const
Verify if the task is active.
DummyWindow(QWidget *parent=0)
Definition: DummyWindow.cpp:29
void setTotalSteps(int value)
Set the task total stepes.
#define TOTAL_STEPS
Definition: DummyWindow.cpp:21
A class that defines the interface of a qt bar progress viewer.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
te::qt::widgets::ProgressViewerWidget * m_widgetViewer
Definition: DummyWindow.h:38
void showThreadProgressBar()
Definition: DummyWindow.cpp:94
QStatusBar * m_statusBar
Definition: DummyWindow.h:35
#define TOTAL_STEPS_INTERNAL
Definition: DummyWindow.cpp:25
#define PART_1
Definition: DummyWindow.cpp:22
te::qt::widgets::ProgressViewerBar * m_barViewer
Definition: DummyWindow.h:39