]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_DialogRunner.cxx
Salome HOME
PAL10332 - references are interpreted as original objects in filters, dialogs, etc.
[modules/visu.git] / src / VISUGUI / VisuGUI_DialogRunner.cxx
1 // File:        VisuGUI_DialogRunner.cxx
2 // Created:     Thu Oct  6 10:17:39 2005
3 // Author:      Alexander SOLOVYOV
4 //              <asl@multiplex.nnov.opencascade.com>
5
6 #include "VisuGUI_DialogRunner.h"
7
8 #include <qdialog.h>
9 #include <qapplication.h>
10
11 VisuGUI_DialogRunner::VisuGUI_DialogRunner( QDialog* dlg )
12 : QObject(),
13   myDlg( dlg ),
14   myInLoop( false )
15 {
16   if( myDlg )
17   {
18     connect( myDlg, SIGNAL( destroyed() ), this, SLOT( onDialogDelete() ) );
19     myDlg->installEventFilter( this );
20   }
21 }
22
23 VisuGUI_DialogRunner::~VisuGUI_DialogRunner()
24 {
25 }
26
27 int VisuGUI_DialogRunner::run( const bool modal )
28 {
29   if( myInLoop || !myDlg )
30     return -1;
31
32   if( modal )
33     return myDlg->exec();
34
35   myInLoop = true;
36   myDlg->show();
37   qApp->enter_loop();
38   return myDlg->result();
39 }
40
41 void VisuGUI_DialogRunner::onDialogDelete()
42 {
43   if( myInLoop )
44     qApp->exit_loop();
45
46   myDlg = 0;
47   myInLoop = false;
48 }
49
50 bool VisuGUI_DialogRunner::eventFilter( QObject* o, QEvent* e )
51 {
52   if( o==myDlg && e && ( e->type()==QEvent::Close || e->type()==QEvent::Hide ) )
53   {
54     if( myInLoop && !myDlg->isMinimized() )
55     {
56       myInLoop = false;
57       qApp->exit_loop();
58     }
59     return false;
60   }
61   else
62     return QObject::eventFilter( o, e );
63 }