Qt 4.8
Public Functions | Properties | List of all members
QDeclarativeGlobalScriptClass Class Reference

#include <qdeclarativeglobalscriptclass_p.h>

Inheritance diagram for QDeclarativeGlobalScriptClass:
QScriptClass

Public Functions

void explicitSetProperty (const QStringList &, const QList< QScriptValue > &)
 
const QSet< QString > & illegalNames () const
 
 QDeclarativeGlobalScriptClass (QScriptEngine *)
 
virtual QueryFlags queryProperty (const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
 Queries this script class for how access to the property with the given name of the given object should be handled. More...
 
virtual void setProperty (QScriptValue &object, const QScriptString &name, uint id, const QScriptValue &value)
 Sets the property with the given name of the given object to the given value. More...
 
const QScriptValuestaticGlobalObject () const
 
- Public Functions inherited from QScriptClass
QScriptEngineengine () const
 Returns the engine that this QScriptClass is associated with. More...
 
virtual QVariant extension (Extension extension, const QVariant &argument=QVariant())
 This virtual function can be reimplemented in a QScriptClass subclass to provide support for extensions. More...
 
virtual QString name () const
 Returns the name of the script class. More...
 
virtual QScriptClassPropertyIteratornewIterator (const QScriptValue &object)
 Returns an iterator for traversing custom properties of the given object. More...
 
virtual QScriptValue property (const QScriptValue &object, const QScriptString &name, uint id)
 Returns the value of the property with the given name of the given object. More...
 
virtual QScriptValue::PropertyFlags propertyFlags (const QScriptValue &object, const QScriptString &name, uint id)
 Returns the flags of the property with the given name of the given object. More...
 
virtual QScriptValue prototype () const
 Returns the object to be used as the prototype of new instances of this class (created with QScriptEngine::newObject()). More...
 
 QScriptClass (QScriptEngine *engine)
 Constructs a QScriptClass object to be used in the given engine. More...
 
virtual bool supportsExtension (Extension extension) const
 Returns true if the QScriptClass supports the given extension; otherwise, false is returned. More...
 
virtual ~QScriptClass ()
 Destroys the QScriptClass object. More...
 

Properties

QSet< QStringm_illegalNames
 
QScriptValue m_staticGlobalObject
 

Additional Inherited Members

- Public Types inherited from QScriptClass
enum  Extension { Callable, HasInstance }
 This enum specifies the possible extensions to a QScriptClass. More...
 
enum  QueryFlag { HandlesReadAccess = 0x01, HandlesWriteAccess = 0x02 }
 This enum describes flags that are used to query a QScriptClass regarding how access to a property should be handled. More...
 
- Protected Functions inherited from QScriptClass
 QScriptClass (QScriptEngine *engine, QScriptClassPrivate &dd)
 
- Protected Variables inherited from QScriptClass
QScopedPointer< QScriptClassPrivated_ptr
 

Detailed Description

Definition at line 61 of file qdeclarativeglobalscriptclass_p.h.

Constructors and Destructors

◆ QDeclarativeGlobalScriptClass()

QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass ( QScriptEngine engine)

Definition at line 57 of file qdeclarativeglobalscriptclass.cpp.

58 : QScriptClass(engine)
59 {
60  QString eval = QLatin1String("eval");
61  QString version = QLatin1String("version");
62 
63  QScriptValue originalGlobalObject = engine->globalObject();
64 
65  QScriptValue newGlobalObject = engine->newObject();
66 
67  {
68  QScriptValueIterator iter(originalGlobalObject);
69  QVector<QString> names;
72  while (iter.hasNext()) {
73  iter.next();
74 
75  QString name = iter.name();
76 
77  if (name == version)
78  continue;
79 
80  if (name != eval) {
81  names.append(name);
82  values.append(iter.value());
83  flags.append(iter.flags() | QScriptValue::Undeletable);
84  }
85  newGlobalObject.setProperty(iter.scriptName(), iter.value());
86 
87  m_illegalNames.insert(name);
88  }
90  engine, names.size(), names.constData(), values.constData(), flags.constData());
91  }
92 
93  newGlobalObject.setScriptClass(this);
94  engine->setGlobalObject(newGlobalObject);
95 }
QScriptValue globalObject() const
Returns this engine&#39;s Global Object.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const_iterator insert(const T &value)
Definition: qset.h:179
QScriptValue newObject()
Creates a QtScript object of class Object.
void setScriptClass(QScriptClass *scriptClass)
Sets the custom script class of this script object to scriptClass.
void setGlobalObject(const QScriptValue &object)
Sets this engine&#39;s Global Object to be the given object.
quint16 values[128]
static QScriptValue newStaticScopeObject(QScriptEngine *, int propertyCount, const QString *names, const QScriptValue *values, const QScriptValue::PropertyFlags *flags)
Creates a scope object with a fixed set of undeletable properties.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
virtual QString name() const
Returns the name of the script class.
QScriptClass(QScriptEngine *engine)
Constructs a QScriptClass object to be used in the given engine.
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

