| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef PatternistSDK_ErrorHandler_H |
| 30 | #define PatternistSDK_ErrorHandler_H |
| 31 | |
| 32 | #include "Global.h" |
| 33 | #include "qabstractmessagehandler.h" |
| 34 | |
| 35 | |
| 36 | QT_BEGIN_NAMESPACE |
| 37 | |
| 38 | template<typename T> class QList; |
| 39 | |
| 40 | namespace QPatternistSDK |
| 41 | { |
| 42 | /** |
| 43 | * @short A MessageHandler which |
| 44 | * accumulates all its received ErrorHandler::Message instances |
| 45 | * in a list, retrievable via messages(). |
| 46 | * |
| 47 | * Thus, ErrorHandler does not report errors, but collects them |
| 48 | * and allows easy access to them. |
| 49 | * |
| 50 | * @ingroup PatternistSDK |
| 51 | * @author Frans Englich <frans.englich@nokia.com> |
| 52 | */ |
| 53 | class ErrorHandler : public QAbstractMessageHandler |
| 54 | { |
| 55 | public: |
| 56 | class Message |
| 57 | { |
| 58 | public: |
| 59 | typedef QList<Message> List; |
| 60 | |
| 61 | QString description() const |
| 62 | { |
| 63 | return m_description; |
| 64 | } |
| 65 | |
| 66 | void setDescription(const QString &desc) |
| 67 | { |
| 68 | m_description = desc; |
| 69 | } |
| 70 | |
| 71 | void setIdentifier(const QUrl &newId) |
| 72 | { |
| 73 | m_identifier = newId; |
| 74 | } |
| 75 | |
| 76 | QUrl identifier() const |
| 77 | { |
| 78 | return m_identifier; |
| 79 | } |
| 80 | |
| 81 | QtMsgType type() const |
| 82 | { |
| 83 | return m_type; |
| 84 | } |
| 85 | |
| 86 | void setType(const QtMsgType t) |
| 87 | { |
| 88 | m_type = t; |
| 89 | } |
| 90 | |
| 91 | private: |
| 92 | QUrl m_identifier; |
| 93 | QtMsgType m_type; |
| 94 | QString m_description; |
| 95 | }; |
| 96 | |
| 97 | /** |
| 98 | * Clears all accumulated errors. |
| 99 | */ |
| 100 | void reset(); |
| 101 | |
| 102 | Message::List messages() const; |
| 103 | |
| 104 | /** |
| 105 | * Calling this function causes all Qt's internal debug messages to be |
| 106 | * sent to @p handler. If @p handler is @c null, Qt's default message |
| 107 | * handler is re-installed. In other words, via an internal proxy function, |
| 108 | * it installs @p handler as Qt's message handler. |
| 109 | * |
| 110 | * If @p handler is heap allocated, it will be leaked. |
| 111 | * |
| 112 | * @see qInstallMessageHandler() |
| 113 | */ |
| 114 | static void installQtMessageHandler(ErrorHandler *const handler); |
| 115 | |
| 116 | static ErrorHandler *handler; |
| 117 | |
| 118 | protected: |
| 119 | virtual void handleMessage(QtMsgType type, |
| 120 | const QString &description, |
| 121 | const QUrl &identifier = QUrl(), |
| 122 | const QSourceLocation &sourceLocation = QSourceLocation()); |
| 123 | |
| 124 | private: |
| 125 | ErrorHandler::Message::List m_messages; |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | QT_END_NAMESPACE |
| 130 | |
| 131 | #endif |
| 132 | // vim: et:ts=4:sw=4:sts=4 |
| 133 | |