Qt 4.8
Classes | Public Functions | Private Functions | Properties | List of all members
QDeclarativeDirParser Class Reference

#include <qdeclarativedirparser_p.h>

Classes

struct  Component
 
struct  Plugin
 

Public Functions

QList< Componentcomponents () const
 
QList< QDeclarativeErrorerrors (const QString &uri) const
 
QString fileSource () const
 
bool hasError () const
 
bool isParsed () const
 
bool parse ()
 
QList< Pluginplugins () const
 
 QDeclarativeDirParser ()
 
void setFileSource (const QString &filePath)
 
void setSource (const QString &source)
 
void setUrl (const QUrl &url)
 
QString source () const
 
QUrl url () const
 
 ~QDeclarativeDirParser ()
 

Private Functions

void reportError (int line, int column, const QString &message)
 

Properties

QList< Component_components
 
QList< QDeclarativeError_errors
 
QString _filePathSouce
 
unsigned _isParsed: 1
 
QList< Plugin_plugins
 
QString _source
 
QUrl _url
 

Detailed Description

Definition at line 62 of file qdeclarativedirparser_p.h.

Constructors and Destructors

◆ QDeclarativeDirParser()

QDeclarativeDirParser::QDeclarativeDirParser ( )

Definition at line 52 of file qdeclarativedirparser.cpp.

53  : _isParsed(false)
54 {
55 }

◆ ~QDeclarativeDirParser()

QDeclarativeDirParser::~QDeclarativeDirParser ( )

Definition at line 57 of file qdeclarativedirparser.cpp.

58 {
59 }

Functions

◆ components()

QList< QDeclarativeDirParser::Component > QDeclarativeDirParser::components ( ) const

Definition at line 273 of file qdeclarativedirparser.cpp.

Referenced by QDeclarativeQmldirData::dataReceived(), and QDeclarativeImportsPrivate::importExtension().

274 {
275  return _components;
276 }
QList< Component > _components

◆ errors()

QList< QDeclarativeError > QDeclarativeDirParser::errors ( const QString uri) const

Definition at line 256 of file qdeclarativedirparser.cpp.

Referenced by QDeclarativeImportsPrivate::importExtension().

257 {
259  for (int i = 0; i < errors.size(); ++i) {
260  QDeclarativeError &e = errors[i];
261  QString description = e.description();
262  description.replace(QLatin1String("$$URI$$"), uri);
263  e.setDescription(description);
264  }
265  return errors;
266 }
void setDescription(const QString &)
Sets the error description.
QList< QDeclarativeError > errors(const QString &uri) const
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString description() const
Returns the error description.
The QDeclarativeError class encapsulates a QML error.
QList< QDeclarativeError > _errors
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ fileSource()

QString QDeclarativeDirParser::fileSource ( ) const

Definition at line 71 of file qdeclarativedirparser.cpp.

72 {
73  return _filePathSouce;
74 }

◆ hasError()

bool QDeclarativeDirParser::hasError ( ) const

Definition at line 248 of file qdeclarativedirparser.cpp.

Referenced by QDeclarativeImportsPrivate::importExtension(), and parse().

