1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
44 #include "qsourcelocation.h"
50 \class QSourceLocation
53 \brief The QSourceLocation class identifies a location in a resource by URI, line, and column.
55 \inmodule QtXmlPatterns
57 QSourceLocation is a simple value based class that has three
58 properties, uri(), line(), and column(), that, taken together,
59 identify a certain point in a resource, e.g., a file or an in-memory
62 line() and column() refer to character counts (not byte counts), and
63 they both start from 1, as opposed to 0.
67 Construct a QSourceLocation that doesn't identify anything at all.
69 For a default constructed QSourceLocation(), isNull() returns \c true.
71 QSourceLocation::QSourceLocation() : m_line(-1), m_column(-1)
76 Constructs a QSourceLocation that is a copy of \a other.
78 QSourceLocation::QSourceLocation(const QSourceLocation &other)
79 : m_line(other.m_line), m_column(other.m_column), m_uri(other.m_uri)
84 Constructs a QSourceLocation with URI \a u, line \a l and column \a c.
86 QSourceLocation::QSourceLocation(const QUrl &u, int l, int c)
87 : m_line(l), m_column(c), m_uri(u)
94 QSourceLocation::~QSourceLocation()
99 Returns true if this QSourceLocation is identical to \a other.
101 Two QSourceLocation instances are equal if their uri(), line() and
104 QSourceLocation instances for which isNull() returns true are
107 bool QSourceLocation::operator==(const QSourceLocation &other) const
109 return m_line == other.m_line
110 && m_column == other.m_column
111 && m_uri == other.m_uri;
115 Returns the opposite of applying operator==() for this QXmlName
118 bool QSourceLocation::operator!=(const QSourceLocation &other) const
120 return operator==(other);
124 Assigns this QSourceLocation instance to \a other.
126 QSourceLocation &QSourceLocation::operator=(const QSourceLocation &other)
130 m_line = other.m_line;
131 m_column = other.m_column;
139 Returns the current column number. The column number refers to the
140 count of characters, not bytes. The first column is column 1, not 0.
141 The default value is -1, indicating the column number is unknown.
143 qint64 QSourceLocation::column() const
149 Sets the column number to \a newColumn. 0 is an invalid column
150 number. The first column number is 1.
152 void QSourceLocation::setColumn(qint64 newColumn)
154 Q_ASSERT_X(newColumn != 0, Q_FUNC_INFO,
155 "0 is an invalid column number. The first column number is 1.");
156 m_column = newColumn;
160 Returns the current line number. The first line number is 1, not 0.
161 The default value is -1, indicating the line number is unknown.
163 qint64 QSourceLocation::line() const
169 Sets the line number to \a newLine. 0 is an invalid line
170 number. The first line number is 1.
172 void QSourceLocation::setLine(qint64 newLine)
178 Returns the resource that this QSourceLocation refers to. For
179 example, the resource could be a file in the local file system,
180 if the URI scheme is \c file.
182 QUrl QSourceLocation::uri() const
188 Sets the URI to \a newUri.
190 void QSourceLocation::setUri(const QUrl &newUri)
196 \relates QSourceLocation
199 Prints \a sourceLocation to the debug stream \a debug.
201 #ifndef QT_NO_DEBUG_STREAM
202 QDebug operator<<(QDebug debug, const QSourceLocation &sourceLocation)
204 debug << "QSourceLocation("
205 << sourceLocation.uri()
207 << sourceLocation.line()
209 << sourceLocation.column()
216 Returns \c true if this QSourceLocation doesn't identify anything.
218 For a default constructed QSourceLocation, this function returns \c
219 true. The same applies for any other QSourceLocation whose uri() is
222 bool QSourceLocation::isNull() const
224 return !m_uri.isValid();
230 Computes a hash key for the QSourceLocation \a location.
232 \relates QSourceLocation
234 uint qHash(const QSourceLocation &location)
236 /* Not the world's best hash function exactly. */
237 return qHash(location.uri().toString()) + location.line() + location.column();