Qt 4.8
Public Functions | Private Functions | Properties | Friends | List of all members
FlatListModel Class Reference

#include <qdeclarativelistmodel_p_p.h>

Public Functions

void clear ()
 
int count () const
 
QVariant data (int index, int role) const
 
 FlatListModel (QDeclarativeListModel *base)
 
QScriptValue get (int index) const
 
bool insert (int index, const QScriptValue &)
 
void move (int from, int to, int count)
 
void remove (int index)
 
QList< int > roles () const
 
void set (int index, const QScriptValue &, QList< int > *roles)
 
void setProperty (int index, const QString &property, const QVariant &value, QList< int > *roles)
 
QString toString (int role) const
 
 ~FlatListModel ()
 

Private Functions

bool addValue (const QScriptValue &value, QHash< int, QVariant > *row, QList< int > *roles)
 
void insertedNode (int index)
 
void moveNodes (int from, int to, int n)
 
void removedNode (int index)
 

Properties

QDeclarativeListModelm_listModel
 
QList< FlatNodeData * > m_nodeData
 
QDeclarativeListModelWorkerAgentm_parentAgent
 
QHash< int, QStringm_roles
 
FlatListScriptClassm_scriptClass
 
QScriptEnginem_scriptEngine
 
QHash< QString, int > m_strings
 
QList< QHash< int, QVariant > > m_values
 

Friends

class FlatListScriptClass
 
class FlatNodeData
 
class QDeclarativeListModel
 
class QDeclarativeListModelWorkerAgent
 

Detailed Description

Definition at line 76 of file qdeclarativelistmodel_p_p.h.

Constructors and Destructors

◆ FlatListModel()

FlatListModel::FlatListModel ( QDeclarativeListModel base)

Definition at line 954 of file qdeclarativelistmodel.cpp.

956 {
957 }
FlatListScriptClass * m_scriptClass
QDeclarativeListModel * m_listModel
QDeclarativeListModelWorkerAgent * m_parentAgent
QScriptEngine * m_scriptEngine

◆ ~FlatListModel()

FlatListModel::~FlatListModel ( )

Definition at line 959 of file qdeclarativelistmodel.cpp.

960 {
962 }
QList< FlatNodeData * > m_nodeData
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ addValue()

bool FlatListModel::addValue ( const QScriptValue value,
QHash< int, QVariant > *  row,
QList< int > *  roles 
)
private

Definition at line 1075 of file qdeclarativelistmodel.cpp.

Referenced by insert(), and set().

