- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qfuturewatcher.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QFUTUREWATCHER_H
    00043 #define QFUTUREWATCHER_H
    00044
    00045 #include <QtCore/qfuture.h>
    00046
    00047 #ifndef QT_NO_QFUTURE
    00048
    00049 #include <QtCore/qobject.h>
    00050
    00051 QT_BEGIN_HEADER
    00052 QT_BEGIN_NAMESPACE
    00053
    00054 QT_MODULE(Core)
    00055
    00056 class QEvent;
    00057
    00058 class QFutureWatcherBasePrivate;
    00059 class Q_CORE_EXPORT QFutureWatcherBase : public QObject
    00060 {
    00061     Q_OBJECT
    00062     Q_DECLARE_PRIVATE(QFutureWatcherBase)
    00063
    00064 public:
    00065     QFutureWatcherBase(QObject *parent = 0);
    00066
    00067     int progressValue() const;
    00068     int progressMinimum() const;
    00069     int progressMaximum() const;
    00070     QString progressText() const;
    00071
    00072     bool isStarted() const;
    00073     bool isFinished() const;
    00074     bool isRunning() const;
    00075     bool isCanceled() const;
    00076     bool isPaused() const;
    00077
    00078     void waitForFinished();
    00079
    00080     void setPendingResultsLimit(int limit);
    00081
    00082     bool event(QEvent *event);
    00083
    00084 Q_SIGNALS:
    00085     void started();
    00086     void finished();
    00087     void canceled();
    00088     void paused();
    00089     void resumed();
    00090     void resultReadyAt(int resultIndex);
    00091     void resultsReadyAt(int beginIndex, int endIndex);
    00092     void progressRangeChanged(int minimum, int maximum);
    00093     void progressValueChanged(int progressValue);
    00094     void progressTextChanged(const QString &progressText);
    00095
    00096 public Q_SLOTS:
    00097     void cancel();
    00098     void setPaused(bool paused);
    00099     void pause();
    00100     void resume();
    00101     void togglePaused();
    00102
    00103 protected:
    00104     void connectNotify (const char * signal);
    00105     void disconnectNotify (const char * signal);
    00106
    00107     // called from setFuture() implemented in template sub-classes
    00108     void connectOutputInterface();
    00109     void disconnectOutputInterface(bool pendingAssignment = false);
    00110
    00111 private:
    00112     // implemented in the template sub-classes
    00113     virtual const QFutureInterfaceBase &futureInterface() const = 0;
    00114     virtual QFutureInterfaceBase &futureInterface() = 0;
    00115 };
    00116
    00117 template <typename T>
    00118 class QFutureWatcher : public QFutureWatcherBase
    00119 {
    00120 public:
    00121     QFutureWatcher(QObject *_parent = 0)
    00122         : QFutureWatcherBase(_parent)
    00123     { }
    00124     ~QFutureWatcher()
    00125     { disconnectOutputInterface(); }
    00126
    00127     void setFuture(const QFuture<T> &future);
    00128     QFuture<T> future() const
    00129     { return m_future; }
    00130
    00131     T result() const { return m_future.result(); }
    00132     T resultAt(int index) const { return m_future.resultAt(index); }
    00133
    00134 #ifdef qdoc
    00135     int progressValue() const;
    00136     int progressMinimum() const;
    00137     int progressMaximum() const;
    00138     QString progressText() const;
    00139
    00140     bool isStarted() const;
    00141     bool isFinished() const;
    00142     bool isRunning() const;
    00143     bool isCanceled() const;
    00144     bool isPaused() const;
    00145
    00146     void waitForFinished();
    00147
    00148     void setPendingResultsLimit(int limit);
    00149
    00150 Q_SIGNALS:
    00151     void started();
    00152     void finished();
    00153     void canceled();
    00154     void paused();
    00155     void resumed();
    00156     void resultReadyAt(int resultIndex);
    00157     void resultsReadyAt(int beginIndex, int endIndex);
    00158     void progressRangeChanged(int minimum, int maximum);
    00159     void progressValueChanged(int progressValue);
    00160     void progressTextChanged(const QString &progressText);
    00161
    00162 public Q_SLOTS:
    00163     void cancel();
    00164     void setPaused(bool paused);
    00165     void pause();
    00166     void resume();
    00167     void togglePaused();
    00168 #endif
    00169
    00170 private:
    00171     QFuture<T> m_future;
    00172     const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
    00173     QFutureInterfaceBase &futureInterface() { return m_future.d; }
    00174 };
    00175
    00176 template <typename T>
    00177 Q_INLINE_TEMPLATE void QFutureWatcher<T>::setFuture(const QFuture<T> &_future)
    00178 {
    00179     if (_future == m_future)
    00180         return;
    00181
    00182     disconnectOutputInterface(true);
    00183     m_future = _future;
    00184     connectOutputInterface();
    00185 }
    00186
    00187 template <>
    00188 class QFutureWatcher<void> : public QFutureWatcherBase
    00189 {
    00190 public:
    00191     QFutureWatcher(QObject *_parent = 0)
    00192         : QFutureWatcherBase(_parent)
    00193     { }
    00194     ~QFutureWatcher()
    00195     { disconnectOutputInterface(); }
    00196
    00197     void setFuture(const QFuture<void> &future);
    00198     QFuture<void> future() const
    00199     { return m_future; }
    00200
    00201 private:
    00202     QFuture<void> m_future;
    00203     const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
    00204     QFutureInterfaceBase &futureInterface() { return m_future.d; }
    00205 };
    00206
    00207 Q_INLINE_TEMPLATE void QFutureWatcher<void>::setFuture(const QFuture<void> &_future)
    00208 {
    00209     if (_future == m_future)
    00210         return;
    00211
    00212     disconnectOutputInterface(true);
    00213     m_future = _future;
    00214     connectOutputInterface();
    00215 }
    00216
    00217 QT_END_NAMESPACE
    00218 QT_END_HEADER
    00219
    00220 #endif // QT_NO_CONCURRENT
    00221
    00222 #endif // QFUTUREWATCHER_H