gepetto-viewer 6.0.0
An user-friendly Graphical Interface
Loading...
Searching...
No Matches
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 <gepetto/gui/fwd.hh>
21// This include must be include before any other Qt include for GLDEBUGPROC
22#include <assert.h>
23
24#include <QApplication>
25
26namespace gepetto {
27namespace gui {
29 public:
31
33 virtual bool safeNotify(QApplication* app, QObject* receiver, QEvent* e) = 0;
34
36 if (child_ == NULL)
37 child_ = child;
38 else
39 child_->addAsLeaf(child);
40 }
41
42 protected:
43 bool impl_notify(QApplication* app, QObject* receiver, QEvent* e) {
44 if (child_ == NULL)
45 return app->QApplication::notify(receiver, e);
46 else
47 return child_->safeNotify(app, receiver, e);
48 }
49
51};
52
53class SafeApplication : public QApplication, public SlotExceptionCatch {
54 public:
55 explicit SafeApplication(int& argc, char** argv) : QApplication(argc, argv) {}
56
57 bool notify(QObject* receiver, QEvent* e) {
58 return impl_notify(this, receiver, e);
59 }
60
61 private:
62 bool safeNotify(QApplication*, QObject*, QEvent*) {
63 assert(false);
64 return false;
65 };
66};
67} // namespace gui
68} // namespace gepetto
69
70#endif // GEPETTO_GUI_SAFEAPPLICATION_HH
Definition safeapplication.hh:53
bool notify(QObject *receiver, QEvent *e)
Definition safeapplication.hh:57
SafeApplication(int &argc, char **argv)
Definition safeapplication.hh:55
Definition safeapplication.hh:28
SlotExceptionCatch * child_
Definition safeapplication.hh:50
void addAsLeaf(SlotExceptionCatch *child)
Definition safeapplication.hh:35
bool impl_notify(QApplication *app, QObject *receiver, QEvent *e)
Definition safeapplication.hh:43
virtual bool safeNotify(QApplication *app, QObject *receiver, QEvent *e)=0
Inherited classes must call impl_notify method surronded by a try/catch.
SlotExceptionCatch()
Definition safeapplication.hh:30
Definition action-search-bar.hh:27