249 {
250  if (! _errors.isEmpty())
251  return true;
252 
253  return false;
254 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QDeclarativeError > _errors

◆ isParsed()

bool QDeclarativeDirParser::isParsed ( ) const

Definition at line 92 of file qdeclarativedirparser.cpp.

93 {
94  return _isParsed;
95 }

◆ parse()

bool QDeclarativeDirParser::parse ( )

Definition at line 97 of file qdeclarativedirparser.cpp.

Referenced by QDeclarativeQmldirData::dataReceived(), and QDeclarativeTypeLoader::qmlDirParser().

98 {
99  if (_isParsed)
100  return true;
101 
102  _isParsed = true;
103  _errors.clear();
104  _plugins.clear();
105  _components.clear();
106 
107  if (_source.isEmpty() && !_filePathSouce.isEmpty()) {
108  QFile file(_filePathSouce);
111  error.setDescription(QString::fromUtf8("cannot load module \"$$URI$$\": File name case mismatch for \"%1\"").arg(_filePathSouce));
112  _errors.prepend(error);
113  return false;
114  } else if (file.open(QFile::ReadOnly)) {
115  _source = QString::fromUtf8(file.readAll());
116  } else {
118  error.setDescription(QString::fromUtf8("module \"$$URI$$\" definition \"%1\" not readable").arg(_filePathSouce));
119  _errors.prepend(error);
120  return false;
121  }
122  }
123 
125  int lineNumber = 0;
126 
127  forever {
128  ++lineNumber;
129 
130  const QString line = stream.readLine();
131  if (line.isNull())
132  break;
133 
134  QString sections[3];
135  int sectionCount = 0;
136 
137  int index = 0;
138  const int length = line.length();
139 
140  while (index != length) {
141  const QChar ch = line.at(index);
142 
143  if (ch.isSpace()) {
144  do { ++index; }
145  while (index != length && line.at(index).isSpace());
146 
147  } else if (ch == QLatin1Char('#')) {
148  // recognized a comment
149  break;
150 
151  } else {
152  const int start = index;
153 
154  do { ++index; }
155  while (index != length && !line.at(index).isSpace());
156 
157  const QString lexeme = line.mid(start, index - start);
158 
159  if (sectionCount >= 3) {
160  reportError(lineNumber, start, QLatin1String("unexpected token"));
161 
162  } else {
163  sections[sectionCount++] = lexeme;
164  }
165  }
166  }
167 
168  if (sectionCount == 0) {
169  continue; // no sections, no party.
170 
171  } else if (sections[0] == QLatin1String("plugin")) {
172  if (sectionCount < 2) {
173  reportError(lineNumber, -1,
174  QString::fromUtf8("plugin directive requires 2 arguments, but %1 were provided").arg(sectionCount + 1));
175 
176  continue;
177  }
178 
179  const Plugin entry(sections[1], sections[2]);
180 
181  _plugins.append(entry);
182 
183  } else if (sections[0] == QLatin1String("internal")) {
184  if (sectionCount != 3) {
185  reportError(lineNumber, -1,
186  QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount + 1));
187  continue;
188  }
189  Component entry(sections[1], sections[2], -1, -1);
190  entry.internal = true;
191  _components.append(entry);
192  } else if (sections[0] == QLatin1String("typeinfo")) {
193  if (sectionCount != 2) {
194  reportError(lineNumber, -1,
195  QString::fromUtf8("typeinfo requires 1 argument, but %1 were provided").arg(sectionCount - 1));
196  continue;
197  }
198 #ifdef QT_CREATOR
199  TypeInfo typeInfo(sections[1]);
200  _typeInfos.append(typeInfo);
201 #endif
202 
203  } else if (sectionCount == 2) {
204  // No version specified (should only be used for relative qmldir files)
205  const Component entry(sections[0], sections[1], -1, -1);
206  _components.append(entry);
207  } else if (sectionCount == 3) {
208  const QString &version = sections[1];
209  const int dotIndex = version.indexOf(QLatin1Char('.'));
210 
211  if (dotIndex == -1) {
212  reportError(lineNumber, -1, QLatin1String("expected '.'"));
213  } else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) {
214  reportError(lineNumber, -1, QLatin1String("unexpected '.'"));
215  } else {
216  bool validVersionNumber = false;
217  const int majorVersion = version.left(dotIndex).toInt(&validVersionNumber);
218 
219  if (validVersionNumber) {
220  const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber);
221 
222  if (validVersionNumber) {
223  const Component entry(sections[0], sections[2], majorVersion, minorVersion);
224 
225  _components.append(entry);
226  }
227  }
228  }
229  } else {
230  reportError(lineNumber, -1,
231  QString::fromUtf8("a component declaration requires 3 arguments, but %1 were provided").arg(sectionCount + 1));
232  }
233  }
234 
235  return hasError();
236 }
QList< Component > _components
void setDescription(const QString &)
Sets the error description.
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
#define error(msg)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
bool QDeclarative_isFileCaseCorrect(const QString &fileName)
Returns true if the case of fileName is equivalent to the file case of fileName on disk...
void reportError(int line, int column, const QString &message)
static FILE * stream
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
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
The QDeclarativeError class encapsulates a QML error.
void clear()
Removes all items from the list.
Definition: qlist.h:764
The Component element encapsulates a QML component definition.
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QList< QDeclarativeError > _errors
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
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint16 index
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ plugins()

