Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYProgressManager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #if TY_USE_IHM
17 
18  #include <iostream>
19 
20  #include <qapplication.h>
21  #include <qcursor.h>
22 
23  #include "OLocalizator.h"
24  #include "TYProgressManager.h"
25 
26  #define TR(id) OLocalizator::getString("TYProgressManager", (id))
27 
28 // Initialisation.
29 TYProgressDialog* TYProgressManager::_pProgressDialog = NULL;
30 int TYProgressManager::_stepSize = 1;
31 
32 /*static*/ void TYProgressManager::create(QWidget* pParent, const char* name /*=0*/)
33 {
34  QString strBtnCancel = TR("id_cancel_btn");
35  if (strBtnCancel.length() == 0)
36  {
37  strBtnCancel = "Cancel";
38  }
39  _pProgressDialog = new TYProgressDialog(name, strBtnCancel, 100, pParent, name, true);
40  _pProgressDialog->setAutoClose(true);
41  _pProgressDialog->setAutoReset(true);
42  _pProgressDialog->setMinimumDuration(0);
43  // "Decoration"
44  _pProgressDialog->setCursor(Qt::ArrowCursor);
45  QString strCaption = TR("id_caption");
46  if (strCaption.length() == 0)
47  {
48  strCaption = name;
49  }
50  _pProgressDialog->setWindowTitle(strCaption);
51  _pProgressDialog->setValue(_pProgressDialog->maximum());
52 }
53 
54 /*static*/ void TYProgressManager::set(int totalSteps, int stepSize /*=1*/)
55 {
56  if (!_pProgressDialog)
57  {
58  return;
59  }
60 
61  _pProgressDialog->reset();
62 
63  if (totalSteps <= 0)
64  {
65  return;
66  }
67  if (stepSize <= 0)
68  {
69  return;
70  }
71 
72  _stepSize = stepSize;
73  _pProgressDialog->setMaximum(totalSteps);
74  _pProgressDialog->show();
75 }
76 
77 /*static*/ void TYProgressManager::step()
78 {
79  bool dummy = false;
80  step(dummy);
81 }
82 
83 /*static*/ void TYProgressManager::step(bool& wasCancelled)
84 {
85  if (!_pProgressDialog)
86  {
87  return;
88  }
89 
90  // Si le bouton "Cancel" a ete enfonce
91  wasCancelled = _pProgressDialog->wasCanceled();
92 
93  // On progresse de la taille du pas
94  _pProgressDialog->setValue(_pProgressDialog->value() + _stepSize);
95 
96  // On donne la main a l'application si necessaire (redraw...)
97  qApp->processEvents();
98 }
99 /*static*/ int TYProgressManager::getProgress()
100 {
101  if (!_pProgressDialog)
102  {
103  return 0;
104  }
105 
106  // on retourne la valeur de progression
107  return _pProgressDialog->value();
108 }
109 
110 /*static*/ void TYProgressManager::setProgress(int progress)
111 {
112  if (!_pProgressDialog)
113  {
114  return;
115  }
116 
117  // on positionne la progression a la valeur donnee
118  _pProgressDialog->setValue(progress);
119 
120  // On donne la main a l'application si necessaire (redraw...)
121  qApp->processEvents();
122 }
123 
124 /*static*/ void TYProgressManager::stepToEnd()
125 {
126  if (!_pProgressDialog)
127  {
128  return;
129  }
130 
131  // On progresse jusqu'a la fin
132  _pProgressDialog->setValue(_pProgressDialog->maximum());
133 
134  // On donne la main a l'application si necessaire (redraw...)
135  qApp->processEvents();
136 }
137 
138 /* static */ void TYProgressManager::setWindowTitle(const char* caption)
139 {
140  if (!_pProgressDialog)
141  {
142  return;
143  }
144 
145  // On progresse jusqu'a la fin
146  _pProgressDialog->setWindowTitle(caption);
147 
148  // On donne la main a l'application si necessaire (redraw...)
149  qApp->processEvents();
150 }
151 /* static */ void TYProgressManager::setMessage(const char* message)
152 {
153  if (!_pProgressDialog)
154  {
155  return;
156  }
157 
158  // On progresse jusqu'a la fin
159  _pProgressDialog->setLabelText(message);
160 
161  // On donne la main a l'application si necessaire (redraw...)
162  qApp->processEvents();
163 }
164 
165 #endif // TY_USE_IHM
#define TR(id)
const char * name
static void set(int totalSteps, int stepSize=1)
static void create(QWidget *pParent, const char *name=0)
static void stepToEnd()