Qt 4.8
Public Types | Public Functions | Protected Functions | Properties | Friends | List of all members
QDeclarativeCustomParser Class Referenceabstract

The QDeclarativeCustomParser class allows you to add new arbitrary types to QML. More...

#include <qdeclarativecustomparser_p.h>

Inheritance diagram for QDeclarativeCustomParser:
QDeclarativeConnectionsParser QDeclarativeGestureAreaParser QDeclarativeListModelParser QDeclarativePropertyChangesParser

Public Types

enum  Flag { NoFlag = 0x00000000, AcceptsAttachedProperties = 0x00000001 }
 

Public Functions

void clearErrors ()
 
virtual QByteArray compile (const QList< QDeclarativeCustomParserProperty > &)=0
 
QList< QDeclarativeErrorerrors () const
 
Flags flags () const
 
 QDeclarativeCustomParser ()
 
 QDeclarativeCustomParser (Flags f)
 
virtual void setCustomData (QObject *, const QByteArray &)=0
 
virtual ~QDeclarativeCustomParser ()
 

Protected Functions

void error (const QString &description)
 Reports an error with the given description. More...
 
void error (const QDeclarativeCustomParserProperty &, const QString &description)
 Reports an error in parsing prop, with the given description. More...
 
void error (const QDeclarativeCustomParserNode &, const QString &description)
 Reports an error in parsing node, with the given description. More...
 
