Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...
#include <tasktree.h>
Signals | |
void | started () |
This signal is emitted when the task tree is started. | |
void | done (DoneWith result) |
This signal is emitted when the task tree finished, passing the final result of the execution. | |
void | asyncCountChanged (int count) |
This signal is emitted when the running task tree is about to return control to the caller's event loop. | |
void | progressValueChanged (int value) |
This signal is emitted when the running task tree finished, canceled, or skipped some tasks. | |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
TaskTree () | |
Constructs an empty task tree. | |
TaskTree (const Group &recipe) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Constructs a task tree with a given recipe. | |
~TaskTree () | |
Destroys the task tree. | |
void | setRecipe (const Group &recipe) |
Sets a given recipe for the task tree. | |
void | start () |
Starts the task tree. | |
void | cancel () |
Cancels the execution of the running task tree. | |
bool | isRunning () const |
Returns true if the task tree is currently running; otherwise returns false . | |
DoneWith | runBlocking () |
Executes a local event loop with QEventLoop::ExcludeUserInputEvents and starts the task tree. | |
DoneWith | runBlocking (const QFuture< void > &future) |
int | asyncCount () const |
Returns the current real count of asynchronous chains of invocations. | |
int | taskCount () const |
Returns the number of asynchronous tasks contained in the stored recipe. | |
int | progressMaximum () const |
Returns the maximum progressValue(). | |
int | progressValue () const |
Returns the current progress value, which is between the 0 and progressMaximum(). | |
template<typename StorageStruct , typename Handler > | |
void | onStorageSetup (const Storage< StorageStruct > &storage, Handler &&handler) |
Installs a storage setup handler for the storage to pass the initial data dynamically to the running task tree. | |
template<typename StorageStruct , typename Handler > | |
void | onStorageDone (const Storage< StorageStruct > &storage, Handler &&handler) |
Installs a storage done handler for the storage to retrieve the final data dynamically from the running task tree. | |
Public Member Functions inherited from QObject | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
bool | moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL) |
Changes the thread affinity for this object and its children and returns true on success. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
void | killTimer (Qt::TimerId id) |
template<typename T > | |
T | findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
T | findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Static Public Member Functions | |
static DoneWith | runBlocking (const Group &recipe, std::chrono::milliseconds timeout=std::chrono::milliseconds::max()) |
static DoneWith | runBlocking (const Group &recipe, const QFuture< void > &future, std::chrono::milliseconds timeout=std::chrono::milliseconds::max()) |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Related Symbols | |
(Note that these are not member symbols.) | |
runBlocking | |
The passed future is used for listening to the cancel event. | |
runBlocking | |
The passed future is used for listening to the cancel event. | |
runBlocking | |
The passed future is used for listening to the cancel event. | |
runBlocking | |
The passed future is used for listening to the cancel event. | |
Related Symbols inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
\threadsafe | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Properties inherited from QObject | |
QString | objectName |
the name of this object | |
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
The TaskTree class runs an async task tree structure defined in a declarative way. \reentrant
Use the Tasking namespace to build extensible, declarative task tree structures that contain possibly asynchronous tasks, such as QProcess, NetworkQuery, or ConcurrentCall<ReturnType>. TaskTree structures enable you to create a sophisticated mixture of a parallel or sequential flow of tasks in the form of a tree and to run it any time later.
Tasking::TaskTree::TaskTree | ( | ) |
Constructs an empty task tree.
Use setRecipe() to pass a declarative description on how the task tree should execute the tasks and how it should handle the finished tasks.
Starting an empty task tree is no-op and the relevant warning message is issued.
Definition at line 3050 of file tasktree.cpp.
Referenced by TaskTree(), Tasking::TaskTreeTaskAdapter::TaskTreeTaskAdapter(), runBlocking(), and runBlocking().
Tasking::TaskTree::TaskTree | ( | const Group & | recipe | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Constructs a task tree with a given recipe.
After the task tree is started, it executes the tasks contained inside the recipe and handles finished tasks according to the passed description.
Definition at line 3063 of file tasktree.cpp.
References TaskTree(), and setRecipe().
Referenced by runBlocking().
Tasking::TaskTree::~TaskTree | ( | ) |
Destroys the task tree.
When the task tree is running while being destructed, it cancels all the running tasks immediately. In this case, no handlers are called, not even the groups' and tasks' done handlers or onStorageDone() handlers. The task tree also doesn't emit any signals from the destructor, not even done() or progressValueChanged() signals. This behavior may always be relied on. It is completely safe to destruct the running task tree.
It's a usual pattern to destruct the running task tree. It's guaranteed that the destruction will run quickly, without having to wait for the currently running tasks to finish, provided that the used tasks implement their destructors in a non-blocking way.
Definition at line 3088 of file tasktree.cpp.
int Tasking::TaskTree::asyncCount | ( | ) | const |
Returns the current real count of asynchronous chains of invocations.
The returned value indicates how many times the control returns to the caller's event loop while the task tree is running. Initially, this value is 0. If the execution of the task tree finishes fully synchronously, this value remains 0. If the task tree contains any asynchronous tasks that are successfully started during a call to start(), this value is bumped to 1 just before the call to start() finishes. Later, when any asynchronous task finishes and any possible continuations are started, this value is bumped again. The bumping continues until the task tree finishes. When the task tree emits the done() signal, the bumping stops. The asyncCountChanged() signal is emitted on every bump of this value.
Definition at line 3315 of file tasktree.cpp.
References Tasking::TaskTreePrivate::m_asyncCount.
Referenced by Tasking::ExecutableItem::withLog().
|
signal |
This signal is emitted when the running task tree is about to return control to the caller's event loop.
When the task tree is started, this signal is emitted with count value of 0, and emitted later on every asyncCount() value bump with an updated count value. Every signal sent (except the initial one with the value of 0) guarantees that the task tree is still running asynchronously after the emission.
void Tasking::TaskTree::cancel | ( | ) |
Cancels the execution of the running task tree.
Cancels all the running tasks immediately. All running tasks finish with an error, invoking their error handlers. All running groups dispatch their handlers according to their workflow policies, invoking their done handlers. The storages' onStorageDone() handlers are invoked, too. The progressValueChanged() signals are also being sent. This behavior may always be relied on.
The cancel()
function is executed synchronously, so that after a call to cancel()
all running tasks are finished and the tree is already canceled. It's guaranteed that cancel()
will run quickly, without any blocking wait for the currently running tasks to finish, provided the used tasks implement their destructors in a non-blocking way.
When the task tree is empty, that is, constructed with a default constructor, a call to cancel()
is no-op and the relevant warning message is issued.
Otherwise, when the task tree wasn't started, a call to cancel()
is ignored.
Definition at line 3197 of file tasktree.cpp.
References Tasking::TaskTreePrivate::stop().
This signal is emitted when the task tree finished, passing the final result of the execution.
The task tree neither calls any handler, nor emits any signal anymore after this signal was emitted.
Referenced by Tasking::TaskTreeTaskAdapter::TaskTreeTaskAdapter(), and runBlocking().
bool Tasking::TaskTree::isRunning | ( | ) | const |
Returns true
if the task tree is currently running; otherwise returns false
.
Definition at line 3209 of file tasktree.cpp.
Referenced by setRecipe(), and start().
|
inline |
Installs a storage done handler for the storage to retrieve the final data dynamically from the running task tree.
The StorageHandler
takes a const
reference to the StorageStruct
instance:
When the running task tree is about to leave a Group where the storage is placed in, it destructs a StorageStruct
instance. Just before the StorageStruct
instance is destructed, and after all possible handlers from this group were called, the task tree invokes the passed handler. This enables reading the final content of the given storage dynamically and processing it further outside of the task tree.
This handler is called also when the running tree is canceled. However, it's not called when the running tree is destructed.
Definition at line 661 of file tasktree.h.
|
inline |
Installs a storage setup handler for the storage to pass the initial data dynamically to the running task tree.
The StorageHandler
takes a reference to the StorageStruct
instance:
When the running task tree enters a Group where the storage is placed in, it creates a StorageStruct
instance, ready to be used inside this group. Just after the StorageStruct
instance is created, and before any handler of this group is called, the task tree invokes the passed handler. This enables setting up initial content for the given storage dynamically. Later, when any group's handler is invoked, the task tree activates the created and initialized storage, so that it's available inside any group's handler.
Definition at line 653 of file tasktree.h.
|
inline |
Returns the maximum progressValue().
Definition at line 649 of file tasktree.h.
References taskCount().
int Tasking::TaskTree::progressValue | ( | ) | const |
Returns the current progress value, which is between the 0
and progressMaximum().
The returned number indicates how many tasks have been already finished, canceled, or skipped while the task tree is running. When the task tree is started, this number is set to 0
. When the task tree is finished, this number always equals progressMaximum().
Definition at line 3379 of file tasktree.cpp.
References Tasking::TaskTreePrivate::m_progressValue.
|
signal |
This signal is emitted when the running task tree finished, canceled, or skipped some tasks.
The value gives the current total number of finished, canceled or skipped tasks. When the task tree is started, and after the started() signal was emitted, this signal is emitted with an initial value of 0
. When the task tree is about to finish, and before the done() signal is emitted, this signal is emitted with the final value of progressMaximum().
DoneWith Tasking::TaskTree::runBlocking | ( | ) |
Executes a local event loop with QEventLoop::ExcludeUserInputEvents and starts the task tree.
Returns DoneWith::Success if the task tree finished successfully; otherwise returns DoneWith::Error.
Definition at line 3225 of file tasktree.cpp.
References runBlocking().
Referenced by runBlocking(), and runBlocking().
|
static |
|
static |
Definition at line 3238 of file tasktree.cpp.
References TaskTree(), Tasking::Cancel, and done().
Sets a given recipe for the task tree.
After the task tree is started, it executes the tasks contained inside the recipe and handles finished tasks according to the passed description.
Definition at line 3105 of file tasktree.cpp.
References isRunning().
Referenced by TaskTree().
void Tasking::TaskTree::start | ( | ) |
Starts the task tree.
Use setRecipe() or the constructor to set the declarative description according to which the task tree will execute the contained tasks and handle finished tasks.
When the task tree is empty, that is, constructed with a default constructor, a call to start()
is no-op and the relevant warning message is issued.
Otherwise, when the task tree is already running, a call to start() is ignored and the relevant warning message is issued.
Otherwise, the task tree is started.
The started task tree may finish synchronously, for example when the main group's start handler returns SetupResult::StopWithError. For this reason, the connection to the done signal should be established before calling start()
. Use isRunning() in order to detect whether the task tree is still running after a call to start()
.
The task tree implementation relies on the running event loop. Make sure you have a QEventLoop or QCoreApplication or one of its subclasses running (or about to be run) when calling this method.
Definition at line 3141 of file tasktree.cpp.
References isRunning().
|
signal |
This signal is emitted when the task tree is started.
The emission of this signal is followed synchronously by the progressValueChanged() signal with an initial 0
value.
int Tasking::TaskTree::taskCount | ( | ) | const |
Returns the number of asynchronous tasks contained in the stored recipe.
1
.Definition at line 3341 of file tasktree.cpp.
Referenced by progressMaximum().
|
related |
The passed future is used for listening to the cancel event.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
When the task tree is canceled, this method cancels the passed future.
|
related |
The passed future is used for listening to the cancel event.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
When the task tree is canceled, this method cancels the passed future.
The passed future is used for listening to the cancel event.
Constructs a temporary task tree using the passed recipe and runs it blocking.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
When the task tree is canceled, this method cancels the passed future.
The optionally provided timeout is used to cancel the tree automatically after timeout milliseconds have passed.
Returns DoneWith::Success if the task tree finished successfully; otherwise returns DoneWith::Error.
Definition at line 3279 of file tasktree.cpp.
References TaskTree(), and runBlocking().
|
related |
The passed future is used for listening to the cancel event.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
When the task tree is canceled, this method cancels the passed future.
References TaskTree(), TaskTree(), and runBlocking().