Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:24

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QFUTUREWATCHER_H
0005 #define QFUTUREWATCHER_H
0006 
0007 #include <QtCore/qfuture.h>
0008 #include <QtCore/qobject.h>
0009 
0010 QT_REQUIRE_CONFIG(future);
0011 
0012 QT_BEGIN_NAMESPACE
0013 
0014 
0015 class QEvent;
0016 
0017 class QFutureWatcherBasePrivate;
0018 class Q_CORE_EXPORT QFutureWatcherBase : public QObject
0019 {
0020     Q_OBJECT
0021     Q_DECLARE_PRIVATE(QFutureWatcherBase)
0022 
0023 public:
0024     explicit QFutureWatcherBase(QObject *parent = nullptr);
0025     // de-inline dtor
0026 
0027     int progressValue() const;
0028     int progressMinimum() const;
0029     int progressMaximum() const;
0030     QString progressText() const;
0031 
0032     bool isStarted() const;
0033     bool isFinished() const;
0034     bool isRunning() const;
0035     bool isCanceled() const;
0036 #if QT_DEPRECATED_SINCE(6, 0)
0037     QT_DEPRECATED_VERSION_X_6_0("Use isSuspending() or isSuspended() instead.")
0038     bool isPaused() const;
0039 #endif
0040     bool isSuspending() const;
0041     bool isSuspended() const;
0042 
0043     void waitForFinished();
0044 
0045     void setPendingResultsLimit(int limit);
0046 
0047     bool event(QEvent *event) override;
0048 
0049 Q_SIGNALS:
0050     void started();
0051     void finished();
0052     void canceled();
0053 #if QT_DEPRECATED_SINCE(6, 0)
0054     QT_DEPRECATED_VERSION_X_6_0("Use suspending() instead.")
0055     void paused();
0056 #endif
0057     void suspending();
0058     void suspended();
0059     void resumed();
0060     void resultReadyAt(int resultIndex);
0061     void resultsReadyAt(int beginIndex, int endIndex);
0062     void progressRangeChanged(int minimum, int maximum);
0063     void progressValueChanged(int progressValue);
0064     void progressTextChanged(const QString &progressText);
0065 
0066 public Q_SLOTS:
0067     void cancel();
0068     void setSuspended(bool suspend);
0069     void suspend();
0070     void resume();
0071     void toggleSuspended();
0072 
0073 #if QT_DEPRECATED_SINCE(6, 0)
0074     QT_DEPRECATED_VERSION_X_6_0("Use setSuspended() instead.")
0075     void setPaused(bool paused);
0076 
0077     QT_DEPRECATED_VERSION_X_6_0("Use suspended() instead.")
0078     void pause();
0079 
0080     QT_DEPRECATED_VERSION_X_6_0("Use toggleSuspended() instead.")
0081     void togglePaused();
0082 #endif
0083 
0084 protected:
0085     void connectNotify (const QMetaMethod &signal) override;
0086     void disconnectNotify (const QMetaMethod &signal) override;
0087 
0088     // called from setFuture() implemented in template sub-classes
0089     void connectOutputInterface();
0090     void disconnectOutputInterface(bool pendingAssignment = false);
0091 
0092 private:
0093     // implemented in the template sub-classes
0094     virtual const QFutureInterfaceBase &futureInterface() const = 0;
0095     virtual QFutureInterfaceBase &futureInterface() = 0;
0096 };
0097 
0098 template <typename T>
0099 class QFutureWatcher : public QFutureWatcherBase
0100 {
0101 public:
0102     explicit QFutureWatcher(QObject *_parent = nullptr)
0103         : QFutureWatcherBase(_parent)
0104     { }
0105     ~QFutureWatcher()
0106     { disconnectOutputInterface(); }
0107 
0108     void setFuture(const QFuture<T> &future);
0109     QFuture<T> future() const
0110     { return m_future; }
0111 
0112     template<typename U = T, typename = QtPrivate::EnableForNonVoid<U>>
0113     T result() const { return m_future.result(); }
0114 
0115     template<typename U = T, typename = QtPrivate::EnableForNonVoid<U>>
0116     T resultAt(int index) const { return m_future.resultAt(index); }
0117 
0118 #ifdef Q_QDOC
0119     int progressValue() const;
0120     int progressMinimum() const;
0121     int progressMaximum() const;
0122     QString progressText() const;
0123 
0124     bool isStarted() const;
0125     bool isFinished() const;
0126     bool isRunning() const;
0127     bool isCanceled() const;
0128 #if QT_DEPRECATED_SINCE(6, 0)
0129     bool isPaused() const;
0130 #endif
0131     bool isSuspending() const;
0132     bool isSuspended() const;
0133 
0134     void waitForFinished();
0135 
0136     void setPendingResultsLimit(int limit);
0137 
0138 Q_SIGNALS:
0139     void started();
0140     void finished();
0141     void canceled();
0142 #if QT_DEPRECATED_SINCE(6, 0)
0143     void paused();
0144 #endif
0145     void suspending();
0146     void suspended();
0147     void resumed();
0148     void resultReadyAt(int resultIndex);
0149     void resultsReadyAt(int beginIndex, int endIndex);
0150     void progressRangeChanged(int minimum, int maximum);
0151     void progressValueChanged(int progressValue);
0152     void progressTextChanged(const QString &progressText);
0153 
0154 public Q_SLOTS:
0155     void cancel();
0156     void setSuspended(bool suspend);
0157     void suspend();
0158     void resume();
0159     void toggleSuspended();
0160 #if QT_DEPRECATED_SINCE(6, 0)
0161     void setPaused(bool paused);
0162     void pause();
0163     void togglePaused();
0164 #endif // QT_DEPRECATED_SINCE(6, 0)
0165 
0166 #endif // Q_QDOC
0167 
0168 private:
0169     QFuture<T> m_future;
0170     const QFutureInterfaceBase &futureInterface() const override { return m_future.d; }
0171     QFutureInterfaceBase &futureInterface() override { return m_future.d; }
0172 };
0173 
0174 template <typename T>
0175 Q_INLINE_TEMPLATE void QFutureWatcher<T>::setFuture(const QFuture<T> &_future)
0176 {
0177     if (_future.d == m_future.d)
0178         return;
0179 
0180     disconnectOutputInterface(true);
0181     m_future = _future;
0182     connectOutputInterface();
0183 }
0184 
0185 QT_END_NAMESPACE
0186 
0187 #endif // QFUTUREWATCHER_H