Qt 4.8
Public Types | Public Functions | Properties | List of all members
QDeclarativeParser::Variant Class Reference

#include <qdeclarativeparser_p.h>

Public Types

enum  Type {
  Invalid, Boolean, Number, String,
  Script
}
 

Public Functions

QDeclarativeJS::AST::NodeasAST () const
 
bool asBoolean () const
 
double asNumber () const
 
QString asScript () const
 
QString asString () const
 
QStringList asStringList () const
 
bool isBoolean () const
 
bool isNumber () const
 
bool isScript () const
 
bool isString () const
 
bool isStringList () const
 
Variantoperator= (const Variant &)
 
Type type () const
 
 Variant ()
 
 Variant (const Variant &)
 
 Variant (bool)
 
 Variant (double, const QString &asWritten=QString())
 
 Variant (const QString &)
 
 Variant (const QString &, QDeclarativeJS::AST::Node *)
 

Properties

union {
   bool   b
 
   double   d
 
   QDeclarativeJS::AST::Node *   n
 
}; 
 
QString s
 
Type t
 

Detailed Description

Definition at line 240 of file qdeclarativeparser_p.h.

Enumerations

◆ Type

Constructors and Destructors

◆ Variant() [1/6]

QDeclarativeParser::Variant::Variant ( )

◆ Variant() [2/6]

QDeclarativeParser::Variant::Variant ( const Variant o)

◆ Variant() [3/6]

QDeclarativeParser::Variant::Variant ( bool  v)

◆ Variant() [4/6]

QDeclarativeParser::Variant::Variant ( double  v,
const QString asWritten = QString() 
)

◆ Variant() [5/6]

QDeclarativeParser::Variant::Variant ( const QString v)

◆ Variant() [6/6]

QDeclarativeParser::Variant::Variant ( const QString v,
QDeclarativeJS::AST::Node n 
)

Functions

◆ asAST()

QDeclarativeJS::AST::Node * QDeclarativeParser::Variant::asAST ( ) const

Definition at line 383 of file qdeclarativeparser.cpp.

Referenced by QDeclarativeBindingCompiler::compile(), and QDeclarativeCompiler::completeComponentBuild().

384 {
385  if (type() == Script)
386  return n;
387  else
388  return 0;
389 }
QDeclarativeJS::AST::Node * n

◆ asBoolean()

bool QDeclarativeParser::Variant::asBoolean ( ) const

◆ asNumber()

double QDeclarativeParser::Variant::asNumber ( ) const

◆ asScript()

QString QDeclarativeParser::Variant::asScript ( ) const

Definition at line 363 of file qdeclarativeparser.cpp.

Referenced by QDeclarativeDomValueBinding::binding(), QDeclarativeGestureAreaParser::compile(), QDeclarativeConnectionsParser::compile(), QDeclarativePropertyChangesParser::compile(), QDeclarativeListModelParser::compileProperty(), QDeclarativeCompiler::completeComponentBuild(), and QDeclarativeCompiler::genObjectBody().

364 {
365  switch(type()) {
366  default:
367  case Invalid:
368  return QString();
369  case Boolean:
370  return b?QLatin1String("true"):QLatin1String("false");
371  case Number:
372  if (s.isEmpty())
373  return QString::number(d);
374  else
375  return s;
376  case String:
377  return escapedString(s);
378  case Script:
379  return s;
380  }
381 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString escapedString(const QString &string)

◆ asString()

QString QDeclarativeParser::Variant::asString ( ) const

◆ asStringList()

QStringList QDeclarativeParser::Variant::asStringList ( ) const

Definition at line 416 of file qdeclarativeparser.cpp.

417 {
418  QStringList rv;
419  if (isString()) {
420  rv << asString();
421  return rv;
422  }
423 
424  AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
425  if (!array)
426  return rv;
427 
429  while (elements) {
430 
431  AST::StringLiteral *string = AST::cast<AST::StringLiteral *>(elements->expression);
432  if (!string)
433  return QStringList();
434  rv.append(string->value->asString());
435 
436  elements = elements->next;
437  }
438 
439  return rv;
440 }
const QString asString() const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QDeclarativeJS::AST::Node * n
static const QTextHtmlElement elements[Html_NumElements]

◆ isBoolean()

bool QDeclarativeParser::Variant::isBoolean ( ) const
inline

◆ isNumber()

bool QDeclarativeParser::Variant::isNumber ( ) const
inline

◆ isScript()

bool QDeclarativeParser::Variant::isScript ( ) const
inline

◆ isString()

bool QDeclarativeParser::Variant::isString ( ) const
inline

◆ isStringList()

bool QDeclarativeParser::Variant::isStringList ( ) const

Definition at line 391 of file qdeclarativeparser.cpp.

392 {
393  if (isString())
394  return true;
395 
396  if (type() != Script || !n)
397  return false;
398 
399  AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
400  if (!array)
401  return false;
402 
404 
405  while (elements) {
406 
407  if (!AST::cast<AST::StringLiteral *>(elements->expression))
408  return false;
409 
410  elements = elements->next;
411  }
412 
413  return true;
414 }
QDeclarativeJS::AST::Node * n
static const QTextHtmlElement elements[Html_NumElements]

◆ operator=()

QDeclarativeParser::Variant & QDeclarativeParser::Variant::operator= ( const Variant o)

Definition at line 292 of file qdeclarativeparser.cpp.

293 {
294  t = o.t;
295  d = o.d;
296  s = o.s;
297  return *this;
298 }

◆ type()

QDeclarativeParser::Variant::Type QDeclarativeParser::Variant::type ( ) const

Properties

◆ @148

union { ... }

◆ b

bool QDeclarativeParser::Variant::b

Definition at line 277 of file qdeclarativeparser_p.h.

Referenced by asBoolean(), and asScript().

◆ d

double QDeclarativeParser::Variant::d

Definition at line 278 of file qdeclarativeparser_p.h.

Referenced by asNumber(), asScript(), and operator=().

◆ n

QDeclarativeJS::AST::Node* QDeclarativeParser::Variant::n

Definition at line 279 of file qdeclarativeparser_p.h.

Referenced by asAST(), asStringList(), and isStringList().

◆ s

QString QDeclarativeParser::Variant::s
private

Definition at line 281 of file qdeclarativeparser_p.h.

Referenced by asScript(), asString(), and operator=().

◆ t

Type QDeclarativeParser::Variant::t
private

Definition at line 275 of file qdeclarativeparser_p.h.

Referenced by operator=(), and type().


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