QList< QDeclarativeDirParser::Plugin > QDeclarativeDirParser::plugins ( ) const

Definition at line 268 of file qdeclarativedirparser.cpp.

Referenced by QDeclarativeImportsPrivate::importExtension().

269 {
270  return _plugins;
271 }

◆ reportError()

void QDeclarativeDirParser::reportError ( int  line,
int  column,
const QString message 
)
private

Definition at line 238 of file qdeclarativedirparser.cpp.

Referenced by parse().

239 {
241  error.setUrl(_url);
242  error.setLine(line);
243  error.setColumn(column);
244  error.setDescription(description);
245  _errors.append(error);
246 }
void setDescription(const QString &)
Sets the error description.
#define error(msg)
void setColumn(int)
Sets the error column number.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QDeclarativeError class encapsulates a QML error.
void setLine(int)
Sets the error line number.
QList< QDeclarativeError > _errors
void setUrl(const QUrl &)
Sets the url for the file that caused this error.

◆ setFileSource()

void QDeclarativeDirParser::setFileSource ( const QString filePath)

Definition at line 76 of file qdeclarativedirparser.cpp.

Referenced by QDeclarativeTypeLoader::qmlDirParser().

77 {
78  _filePathSouce = filePath;
79 }

◆ setSource()

void QDeclarativeDirParser::setSource ( const QString source)

Definition at line 86 of file qdeclarativedirparser.cpp.

Referenced by QDeclarativeQmldirData::dataReceived().

◆ setUrl()

void QDeclarativeDirParser::setUrl ( const QUrl url)

◆ source()

QString QDeclarativeDirParser::source ( ) const

Definition at line 81 of file qdeclarativedirparser.cpp.

Referenced by setSource().

82 {
83  return _source;
84 }

◆ url()

QUrl QDeclarativeDirParser::url ( ) const

Definition at line 61 of file qdeclarativedirparser.cpp.

Referenced by setUrl().

62 {
63  return _url;
64 }

Properties

◆ _components

QList<Component> QDeclarativeDirParser::_components
private

Definition at line 136 of file qdeclarativedirparser_p.h.

Referenced by components(), and parse().

◆ _errors

QList<QDeclarativeError> QDeclarativeDirParser::_errors
private

Definition at line 132 of file qdeclarativedirparser_p.h.

Referenced by errors(), hasError(), parse(), and reportError().

◆ _filePathSouce

QString QDeclarativeDirParser::_filePathSouce
private

Definition at line 135 of file qdeclarativedirparser_p.h.

Referenced by fileSource(), parse(), and setFileSource().

◆ _isParsed

unsigned QDeclarativeDirParser::_isParsed
private

Definition at line 141 of file qdeclarativedirparser_p.h.

Referenced by isParsed(), parse(), and setSource().

◆ _plugins

QList<Plugin> QDeclarativeDirParser::_plugins
private

Definition at line 137 of file qdeclarativedirparser_p.h.

Referenced by parse(), and plugins().

◆ _source

QString QDeclarativeDirParser::_source
private

Definition at line 134 of file qdeclarativedirparser_p.h.

Referenced by parse(), setSource(), and source().

◆ _url

QUrl QDeclarativeDirParser::_url
private

Definition at line 133 of file qdeclarativedirparser_p.h.

Referenced by reportError(), setUrl(), and url().


The documentation for this class was generated from the following files: