GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/gepetto/gui/safeapplication.hh Lines: 0 11 0.0 %
Date: 2020-05-14 11:23:33 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 <assert.h>
21
22
#include <gepetto/gui/fwd.hh>
23
24
#include <QApplication>
25
26
namespace gepetto {
27
  namespace gui {
28
    class SlotExceptionCatch
29
    {
30
      public:
31
        SlotExceptionCatch () : child_ (NULL) {}
32
33
        /// Inherited classes must call impl_notify method surronded by a try/catch
34
        virtual bool safeNotify (QApplication* app, QObject* receiver, QEvent* e) = 0;
35
36
        void addAsLeaf (SlotExceptionCatch* child)
37
        {
38
          if (child_ == NULL) child_ = child;
39
          else child_->addAsLeaf (child);
40
        }
41
42
      protected:
43
        bool impl_notify(QApplication* app, QObject* receiver, QEvent* e)
44
        {
45
          if (child_ == NULL)
46
            return app->QApplication::notify(receiver, e);
47
          else
48
            return child_->safeNotify(app, receiver, e);
49
        }
50
51
        SlotExceptionCatch* child_;
52
    };
53
54
    class SafeApplication : public QApplication, public SlotExceptionCatch
55
    {
56
      public:
57
        explicit SafeApplication (int& argc, char ** argv)
58
          : QApplication(argc, argv) {}
59
60
        bool notify(QObject* receiver, QEvent* e)
61
        {
62
          return impl_notify (this, receiver, e);
63
        }
64
65
      private:
66
        bool safeNotify (QApplication*, QObject*, QEvent*) { assert(false); return false; };
67
    };
68
  } // namespace gui
69
} // namespace gepetto
70
71
#endif // GEPETTO_GUI_SAFEAPPLICATION_HH