src/declarative/util/qdeclarativelistmodel_p.h
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QDECLARATIVELISTMODEL_H
       
    43 #define QDECLARATIVELISTMODEL_H
       
    44 
       
    45 #include <qdeclarative.h>
       
    46 #include <private/qdeclarativecustomparser_p.h>
       
    47 
       
    48 #include <QtCore/QObject>
       
    49 #include <QtCore/QStringList>
       
    50 #include <QtCore/QHash>
       
    51 #include <QtCore/QList>
       
    52 #include <QtCore/QVariant>
       
    53 #include <private/qlistmodelinterface_p.h>
       
    54 #include <QtScript/qscriptvalue.h>
       
    55 
       
    56 QT_BEGIN_HEADER
       
    57 
       
    58 QT_BEGIN_NAMESPACE
       
    59 
       
    60 QT_MODULE(Declarative)
       
    61 
       
    62 class FlatListModel;
       
    63 class NestedListModel;
       
    64 class QDeclarativeListModelWorkerAgent;
       
    65 struct ModelNode;
       
    66 class Q_DECLARATIVE_EXPORT QDeclarativeListModel : public QListModelInterface
       
    67 {
       
    68     Q_OBJECT
       
    69     Q_PROPERTY(int count READ count NOTIFY countChanged)
       
    70 
       
    71 public:
       
    72     QDeclarativeListModel(QObject *parent=0);
       
    73     ~QDeclarativeListModel();
       
    74 
       
    75     virtual QList<int> roles() const;
       
    76     virtual QString toString(int role) const;
       
    77     virtual int count() const;
       
    78     virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
       
    79     virtual QVariant data(int index, int role) const;
       
    80 
       
    81     Q_INVOKABLE void clear();
       
    82     Q_INVOKABLE void remove(int index);
       
    83     Q_INVOKABLE void append(const QScriptValue&);
       
    84     Q_INVOKABLE void insert(int index, const QScriptValue&);
       
    85     Q_INVOKABLE QScriptValue get(int index) const;
       
    86     Q_INVOKABLE void set(int index, const QScriptValue&);
       
    87     Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value);
       
    88     Q_INVOKABLE void move(int from, int to, int count);
       
    89     Q_INVOKABLE void sync();
       
    90 
       
    91     QDeclarativeListModelWorkerAgent *agent();
       
    92 
       
    93 Q_SIGNALS:
       
    94     void countChanged();
       
    95 
       
    96 private:
       
    97     friend class QDeclarativeListModelParser;
       
    98     friend class QDeclarativeListModelWorkerAgent;
       
    99     friend struct ModelNode;
       
   100 
       
   101     QDeclarativeListModel(bool workerCopy, QObject *parent=0);
       
   102     bool flatten();
       
   103     bool modifyCheck();
       
   104 
       
   105     QDeclarativeListModelWorkerAgent *m_agent;
       
   106     NestedListModel *m_nested;
       
   107     FlatListModel *m_flat;
       
   108     bool m_isWorkerCopy;
       
   109 };
       
   110 
       
   111 // ### FIXME
       
   112 class QDeclarativeListElement : public QObject
       
   113 {
       
   114 Q_OBJECT
       
   115 };
       
   116 
       
   117 class QDeclarativeListModelParser : public QDeclarativeCustomParser
       
   118 {
       
   119 public:
       
   120     QByteArray compile(const QList<QDeclarativeCustomParserProperty> &);
       
   121     void setCustomData(QObject *, const QByteArray &);
       
   122 
       
   123 private:
       
   124     struct ListInstruction
       
   125     {
       
   126         enum { Push, Pop, Value, Set } type;
       
   127         int dataIdx;
       
   128     };
       
   129     struct ListModelData
       
   130     {
       
   131         int dataOffset;
       
   132         int instrCount;
       
   133         ListInstruction *instructions() const;
       
   134     };
       
   135     bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data);
       
   136 
       
   137     bool definesEmptyList(const QString &);
       
   138 };
       
   139 
       
   140 
       
   141 QT_END_NAMESPACE
       
   142 
       
   143 QML_DECLARE_TYPE(QDeclarativeListModel)
       
   144 QML_DECLARE_TYPE(QDeclarativeListElement)
       
   145 
       
   146 QT_END_HEADER
       
   147 
       
   148 #endif // QDECLARATIVELISTMODEL_H