COPASI API  4.16.103
Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
CProgressBar Class Reference

#include <CProgressBar.h>

Inheritance diagram for CProgressBar:
Inheritance graph
[legend]
Collaboration diagram for CProgressBar:
Collaboration graph
[legend]

Signals

void signalAddItem (const int handle)
 
void signalFinishItem (const int handle)
 
void signalProgressAll ()
 
void signalSetName (QString name)
 

Public Member Functions

virtual bool finish ()
 
virtual bool finishItem (const size_t &handle)
 
virtual bool proceed ()
 
virtual bool progressItem (const size_t &handle)
 
virtual bool resetItem (const size_t &handle)
 
virtual bool setName (const std::string &name)
 
virtual ~CProgressBar ()
 
- Public Member Functions inherited from CQProgressDialog
 CQProgressDialog (QWidget *parent=0, const char *name=0, Qt::WindowModality windowModality=Qt::WindowModal, Qt::WindowFlags fl=0)
 
bool insertProgressItem (CQProgressItem *pItem)
 
bool removeProgressItem (CQProgressItem *pItem)
 
 ~CQProgressDialog ()
 
- Public Member Functions inherited from CProcessReport
size_t addItem (const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
 
size_t addItem (const std::string &name, const C_INT32 &value, const C_INT32 *pEndValue=NULL)
 
size_t addItem (const std::string &name, const unsigned C_INT32 &value, const unsigned C_INT32 *pEndValue=NULL)
 
size_t addItem (const std::string &name, const C_FLOAT64 &value, const C_FLOAT64 *pEndValue=NULL)
 
 CProcessReport (const unsigned int &maxTime=0)
 
virtual bool isValidHandle (const size_t handle) const
 
virtual bool progress ()
 
virtual bool reset ()
 
virtual ~CProcessReport ()
 

Static Public Member Functions

static CProgressBarcreate (QWidget *parent=0, const char *name=0, Qt::WindowModality windowModality=Qt::WindowModal)
 

Protected Slots

virtual void btnContinuePressed ()
 
virtual void btnStopPressed ()
 
virtual void slotAddItem (const int handle)
 
virtual void slotFinishItem (const int handle)
 
virtual void slotProgressAll ()
 
virtual void slotSetName (QString name)
 
- Protected Slots inherited from CQProgressDialog
virtual void accept ()
 
virtual void btnContinuePressed ()
 
virtual void btnPausePressed ()
 
virtual void btnStopPressed ()
 
virtual void done (int)
 
virtual void reject ()
 
void timerShow ()
 

Protected Member Functions

virtual size_t addItem (const std::string &name, const CCopasiParameter::Type &type, const void *pValue, const void *pEndValue=NULL)
 
virtual void closeEvent (QCloseEvent *e)
 

Protected Attributes

size_t mLastHItem
 
QMutex mMutex
 
bool mSlotFinished
 
QWaitCondition mWaitPause
 
QWaitCondition mWaitSlot
 
- Protected Attributes inherited from CQProgressDialog
bool mPause
 
bool mProceed
 
- Protected Attributes inherited from CProcessReport
std::string mName
 
CCopasiTimeVariablempEndTime
 
CVector< CProcessReportItem * > mProcessReportItemList
 

Private Member Functions

 CProgressBar (QWidget *parent, const char *name, Qt::WindowModality windowModality)
 

Private Attributes

QDateTime mNextEventProcessing
 
QWidget * mpMainWidget
 
CVector< CQProgressItem * > mProgressItemList
 

Detailed Description

This is used to call the progress bar code We do not want to call GUI stuff directly from the CModel.

Definition at line 41 of file CProgressBar.h.

Constructor & Destructor Documentation

CProgressBar::CProgressBar ( QWidget *  parent,
const char *  name,
Qt::WindowModality  windowModality 
)
private

Definition at line 56 of file CProgressBar.cpp.

References CopasiUI3Window::disableSliders(), CopasiUI3Window::getMainWindow(), mProgressItemList, signalAddItem(), signalFinishItem(), signalProgressAll(), signalSetName(), slotAddItem(), slotFinishItem(), slotProgressAll(), and slotSetName().

Referenced by create().

56  :
57  CQProgressDialog(parent, name, windowModality, Qt::WindowMinimizeButtonHint),
60  mNextEventProcessing(QDateTime::currentDateTime()),
61  mpMainWidget(NULL)
62 {
64 
65  mProgressItemList[0] = NULL;
66 
67  connect(this, SIGNAL(signalAddItem(const int)),
68  this, SLOT(slotAddItem(const int)));
69 
70  connect(this, SIGNAL(signalSetName(QString)),
71  this, SLOT(slotSetName(QString)));
72 
73  connect(this, SIGNAL(signalProgressAll()),
74  this, SLOT(slotProgressAll()));
75 
76  connect(this, SIGNAL(signalFinishItem(const int)),
77  this, SLOT(slotFinishItem(const int)));
78 }
virtual void slotAddItem(const int handle)
CProcessReport(const unsigned int &maxTime=0)
virtual void slotSetName(QString name)
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
void disableSliders(bool disable)
void signalFinishItem(const int handle)
QDateTime mNextEventProcessing
Definition: CProgressBar.h:137
static CopasiUI3Window * getMainWindow()
void signalSetName(QString name)
virtual void slotFinishItem(const int handle)
CQProgressDialog(QWidget *parent=0, const char *name=0, Qt::WindowModality windowModality=Qt::WindowModal, Qt::WindowFlags fl=0)
void signalAddItem(const int handle)
void signalProgressAll()
virtual void slotProgressAll()
QWidget * mpMainWidget
Definition: CProgressBar.h:139
CProgressBar::~CProgressBar ( )
virtual

Definition at line 80 of file CProgressBar.cpp.

References finish(), mProgressItemList, pdelete, and CVectorCore< CType >::size().

81 {
82  finish();
83 
84  size_t i, imax = mProgressItemList.size();
85 
86  for (i = 0; i < imax; i++)
88 }
#define pdelete(p)
Definition: copasi.h:215
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
size_t size() const
Definition: CVector.h:100
virtual bool finish()

Member Function Documentation

size_t CProgressBar::addItem ( const std::string &  name,
const CCopasiParameter::Type type,
const void pValue,
const void pEndValue = NULL 
)
protectedvirtual

Add a process report item to to the list of reporting items. The return value is the handle of the item and can be used to indicate process, finish, or reset the item. If the method fails C_INVALID_INDEX is returned.

Parameters
conststd::string & name
constCCopasiParameter::Type & type
constvoid * pValue
constvoid * pEndValue = NULL
Returns
size_t handle

Reimplemented from CProcessReport.

Definition at line 90 of file CProgressBar.cpp.

References CProcessReport::addItem(), CopasiUI3Window::isMainThread(), mMutex, mSlotFinished, mWaitSlot, signalAddItem(), and slotAddItem().

95 {
96  size_t hItem = CProcessReport::addItem(name, type, pValue, pEndValue);
97 
99  {
100  QMutexLocker Locker(&mMutex);
101  mSlotFinished = false;
102 
103  emit signalAddItem((int) hItem);
104 
105  if (!mSlotFinished)
106  {
107  mWaitSlot.wait(&mMutex);
108  }
109  }
110  else
111  {
112  slotAddItem((int) hItem);
113  QCoreApplication::processEvents();
114  }
115 
116  return hItem;
117 }
virtual void slotAddItem(const int handle)
static bool isMainThread()
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
void signalAddItem(const int handle)
QWaitCondition mWaitSlot
Definition: CProgressBar.h:129
bool mSlotFinished
Definition: CProgressBar.h:126
void CProgressBar::btnContinuePressed ( )
protectedvirtualslot

Definition at line 346 of file CProgressBar.cpp.

References CQProgressDialog::btnContinuePressed(), and mWaitPause.

347 {
349  mWaitPause.wakeAll();
350 }
QWaitCondition mWaitPause
Definition: CProgressBar.h:130
virtual void btnContinuePressed()
void CProgressBar::btnStopPressed ( )
protectedvirtualslot

Definition at line 339 of file CProgressBar.cpp.

References CQProgressDialog::btnStopPressed(), and mWaitPause.

340 {
342  mWaitPause.wakeAll();
343 }
QWaitCondition mWaitPause
Definition: CProgressBar.h:130
virtual void btnStopPressed()
void CProgressBar::closeEvent ( QCloseEvent *  e)
protectedvirtual

Definition at line 330 of file CProgressBar.cpp.

References CQMessageBox::information().

331 {
332  CQMessageBox::information(this, "COPASI", "COPASI is currently executing tasks.\n"
333  "Please stop them first before closing COPASI.");
334 
335  e->ignore();
336 }
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
CProgressBar * CProgressBar::create ( QWidget *  parent = 0,
const char *  name = 0,
Qt::WindowModality  windowModality = Qt::WindowModal 
)
static

Definition at line 37 of file CProgressBar.cpp.

References CProgressBar(), CopasiUI3Window::getMainWindow(), and CopasiUI3Window::isMainThread().

Referenced by TaskWidget::commonBeforeRunTask(), DataModelGUI::exportMathModel(), DataModelGUI::exportSBML(), DataModelGUI::exportSBMLToString(), DataModelGUI::importSBML(), DataModelGUI::importSBMLFromString(), DataModelGUI::loadModel(), DataModelGUI::saveModel(), and DataModelGUI::updateMIRIAM().

38 {
39  QWidget * pParent = parent;
40 
41  if (pParent == NULL)
42  {
44  }
45 
47  {
48  return new CProgressBar(pParent, name, windowModality);
49  }
50  else
51  {
52  return NULL;
53  }
54 }
static bool isMainThread()
static CopasiUI3Window * getMainWindow()
CProgressBar(QWidget *parent, const char *name, Qt::WindowModality windowModality)
bool CProgressBar::finish ( )
virtual

Indicate that all items are finished reporting. All item handles loose their validity. If the return value is false the calling process must halt execution and return.

Parameters
boolcontinue

Reimplemented from CProcessReport.

Definition at line 208 of file CProgressBar.cpp.

References CVectorCore< CType >::array(), CopasiUI3Window::disableSliders(), CQProgressDialog::done(), CProcessReport::finish(), CopasiUI3Window::getMainWindow(), CopasiUI3Window::isMainThread(), CQProgressDialog::mProceed, CProcessReport::mProcessReportItemList, mProgressItemList, CQProgressDialog::removeProgressItem(), and CVectorCore< CType >::size().

Referenced by TaskWidget::commonAfterRunTask(), TaskWidget::commonRunTask(), TaskWidget::finishTask(), DataModelGUI::threadFinished(), and ~CProgressBar().

209 {
210  // Assure that all signals have been properly handled before we delete
211  // the progress items
213  QCoreApplication::processEvents();
214 
215  // The method must only be called from the main thread!
217  CQProgressItem ** ppEnd = ppIt + mProgressItemList.size();
219 
220  for (; ppIt != ppEnd; ++ppIt, ++ppItem)
221  {
222  if (*ppIt != NULL)
223  {
224  removeProgressItem(*ppIt);
225 
226  // We must make sure the CProcessReportItem is not deleted prior to the actual delete.
227  // The destructor of CQProgressItem will take care of the deletion.
228  *ppItem = NULL;
229 
230  (*ppIt)->deleteLater();
231  (*ppIt) = NULL;
232  }
233  }
234 
236 
238  done(1);
239 
240  return mProceed;
241 }
virtual bool finish()
virtual void done(int)
static bool isMainThread()
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
void disableSliders(bool disable)
bool removeProgressItem(CQProgressItem *pItem)
static CopasiUI3Window * getMainWindow()
CVector< CProcessReportItem * > mProcessReportItemList
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
bool CProgressBar::finishItem ( const size_t &  handle)
virtual

Indicate that item handle is finished reporting. The handle of that item is no longer valid after the call. If the return value is false the calling process must halt execution and return.

Parameters
constsize_t & handle
boolcontinue

Reimplemented from CProcessReport.

Definition at line 243 of file CProgressBar.cpp.

References CopasiUI3Window::isMainThread(), CProcessReport::isValidHandle(), mMutex, CQProgressDialog::mProceed, mProgressItemList, mSlotFinished, mWaitSlot, signalFinishItem(), and slotFinishItem().

244 {
245  if (!isValidHandle(handle) || mProgressItemList[handle] == NULL) return false;
246 
248  {
249  QMutexLocker Locker(&mMutex);
250  mSlotFinished = false;
251 
252  emit signalFinishItem((int) handle);
253 
254  if (!mSlotFinished)
255  {
256  mWaitSlot.wait(&mMutex);
257  }
258  }
259  else
260  {
261  slotFinishItem((int) handle);
262  QCoreApplication::processEvents();
263  }
264 
265  return mProceed;
266 }
static bool isMainThread()
virtual bool isValidHandle(const size_t handle) const
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
void signalFinishItem(const int handle)
virtual void slotFinishItem(const int handle)
QWaitCondition mWaitSlot
Definition: CProgressBar.h:129
bool mSlotFinished
Definition: CProgressBar.h:126
bool CProgressBar::proceed ( )
virtual

Check whether processing shall proceed. If the return value is false the calling process must halt execution and return. This method is provided so that lengthy processing without advances in any of the reporting items can check whether continuation is requested.

Parameters
boolcontinue

Reimplemented from CProcessReport.

Definition at line 291 of file CProgressBar.cpp.

References CQProgressDialog::mProceed.

292 {
293  return mProceed;
294 }
bool CProgressBar::progressItem ( const size_t &  handle)
virtual

Report process on item handle. If the return value is false the calling process must halt execution and return.

Parameters
constsize_t & handle
boolcontinue

Reimplemented from CProcessReport.

Definition at line 158 of file CProgressBar.cpp.

References CopasiUI3Window::isMainThread(), CProcessReport::isValidHandle(), mMutex, mNextEventProcessing, CQProgressDialog::mPause, CQProgressDialog::mProceed, mProgressItemList, mSlotFinished, mWaitPause, signalProgressAll(), and slotProgressAll().

Referenced by DataModelGUI::miriamDownloadFinished(), and DataModelGUI::miriamDownloadProgress().

159 {
160  if (!isValidHandle(handle) || mProgressItemList[handle] == NULL) return false;
161 
162  QDateTime currDateTime = QDateTime::currentDateTime();
163 
164  if (mNextEventProcessing >= currDateTime)
165  return mProceed;
166 
167  mNextEventProcessing = currDateTime.addSecs(1);
168 
169  if (mPause)
170  {
171  QMutexLocker Locker(&mMutex);
172  mWaitPause.wait(&mMutex);
173  }
174 
176  {
177  if (mSlotFinished)
178  {
179  mSlotFinished = false;
180 
181  emit signalProgressAll();
182  }
183  }
184  else
185  {
186  slotProgressAll();
187  QCoreApplication::processEvents();
188  }
189 
190  return mProceed;
191 }
static bool isMainThread()
virtual bool isValidHandle(const size_t handle) const
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
QDateTime mNextEventProcessing
Definition: CProgressBar.h:137
QWaitCondition mWaitPause
Definition: CProgressBar.h:130
void signalProgressAll()
virtual void slotProgressAll()
bool mSlotFinished
Definition: CProgressBar.h:126
bool CProgressBar::resetItem ( const size_t &  handle)
virtual

Reset item handle. This means that the value of the item has changed but not as part of a continuous process. If you run multiple processes call reset between them. If the return value is false the calling process must halt execution and return.

Parameters
constsize_t & handle
boolcontinue

Reimplemented from CProcessReport.

Definition at line 151 of file CProgressBar.cpp.

References CProcessReport::isValidHandle(), CQProgressDialog::mProceed, mProgressItemList, and CProcessReport::reset().

152 {
153  if (!isValidHandle(handle) || mProgressItemList[handle] == NULL) return false;
154 
155  return (mProgressItemList[handle]->reset() && mProceed);
156 }
virtual bool isValidHandle(const size_t handle) const
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
virtual bool reset()
bool CProgressBar::setName ( const std::string &  name)
virtual

Set the name of the process.

Parameters
conststd::string & name
Returns
success

Reimplemented from CProcessReport.

Definition at line 297 of file CProgressBar.cpp.

References FROM_UTF8, CopasiUI3Window::isMainThread(), mMutex, mSlotFinished, mWaitSlot, signalSetName(), and slotSetName().

Referenced by DataModelGUI::updateMIRIAM().

298 {
300  {
301  QMutexLocker Locker(&mMutex);
302  mSlotFinished = false;
303 
304  emit signalSetName(FROM_UTF8(name));
305 
306  if (!mSlotFinished)
307  {
308  mWaitSlot.wait(&mMutex);
309  }
310  }
311  else
312  {
313  slotSetName(FROM_UTF8(name));
314  QCoreApplication::processEvents();
315  }
316 
317  return true;
318 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual void slotSetName(QString name)
static bool isMainThread()
void signalSetName(QString name)
QWaitCondition mWaitSlot
Definition: CProgressBar.h:129
bool mSlotFinished
Definition: CProgressBar.h:126
void CProgressBar::signalAddItem ( const int  handle)
signal

Referenced by addItem(), and CProgressBar().

void CProgressBar::signalFinishItem ( const int  handle)
signal

Referenced by CProgressBar(), and finishItem().

void CProgressBar::signalProgressAll ( )
signal

Referenced by CProgressBar(), and progressItem().

void CProgressBar::signalSetName ( QString  name)
signal

Referenced by CProgressBar(), and setName().

void CProgressBar::slotAddItem ( const int  handle)
protectedvirtualslot

Definition at line 119 of file CProgressBar.cpp.

References C_INVALID_INDEX, CQProgressDialog::insertProgressItem(), mMutex, CProcessReport::mProcessReportItemList, mProgressItemList, mSlotFinished, mWaitSlot, CVector< CType >::resize(), and CVectorCore< CType >::size().

Referenced by addItem(), and CProgressBar().

120 {
121  size_t Handle = (size_t) handle;
122 
123  if (Handle == C_INVALID_INDEX) return;
124 
125  QMutexLocker Locker(&mMutex);
126 
127  if (Handle >= mProgressItemList.size()) // we need to resize
128  {
129  size_t i, imax = mProgressItemList.size();
130 
131  mProgressItemList.resize(2 * imax, true); // Note, imax is never zero
132 
133  i = imax;
134  imax *= 2;
135 
136  while (i < imax) mProgressItemList[i++] = NULL;
137  }
138 
139  if (mProcessReportItemList[Handle]->hasEndValue())
140  mProgressItemList[Handle] = new CQProgressItemBar(static_cast<CQProgressDialog *>(this));
141  else
142  mProgressItemList[Handle] = new CQProgressItemText(static_cast<CQProgressDialog *>(this));
143 
144  mProgressItemList[Handle]->initFromProcessReportItem(mProcessReportItemList[Handle]);
146 
147  mSlotFinished = true;
148  mWaitSlot.wakeAll();
149 }
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
#define C_INVALID_INDEX
Definition: copasi.h:222
CVector< CProcessReportItem * > mProcessReportItemList
bool insertProgressItem(CQProgressItem *pItem)
size_t size() const
Definition: CVector.h:100
QWaitCondition mWaitSlot
Definition: CProgressBar.h:129
bool mSlotFinished
Definition: CProgressBar.h:126
void CProgressBar::slotFinishItem ( const int  handle)
protectedvirtualslot

Definition at line 268 of file CProgressBar.cpp.

References CProcessReport::isValidHandle(), mMutex, CProcessReport::mProcessReportItemList, mProgressItemList, mSlotFinished, mWaitSlot, and CQProgressDialog::removeProgressItem().

Referenced by CProgressBar(), and finishItem().

269 {
270  size_t Handle = (size_t) handle;
271 
272  if (isValidHandle(Handle) &&
273  mProgressItemList[Handle] != NULL)
274  {
275  QMutexLocker Locker(&mMutex);
276 
278 
279  // We must make sure the CProcessReportItem is not deleted prior to the actual delete.
280  // The destructor of CQProgressItem will take care of the deletion.
281  mProcessReportItemList[Handle] = NULL;
282 
283  mProgressItemList[Handle]->deleteLater();
284  mProgressItemList[Handle] = NULL;
285  }
286 
287  mSlotFinished = true;
288  mWaitSlot.wakeAll();
289 }
virtual bool isValidHandle(const size_t handle) const
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
bool removeProgressItem(CQProgressItem *pItem)
CVector< CProcessReportItem * > mProcessReportItemList
QWaitCondition mWaitSlot
Definition: CProgressBar.h:129
bool mSlotFinished
Definition: CProgressBar.h:126
void CProgressBar::slotProgressAll ( )
protectedvirtualslot

Definition at line 193 of file CProgressBar.cpp.

References mMutex, CQProgressDialog::mProceed, mProgressItemList, mSlotFinished, and CVectorCore< CType >::size().

Referenced by CProgressBar(), and progressItem().

194 {
195  size_t hItem, hmax = mProgressItemList.size();
196 
197  QMutexLocker Locker(&mMutex);
198 
199  for (hItem = 0; hItem < hmax; hItem++)
200  {
201  if (mProgressItemList[hItem])
202  mProceed &= mProgressItemList[hItem]->process();
203  }
204 
205  mSlotFinished = true;
206 }
CVector< CQProgressItem * > mProgressItemList
Definition: CProgressBar.h:135
size_t size() const
Definition: CVector.h:100
bool mSlotFinished
Definition: CProgressBar.h:126
void CProgressBar::slotSetName ( QString  name)
protectedvirtualslot

Definition at line 319 of file CProgressBar.cpp.

References mMutex, mSlotFinished, mWaitSlot, CProcessReport::setName(), and TO_UTF8.

Referenced by CProgressBar(), and setName().

320 {
321  QMutexLocker Locker(&mMutex);
322 
323  setWindowTitle(name);
325 
326  mSlotFinished = true;
327  mWaitSlot.wakeAll();
328 }
virtual bool setName(const std::string &name)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
QWaitCondition mWaitSlot
Definition: CProgressBar.h:129
bool mSlotFinished
Definition: CProgressBar.h:126

Member Data Documentation

size_t CProgressBar::mLastHItem
protected

Definition at line 132 of file CProgressBar.h.

QMutex CProgressBar::mMutex
protected
QDateTime CProgressBar::mNextEventProcessing
private

Definition at line 137 of file CProgressBar.h.

Referenced by progressItem().

QWidget* CProgressBar::mpMainWidget
private

Definition at line 139 of file CProgressBar.h.

CVector< CQProgressItem * > CProgressBar::mProgressItemList
private
bool CProgressBar::mSlotFinished
protected
QWaitCondition CProgressBar::mWaitPause
protected

Definition at line 130 of file CProgressBar.h.

Referenced by btnContinuePressed(), btnStopPressed(), and progressItem().

QWaitCondition CProgressBar::mWaitSlot
protected

Definition at line 129 of file CProgressBar.h.

Referenced by addItem(), finishItem(), setName(), slotAddItem(), slotFinishItem(), and slotSetName().


The documentation for this class was generated from the following files: