1
/****************************************************************************
3
** Copyright (C) 2009 Stephen Kelly <steveire@gmail.com>
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the test suite of the Qt Toolkit.
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
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.
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.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
40
****************************************************************************/
42
#ifndef DYNAMICTREEMODEL_H
43
#define DYNAMICTREEMODEL_H
45
#include <QtCore/QAbstractItemModel>
47
#include <QtCore/QHash>
48
#include <QtCore/QList>
51
class DynamicTreeModel : public QAbstractItemModel
56
DynamicTreeModel(QObject *parent = 0);
58
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
59
QModelIndex parent(const QModelIndex &index) const;
60
int rowCount(const QModelIndex &index = QModelIndex()) const;
61
int columnCount(const QModelIndex &index = QModelIndex()) const;
63
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
70
Finds the parent id of the string with id @p searchId.
72
Returns -1 if not found.
74
qint64 findParentId(qint64 searchId) const;
77
QHash<qint64, QString> m_items;
78
QHash<qint64, QList<QList<qint64> > > m_childItems;
80
qint64 newId() { return nextId++; };
82
QModelIndex m_nextParentIndex;
88
friend class ModelInsertCommand;
89
friend class ModelMoveCommand;
90
friend class ModelResetCommand;
91
friend class ModelResetCommandFixed;
96
class ModelChangeCommand : public QObject
101
ModelChangeCommand( DynamicTreeModel *model, QObject *parent = 0 );
103
virtual ~ModelChangeCommand() {}
105
void setAncestorRowNumbers(QList<int> rowNumbers) { m_rowNumbers = rowNumbers; }
107
QModelIndex findIndex(QList<int> rows);
109
void setStartRow(int row) { m_startRow = row; }
111
void setEndRow(int row) { m_endRow = row; }
113
void setNumCols(int cols) { m_numCols = cols; }
115
virtual void doCommand() = 0;
118
DynamicTreeModel* m_model;
119
QList<int> m_rowNumbers;
126
typedef QList<ModelChangeCommand*> ModelChangeCommandList;
128
class ModelInsertCommand : public ModelChangeCommand
134
ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0 );
135
virtual ~ModelInsertCommand() {}
137
virtual void doCommand();
141
class ModelMoveCommand : public ModelChangeCommand
145
ModelMoveCommand(DynamicTreeModel *model, QObject *parent);
147
virtual ~ModelMoveCommand() {}
149
virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
151
virtual void doCommand();
153
virtual void emitPostSignal();
155
void setDestAncestors( QList<int> rows ) { m_destRowNumbers = rows; }
157
void setDestRow(int row) { m_destRow = row; }
160
QList<int> m_destRowNumbers;
165
A command which does a move and emits a reset signal.
167
class ModelResetCommand : public ModelMoveCommand
171
ModelResetCommand(DynamicTreeModel* model, QObject* parent = 0);
173
virtual ~ModelResetCommand();
175
virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
176
virtual void emitPostSignal();
181
A command which does a move and emits a beginResetModel and endResetModel signals.
183
class ModelResetCommandFixed : public ModelMoveCommand
187
ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent = 0);
189
virtual ~ModelResetCommandFixed();
191
virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
192
virtual void emitPostSignal();