itom
Loading...
Searching...
No Matches
ito::FunctionCancellationAndObserver Class Reference

This class can be passed to a long running method (e.g. as QSharedPointer instance) for two reasons: More...

#include <functionCancellationAndObserver.h>

Inheritance diagram for ito::FunctionCancellationAndObserver:

Public Types

enum  CancellationReason { ReasonGeneral = 1 , ReasonKeyboardInterrupt = 2 }
 

Public Slots

void requestCancellation (CancellationReason reason=CancellationReason::ReasonGeneral)
 call this method (from any thread) to signal a cancellation request.
 
void reset ()
 resets this object (e.g. emptys the current progress text, set the progress value to its minimum and resets the cancellation request)
 

Signals

void progressTextChanged (QString text)
 
void progressValueChanged (int value)
 
void cancellationRequested ()
 
void resetDone ()
 

Public Member Functions

 FunctionCancellationAndObserver (int progressMinimum=0, int progressMaximum=100, QObject *parent=NULL)
 constructor
 
virtual ~FunctionCancellationAndObserver ()
 destructor (do not call directly, instead free the semaphore by ItomSharedSemaphore::deleteSemaphore
 
bool isCancelled () const
 return true if a cancellation request has been signalled. Else false.
 
CancellationReason cancellationReason ()
 return the cancellation reason (call this only if isCancelled returned true)
 
int progressMinimum () const
 returns the minimum progress value
 
int progressMaximum () const
 returns the maximum progress value
 
void setProgressValue (int value)
 changes the current value of the progress.
 
int progressValue () const
 returns the current progress value
 
void setProgressText (const QString &text)
 changes the current text of the progress
 
QString progressText ()
 returns the current text of the progress
 

Private Member Functions

 Q_DECLARE_PRIVATE (FunctionCancellationAndObserver)
 

Private Attributes

QScopedPointer< FunctionCancellationAndObserverPrivated_ptr
 

Detailed Description

This class can be passed to a long running method (e.g. as QSharedPointer instance) for two reasons:

  1. The long running method can use the progress methods in order to signal a progress. These changes of the progress are then signalled using specific signals.
  2. The caller of the long running method can set a cancellation request. The method itself should then check for the existence of this request and stop its calculation. The method should then return with an error message.

This method is fully thread-safe such that read and write methods for progress as well as cancellation status can be called from different threads.

Constructor & Destructor Documentation

◆ FunctionCancellationAndObserver()

ito::FunctionCancellationAndObserver::FunctionCancellationAndObserver ( int progressMinimum = 0,
int progressMaximum = 100,
QObject * parent = NULL )

constructor

A new FuncitonCancellationAndObserver object is created.

Pass this object to a function (thread-safe) in order to signal a possible cancellation request and / or to let the function signal its current progress (value and / or text).

The progress should always be reported in the given range [progressMinimum, progressMaximum]

Member Function Documentation

◆ Q_DECLARE_PRIVATE()

ito::FunctionCancellationAndObserver::Q_DECLARE_PRIVATE ( FunctionCancellationAndObserver )
private

‍self-managed pointer to the private class container (deletes itself if d_ptr is destroyed)


The documentation for this class was generated from the following files: