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 QtXmlPatterns module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
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 Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "private/qobject_p.h" |
41 | #include "qabstractmessagehandler.h" |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | /*! |
46 | \class QAbstractMessageHandler |
47 | \since 4.4 |
48 | \ingroup xml-tools |
49 | \inmodule QtXmlPatterns |
50 | \brief The QAbstractMessageHandler class provides a callback interface for handling messages. |
51 | |
52 | QAbstractMessageHandler is an abstract base class that provides a |
53 | callback interface for handling messages. For example, class |
54 | QXmlQuery parses and runs an XQuery. When it detects a compile |
55 | or runtime error, it generates an appropriate error message, |
56 | but rather than output the message itself, it passes the message to |
57 | the message() function of its QAbstractMessageHandler. |
58 | See QXmlQuery::setMessageHandler(). |
59 | |
60 | You create a message handler by subclassing QAbstractMessageHandler |
61 | and implementing handleMessage(). You then pass a pointer to an |
62 | instance of your subclass to any classes that must generate |
63 | messages. The messages are sent to the message handler via the |
64 | message() function, which forwards them to your handleMessge(). |
65 | |
66 | A single instance of QAbstractMessageHandler can be called on to |
67 | handle messages from multiple sources. Hence, the content of a |
68 | message, which is the \e description parameter passed to message() |
69 | and handleMessage(), must be interpreted in light of the context |
70 | that required the message to be sent. That context is specified by |
71 | the \e identifier and \e sourceLocation parameters to message() |
72 | handleMessage(). |
73 | */ |
74 | |
75 | /*! |
76 | Constructs a QAbstractMessageHandler. The \a parent is passed |
77 | to the QObject base class constructor. |
78 | */ |
79 | QAbstractMessageHandler::QAbstractMessageHandler(QObject *parent) : QObject(parent) |
80 | { |
81 | } |
82 | |
83 | /*! |
84 | Destructs this QAbstractMessageHandler. |
85 | */ |
86 | QAbstractMessageHandler::~QAbstractMessageHandler() |
87 | { |
88 | } |
89 | |
90 | /*! |
91 | Sends a message to this message handler. \a type is the kind of |
92 | message being sent. \a description is the message content. The \a |
93 | identifier is a URI that identifies the message and is the key to |
94 | interpreting the other arguments. |
95 | |
96 | Typically, this class is used for reporting errors, as is the case |
97 | for QXmlQuery, which uses a QAbstractMessageHandler to report |
98 | compile and runtime XQuery errors. Hence, using a QUrl as the |
99 | message \a identifier is was inspired by the explanation of \l{error |
100 | handling in the XQuery language}. Because the \a identifier is |
101 | composed of a namespace URI and a local part, identifiers with the |
102 | same local part are unique. The caller is responsible for ensuring |
103 | that \a identifier is either a valid QUrl or a default constructed |
104 | QUrl. |
105 | |
106 | \a sourceLocation identifies a location in a resource (i.e., file or |
107 | document) where the need for reporting a message was detected. |
108 | |
109 | This function unconditionally calls handleMessage(), passing all |
110 | its parameters unmodified. |
111 | |
112 | \sa {http://www.w3.org/TR/xquery/#errors} |
113 | */ |
114 | void QAbstractMessageHandler::message(QtMsgType type, |
115 | const QString &description, |
116 | const QUrl &identifier, |
117 | const QSourceLocation &sourceLocation) |
118 | { |
119 | handleMessage(type, description, identifier, sourceLocation); |
120 | } |
121 | |
122 | /*! |
123 | \fn void QAbstractMessageHandler::handleMessage(QtMsgType type, |
124 | const QString &description, |
125 | const QUrl &identifier = QUrl(), |
126 | const QSourceLocation &sourceLocation = QSourceLocation()) = 0 |
127 | |
128 | This function must be implemented by the sub-class. message() will |
129 | call this function, passing in its parameters, \a type, |
130 | \a description, \a identifier and \a sourceLocation unmodified. |
131 | |
132 | This function can potentially be called from multiple threads. It's the reimplementation's |
133 | responsibility to ensure thread safety. |
134 | */ |
135 | |
136 | QT_END_NAMESPACE |
137 | |
138 | |