Qt 4.8
qdeclarativeinfo.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative 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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdeclarativeinfo.h"
43 
44 #include "private/qdeclarativedata_p.h"
45 #include "qdeclarativecontext.h"
46 #include "private/qdeclarativecontext_p.h"
47 #include "private/qdeclarativemetatype_p.h"
48 #include "private/qdeclarativeengine_p.h"
49 
50 #include <QCoreApplication>
51 
53 
84 {
85 public:
87 
88  int ref;
89  const QObject *object;
92 };
93 
95 : QDebug(&p->buffer), d(p)
96 {
97  nospace();
98 }
99 
101 : QDebug(other), d(other.d)
102 {
103  d->ref++;
104 }
105 
107 {
108  if (0 == --d->ref) {
110 
111  QDeclarativeEngine *engine = 0;
112 
113  if (!d->buffer.isEmpty()) {
115 
116  QObject *object = const_cast<QObject *>(d->object);
117 
118  if (object) {
119  engine = qmlEngine(d->object);
122  if (type) {
123  typeName = QLatin1String(type->qmlTypeName());
124  int lastSlash = typeName.lastIndexOf(QLatin1Char('/'));
125  if (lastSlash != -1)
126  typeName = typeName.mid(lastSlash+1);
127  } else {
128  typeName = QString::fromUtf8(object->metaObject()->className());
129  int marker = typeName.indexOf(QLatin1String("_QMLTYPE_"));
130  if (marker != -1)
131  typeName = typeName.left(marker);
132  }
133 
134  d->buffer.prepend(QLatin1String("QML ") + typeName + QLatin1String(": "));
135 
136  QDeclarativeData *ddata = QDeclarativeData::get(object, false);
137  if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) {
138  error.setUrl(ddata->outerContext->url);
139  error.setLine(ddata->lineNumber);
140  error.setColumn(ddata->columnNumber);
141  }
142  }
143 
144  error.setDescription(d->buffer);
145 
146  errors.prepend(error);
147  }
148 
149  QDeclarativeEnginePrivate::warning(engine, errors);
150 
151  delete d;
152  }
153 }
154 
156 {
158  d->object = me;
159  return QDeclarativeInfo(d);
160 }
161 
163 {
165  d->object = me;
166  d->errors << error;
167  return QDeclarativeInfo(d);
168 }
169 
171 {
173  d->object = me;
174  d->errors = errors;
175  return QDeclarativeInfo(d);
176 }
177 
178 
QDeclarativeContextData * outerContext
friend Q_DECLARATIVE_EXPORT QDeclarativeInfo qmlInfo(const QObject *me)
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
static QDeclarativeData * get(const QObject *object, bool create=false)
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setDescription(const QString &)
Sets the error description.
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
#define error(msg)
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QString & prepend(QChar c)
Definition: qstring.h:261
QDeclarativeInfo(const QDeclarativeInfo &)
void setColumn(int)
Sets the error column number.
static QDeclarativeType * qmlType(const QByteArray &, int, int)
Returns the type (if any) of URI-qualified named name in version specified by version_major and versi...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
const char * typeName
Definition: qmetatype.cpp:239
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QByteArray qmlTypeName() const
The QDeclarativeError class encapsulates a QML error.
void setLine(int)
Sets the error line number.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QList< QDeclarativeError > errors
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
The QDeclarativeEngine class provides an environment for instantiating QML components.
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
void warning(const QDeclarativeError &)
QDeclarativeInfoPrivate * d
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.