322317f5044b11bd4aa2bb68d3227b5113d15520
[profile/ivi/qtxmlpatterns.git] / tests / auto / xmlpatternssdk / ErrorHandler.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef PatternistSDK_ErrorHandler_H
43 #define PatternistSDK_ErrorHandler_H
44
45 #include "Global.h"
46 #include "qabstractmessagehandler.h"
47
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 template<typename T> class QList;
54
55 namespace QPatternistSDK
56 {
57     /**
58      * @short A MessageHandler which
59      * accumulates all its received ErrorHandler::Message instances
60      * in a list, retrievable via messages().
61      *
62      * Thus, ErrorHandler does not report errors, but collects them
63      * and allows easy access to them.
64      *
65      * @ingroup PatternistSDK
66      * @author Frans Englich <frans.englich@nokia.com>
67      */
68     class Q_PATTERNISTSDK_EXPORT ErrorHandler : public QAbstractMessageHandler
69     {
70     public:
71         class Message
72         {
73         public:
74             typedef QList<Message> List;
75
76             QString description() const
77             {
78                 return m_description;
79             }
80
81             void setDescription(const QString &desc)
82             {
83                 m_description = desc;
84             }
85
86             void setIdentifier(const QUrl &newId)
87             {
88                 m_identifier = newId;
89             }
90
91             QUrl identifier() const
92             {
93                 return m_identifier;
94             }
95
96             QtMsgType type() const
97             {
98                 return m_type;
99             }
100
101             void setType(const QtMsgType t)
102             {
103                 m_type = t;
104             }
105
106         private:
107             QUrl        m_identifier;
108             QtMsgType   m_type;
109             QString     m_description;
110         };
111
112         /**
113          * Clears all accumulated errors.
114          */
115         void reset();
116
117         Message::List messages() const;
118
119         /**
120          * Calling this function causes all Qt's internal debug messages to be
121          * sent to @p handler. If @p handler is @c null, Qt's default message
122          * handler is re-installed. In other words, via an internal proxy function,
123          * it installs @p handler as Qt's message handler.
124          *
125          * If @p handler is heap allocated, it will be leaked.
126          *
127          * @see qInstallMsgHandler()
128          */
129         static void installQtMessageHandler(ErrorHandler *const handler);
130
131         static ErrorHandler *handler;
132
133     protected:
134         virtual void handleMessage(QtMsgType type,
135                                    const QString &description,
136                                    const QUrl &identifier = QUrl(),
137                                    const QSourceLocation &sourceLocation = QSourceLocation());
138
139     private:
140         ErrorHandler::Message::List m_messages;
141     };
142 }
143
144 QT_END_NAMESPACE
145
146 QT_END_HEADER
147
148 #endif
149 // vim: et:ts=4:sw=4:sts=4