The Task class is a ready to use implementation of the Qtilities::Core::Interfaces::ITask interface. More...
#include <Task.h>
Public Types | |
enum | TaskLifeTime { LifeTimeManual = 1, LifeTimeDestroyWhenSuccessful = 2, LifeTimeDestroyWhenSuccessfullWithWarnings = 4, LifeTimeDestroyWhenStopped = 8, LifeTimeDestroyWhenFailed = 16 } |
The possible ways that the lifetime of this task can be managed. More... | |
Public Types inherited from Qtilities::Core::Interfaces::ITask | |
enum | SubTaskPerformanceIndication { SubTaskNoPerformanceIndication = 0, SubTaskTimeFromTaskStart = 1 } |
Indicates how sub tasks are timed. More... | |
enum | TaskBusyState { TaskBusyClean = 0, TaskBusyWithWarnings = 1, TaskBusyWithErrors = 2 } |
The possible busy states of the task. More... | |
enum | TaskRemoveAction { TaskDeleteWhenRemoved = 0, TaskHideWhenRemoved = 1 } |
Indicates what should happen to the task when the user click's on the "Remove Task" button in a Qtilities::CoreGui::SingleTaskWidget. The "Stop Task" becomes the "Remove Task" button when the task was stopped or completed. More... | |
enum | TaskResult { TaskNoResult = 0, TaskSuccessful = 1, TaskSuccessfulWithWarnings = 2, TaskSuccessfulWithErrors = 3, TaskResultFromBusyStateFailOnError = 4, TaskResultFromBusyStateSuccessOnError = 5, TaskFailed = 6 } |
The possible results of a completed task. More... | |
enum | TaskState { TaskNotStarted = 1, TaskBusy = 2, TaskPaused = 4, TaskStopped = 8, TaskCompleted = 16, TaskIdle = TaskNotStarted | TaskCompleted | TaskStopped } |
The possible states in which a task might find itself. More... | |
enum | TaskStopAction { TaskDeleteWhenStopped = 0, TaskHideWhenStopped = 1, TaskDoNothingWhenStopped = 2 } |
Indicates what should happen to the task when the user stops it in a Qtilities::CoreGui::SingleTaskWidget. More... | |
enum | TaskStopConfirmation { TaskStopConfirmationNone = 0, TaskStopConfirmationMsgBox = 1 } |
Indicates if an confirmation message is required when an user stops the task in a Qtilities::CoreGui::SingleTaskWidget. More... | |
enum | TaskType { TaskLocal = 0, TaskGlobal = 1 } |
The possible types of tasks. More... |
Public Slots | |
void | addCompletedSubTasks (int number_of_sub_tasks=1, const QString &message=QString(), Logger::MessageType type=Logger::Info) |
Function which should be used to add completed tasks from the process's side. | |
bool | completeTask (ITask::TaskResult result=ITask::TaskResultFromBusyStateFailOnError, const QString &message=QString(), Logger::MessageType type=Logger::Info) |
Function which should be used to complete the task from the process's side. | |
virtual void | pause () |
Pauses the task from the user interface. | |
bool | pauseTask (const QString &message=QString(), Logger::MessageType type=Logger::Info) |
Function which should be used to stop tasks from the process's side. | |
virtual void | resume () |
Resumes the task after it has been paused. | |
bool | resumeTask (const QString &message=QString(), Logger::MessageType type=Logger::Info) |
Function which should be used to stop tasks from the process's side. | |
virtual void | start () |
Starts the task from the user interface. | |
bool | startTask (int expected_subtasks=-1, const QString &message=QString(), Logger::MessageType type=Logger::Info) |
Function which should be used to start tasks from the process's side. | |
virtual void | stop () |
Stops the task from the user interface. | |
bool | stopTask (const QString &message=QString(), Logger::MessageType type=Logger::Info) |
Function which should be used to stop tasks from the process's side. |
Signals | |
void | busyStateChanged (ITask::TaskBusyState new_busy_state, ITask::TaskBusyState old_busy_state) const |
Signal emitted when the busy state of the task changes. | |
void | canPauseChanged (bool new_value) const |
Signal emitted when a task's ability to be paused changed. | |
void | canStartChanged (bool new_value) const |
Signal emitted when a task's ability to be started changed. | |
void | canStopChanged (bool new_value) const |
Signal emitted when a task's ability to be stopped changed. | |
void | displayedNameChanged (const QString &displayed_name) const |
Signal emitted when the task's displayed name changes. | |
void | newMessageLogged (const QString &message, Logger::MessageType) const |
Signal emitted when the new messages are logged in this task. | |
void | stateChanged (ITask::TaskState new_state, ITask::TaskState old_state) const |
Signal emitted when the task's state changes. | |
void | subTaskCompleted (int number_task_completed=1, const QString &message=QString(), Logger::MessageType type=Logger::Info) const |
Signal emitted when subtasks are completed in order to show the correct progress information. | |
void | taskAboutToComplete () const |
Signal emitted when the task is about to be completed. | |
void | taskAboutToPause () const |
Signal emitted when the task is about to be paused. | |
void | taskAboutToResume () const |
Signal emitted when the task is about to be resumed from a paused state. | |
void | taskAboutToStart () const |
Signal emitted when the task is about to be started. | |
void | taskAboutToStop () const |
Signal emitted when the task is about to be stopped. | |
void | taskCompleted (ITask::TaskResult result, const QString &message=QString(), Logger::MessageType type=Logger::Info) const |
Signal emitted when the task started. | |
void | taskElapsedTimeChanged (int msec) const |
Signal emitted when the task's elapsed time changes. | |
void | taskPaused () const |
Signal emitted when the task is paused. | |
void | taskResumed () const |
Signal emitted when the task is resumed after it was paused. | |
void | taskStarted (int expected_subtasks=-1, const QString &message=QString(), Logger::MessageType type=Logger::Info) const |
Signal emitted when the task started. | |
void | taskStopped () const |
Signal emitted when the task is stopped during execution. | |
void | taskSubTaskAboutToComplete () const |
Signal emitted when a sub task is about to be completed. | |
void | taskTypeChanged (ITask::TaskType new_task_type) const |
Signal emitted when the task's type changes. |
Public Member Functions | |
TaskBusyState | busyState () const |
The busy state of the task. | |
bool | canPause () const |
bool | canStart () const |
bool | canStop () const |
void | clearLog () |
Clears the task's log. | |
bool | clearLogOnStart () const |
When true, the task's log will be cleared everytime the task is started. | |
int | currentProgress () const |
Returns the number of subtasks completed. | |
AbstractLoggerEngine * | customLoggerEngine () const |
Returns the custom logger engine used by this task. | |
QString | displayName () const |
Returns the display name for the task. The display name will typically be set just before emitting taskStarted() and contain a little bit more information than taskName(). | |
int | elapsedTime () const |
Returns the elapsed time in miliseconds of the last time the task was run. | |
QStringList | lastErrorMessages (int count) const |
Returns the last error logged in the task while it was busy. | |
int | lastErrorMessagesStackSize () const |
Gets the last error logged stack size. | |
void | logError (const QString &message) |
Convenience function to log an error in the task log. | |
AbstractLoggerEngine * | loggerEngine () const |
Returns a reference to the logger engine logging activities of this task. When loggingEnabled() is false, this function will always return 0. | |
bool | loggingEnabled () const |
Indicates if the activities of this task is logged. | |
void | logMessage (const QString &message, Logger::MessageType type=Logger::Info) |
Logs a message to this task. | |
void | logWarning (const QString &message) |
Convenience function to log a warning in the task log. | |
int | numberOfSubTasks () const |
Returns the number of subtasks associated with the task. | |
QObject * | objectBase () |
Returns the QObject* base of the interface. | |
const QObject * | objectBase () const |
Returns a const QObject* base of the interface. | |
ITask * | parentTask () const |
The parent task of this task. | |
void | removeCustomLoggerEngine () |
Removes the current custom logger engine from this task. | |
void | removeParentTask () |
Removes the parent task of this task. | |
TaskResult | result () const |
The result of the task. | |
void | setClearLogOnStart (bool clear_log_on_start=true) const |
Sets if the log must be cleared when the task is started. | |
void | setCustomLoggerEngine (AbstractLoggerEngine *engine, bool use_only_this_engine=false) |
Sets a custom logger engine to be used by this task. | |
void | setDisplayName (const QString &display_name) |
Sets the display name of the task. | |
void | setLastErrorMessagesStackSize (int size) |
Sets the last error logged stack size. | |
void | setLastRunTime (int msec) |
This function allows you to overwrite the last run time of the task. | |
void | setLogContext (Logger::MessageContextFlags message_context) |
Sets the default message logging context flags of this task. | |
void | setLoggerEngine (AbstractLoggerEngine *engine) |
Sets the logger engine to be used by this task. | |
void | setParentTask (ITask *parent_task) |
void | setSubTaskPerformanceIndication (SubTaskPerformanceIndication performance_indication) |
Sets what performance measures are used for sub tasks. | |
void | setTaskLifeTimeFlags (TaskLifeTimeFlags task_lifetime_flags) |
Sets the task lifetime. | |
void | setTaskName (const QString &task_name) |
Sets the name of the task. | |
void | setTaskRemoveAction (TaskRemoveAction task_remove_action) |
Sets the task's remove action. | |
void | setTaskStopAction (TaskStopAction task_stop_action) |
Sets the task's stop action. | |
void | setTaskStopConfirmation (TaskStopConfirmation task_stop_confirmation) |
Sets the task's stop configuration action. | |
void | setTaskType (TaskType task_type) |
Sets the task type. | |
TaskState | state () const |
The state of the task. | |
SubTaskPerformanceIndication | subTaskPerformanceIndication () const |
Gets what performance measures are used for sub tasks. | |
Task (const QString &task_name, bool enable_logging=true, QObject *parent=0) | |
Default constructor. | |
TaskLifeTimeFlags | taskLifeTimeFlags () const |
Gets the task lifetime. | |
QString | taskName () const |
The name of the task. | |
TaskRemoveAction | taskRemoveAction () const |
Indicates what should happen to the task when the user click's on the "Remove Task" button in a Qtilities::CoreGui::SingleTaskWidget. | |
TaskStopAction | taskStopAction () const |
Indicates what should happen to the task when the user click's on the "Stop Task" button in a Qtilities::CoreGui::SingleTaskWidget. | |
TaskStopConfirmation | taskStopConfirmation () const |
Indicates what should happen to the task when the user click's on the "Stop Task" button in a Qtilities::CoreGui::SingleTaskWidget. | |
TaskType | taskType () const |
The type of this task. | |
Public Member Functions inherited from Qtilities::Core::Interfaces::ITask | |
bool | elapsedTimeChangedNotificationsEnabled () const |
Indicates if elapsed time changed notifications through taskElapsedTimeChanged() are enabled. | |
virtual QString | elapsedTimeString (int msec=-1, const QString &format="hh:mm:ss.zzz") const |
Returns the elapsed time of the task as a string. | |
int | getWidgetLoggerEngineDisplaysFlag () const |
Gets the (int) WidgetLoggerEngine::MessageDisplaysFlag used when assigning logger engines to tasks. | |
void | setWidgetLoggerEngineDisplaysFlag (int message_display_flags) |
Sets the (int) WidgetLoggerEngine::MessageDisplaysFlag used when assigning logger engines to tasks. | |
int | taskID () const |
The ID of this task. | |
void | toggleElapsedTimeChangedNotifications (bool is_enabled) |
Enables elapsed time changed notifications through taskElapsedTimeChanged(). | |
Public Member Functions inherited from Qtilities::Core::Interfaces::IObjectBase | |
QString | objectOriginID () const |
Allows interfaces to provide some sort of source identification. | |
void | setObjectOriginID (const QString &object_origin_id) |
Allows setting of the object source ID of this interface implementation. |
Additional Inherited Members | |
Static Public Member Functions inherited from Qtilities::Core::Interfaces::ITask | |
static void | logMessageToTask (const QString &message, ITask *task=0, Logger::MessageType type=Logger::Info) |
Message logging function which directs messages aimed for a task to the task if the task exists, or to the logger as system wide messages if the task does not exist. | |
static void | logPriorityMessageToTask (const QString &message, ITask *task=0, Logger::MessageType type=Logger::Info) |
Message logging function which logs the message as a priority message and directs messages aimed for a task to the task if the task exists, or to the logger as system wide messages if the task does not exist. |
The Task class is a ready to use implementation of the Qtilities::Core::Interfaces::ITask interface.
See the Tasking article for more information on tasking.
This class was added in Qtilities v1.0.
The possible ways that the lifetime of this task can be managed.
The default is LifetimeManual.
Qtilities::Core::Task::Task | ( | const QString & | task_name, |
bool | enable_logging = true , |
||
QObject * | parent = 0 |
||
) |
Default constructor.
task_name | A name for the task. |
enable_logging | When true, the activity of this task will be logged. Thus, logMessage() will route messages to a logger engine created for this task. |
|
virtual |
The busy state of the task.
Default is TaskBusyClean.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the busy state of the task changes.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
False by default in Qtilities::Core::Task.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when a task's ability to be paused changed.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
False by default in Qtilities::Core::Task.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when a task's ability to be started changed.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
False by default in Qtilities::Core::Task.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when a task's ability to be stopped changed.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Returns the number of subtasks completed.
Default implementation returns 0, thus no sub tasks.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Returns the custom logger engine used by this task.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task's displayed name changes.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Returns the display name for the task. The display name will typically be set just before emitting taskStarted() and contain a little bit more information than taskName().
The default implementation will just return the task name for the task. However in many cases its possible to provide a more detailed name to display in any task widget.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Returns the elapsed time in miliseconds of the last time the task was run.
When a task was paused, the timer will continue to time for the duration that the task was paused.
When the task has not been run 0 is returned. When busy the function will return the elapsed time when the function is called. When the task is completed, the function will return the total time the task took to complete.
This function was added in Qtilities v1.1.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Returns the last error logged in the task while it was busy.
count | The number of messages to return. Note that the maximum returnable number of messages are defined by errorMessageStackSize(). Also, if the number of error messages that were logged at the time this function is called is less than the count specified, only the number of currently logged messages will be returned. When -1 (default) all messages in the stack are returned. |
This function was added in Qtilities v1.4.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Gets the last error logged stack size.
The default is 10.
This function was added in Qtilities v1.4.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Returns a reference to the logger engine logging activities of this task. When loggingEnabled() is false, this function will always return 0.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Indicates if the activities of this task is logged.
False by default.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the new messages are logged in this task.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Returns the number of subtasks associated with the task.
Default implementation returns -1, thus no sub tasks.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
inlinevirtual |
Returns a const QObject* base of the interface.
This function can be used in const methods, but make sure that you don't modify things that should stay const. An example where this is used is when we want to get a property on an object in a const method. This is a const operation.
Implements Qtilities::Core::Interfaces::IObjectBase.
|
virtual |
The parent task of this task.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualslot |
Pauses the task from the user interface.
In Qtilities::Core::Task, the task will emit pauseTaskRequest() which must be handled by the process represented by Task. Qtilities::Core::QtilitiesProcess is a good example of this.
The task can be resumed through resume().
The default implementation of ITask does nothing.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Removes the current custom logger engine from this task.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Removes the parent task of this task.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
|
virtualslot |
Resumes the task after it has been paused.
In Qtilities::Core::Task, the task will emit resumeTaskRequest() which must be handled by the process represented by Task. Qtilities::Core::QtilitiesProcess is a good example of this.
The default implementation of ITask does nothing.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Sets if the log must be cleared when the task is started.
True by default.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Sets a custom logger engine to be used by this task.
The task will not take ownership of the custom logger engine.
use_only_this_engine | When true, the task's own logger engine will be deleted and only the custom engine will be used to log messages. |
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Sets the last error logged stack size.
size | The new size of the last error messages stack. |
This function was added in Qtilities v1.4.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
This function allows you to overwrite the last run time of the task.
setElapsedTime This is usefull when you need to restore the state of a task for example.
msec | The new elapsed time in msec. |
This function was added in Qtilities v1.2.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Sets the default message logging context flags of this task.
Default is Logger::EngineSpecificMessages.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Sets the logger engine to be used by this task.
When logging is enabled this function will be called automatically by Qtilities::CoreGui::TaskManagerGui when the task is registered in the global object pool.
If you want this task's messages to be logged in a different logger engine you should call setCustomLoggerEngine(). An example where this is usefull is when you want to log the messages of a task in the log of another task. In that case, call setCustomLoggerEngine() with the loggerEngine() of the task where the messages should be logged.
The task will take ownership of the logger engine. This function can only be called once. Thus, if the task already has a logger engine calling this function will do nothing. To use a custom logger engine, see setCustomLoggerEngine().
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
The lifetime of the parent task will be tracked. Thus, if your parent task is deleted this task will stop to log messages to it.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Sets what performance measures are used for sub tasks.
This function was added in Qtilities v1.1.
Implements Qtilities::Core::Interfaces::ITask.
void Qtilities::Core::Task::setTaskLifeTimeFlags | ( | TaskLifeTimeFlags | task_lifetime_flags | ) |
Sets the task lifetime.
Set this before starting your task.
void Qtilities::Core::Task::setTaskName | ( | const QString & | task_name | ) |
Sets the name of the task.
task_name | The new name of the task. This name is not validated in here, thus make sure its correct. |
This function was added in Qtilities v1.2.
|
virtual |
Sets the task's stop configuration action.
This function was added in Qtilities v1.3.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualslot |
Starts the task from the user interface.
The slot called when the user starts the task from it's Qtilities::CoreGui::SingleTaskWidget. Programmatically, you should use startTask() instead of start(). In Qtilities::Core::Task, the task will emit startTaskRequest() which must be handled by the task represented by Task. Qtilities::Core::QtilitiesProcess is a good example of this.
The default implementation of ITask does nothing.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
|
virtualsignal |
Signal emitted when the task's state changes.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualslot |
Stops the task from the user interface.
In Qtilities::Core::Task, the task will emit stopTaskRequest() which must be handled by the process represented by Task. Qtilities::Core::QtilitiesProcess is a good example of this.
The default implementation of ITask does nothing.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when subtasks are completed in order to show the correct progress information.
number_task_completed | The number of subtasks completed, 1 by default. |
subtask_message | A message which describes the subtask(s) completed. |
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Gets what performance measures are used for sub tasks.
Default is SubTaskTimeFromTaskStart.
This function was added in Qtilities v1.1.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is about to be completed.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is about to be paused.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is about to be resumed from a paused state.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is about to be started.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is about to be stopped.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task started.
result | The result of the task. |
message | A message which describes the completion of the task. |
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task's elapsed time changes.
This function is only emitted while the task is busy, and when elapsed time change notifications are enabled. See toggleElapsedTimeChangedNotifications(). When enabled, it will emit every second while the task is busy.
The | elapsed time in miliseconds of the task at the time that the signal was emitted. You can format the received msec value to a string using elapsedTimeString(). |
This function is only emitted while the task is busy.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
The name of the task.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is paused.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Indicates what should happen to the task when the user click's on the "Remove Task" button in a Qtilities::CoreGui::SingleTaskWidget.
Default is TaskHideWhenRemoved.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is resumed after it was paused.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task started.
expected_subtasks | The number of subtasks which must be completed in order for this task to complete. If you don't provide the number of subtasks, progress for the task will be shown as a progress bar as a busy indicator. See QProgressBar for more information on this. If you do provide the number of subtasks, the progress be updated everytime subtaskCompleted() is emitted. |
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
Indicates what should happen to the task when the user click's on the "Stop Task" button in a Qtilities::CoreGui::SingleTaskWidget.
Default is TaskDoNothingWhenStopped.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtual |
Indicates what should happen to the task when the user click's on the "Stop Task" button in a Qtilities::CoreGui::SingleTaskWidget.
Default is TaskStopConfirmationMsgBox.
This function was added in Qtilities v1.3.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task is stopped during execution.
Implements Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when a sub task is about to be completed.
Implements Qtilities::Core::Interfaces::ITask.
|
virtual |
The type of this task.
Default is TaskGlobal.
Reimplemented from Qtilities::Core::Interfaces::ITask.
|
virtualsignal |
Signal emitted when the task's type changes.
Implements Qtilities::Core::Interfaces::ITask.
Qtilities : Reference Documentation | Back to top |
Copyright © 2009-2013, Jaco Naudé
|