File indexing completed on 2024-05-12 16:02:31
0001 /* This file is part of the KDE project 0002 * 0003 * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org> 0004 * SPDX-FileCopyrightText: 2009 Boudewijn Rempt <boud@valdyas.org> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 #ifndef KO_UPDATER_H 0009 #define KO_UPDATER_H 0010 0011 #include "KoProgressProxy.h" 0012 #include <QObject> 0013 #include <QPointer> 0014 0015 class KoProgressUpdater; 0016 class KoUpdaterPrivate; 0017 0018 0019 /** 0020 * An KoUpdater is a helper for keeping the progress of each subtask up to speed. 0021 * This class is not thread safe, and it should only be used from one thread. 0022 * The thread it is used in can be different from any other subtask or the 0023 * KoProgressUpdater, though. 0024 * 0025 * It is possible to create a KoProgressUpdater on a KoUpdater for when you 0026 * need to recursively split up progress reporting. (For instance, when your 0027 * progress reporting routine can be called by other progress reporting 0028 * routines.) 0029 * 0030 * KoUpdater implements KoProgressProxy because it is possible to recursively 0031 * create another KoProgressUpdater with an updater as progress proxy. 0032 * 0033 * @see KoProgressUpdater::startSubtask() 0034 */ 0035 class KRITAWIDGETUTILS_EXPORT KoUpdater : public QObject, public KoProgressProxy { 0036 0037 Q_OBJECT 0038 0039 public: 0040 virtual ~KoUpdater(); 0041 0042 /** 0043 * Call this when this subtask wants to abort all the actions. 0044 */ 0045 void cancel(); 0046 0047 public Q_SLOTS: 0048 /** 0049 * Update your progress. Progress is always from 0 to 100. 0050 * The global progress shown to the user is determined by the total 0051 * amount of subtasks there are. This means that each subtasks can just 0052 * report its own private progress in the range from 0 to 100. 0053 */ 0054 void setProgress(int percent); 0055 0056 public: 0057 /** 0058 * return true when this task should stop processing immediately. 0059 * When the task has been cancelled all the subtasks will get interrupted 0060 * and should stop working. It is therefore important to have repeated calls to 0061 * this method at regular (time) intervals and as soon as the method returns true 0062 * cancel the subtask. 0063 * @return true when this task should stop processing immediately. 0064 */ 0065 bool interrupted() const; 0066 0067 /** 0068 * return the progress this subtask has made. 0069 */ 0070 int progress() const; 0071 0072 public: // KoProgressProxy implementation 0073 0074 int maximum() const override; 0075 void setValue( int value ) override; 0076 void setRange( int minimum, int maximum ) override; 0077 void setFormat( const QString & format ) override; 0078 void setAutoNestedName(const QString &name) override; 0079 0080 Q_SIGNALS: 0081 0082 /// emitted whenever the subtask has called cancel on us 0083 void sigCancel(); 0084 0085 /// emitted whenever the subtask has called setProgress on us 0086 void sigProgress( int percent ); 0087 0088 void sigNestedNameChanged(const QString &value); 0089 void sigHasValidRangeChanged(bool value); 0090 0091 protected: 0092 0093 friend class KoUpdaterPrivate; 0094 KoUpdater(KoUpdaterPrivate *_d); 0095 0096 public: 0097 0098 QPointer<KoUpdaterPrivate> d; 0099 int range; 0100 int min; 0101 int max; 0102 0103 private Q_SLOTS: 0104 0105 void setInterrupted(bool value); 0106 0107 private: 0108 0109 bool m_interrupted; 0110 int m_progressPercent; 0111 }; 0112 0113 /// An updater that does nothing 0114 class KRITAWIDGETUTILS_EXPORT KoDummyUpdater : public KoUpdater 0115 { 0116 public: 0117 KoDummyUpdater(); 0118 }; 0119 0120 #endif 0121