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

#include <qscriptobjectsnapshot_p.h>

Classes

struct  Delta
 

Public Functions

Delta capture (const QScriptValue &object)
 
QScriptValueProperty findProperty (const QString &name) const
 
QScriptValuePropertyList properties () const
 
 QScriptObjectSnapshot ()
 
 ~QScriptObjectSnapshot ()
 

Properties

QScriptValuePropertyList m_properties
 

Detailed Description

Definition at line 63 of file qscriptobjectsnapshot_p.h.

Constructors and Destructors

◆ QScriptObjectSnapshot()

QScriptObjectSnapshot::QScriptObjectSnapshot ( )

Definition at line 52 of file qscriptobjectsnapshot.cpp.

53 {
54 }

◆ ~QScriptObjectSnapshot()

QScriptObjectSnapshot::~QScriptObjectSnapshot ( )

Definition at line 56 of file qscriptobjectsnapshot.cpp.

57 {
58 }

Functions

◆ capture()

QScriptObjectSnapshot::Delta QScriptObjectSnapshot::capture ( const QScriptValue object)

Definition at line 69 of file qscriptobjectsnapshot.cpp.

Referenced by QScriptDebuggerCommandExecutor::execute().

70 {
71  Delta result;
73  QHash<QString, int> propertyNameToIndex;
74  {
75  int i = 0;
76  QScriptValueIterator it(object);
77  while (it.hasNext()) {
78  it.next();
79  QScriptValueProperty prop(it.name(), it.value(), it.flags());
80  currProps.insert(it.name(), prop);
81  propertyNameToIndex.insert(it.name(), i);
82  ++i;
83  }
84  if (object.prototype().isValid()) {
85  QString __proto__ = QString::fromLatin1("__proto__");
86  QScriptValueProperty protoProp(
87  __proto__, object.prototype(),
89  currProps.insert(__proto__, protoProp);
90  propertyNameToIndex.insert(__proto__, i);
91  ++i;
92  }
93  }
94 
95  QSet<QString> prevSet;
96  for (int i = 0; i < m_properties.size(); ++i)
97  prevSet.insert(m_properties.at(i).name());
98  QSet<QString> currSet = currProps.keys().toSet();
99  QSet<QString> removedProperties = prevSet - currSet;
100  QSet<QString> addedProperties = currSet - prevSet;
101  QSet<QString> maybeChangedProperties = currSet & prevSet;
102 
103  {
106  for (it = addedProperties.constBegin(); it != addedProperties.constEnd(); ++it) {
107  int idx = propertyNameToIndex[*it];
108  am[idx] = currProps[*it];
109  }
110  result.addedProperties = am.values();
111  }
112 
113  {
115  for (it = maybeChangedProperties.constBegin(); it != maybeChangedProperties.constEnd(); ++it) {
116  const QScriptValueProperty &p1 = currProps[*it];
117  const QScriptValueProperty &p2 = findProperty(*it);
118  if (!_q_equal(p1.value(), p2.value())
119  || (p1.flags() != p2.flags())) {
120  result.changedProperties.append(p1);
121  }
122  }
123  }
124 
125  result.removedProperties = removedProperties.toList();
126 
127  m_properties = currProps.values();
128 
129  return result;
130 }
QSet< T > toSet() const
Returns a QSet object with the data contained in this QList.
Definition: qset.h:309
#define it(className, varName)
QScriptValuePropertyList m_properties
const_iterator constEnd() const
Definition: qset.h:171
QList< T > values() const
Returns a list containing all the values in the map, in ascending order of their keys.
Definition: qmap.h:863
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString name() const
Returns the name of this QScriptValueProperty.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QScriptValue::PropertyFlags flags() const
Returns the flags of this QScriptValueProperty.
QList< T > toList() const
Definition: qset.h:296
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const_iterator insert(const T &value)
Definition: qset.h:179
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
QScriptValue value() const
Returns the value of this QScriptValueProperty.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
static bool _q_equal(const QScriptValue &v1, const QScriptValue &v2)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const_iterator constBegin() const
Definition: qset.h:168
QScriptValueProperty findProperty(const QString &name) const
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ findProperty()

QScriptValueProperty QScriptObjectSnapshot::findProperty ( const QString name) const

Definition at line 132 of file qscriptobjectsnapshot.cpp.

Referenced by capture().

133 {
134  for (int i = 0; i < m_properties.size(); ++i) {
135  if (m_properties.at(i).name() == name)
136  return m_properties.at(i);
137  }
138  return QScriptValueProperty();
139 }
QScriptValuePropertyList m_properties
QString name() const
Returns the name of this QScriptValueProperty.
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ properties()

QScriptValuePropertyList QScriptObjectSnapshot::properties ( ) const

Definition at line 141 of file qscriptobjectsnapshot.cpp.

142 {
143  return m_properties;
144 }
QScriptValuePropertyList m_properties

Properties

◆ m_properties

QScriptValuePropertyList QScriptObjectSnapshot::m_properties
private

Definition at line 81 of file qscriptobjectsnapshot_p.h.

Referenced by capture(), findProperty(), and properties().


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