~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/akonadi_next/tests/dynamictreemodel.h

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2009-07-10 06:34:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20090710063450-neojgew2fh0n3y0u
Tags: 4:4.2.96-0ubuntu1
* New upstream release
* Bump kde build-deps to 4.2.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
3
 
 
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.
8
 
 
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.
13
 
 
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
17
 
    02110-1301, USA.
18
 
*/
19
 
 
20
 
#ifndef DYNAMICTREEMODEL_H
21
 
#define DYNAMICTREEMODEL_H
22
 
 
23
 
// #include <QAbstractItemModel>
24
 
 
25
 
#include "../abstractitemmodel.h"
26
 
 
27
 
#include <QHash>
28
 
#include <QList>
29
 
#include <QUuid>
30
 
 
31
 
#include <QDebug>
32
 
 
33
 
#include <kdebug.h>
34
 
 
35
 
template<typename T> class QList;
36
 
 
37
 
class DynamicTreeModel : public AbstractItemModel
38
 
{
39
 
  Q_OBJECT
40
 
 
41
 
public:
42
 
  DynamicTreeModel(QObject *parent = 0);
43
 
 
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;
48
 
 
49
 
  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
50
 
 
51
 
protected slots:
52
 
 
53
 
  /**
54
 
  Finds the parent id of the string with id @p searchId.
55
 
 
56
 
  Returns -1 if not found.
57
 
  */
58
 
  qint64 findParentId(qint64 searchId) const;
59
 
 
60
 
private:
61
 
  QHash<qint64, QString> m_items;
62
 
  QHash<qint64, QList<QList<qint64> > > m_childItems;
63
 
  qint64 nextId;
64
 
  qint64 newId() { return nextId++; };
65
 
 
66
 
  QModelIndex m_nextParentIndex;
67
 
  int m_nextRow;
68
 
 
69
 
  int m_depth;
70
 
  int maxDepth;
71
 
 
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;
80
 
 
81
 
};
82
 
 
83
 
 
84
 
class ModelChangeCommand : public QObject
85
 
{
86
 
  Q_OBJECT
87
 
public:
88
 
 
89
 
  ModelChangeCommand( DynamicTreeModel *model, QObject *parent = 0 );
90
 
 
91
 
  virtual ~ModelChangeCommand() {}
92
 
 
93
 
  void setAncestorRowNumbers(QList<int> rowNumbers) { m_rowNumbers = rowNumbers; }
94
 
 
95
 
  QModelIndex findIndex(QList<int> rows);
96
 
 
97
 
  void setStartRow(int row) { m_startRow = row; }
98
 
 
99
 
  void setEndRow(int row) { m_endRow = row; }
100
 
 
101
 
  void setNumCols(int cols) { m_numCols = cols; }
102
 
 
103
 
  virtual void doCommand() = 0;
104
 
 
105
 
protected:
106
 
  DynamicTreeModel* m_model;
107
 
  QList<int> m_rowNumbers;
108
 
  int m_startRow;
109
 
  int m_endRow;
110
 
  int m_numCols;
111
 
 
112
 
};
113
 
 
114
 
class ModelInsertCommand : public ModelChangeCommand
115
 
{
116
 
  Q_OBJECT
117
 
 
118
 
public:
119
 
 
120
 
  ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0 );
121
 
  virtual ~ModelInsertCommand() {}
122
 
 
123
 
  virtual void doCommand();
124
 
};
125
 
 
126
 
class ModelInsertWithDescendantsCommand : public ModelInsertCommand
127
 
{
128
 
  Q_OBJECT
129
 
 
130
 
public:
131
 
  ModelInsertWithDescendantsCommand(DynamicTreeModel *model, QObject *parent = 0);
132
 
  virtual ~ModelInsertWithDescendantsCommand() {}
133
 
 
134
 
  void setNumDescendants(QList<QPair<int, int > > descs);
135
 
 
136
 
  virtual void doCommand();
137
 
 
138
 
protected:
139
 
  QList<QPair<int, int> > m_descs;
140
 
};
141
 
 
142
 
class ModelRemoveCommand : public ModelChangeCommand
143
 
{
144
 
  Q_OBJECT
145
 
public:
146
 
  ModelRemoveCommand(DynamicTreeModel *model, QObject *parent = 0 );
147
 
  virtual ~ModelRemoveCommand() {}
148
 
 
149
 
  virtual void doCommand();
150
 
 
151
 
  void purgeItem(qint64 parent);
152
 
};
153
 
 
154
 
class ModelDataChangeCommand : public ModelChangeCommand
155
 
{
156
 
  Q_OBJECT
157
 
public:
158
 
  ModelDataChangeCommand(DynamicTreeModel *model, QObject *parent = 0);
159
 
 
160
 
  virtual ~ModelDataChangeCommand() {}
161
 
 
162
 
  virtual void doCommand();
163
 
 
164
 
  void setStartColumn(int column) { m_startColumn = column; }
165
 
 
166
 
protected:
167
 
  int m_startColumn;
168
 
};
169
 
 
170
 
class ModelMoveCommand : public ModelChangeCommand
171
 
{
172
 
  Q_OBJECT
173
 
public:
174
 
  ModelMoveCommand(DynamicTreeModel *model, QObject *parent);
175
 
 
176
 
  virtual ~ModelMoveCommand() {}
177
 
 
178
 
  virtual void doCommand();
179
 
 
180
 
  void setDestAncestors( QList<int> rows ) { m_destRowNumbers = rows; }
181
 
 
182
 
  void setDestRow(int row) { m_destRow = row; }
183
 
 
184
 
protected:
185
 
  QList<int> m_destRowNumbers;
186
 
  int m_destRow;
187
 
};
188
 
 
189
 
 
190
 
#endif