GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/gepetto/gui/safeapplication.hh Lines: 0 10 0.0 %
Date: 2023-03-14 11:04:37 Branches: 0 2 0.0 %

Line Branch Exec Source
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
26
namespace gepetto {
27
namespace gui {
28
class SlotExceptionCatch {
29
 public:
30
  SlotExceptionCatch() : child_(NULL) {}
31
32
  /// Inherited classes must call impl_notify method surronded by a try/catch
33
  virtual bool safeNotify(QApplication* app, QObject* receiver, QEvent* e) = 0;
34
35
  void addAsLeaf(SlotExceptionCatch* child) {
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
50
  SlotExceptionCatch* child_;
51
};
52
53
class 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