MorphoGraphX  2.0-1-227
Progress.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef PROGRESS_H
12 #define PROGRESS_H
13 
14 #include <Config.hpp>
15 
16 #include <QEvent>
17 #include <QList>
18 #include <QMutex>
19 #include <QObject>
20 #include <QPointer>
21 #include <QString>
22 #include <QProgressBar>
23 #include <QLabel>
24 #include <QToolBar>
25 #include <QPushButton>
26 #include <QtCore>
27 #include <string>
28 
29 namespace mgx
30 {
31  // Progress class
32  class mgx_EXPORT Progress : public QObject
33  {
34  Q_OBJECT
35 
36  QWidget* _parent;
37  QProgressBar* _progressBar;
38  QLabel* _progressText;
39  QPushButton* _progressStop;
40  static Progress* _instance;
41 
42  bool _canceled;
43  int _step;
44  int _steps;
45  QString _msg;
46 
47  public:
48  Progress();
49  ~Progress();
50 
51  bool processEvent(QEvent *e);
52  void setupProgress(QWidget* parent, QToolBar* progressToolBar);
53 
54  void start(const QString& msg, int steps, bool allowCancel = true);
55  void start(const char* msg, int steps, bool allowCancel = true)
56  {
57  start(QString::fromLocal8Bit(msg), steps, allowCancel);
58  }
59  void start(std::string msg, int steps, bool allowCancel = true)
60  {
61  start(QString::fromStdString(msg), steps, allowCancel);
62  }
63  bool advance(int step = -1);
64  bool canceled();
65  void cancel();
66  void stop();
67  void setMax(int steps);
68  void setMsg(const QString& msg);
69  void setMsg(const char* msg) { setMsg(QString::fromLocal8Bit(msg)); }
70  void setMsg(std::string msg) { setMsg(QString::fromStdString(msg)); }
71 
72  static Progress& instance();
73 
74  private:
75  QString makeMsg() const;
76  };
77 
78  mgx_EXPORT void progressStart(const QString& msg, int steps = 0, bool allowCancel = true);
79  mgx_EXPORT void progressStart(const char* msg, int steps = 0, bool allowCancel = true);
80  mgx_EXPORT void progressStart(const std::string &msg, int steps = 0, bool allowCancel = true);
81  mgx_EXPORT void progressStop();
82  mgx_EXPORT bool progressAdvance(int step = -1);
83  mgx_EXPORT bool progressCanceled();
84  mgx_EXPORT void progressCancel();
85  mgx_EXPORT void progressSetMsg(const QString &msg);
86  mgx_EXPORT void progressSetMsg(const char *msg);
87  mgx_EXPORT void progressSetMsg(const std::string &msg);
88  mgx_EXPORT void progressSetMax(int steps = 0);
89 }
90 #endif
mgx::Progress::setMsg
void setMsg(std::string msg)
Definition: Progress.hpp:70
mgx::Progress::setMsg
void setMsg(const char *msg)
Definition: Progress.hpp:69
mgx::progressSetMsg
void progressSetMsg(const std::string &msg)
mgx::Progress::start
void start(const char *msg, int steps, bool allowCancel=true)
Definition: Progress.hpp:55
mgx::progressCanceled
mgx_EXPORT bool progressCanceled()
mgx::Progress::start
void start(std::string msg, int steps, bool allowCancel=true)
Definition: Progress.hpp:59
mgx::progressSetMax
mgx_EXPORT void progressSetMax(int steps=0)
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::progressStart
void progressStart(const std::string &msg, int steps)
mgx::Progress
Definition: Progress.hpp:32
mgx::progressAdvance
bool progressAdvance()
mgx::progressStop
void progressStop()
mgx::progressCancel
mgx_EXPORT void progressCancel()