| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 5 |
* * |
| 6 |
* This file is part of the FreeCAD CAx development system. * |
| 7 |
* * |
| 8 |
* This library is free software; you can redistribute it and/or * |
| 9 |
* modify it under the terms of the GNU Library General Public * |
| 10 |
* License as published by the Free Software Foundation; either * |
| 11 |
* version 2 of the License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* This library is distributed in the hope that it will be useful, * |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 |
* GNU Library General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Library General Public * |
| 19 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 20 |
* write to the Free Software Foundation, Inc., 51 Franklin Street, * |
| 21 |
* Fifth Floor, Boston, MA 02110-1301, USA * |
| 22 |
* * |
| 23 |
***************************************************************************/ |
| 24 |
|
| 25 |
|
| 26 |
#ifndef BASE_DEBUGGER_H |
| 27 |
#define BASE_DEBUGGER_H |
| 28 |
|
| 29 |
#include <QEventLoop> |
| 30 |
#include <QObject> |
| 31 |
#ifndef FC_GLOBAL_H |
| 32 |
# include <FCGlobal.h> |
| 33 |
#endif |
| 34 |
|
| 35 |
namespace Base |
| 36 |
{ |
| 37 |
/** |
| 38 |
This is a utility class to break the application at a point to inspect e.g. the result of |
| 39 |
an algorithm. |
| 40 |
You usually use it like this |
| 41 |
\code |
| 42 |
... |
| 43 |
Base::Debugger dbg; |
| 44 |
dbg.attach(); |
| 45 |
dbg.exec(); |
| 46 |
... |
| 47 |
\endcode |
| 48 |
Or you can connect it with a button and let the user click it in order to continue. |
| 49 |
\code |
| 50 |
QPushButton* btn = new QPushButton(); |
| 51 |
btn->setText("Continue"); |
| 52 |
btn->show(); |
| 53 |
Base::Debugger dbg; |
| 54 |
connect(btn, &QPushButton::clicked, &dbg, &Debugger::quit); |
| 55 |
dbg.exec(); |
| 56 |
\endcode |
| 57 |
\author Werner Mayer |
| 58 |
*/ |
| 59 |
class BaseExport Debugger: public QObject |
| 60 |
{ |
| 61 |
Q_OBJECT |
| 62 |
|
| 63 |
public: |
| 64 |
explicit Debugger(QObject* parent = nullptr); |
| 65 |
~Debugger() override; |
| 66 |
|
| 67 |
Debugger(const Debugger&) = delete; |
| 68 |
Debugger(Debugger&&) = delete; |
| 69 |
Debugger& operator=(const Debugger&) = delete; |
| 70 |
Debugger& operator=(Debugger&&) = delete; |
| 71 |
|
| 72 |
void attach(); |
| 73 |
void detach(); |
| 74 |
bool eventFilter(QObject* obj, QEvent* event) override; |
| 75 |
int exec(); |
| 76 |
|
| 77 |
public Q_SLOTS: |
| 78 |
void quit(); |
| 79 |
|
| 80 |
private: |
| 81 |
bool isAttached {false}; |
| 82 |
QEventLoop loop; |
| 83 |
}; |
| 84 |
|
| 85 |
} // namespace Base |
| 86 |
|
| 87 |
#endif // BASE_DEBUGGER_H |