Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ABSTRACTPROGRESS_H
00029 #define ABSTRACTPROGRESS_H
00030
00031 #include <time.h>
00032
00033 #include "QGpCoreToolsDLLExport.h"
00034 #include "Trace.h"
00035
00036 namespace QGpCoreTools {
00037
00038 class QGPCORETOOLS_EXPORT AbstractProgress
00039 {
00040 public:
00041 AbstractProgress();
00042 virtual ~AbstractProgress() {}
00043
00044 virtual void setMaximum(int val);
00045 int maximum() const;
00046
00047 virtual void setCaption(QString c);
00048 const QString& caption() const;
00049
00050 inline void setValue(int val);
00051 inline void increaseValue(int val=1);
00052 int value() const {return _value+_deltaValue;}
00053 protected:
00054 virtual void paint(QString caption, int value, int maximum)=0;
00055 QString valueString(int value, int maximum);
00056
00057 mutable QMutex _mutex;
00058 QString _caption;
00059 int _value;
00060 int _maximum;
00061 private:
00062 inline void show();
00063 void setValueInternal(int val);
00064 void increaseValueInternal();
00065
00066 QAtomicInt _lastTime;
00067 int _deltaValue;
00068 };
00069
00070 inline void AbstractProgress::increaseValue(int val)
00071 {
00072 TRACE;
00073 _deltaValue+=val;
00074 int now=time(0);
00075 if(_lastTime.fetchAndStoreOrdered(now)!=now) {
00076 increaseValueInternal();
00077 _deltaValue=0;
00078 }
00079 }
00080
00081 inline void AbstractProgress::setValue(int val)
00082 {
00083 TRACE;
00084 int now=time(0);
00085 if(_lastTime.fetchAndStoreOrdered(now)!=now || val==_maximum) {
00086 setValueInternal(val);
00087 }
00088 }
00089
00090 }
00091
00092 #endif // ABSTRACTPROGRESS_H