Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExceptionList.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include <memory>
20 #include <omni/exception.h>
21 #include <QDialog>
22 #include <QStandardItemModel>
23 
24 namespace omni {
25  namespace ui {
26  namespace Ui {
27  class ExceptionList;
28  }
29 
30  /// A list of all exceptions occured during a process
31  class ExceptionList : public QDialog {
32  Q_OBJECT
33 
34  public:
35  ExceptionList(QWidget * = nullptr);
37 
38  /// Add exception to list
39  void addException(Exception const&);
40 
41  /// Number of exceptions in list
42  int exceptionCount() const;
43 
44  public slots:
45  /// Clear list of exceptions
46  void clear();
47 
48  private:
49  void setupModel();
50 
51  std::unique_ptr<Ui::ExceptionList> ui_;
52  std::unique_ptr<QStandardItemModel> model_;
53  };
54 
55  // Function body template for a try...catch block with executing exception list widget
56  template<typename EXCEPTION, typename F>
58  std::unique_ptr<ExceptionList> _widget(new ExceptionList);
59  try {
60  f();
61  } catch(EXCEPTION& _e) {
62  _widget->addException(_e);
63  }
64  if (_widget->exceptionCount() > 0) {
65  _widget->exec();
66  }
67  }
68  }
69 }
void clear()
Clear list of exceptions.
Definition: ExceptionList.cpp:50
ExceptionList(QWidget *=nullptr)
Definition: ExceptionList.cpp:26
std::unique_ptr< Ui::ExceptionList > ui_
Definition: ExceptionList.h:51
~ExceptionList()
Definition: ExceptionList.cpp:34
int exceptionCount() const
Number of exceptions in list.
Definition: ExceptionList.cpp:55
void setupModel()
Definition: ExceptionList.cpp:59
A list of all exceptions occured during a process.
Definition: ExceptionList.h:31
Base class for all exception. Throws a message with QString type.
Definition: exception.h:29
void addException(Exception const &)
Add exception to list.
Definition: ExceptionList.cpp:36
std::unique_ptr< QStandardItemModel > model_
Definition: ExceptionList.h:52
void tryWithExceptionList(F f)
Definition: ExceptionList.h:57