int evaluateEnum (const QByteArray &) const
 If script is a simply enum expression (eg. More...
 
const QMetaObjectresolveType (const QByteArray &) const
 Resolves name to a type, or 0 if it is not a type. More...
 
QDeclarativeBinding::Identifier rewriteBinding (const QString &, const QByteArray &)
 Rewrites expression and returns an identifier that can be used to construct the binding later. More...
 

Properties

QDeclarativeCompilercompiler
 
QList< QDeclarativeErrorexceptions
 
Flags m_flags
 
QDeclarativeParser::Objectobject
 

Friends

class QDeclarativeCompiler
 

Detailed Description

The QDeclarativeCustomParser class allows you to add new arbitrary types to QML.

Warning
This function is not part of the public interface.

By subclassing QDeclarativeCustomParser, you can add a parser for building a particular type.

The subclass must implement compile() and setCustomData(), and register itself in the meta type system by calling the macro:

QML_REGISTER_CUSTOM_TYPE(Module, MajorVersion, MinorVersion, Name, TypeClass, ParserClass)

Definition at line 114 of file qdeclarativecustomparser_p.h.

Enumerations

◆ Flag

Enumerator
NoFlag 
AcceptsAttachedProperties 

Definition at line 117 of file qdeclarativecustomparser_p.h.

Constructors and Destructors

◆ QDeclarativeCustomParser() [1/2]

QDeclarativeCustomParser::QDeclarativeCustomParser ( )
inline

◆ QDeclarativeCustomParser() [2/2]

QDeclarativeCustomParser::QDeclarativeCustomParser ( Flags  f)
inline

Definition at line 124 of file qdeclarativecustomparser_p.h.

◆ ~QDeclarativeCustomParser()

virtual QDeclarativeCustomParser::~QDeclarativeCustomParser ( )
inlinevirtual

Definition at line 125 of file qdeclarativecustomparser_p.h.

125 {}

Functions

◆ clearErrors()

void QDeclarativeCustomParser::clearErrors ( )

Definition at line 237 of file qdeclarativecustomparser.cpp.

Referenced by QDeclarativeCompiler::buildObject().

238 {
239  exceptions.clear();
240 }
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QDeclarativeError > exceptions

◆ compile()

virtual QByteArray QDeclarativeCustomParser::compile ( const QList< QDeclarativeCustomParserProperty > &  )
pure virtual

◆ error() [1/3]

void QDeclarativeCustomParser::error ( const QString description)
protected

Reports an error with the given description.

This can only be used during the compile() step. For errors during setCustomData(), use qmlInfo().

An error is generated referring to the position of the element in the source file.

Definition at line 249 of file qdeclarativecustomparser.cpp.

250 {
251  Q_ASSERT(object);
253  QString exceptionDescription;
254  error.setLine(object->location.start.line);
256  error.setDescription(description);
257  exceptions << error;
258 }
void setDescription(const QString &)
Sets the error description.
void setColumn(int)
Sets the error column number.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void error(const QString &description)
Reports an error with the given description.
The QDeclarativeError class encapsulates a QML error.
void setLine(int)
Sets the error line number.
QDeclarativeParser::Object * object
QList< QDeclarativeError > exceptions

◆ error() [2/3]

void QDeclarativeCustomParser::error ( const QDeclarativeCustomParserProperty prop,
const QString description 
)
protected

Reports an error in parsing prop, with the given description.

An error is generated referring to the position of node in the source file.

Definition at line 265 of file qdeclarativecustomparser.cpp.

266 {
268  QString exceptionDescription;
269  error.setLine(prop.location().line);
270  error.setColumn(prop.location().column);
271  error.setDescription(description);
272  exceptions << error;
273 }
void setDescription(const QString &)
Sets the error description.
QDeclarativeParser::Location location() const
void setColumn(int)
Sets the error column number.
The QString class provides a Unicode character string.
Definition: qstring.h:83
void error(const QString &description)
Reports an error with the given description.
The QDeclarativeError class encapsulates a QML error.
void setLine(int)
Sets the error line number.
QList< QDeclarativeError > exceptions

◆ error() [3/3]

void QDeclarativeCustomParser::error ( const QDeclarativeCustomParserNode node,
const QString description 
)
protected

Reports an error in parsing node, with the given description.

An error is generated referring to the position of node in the source file.

Definition at line 280 of file qdeclarativecustomparser.cpp.

281 {
283  QString exceptionDescription;
284  error.setLine(node.location().line);
285  error.setColumn(node.location().column);
286  error.setDescription(description);
287  exceptions << error;
288 }
void setDescription(const QString &)
Sets the error description.
void setColumn(int)
Sets the error column number.
QDeclarativeParser::Location location() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
void error(const QString &description)
Reports an error with the given description.
The QDeclarativeError class encapsulates a QML error.
void setLine(int)
Sets the error line number.
QList< QDeclarativeError > exceptions

◆ errors()

QList<QDeclarativeError> QDeclarativeCustomParser::errors ( ) const
inline

Definition at line 133 of file qdeclarativecustomparser_p.h.

Referenced by QDeclarativeCompiler::buildObject().

133 { return exceptions; }
QList< QDeclarativeError > exceptions

◆ evaluateEnum()

int QDeclarativeCustomParser::evaluateEnum ( const QByteArray script) const
protected

If script is a simply enum expression (eg.

Text.AlignLeft), returns the integer equivalent (eg. 1).

Otherwise, returns -1.

Definition at line 296 of file qdeclarativecustomparser.cpp.

297 {
298  return compiler->evaluateEnum(script);
299 }
int evaluateEnum(const QByteArray &script) const

◆ flags()

Flags QDeclarativeCustomParser::flags ( ) const
inline

◆ resolveType()

const QMetaObject * QDeclarativeCustomParser::resolveType ( const QByteArray name) const
protected

Resolves name to a type, or 0 if it is not a type.

This can be used to type-check object nodes.

Definition at line 305 of file qdeclarativecustomparser.cpp.

306 {
307  return compiler->resolveType(name);
308 }
const QMetaObject * resolveType(const QByteArray &name) const

◆ rewriteBinding()

QDeclarativeBinding::Identifier QDeclarativeCustomParser::rewriteBinding ( const QString expression,
const QByteArray name 
)
protected

Rewrites expression and returns an identifier that can be used to construct the binding later.

name is used as the name of the rewritten function.

Definition at line 315 of file qdeclarativecustomparser.cpp.

316 {
317  return compiler->rewriteBinding(expression, name);
318 }
int rewriteBinding(const QString &expression, const QByteArray &name)

◆ setCustomData()

virtual void QDeclarativeCustomParser::setCustomData ( QObject ,
const QByteArray  
)
pure virtual

Friends and Related Functions

◆ QDeclarativeCompiler

friend class QDeclarativeCompiler
friend

Definition at line 151 of file qdeclarativecustomparser_p.h.

Properties

◆ compiler

QDeclarativeCompiler* QDeclarativeCustomParser::compiler
private

Definition at line 148 of file qdeclarativecustomparser_p.h.

Referenced by QDeclarativeCompiler::buildObject().

◆ exceptions

QList<QDeclarativeError> QDeclarativeCustomParser::exceptions
private

Definition at line 147 of file qdeclarativecustomparser_p.h.

◆ m_flags

Flags QDeclarativeCustomParser::m_flags
private

Definition at line 150 of file qdeclarativecustomparser_p.h.

◆ object

QDeclarativeParser::Object* QDeclarativeCustomParser::object
private

Definition at line 149 of file qdeclarativecustomparser_p.h.

Referenced by QDeclarativeCompiler::buildObject().


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