1076 {
1077  QScriptValueIterator it(value);
1078  while (it.hasNext()) {
1079  it.next();
1080  QScriptValue value = it.value();
1081  if (!value.isVariant() && !value.isRegExp() && !value.isDate() && value.isObject()) {
1082  qmlInfo(m_listModel) << "Cannot add list-type data when modifying or after modification from a worker script";
1083  return false;
1084  }
1085 
1086  QString name = it.name();
1087  QVariant v = it.value().toVariant();
1088 
1090  if (iter == m_strings.end()) {
1091  int role = m_roles.count();
1092  m_roles.insert(role, name);
1093  iter = m_strings.insert(name, role);
1094  if (roles)
1095  roles->append(role);
1096  } else {
1097  int role = iter.value();
1098  if (roles && row->contains(role) && row->value(role) != v)
1099  roles->append(role);
1100  }
1101  row->insert(*iter, v);
1102  }
1103  return true;
1104 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define it(className, varName)
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
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QDeclarativeListModel * m_listModel
const char * name
QHash< int, QString > m_roles
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
QHash< QString, int > m_strings
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
QDeclarativeInfo qmlInfo(const QObject *me)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

◆ clear()

void FlatListModel::clear ( )

Definition at line 989 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::clear().

990 {
991  m_values.clear();
992 
994  m_nodeData.clear();
995 }
QList< FlatNodeData * > m_nodeData
QList< QHash< int, QVariant > > m_values
void clear()
Removes all items from the list.
Definition: qlist.h:764
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

◆ count()

int FlatListModel::count ( ) const

Definition at line 984 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::data().

985 {
986  return m_values.count();
987 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QHash< int, QVariant > > m_values

◆ data()

QVariant FlatListModel::data ( int  index,
int  role 
) const

Definition at line 964 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::data(), FlatNodeData::FlatNodeData(), get(), and FlatNodeData::~FlatNodeData().

965 {
966  Q_ASSERT(index >= 0 && index < m_values.count());
967  if (m_values[index].contains(role))
968  return m_values[index][role];
969  return QVariant();
970 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QHash< int, QVariant > > m_values
quint16 index

◆ get()

QScriptValue FlatListModel::get ( int  index) const

Definition at line 1017 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::get().

1018 {
1020 
1021  if (!scriptEngine)
1022  return 0;
1023 
1024  if (index < 0 || index >= m_values.count())
1025  return scriptEngine->undefinedValue();
1026 
1027  FlatListModel *that = const_cast<FlatListModel*>(this);
1028  if (!m_scriptClass)
1029  that->m_scriptClass = new FlatListScriptClass(that, scriptEngine);
1030 
1032  if (!data) {
1033  data = new FlatNodeData(index);
1034  that->m_nodeData.replace(index, data);
1035  }
1036 
1037  return QScriptDeclarativeClass::newObject(scriptEngine, m_scriptClass, new FlatNodeObjectData(data));
1038 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
QVariant data(int index, int role) const
friend class FlatListScriptClass
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
FlatListScriptClass * m_scriptClass
The QScriptEngine class provides an environment for evaluating Qt Script code.
QList< FlatNodeData * > m_nodeData
QDeclarativeListModel * m_listModel
QList< QHash< int, QVariant > > m_values
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
void replace(int i, const T &t)
Replaces the item at index position i with value.
Definition: qlist.h:609
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
quint16 index
QScriptEngine * m_scriptEngine
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.

◆ insert()

bool FlatListModel::insert ( int  index,
const QScriptValue value 
)

Definition at line 1003 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::insert().

1004 {
1005  Q_ASSERT(index >= 0 && index <= m_values.count());
1006 
1008  if (!addValue(value, &row, 0))
1009  return false;
1010 
1011  m_values.insert(index, row);
1013 
1014  return true;
1015 }
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void insertedNode(int index)
QList< QHash< int, QVariant > > m_values
quint16 index
bool addValue(const QScriptValue &value, QHash< int, QVariant > *row, QList< int > *roles)

◆ insertedNode()

void FlatListModel::insertedNode ( int  index)
private

Definition at line 1106 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModelWorkerAgent::event(), and insert().

1107 {
1108  if (index >= 0 && index <= m_values.count()) {
1109  m_nodeData.insert(index, 0);
1110 
1111  for (int i=index + 1; i<m_nodeData.count(); i++) {
1112  if (m_nodeData[i])
1113  m_nodeData[i]->index = i;
1114  }
1115  }
1116 }
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< FlatNodeData * > m_nodeData
QList< QHash< int, QVariant > > m_values
quint16 index

◆ move()

void FlatListModel::move ( int  from,
int  to,
int  count 
)

Definition at line 1069 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::move().

1070 {
1071  qdeclarativelistmodel_move<QList<QHash<int, QVariant> > >(from, to, n, &m_values);
1072  moveNodes(from, to, n);
1073 }
void moveNodes(int from, int to, int n)
QList< QHash< int, QVariant > > m_values

◆ moveNodes()

void FlatListModel::moveNodes ( int  from,
int  to,
int  n 
)
private

Definition at line 1130 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModelWorkerAgent::event(), and move().

1131 {
1132  if (!m_listModel->canMove(from, to, n))
1133  return;
1134 
1135  qdeclarativelistmodel_move<QList<FlatNodeData *> >(from, to, n, &m_nodeData);
1136 
1137  for (int i=from; i<from + (to-from); i++) {
1138  if (m_nodeData[i])
1139  m_nodeData[i]->index = i;
1140  }
1141 }
QList< FlatNodeData * > m_nodeData
QDeclarativeListModel * m_listModel
bool canMove(int from, int to, int n) const

◆ remove()

void FlatListModel::remove ( int  index)

Definition at line 997 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::remove().

998 {
1000  removedNode(index);
1001 }
QList< QHash< int, QVariant > > m_values
void removedNode(int index)
quint16 index
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ removedNode()

void FlatListModel::removedNode ( int  index)
private

Definition at line 1118 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModelWorkerAgent::event(), and remove().

1119 {
1120  if (index >= 0 && index < m_nodeData.count()) {
1121  delete m_nodeData.takeAt(index);
1122 
1123  for (int i=index; i<m_nodeData.count(); i++) {
1124  if (m_nodeData[i])
1125  m_nodeData[i]->index = i;
1126  }
1127  }
1128 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< FlatNodeData * > m_nodeData
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
quint16 index

◆ roles()

QList< int > FlatListModel::roles ( ) const

Definition at line 972 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::roles().

973 {
974  return m_roles.keys();
975 }
QHash< int, QString > m_roles
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648

◆ set()

void FlatListModel::set ( int  index,
const QScriptValue value,
QList< int > *  roles 
)

Definition at line 1040 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::set().

1041 {
1042  Q_ASSERT(index >= 0 && index < m_values.count());
1043 
1045  if (addValue(value, &row, roles))
1046  m_values[index] = row;
1047 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QHash< int, QVariant > > m_values
quint16 index
bool addValue(const QScriptValue &value, QHash< int, QVariant > *row, QList< int > *roles)

◆ setProperty()

void FlatListModel::setProperty ( int  index,
const QString property,
const QVariant value,
QList< int > *  roles 
)

Definition at line 1049 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::setProperty().

1050 {
1051  Q_ASSERT(index >= 0 && index < m_values.count());
1052 
1053  QHash<QString, int>::Iterator iter = m_strings.find(property);
1054  int role;
1055  if (iter == m_strings.end()) {
1056  role = m_roles.count();
1057  m_roles.insert(role, property);
1058  m_strings.insert(property, role);
1059  } else {
1060  role = iter.value();
1061  }
1062 
1063  if (m_values[index][role] != value) {
1064  roles->append(role);
1065  m_values[index][role] = value;
1066  }
1067 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QHash< int, QVariant > > m_values
QHash< int, QString > m_roles
QHash< QString, int > m_strings
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
quint16 index
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865

◆ toString()

QString FlatListModel::toString ( int  role) const

Definition at line 977 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModel::toString().

978 {
979  if (m_roles.contains(role))
980  return m_roles[role];
981  return QString();
982 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
QHash< int, QString > m_roles

Friends and Related Functions

◆ FlatListScriptClass

friend class FlatListScriptClass
friend

Definition at line 99 of file qdeclarativelistmodel_p_p.h.

Referenced by get().

◆ FlatNodeData

friend class FlatNodeData
friend

Definition at line 100 of file qdeclarativelistmodel_p_p.h.

Referenced by get().

◆ QDeclarativeListModel

Definition at line 98 of file qdeclarativelistmodel_p_p.h.

◆ QDeclarativeListModelWorkerAgent

Definition at line 97 of file qdeclarativelistmodel_p_p.h.

Properties

◆ m_listModel

QDeclarativeListModel* FlatListModel::m_listModel
private

◆ m_nodeData

QList<FlatNodeData *> FlatListModel::m_nodeData
private

◆ m_parentAgent

QDeclarativeListModelWorkerAgent* FlatListModel::m_parentAgent
private

◆ m_roles

QHash<int, QString> FlatListModel::m_roles
private

◆ m_scriptClass

FlatListScriptClass* FlatListModel::m_scriptClass
private

Definition at line 113 of file qdeclarativelistmodel_p_p.h.

Referenced by get().

◆ m_scriptEngine

QScriptEngine* FlatListModel::m_scriptEngine
private

◆ m_strings

QHash<QString, int> FlatListModel::m_strings
private

◆ m_values

QList<QHash<int, QVariant> > FlatListModel::m_values
private

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