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

#include <qdeclarativelistmodel_p_p.h>

Inheritance diagram for FlatListScriptClass:
QScriptDeclarativeClass

Public Functions

bool compare (Object *, Object *)
 
 FlatListScriptClass (FlatListModel *model, QScriptEngine *seng)
 
Value property (Object *, const Identifier &)
 
QScriptClass::QueryFlags queryProperty (Object *, const Identifier &, QScriptClass::QueryFlags flags)
 
void setProperty (Object *, const Identifier &name, const QScriptValue &)
 
- Public Functions inherited from QScriptDeclarativeClass
virtual Value call (Object *, QScriptContext *)
 
QScriptContextcontext () const
 
PersistentIdentifier createPersistentIdentifier (const QString &)
 
PersistentIdentifier createPersistentIdentifier (const Identifier &)
 
QScriptEngineengine () const
 
virtual bool isQObject () const
 
virtual QScriptValue::PropertyFlags propertyFlags (Object *, const Identifier &)
 
virtual QStringList propertyNames (Object *)
 
 QScriptDeclarativeClass (QScriptEngine *engine)
 
void setSupportsCall (bool)
 
bool startsWithUpper (const Identifier &)
 
bool supportsCall () const
 
quint32 toArrayIndex (const Identifier &, bool *ok)
 
virtual QObjecttoQObject (Object *, bool *ok=0)
 
QString toString (const Identifier &)
 
virtual QVariant toVariant (Object *, bool *ok=0)
 
virtual ~QScriptDeclarativeClass ()
 

Properties

FlatListModelm_model
 

Additional Inherited Members

- Public Types inherited from QScriptDeclarativeClass
typedef void * Identifier
 
- Static Public Functions inherited from QScriptDeclarativeClass
static QScriptValue function (const QScriptValue &, const Identifier &)
 
static Value functionValue (const QScriptValue &, const Identifier &)
 
static QScriptValue newObject (QScriptEngine *, QScriptDeclarativeClass *, Object *)
 
static Value newObjectValue (QScriptEngine *, QScriptDeclarativeClass *, Object *)
 
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. More...
 
static QScriptValue newStaticScopeObject (QScriptEngine *)
 Creates a static scope object that's initially empty, but to which new properties can be added. More...
 
static Objectobject (const QScriptValue &)
 
static QScriptValue property (const QScriptValue &, const Identifier &)
 
static Value propertyValue (const QScriptValue &, const Identifier &)
 
static QScriptContextpushCleanContext (QScriptEngine *)
 Enters a new execution context and returns the associated QScriptContext object. More...
 
static QScriptValue scopeChainValue (QScriptContext *, int index)
 
static QScriptDeclarativeClassscriptClass (const QScriptValue &)
 
- Protected Variables inherited from QScriptDeclarativeClass
QScopedPointer< QScriptDeclarativeClassPrivated_ptr
 

Detailed Description

Definition at line 123 of file qdeclarativelistmodel_p_p.h.

Constructors and Destructors

◆ FlatListScriptClass()

FlatListScriptClass::FlatListScriptClass ( FlatListModel model,
QScriptEngine seng 
)

Definition at line 1164 of file qdeclarativelistmodel.cpp.

1165  : QScriptDeclarativeClass(seng),
1166  m_model(model)
1167 {
1168 }
QScriptDeclarativeClass(QScriptEngine *engine)

Functions

◆ compare()

bool FlatListScriptClass::compare ( Object obj1,
Object obj2 
)
virtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 1226 of file qdeclarativelistmodel.cpp.

1227 {
1228  FlatNodeObjectData *data1 = static_cast<FlatNodeObjectData*>(obj1);
1229  FlatNodeObjectData *data2 = static_cast<FlatNodeObjectData*>(obj2);
1230 
1231  if (!data1->nodeData || !data2->nodeData)
1232  return false;
1233 
1234  return data1->nodeData->index == data2->nodeData->index;
1235 }

◆ property()

QScriptDeclarativeClass::Value FlatListScriptClass::property ( Object obj,
const Identifier name 
)
virtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 1170 of file qdeclarativelistmodel.cpp.

1171 {
1172  FlatNodeObjectData *objData = static_cast<FlatNodeObjectData*>(obj);
1173  if (!objData->nodeData) // item at this index has been deleted
1174  return QScriptDeclarativeClass::Value(engine(), engine()->undefinedValue());
1175 
1176  int index = objData->nodeData->index;
1177  QString propName = toString(name);
1178  int role = m_model->m_strings.value(propName, -1);
1179 
1180  if (role >= 0 && index >=0 ) {
1181  const QHash<int, QVariant> &row = m_model->m_values[index];
1182  QScriptValue sv = engine()->toScriptValue<QVariant>(row[role]);
1183  return QScriptDeclarativeClass::Value(engine(), sv);
1184  }
1185 
1186  return QScriptDeclarativeClass::Value(engine(), engine()->undefinedValue());
1187 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScriptValue toScriptValue(const T &value)
Creates a QScriptValue with the given value.
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
The QScriptDeclarativeClass::Value class acts as a container for JavaScript data types.
const char * name
QScriptEngine * engine() const
QList< QHash< int, QVariant > > m_values
QHash< QString, int > m_strings
quint16 index
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QString toString(const Identifier &)

◆ queryProperty()

QScriptClass::QueryFlags FlatListScriptClass::queryProperty ( Object ,
const Identifier ,
QScriptClass::QueryFlags  flags 
)
virtual

◆ setProperty()

void FlatListScriptClass::setProperty ( Object obj,
const Identifier name,
const QScriptValue value 
)
virtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 1189 of file qdeclarativelistmodel.cpp.

1190 {
1191  if (!value.isVariant() && !value.isRegExp() && !value.isDate() && value.isObject()) {
1192  qmlInfo(m_model->m_listModel) << "Cannot add list-type data when modifying or after modification from a worker script";
1193  return;
1194  }
1195 
1196  FlatNodeObjectData *objData = static_cast<FlatNodeObjectData*>(obj);
1197  if (!objData->nodeData) // item at this index has been deleted
1198  return;
1199 
1200  int index = objData->nodeData->index;
1201  QString propName = toString(name);
1202 
1203  int role = m_model->m_strings.value(propName, -1);
1204  if (role >= 0 && index >= 0) {
1206  row[role] = value.toVariant();
1207 
1208  QList<int> roles;
1209  roles << role;
1210  if (m_model->m_parentAgent) {
1211  // This is the list in the worker thread, so tell the agent to
1212  // emit itemsChanged() later
1213  m_model->m_parentAgent->changedData(index, 1, roles);
1214  } else {
1215  // This is the list in the main thread, so emit itemsChanged()
1216  emit m_model->m_listModel->itemsChanged(index, 1, roles);
1217  }
1218  }
1219 }
void changedData(int index, int count, const QList< int > &roles)
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QDeclarativeListModel * m_listModel
const char * name
#define emit
Definition: qobjectdefs.h:76
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
QList< QHash< int, QVariant > > m_values
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
void itemsChanged(int index, int count, const QList< int > &roles)
Emit this signal when count items at index have had their roles changed.
QHash< QString, int > m_strings
QDeclarativeListModelWorkerAgent * m_parentAgent
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
quint16 index
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
QDeclarativeInfo qmlInfo(const QObject *me)
QString toString(const Identifier &)
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

Properties

◆ m_model

FlatListModel* FlatListScriptClass::m_model
private

Definition at line 134 of file qdeclarativelistmodel_p_p.h.

Referenced by property(), and setProperty().


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