Image Component Library (ICL)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Slots | Static Private Attributes | List of all members
icl::qt::ICLApplication Class Reference

QApplication extension for ICL based applications. More...

#include <Application.h>

Inheritance diagram for icl::qt::ICLApplication:

Classes

struct  AsynchronousEvent
 interface for events that must be executed in the GUI Thread More...
 
struct  SecondSingeltonException
 Such an exception is returned if a 2nd instance of ICLApplication is created. More...
 

Public Types

typedef void(* callback) (void)
 just type definition for convenience a void valued function with no args) More...
 

Public Member Functions

 ICLApplication (int argc, char **argv, const std::string &paInitString="", callback init=0, callback run=0, callback run2=0, callback run3=0, callback run4=0, callback run5=0)
 Constructor. More...
 
 ~ICLApplication ()
 Destructor. More...
 
void addThread (callback cb)
 adds a new threaded function More...
 
void addInit (callback cb)
 adds a new initialization function More...
 
void addFinalization (callback cb)
 adds a new finalization function More...
 
void addPrepareShutDown (callback cb)
 adds a new preparation-for-shutdown function More...
 
int exec ()
 executes this ICLApplication More...
 
void executeInGUIThread (AsynchronousEvent *event, bool blocking=false, bool forcePostEvent=false)
 internally posts the event to the GUI Thread More...
 
template<class T >
void executeInGUIThread (utils::Function< void, T > f, T data, bool blocking=false, bool forcePostEvent=false)
 utility class for executing functions with given arguments in the GUI thread More...
 
template<class T , class U >
void executeInGUIThread (utils::Function< void, T, U > f, T t, U u, bool blocking=false, bool forcePostEvent=false)
 utility class for executing functions with given arguments in the GUI thread More...
 
virtual bool event (QEvent *eIn)
 overloaded event function More...
 

Static Public Member Functions

static ICLApplicationinstance ()
 returns the singelton ICLApplication instance (or NULL if there is none) More...
 
static bool isGUIThreadActive ()
 returns whether we are currently in the GUI thread More...
 

Public Attributes

QApplication * app
 
QGLWidget * sharedWidget
 

Private Slots

void lastWindowClosed ()
 

Static Private Attributes

static ICLApplications_app
 singelton instance More...
 
static std::vector< ExecThread * > s_threads
 list of threads More...
 
static std::vector< callbacks_inits
 list of initialization functions More...
 
static std::vector< callbacks_callbacks
 list of callback functions More...
 
static std::vector< callbacks_finalizes
 list of finalization functions More...
 
static std::vector< callbacks_prepare_shutdowns
 list of finalization functions More...
 

Detailed Description

QApplication extension for ICL based applications.

After the 100th time of writing

void init(){...}
void run(){...}
int main(int n, char **ppc){
pa_init("...");
ExecThread x(run);
QApplication app(n,ppc);
init();
x.run();
return app.exec();
}

I wrote a utility class that does all the stuff above for me:

void init(){...}
void run(){...}
int main(int n, char **ppc){
return ICLApplication(n,ppc,"...",init,run).exec();
}

Of course sometimes we need more than on initialization functions or even more than one extra-thread:

void init1(){...}
void init2(){...}
void run1(){...}
void run2(){...}
void run3(){...}
int main(int n, char **ppc){
ICLApplication app(n,ppc,"...");
app.addInit(init1);
app.addInit(init2);
app.addThread(run1);
app.addThread(run2);
app.addThread(run3);
return app.exec();
}

I guess there's nothing more to explain, isn't it?

Member Typedef Documentation

◆ callback

typedef void(* icl::qt::ICLApplication::callback) (void)

just type definition for convenience a void valued function with no args)

Constructor & Destructor Documentation

◆ ICLApplication()

icl::qt::ICLApplication::ICLApplication ( int  argc,
char **  argv,
const std::string &  paInitString = "",
callback  init = 0,
callback  run = 0,
callback  run2 = 0,
callback  run3 = 0,
callback  run4 = 0,
callback  run5 = 0 
)

Constructor.