Functions

◆ explicitSetProperty()

void QDeclarativeGlobalScriptClass::explicitSetProperty ( const QStringList names,
const QList< QScriptValue > &  values 
)

Definition at line 122 of file qdeclarativeglobalscriptclass.cpp.

123 {
124  Q_ASSERT(names.count() == values.count());
125  QScriptValue globalObject = engine()->globalObject();
126 
127  QScriptValue v = engine()->newObject();
128 
129  QScriptValueIterator iter(v);
130  while (iter.hasNext()) {
131  iter.next();
132  v.setProperty(iter.scriptName(), iter.value());
133  }
134 
135  for (int ii = 0; ii < names.count(); ++ii) {
136  const QString &name = names.at(ii);
137  const QScriptValue &value = values.at(ii);
138  v.setProperty(name, value);
139  }
140 
141  v.setScriptClass(this);
142 
143  engine()->setGlobalObject(v);
144 }
QScriptValue globalObject() const
Returns this engine&#39;s Global Object.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QScriptEngine * engine() const
Returns the engine that this QScriptClass is associated with.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QScriptValue newObject()
Creates a QtScript object of class Object.
void setScriptClass(QScriptClass *scriptClass)
Sets the custom script class of this script object to scriptClass.
void setGlobalObject(const QScriptValue &object)
Sets this engine&#39;s Global Object to be the given object.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
virtual QString name() const
Returns the name of the script class.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ illegalNames()

const QSet<QString>& QDeclarativeGlobalScriptClass::illegalNames ( ) const
inline

◆ queryProperty()

QScriptClass::QueryFlags QDeclarativeGlobalScriptClass::queryProperty ( const QScriptValue object,
const QScriptString name,
QueryFlags  flags,
uint id 
)
virtual

Queries this script class for how access to the property with the given name of the given object should be handled.

The given flags specify the aspects of interest. This function should return a subset of flags to indicate which aspects of property access should be further handled by the script class.

For example, if the flags contain HandlesReadAccess, and you would like your class to handle the reading of the property (through the property() function), the returned flags should include HandlesReadAccess. If the returned flags do not contain HandlesReadAccess, the property will be handled as a normal script object property.

You can optionally use the id argument to store a value that will subsequently be passed on to functions such as property() and setProperty().

The default implementation of this function returns 0.

Note: This function is only called if the given property isn't already a normal property of the object. For example, say you advertise that you want to handle read access to property foo, but not write access; if foo is then assigned a value, it will become a normal script object property, and subsequently you will no longer be queried regarding read access to foo.

See also
property()

Reimplemented from QScriptClass.

Definition at line 98 of file qdeclarativeglobalscriptclass.cpp.

101 {
102  Q_UNUSED(object);
103  Q_UNUSED(name);
104  Q_UNUSED(flags);
105  Q_UNUSED(id);
106  return HandlesWriteAccess;
107 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setProperty()

void QDeclarativeGlobalScriptClass::setProperty ( QScriptValue object,
const QScriptString name,
uint  id,
const QScriptValue value 
)
virtual

Sets the property with the given name of the given object to the given value.

The id argument is only useful if you assigned a value to it in queryProperty().

The default implementation does nothing.

An invalid value represents a request to remove the property.

See also
property()

Reimplemented from QScriptClass.

Definition at line 109 of file qdeclarativeglobalscriptclass.cpp.

112 {
113  Q_UNUSED(object);
114  Q_UNUSED(id);
115  Q_UNUSED(value);
116  QString error = QLatin1String("Invalid write to global property \"") +
117  name.toString() + QLatin1Char('\"');
118  engine()->currentContext()->throwError(error);
119 }
#define error(msg)
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScriptEngine * engine() const
Returns the engine that this QScriptClass is associated with.
QScriptContext * currentContext() const
Returns the current context.
QString toString() const
Returns the string that this QScriptString represents, or a null string if this QScriptString is not ...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ staticGlobalObject()

const QScriptValue& QDeclarativeGlobalScriptClass::staticGlobalObject ( ) const
inline

Properties

◆ m_illegalNames

QSet<QString> QDeclarativeGlobalScriptClass::m_illegalNames
private

Definition at line 80 of file qdeclarativeglobalscriptclass_p.h.

Referenced by QDeclarativeGlobalScriptClass().

◆ m_staticGlobalObject

QScriptValue QDeclarativeGlobalScriptClass::m_staticGlobalObject
private

Definition at line 81 of file qdeclarativeglobalscriptclass_p.h.

Referenced by QDeclarativeGlobalScriptClass().


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