2
Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#ifndef DYNAMICTREEMODEL_H
21
#define DYNAMICTREEMODEL_H
23
// #include <QAbstractItemModel>
25
#include "../abstractitemmodel.h"
35
template<typename T> class QList;
37
class DynamicTreeModel : public AbstractItemModel
42
DynamicTreeModel(QObject *parent = 0);
44
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
45
QModelIndex parent(const QModelIndex &index) const;
46
int rowCount(const QModelIndex &index = QModelIndex()) const;
47
int columnCount(const QModelIndex &index = QModelIndex()) const;
49
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
54
Finds the parent id of the string with id @p searchId.
56
Returns -1 if not found.
58
qint64 findParentId(qint64 searchId) const;
61
QHash<qint64, QString> m_items;
62
QHash<qint64, QList<QList<qint64> > > m_childItems;
64
qint64 newId() { return nextId++; };
66
QModelIndex m_nextParentIndex;
72
friend class ModelInsertCommand;
73
friend class ModelInsertWithDescendantsCommand;
74
friend class ModelRemoveCommand;
75
friend class ModelDataChangeCommand;
76
friend class ModelMoveCommand;
77
friend class ModelMoveLayoutChangeCommand;
78
// friend class ModelSortIndexCommand;
79
friend class ModelSortIndexLayoutChangeCommand;
84
class ModelChangeCommand : public QObject
89
ModelChangeCommand( DynamicTreeModel *model, QObject *parent = 0 );
91
virtual ~ModelChangeCommand() {}
93
void setAncestorRowNumbers(QList<int> rowNumbers) { m_rowNumbers = rowNumbers; }
95
QModelIndex findIndex(QList<int> rows);
97
void setStartRow(int row) { m_startRow = row; }
99
void setEndRow(int row) { m_endRow = row; }
101
void setNumCols(int cols) { m_numCols = cols; }
103
virtual void doCommand() = 0;
106
DynamicTreeModel* m_model;
107
QList<int> m_rowNumbers;
114
class ModelInsertCommand : public ModelChangeCommand
120
ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0 );
121
virtual ~ModelInsertCommand() {}
123
virtual void doCommand();
126
class ModelInsertWithDescendantsCommand : public ModelInsertCommand
131
ModelInsertWithDescendantsCommand(DynamicTreeModel *model, QObject *parent = 0);
132
virtual ~ModelInsertWithDescendantsCommand() {}
134
void setNumDescendants(QList<QPair<int, int > > descs);
136
virtual void doCommand();
139
QList<QPair<int, int> > m_descs;
142
class ModelRemoveCommand : public ModelChangeCommand
146
ModelRemoveCommand(DynamicTreeModel *model, QObject *parent = 0 );
147
virtual ~ModelRemoveCommand() {}
149
virtual void doCommand();
151
void purgeItem(qint64 parent);
154
class ModelDataChangeCommand : public ModelChangeCommand
158
ModelDataChangeCommand(DynamicTreeModel *model, QObject *parent = 0);
160
virtual ~ModelDataChangeCommand() {}
162
virtual void doCommand();
164
void setStartColumn(int column) { m_startColumn = column; }
170
class ModelMoveCommand : public ModelChangeCommand
174
ModelMoveCommand(DynamicTreeModel *model, QObject *parent);
176
virtual ~ModelMoveCommand() {}
178
virtual void doCommand();
180
void setDestAncestors( QList<int> rows ) { m_destRowNumbers = rows; }
182
void setDestRow(int row) { m_destRow = row; }
185
QList<int> m_destRowNumbers;