Parameters
argcC++-main function arg-count
argvC++-main function argument list (as obtained by int main(argc,argv))
paInitStringif not equal to "", pa_init is called with this string
initinitialization function pointer. Which is just called once when exec() is called
runfirst threaded function which is called in a loop before the QApplication is started using QApplication::exec();
run2second threaded function which is called in a loop before the QApplication is started using QApplication::exec();
run3third threaded function which is called in a loop before the QApplication is started using QApplication::exec();
run4fourth threaded function which is called in a loop before the QApplication is started using QApplication::exec();
run5fifth threaded function which is called in a loop before the QApplication is started using QApplication::exec();

◆ ~ICLApplication()

icl::qt::ICLApplication::~ICLApplication ( )

Destructor.

Member Function Documentation

◆ addFinalization()

void icl::qt::ICLApplication::addFinalization ( callback  cb)

adds a new finalization function

Finalization functions are called, when the singelton ICLApplication instance is deleted

◆ addInit()

void icl::qt::ICLApplication::addInit ( callback  cb)

adds a new initialization function

Initialization functions are called at the beginning of an ICLApplication::exec() call

◆ addPrepareShutDown()

void icl::qt::ICLApplication::addPrepareShutDown ( callback  cb)

adds a new preparation-for-shutdown function

Prepare for shutdown functions are called, when the singelton ICLApplication instance is deleted and before the worker threads are stopped!

◆ addThread()

void icl::qt::ICLApplication::addThread ( callback  cb)

adds a new threaded function

Threaded function are executed in a loop. Execution is started immediately before the QApplication is executed within ICLApplication::exec()

◆ event()

virtual bool icl::qt::ICLApplication::event ( QEvent *  eIn)
virtual

overloaded event function

◆ exec()

int icl::qt::ICLApplication::exec ( )

executes this ICLApplication

callbacks are executed in the following order: init functions, entry by entry in same order as their addition to this instance threads functions, are started in a extra thead, entry by entry in same order as their addition to this instance QApplication is executed and it's return code is f passed using 'return QApplication::exec();'

◆ executeInGUIThread() [1/3]

void icl::qt::ICLApplication::executeInGUIThread ( AsynchronousEvent event,
bool  blocking = false,
bool  forcePostEvent = false 
)

internally posts the event to the GUI Thread

The event's ownwership is passed. It is deleted internally after it is processed (please note, that the deletion will also take place within the GUI thread

◆ executeInGUIThread() [2/3]

template<class T >
void icl::qt::ICLApplication::executeInGUIThread ( utils::Function< void, T >  f,
data,
bool  blocking = false,
bool  forcePostEvent = false 
)
inline

utility class for executing functions with given arguments in the GUI thread

This function is a simple convenience wrapper for executeInGUIThread(AsynchronousEvent*,bool)

◆ executeInGUIThread() [3/3]

template<class T , class U >
void icl::qt::ICLApplication::executeInGUIThread ( utils::Function< void, T, U >  f,
t,
u,
bool  blocking = false,
bool  forcePostEvent = false 
)
inline

utility class for executing functions with given arguments in the GUI thread

This function is a simple convenience wrapper for executeInGUIThread(AsynchronousEvent*,bool)

◆ instance()

static ICLApplication* icl::qt::ICLApplication::instance ( )
static

returns the singelton ICLApplication instance (or NULL if there is none)

◆ isGUIThreadActive()

static bool icl::qt::ICLApplication::isGUIThreadActive ( )
static

returns whether we are currently in the GUI thread

◆ lastWindowClosed

void icl::qt::ICLApplication::lastWindowClosed ( )
privateslot

Member Data Documentation

◆ app

QApplication* icl::qt::ICLApplication::app

◆ s_app

ICLApplication* icl::qt::ICLApplication::s_app
staticprivate

singelton instance

◆ s_callbacks

std::vector<callback> icl::qt::ICLApplication::s_callbacks
staticprivate

list of callback functions

◆ s_finalizes

std::vector<callback> icl::qt::ICLApplication::s_finalizes
staticprivate

list of finalization functions

◆ s_inits

std::vector<callback> icl::qt::ICLApplication::s_inits
staticprivate

list of initialization functions

◆ s_prepare_shutdowns

std::vector<callback> icl::qt::ICLApplication::s_prepare_shutdowns
staticprivate

list of finalization functions

◆ s_threads

std::vector<ExecThread*> icl::qt::ICLApplication::s_threads
staticprivate

list of threads

◆ sharedWidget

QGLWidget* icl::qt::ICLApplication::sharedWidget

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