gepetto-viewer  4.13.0
An user-friendly Graphical Interface
safeapplication.hh
Go to the documentation of this file.
1 // Copyright (c) 2015-2018, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef GEPETTO_GUI_SAFEAPPLICATION_HH
18 #define GEPETTO_GUI_SAFEAPPLICATION_HH
19 
20 #include <assert.h>
21 
22 #include <QApplication>
23 #include <gepetto/gui/fwd.hh>
24 
25 namespace gepetto {
26 namespace gui {
28  public:
30 
32  virtual bool safeNotify(QApplication* app, QObject* receiver, QEvent* e) = 0;
33 
35  if (child_ == NULL)
36  child_ = child;
37  else
38  child_->addAsLeaf(child);
39  }
40 
41  protected:
42  bool impl_notify(QApplication* app, QObject* receiver, QEvent* e) {
43  if (child_ == NULL)
44  return app->QApplication::notify(receiver, e);
45  else
46  return child_->safeNotify(app, receiver, e);
47  }
48 
50 };
51 
52 class SafeApplication : public QApplication, public SlotExceptionCatch {
53  public:
54  explicit SafeApplication(int& argc, char** argv) : QApplication(argc, argv) {}
55 
56  bool notify(QObject* receiver, QEvent* e) {
57  return impl_notify(this, receiver, e);
58  }
59 
60  private:
61  bool safeNotify(QApplication*, QObject*, QEvent*) {
62  assert(false);
63  return false;
64  };
65 };
66 } // namespace gui
67 } // namespace gepetto
68 
69 #endif // GEPETTO_GUI_SAFEAPPLICATION_HH
Definition: safeapplication.hh:52
Definition: safeapplication.hh:27
Definition: action-search-bar.hh:26
virtual bool safeNotify(QApplication *app, QObject *receiver, QEvent *e)=0
Inherited classes must call impl_notify method surronded by a try/catch.
bool impl_notify(QApplication *app, QObject *receiver, QEvent *e)
Definition: safeapplication.hh:42
bool notify(QObject *receiver, QEvent *e)
Definition: safeapplication.hh:56
SafeApplication(int &argc, char **argv)
Definition: safeapplication.hh:54
void addAsLeaf(SlotExceptionCatch *child)
Definition: safeapplication.hh:34
SlotExceptionCatch()
Definition: safeapplication.hh:29
SlotExceptionCatch * child_
Definition: safeapplication.hh:49