1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QFUTUREWATCHER_H
43 #define QFUTUREWATCHER_H
45 #include <QtConcurrent/qtconcurrent_global.h>
47 #include <QtConcurrent/qfuture.h>
51 #include <QtCore/qobject.h>
59 class QFutureWatcherBasePrivate;
60 class Q_CONCURRENT_EXPORT QFutureWatcherBase : public QObject
63 Q_DECLARE_PRIVATE(QFutureWatcherBase)
66 QFutureWatcherBase(QObject *parent = 0);
68 int progressValue() const;
69 int progressMinimum() const;
70 int progressMaximum() const;
71 QString progressText() const;
73 bool isStarted() const;
74 bool isFinished() const;
75 bool isRunning() const;
76 bool isCanceled() const;
77 bool isPaused() const;
79 void waitForFinished();
81 void setPendingResultsLimit(int limit);
83 bool event(QEvent *event);
91 void resultReadyAt(int resultIndex);
92 void resultsReadyAt(int beginIndex, int endIndex);
93 void progressRangeChanged(int minimum, int maximum);
94 void progressValueChanged(int progressValue);
95 void progressTextChanged(const QString &progressText);
99 void setPaused(bool paused);
105 void connectNotify (const char * signal);
106 void disconnectNotify (const char * signal);
108 // called from setFuture() implemented in template sub-classes
109 void connectOutputInterface();
110 void disconnectOutputInterface(bool pendingAssignment = false);
113 // implemented in the template sub-classes
114 virtual const QFutureInterfaceBase &futureInterface() const = 0;
115 virtual QFutureInterfaceBase &futureInterface() = 0;
118 template <typename T>
119 class QFutureWatcher : public QFutureWatcherBase
122 QFutureWatcher(QObject *_parent = 0)
123 : QFutureWatcherBase(_parent)
126 { disconnectOutputInterface(); }
128 void setFuture(const QFuture<T> &future);
129 QFuture<T> future() const
132 T result() const { return m_future.result(); }
133 T resultAt(int index) const { return m_future.resultAt(index); }
136 int progressValue() const;
137 int progressMinimum() const;
138 int progressMaximum() const;
139 QString progressText() const;
141 bool isStarted() const;
142 bool isFinished() const;
143 bool isRunning() const;
144 bool isCanceled() const;
145 bool isPaused() const;
147 void waitForFinished();
149 void setPendingResultsLimit(int limit);
157 void resultReadyAt(int resultIndex);
158 void resultsReadyAt(int beginIndex, int endIndex);
159 void progressRangeChanged(int minimum, int maximum);
160 void progressValueChanged(int progressValue);
161 void progressTextChanged(const QString &progressText);
165 void setPaused(bool paused);
173 const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
174 QFutureInterfaceBase &futureInterface() { return m_future.d; }
177 template <typename T>
178 Q_INLINE_TEMPLATE void QFutureWatcher<T>::setFuture(const QFuture<T> &_future)
180 if (_future == m_future)
183 disconnectOutputInterface(true);
185 connectOutputInterface();
189 class QFutureWatcher<void> : public QFutureWatcherBase
192 QFutureWatcher(QObject *_parent = 0)
193 : QFutureWatcherBase(_parent)
196 { disconnectOutputInterface(); }
198 void setFuture(const QFuture<void> &future);
199 QFuture<void> future() const
203 QFuture<void> m_future;
204 const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
205 QFutureInterfaceBase &futureInterface() { return m_future.d; }
208 Q_INLINE_TEMPLATE void QFutureWatcher<void>::setFuture(const QFuture<void> &_future)
210 if (_future == m_future)
213 disconnectOutputInterface(true);
215 connectOutputInterface();
221 #endif // QT_NO_CONCURRENT
223 #endif // QFUTUREWATCHER_H