Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qfuturewatcher.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qfuturewatcher.h"
5#include "qfuturewatcher_p.h"
6
7#include <QtCore/qcoreevent.h>
8#include <QtCore/qcoreapplication.h>
9#include <QtCore/qmetaobject.h>
10#include <QtCore/qthread.h>
11
13
72
96{
97 futureInterface().cancel();
98}
99
100#if QT_DEPRECATED_SINCE(6, 0)
122void QFutureWatcherBase::setPaused(bool paused)
123{
124 futureInterface().setSuspended(paused);
125}
126
137void QFutureWatcherBase::pause()
138{
139 futureInterface().setSuspended(true);
140}
141
142#endif // QT_DEPRECATED_SINCE(6, 0)
143
165{
166 futureInterface().setSuspended(suspend);
167}
168
179{
180 futureInterface().setSuspended(true);
181}
182
192{
193 futureInterface().setSuspended(false);
194}
195
196#if QT_DEPRECATED_SINCE(6, 0)
208void QFutureWatcherBase::togglePaused()
209{
210 futureInterface().toggleSuspended();
211}
212#endif // QT_DEPRECATED_SINCE(6, 0)
213
226{
227 futureInterface().toggleSuspended();
228}
229
238{
239 return futureInterface().progressValue();
240}
241
249{
250 return futureInterface().progressMinimum();
251}
252
260{
261 return futureInterface().progressMaximum();
262}
263
273{
274 return futureInterface().progressText();
275}
276
283{
285}
286
293{
294 return futureInterface().isFinished();
295}
296
303{
305}
306
319
320#if QT_DEPRECATED_SINCE(6, 0)
321
336bool QFutureWatcherBase::isPaused() const
337{
340 return futureInterface().isPaused();
342}
343#endif // QT_DEPRECATED_SINCE(6, 0)
344
358{
359 return futureInterface().isSuspending();
360}
361
373{
374 return futureInterface().isSuspended();
375}
376
383{
384 futureInterface().waitForFinished();
385}
386
388{
390 if (event->type() == QEvent::FutureCallOut) {
391 QFutureCallOutEvent *callOutEvent = static_cast<QFutureCallOutEvent *>(event);
392 d->sendCallOutEvent(callOutEvent);
393 return true;
394 }
395 return QObject::event(event);
396}
397
407{
409 d->maximumPendingResultsReady = limit;
410}
411
413{
415 static const QMetaMethod resultReadyAtSignal = QMetaMethod::fromSignal(&QFutureWatcherBase::resultReadyAt);
416 if (signal == resultReadyAtSignal)
417 d->resultAtConnected.ref();
418#ifndef QT_NO_DEBUG
420 if (signal == finishedSignal) {
421 if (futureInterface().isRunning()) {
422 //connections should be established before calling stFuture to avoid race.
423 // (The future could finish before the connection is made.)
424 qWarning("QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race");
425 }
426 }
427#endif
428}
429
431{
433 static const QMetaMethod resultReadyAtSignal = QMetaMethod::fromSignal(&QFutureWatcherBase::resultReadyAt);
434 if (signal == resultReadyAtSignal)
435 d->resultAtConnected.deref();
436}
437
442 : maximumPendingResultsReady(QThread::idealThreadCount() * 2),
443 resultAtConnected(0)
444{ }
445
450{
451 futureInterface().d->connectOutputInterface(d_func());
452}
453
458{
459 if (pendingAssignment) {
461 d->pendingResultsReady.storeRelaxed(0);
462 }
463
464 futureInterface().d->disconnectOutputInterface(d_func());
465}
466
468{
470
471 if (callOutEvent.callOutType == QFutureCallOutEvent::ResultsReady) {
473 q->futureInterface().d->internal_setThrottled(true);
474 }
475
476 QCoreApplication::postEvent(q, callOutEvent.clone());
477}
478
483
485{
487
488 switch (event->callOutType) {
490 emit q->started();
491 break;
493 emit q->finished();
494 break;
497 emit q->canceled();
498 break;
500 if (q->futureInterface().isCanceled())
501 break;
502 emit q->suspending();
503#if QT_DEPRECATED_SINCE(6, 0)
506 emit q->paused();
508#endif
509 break;
511 if (q->futureInterface().isCanceled())
512 break;
513 emit q->suspended();
514 break;
516 if (q->futureInterface().isCanceled())
517 break;
518 emit q->resumed();
519 break;
521 if (q->futureInterface().isCanceled())
522 break;
523
525 q->futureInterface().setThrottled(false);
526
527 const int beginIndex = event->index1;
528 const int endIndex = event->index2;
529
530 emit q->resultsReadyAt(beginIndex, endIndex);
531
533 break;
534
535 for (int i = beginIndex; i < endIndex; ++i)
536 emit q->resultReadyAt(i);
537
538 } break;
540 if (q->futureInterface().isCanceled())
541 break;
542
543 emit q->progressValueChanged(event->index1);
544 if (!event->text.isNull()) // ###
545 emit q->progressTextChanged(event->text);
546 break;
548 emit q->progressRangeChanged(event->index1, event->index2);
549 break;
550 default: break;
551 }
552}
553
554
628#if QT_DEPRECATED_SINCE(6, 0)
644#endif // QT_DEPRECATED_SINCE(6, 0)
645
703
704#include "moc_qfuturewatcher.cpp"
void storeRelaxed(T newValue) noexcept
T fetchAndAddRelaxed(T valueToAdd) noexcept
T loadRelaxed() const noexcept
static void removePostedEvents(QObject *receiver, int eventType=0)
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
\inmodule QtCore
Definition qcoreevent.h:45
@ FutureCallOut
Definition qcoreevent.h:223
void postCallOutEvent(const QFutureCallOutEvent &callOutEvent) override
void sendCallOutEvent(QFutureCallOutEvent *event)
void callOutInterfaceDisconnected() override
bool isSuspending() const
virtual const QFutureInterfaceBase & futureInterface() const =0
void setPendingResultsLimit(int limit)
int progressMaximum() const
void setSuspended(bool suspend)
QFutureWatcherBase(QObject *parent=nullptr)
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void connectNotify(const QMetaMethod &signal) override
void disconnectOutputInterface(bool pendingAssignment=false)
int progressMinimum() const
void disconnectNotify(const QMetaMethod &signal) override
QString progressText() const
void resultReadyAt(int resultIndex)
\inmodule QtCore
Definition qmetaobject.h:19
static QMetaMethod fromSignal(PointerToMemberFunction signal)
\inmodule QtCore
Definition qobject.h:103
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1389
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
auto signal
Combined button and popup list for selecting options.
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_DEPRECATED
#define QT_WARNING_PUSH
#define qWarning
Definition qlogging.h:166
struct _cl_event * event
GLint limit
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit
future suspend()