~ubuntu-branches/ubuntu/raring/plasma-mobile/raring-proposed

« back to all changes in this revision

Viewing changes to components/runnermodel/test/dynamictreemodel.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-17 12:04:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120717120443-q3ig9u2fnltx67yg
Tags: 2.0+git2012071701-0ubuntu1
* New upstream snapshot
* Remove build-dep on kde-runtime-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2009 Stephen Kelly <steveire@gmail.com>
4
 
** All rights reserved.
5
 
** Contact: Nokia Corporation (qt-info@nokia.com)
6
 
**
7
 
** This file is part of the test suite 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 DYNAMICTREEMODEL_H
43
 
#define DYNAMICTREEMODEL_H
44
 
 
45
 
#include <QtCore/QAbstractItemModel>
46
 
 
47
 
#include <QtCore/QHash>
48
 
#include <QtCore/QList>
49
 
 
50
 
 
51
 
class DynamicTreeModel : public QAbstractItemModel
52
 
{
53
 
  Q_OBJECT
54
 
 
55
 
public:
56
 
  DynamicTreeModel(QObject *parent = 0);
57
 
 
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;
62
 
 
63
 
  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
64
 
 
65
 
  void clear();
66
 
 
67
 
protected slots:
68
 
 
69
 
  /**
70
 
  Finds the parent id of the string with id @p searchId.
71
 
 
72
 
  Returns -1 if not found.
73
 
  */
74
 
  qint64 findParentId(qint64 searchId) const;
75
 
 
76
 
private:
77
 
  QHash<qint64, QString> m_items;
78
 
  QHash<qint64, QList<QList<qint64> > > m_childItems;
79
 
  qint64 nextId;
80
 
  qint64 newId() { return nextId++; };
81
 
 
82
 
  QModelIndex m_nextParentIndex;
83
 
  int m_nextRow;
84
 
 
85
 
  int m_depth;
86
 
  int maxDepth;
87
 
 
88
 
  friend class ModelInsertCommand;
89
 
  friend class ModelMoveCommand;
90
 
  friend class ModelResetCommand;
91
 
  friend class ModelResetCommandFixed;
92
 
 
93
 
};
94
 
 
95
 
 
96
 
class ModelChangeCommand : public QObject
97
 
{
98
 
  Q_OBJECT
99
 
public:
100
 
 
101
 
  ModelChangeCommand( DynamicTreeModel *model, QObject *parent = 0 );
102
 
 
103
 
  virtual ~ModelChangeCommand() {}
104
 
 
105
 
  void setAncestorRowNumbers(QList<int> rowNumbers) { m_rowNumbers = rowNumbers; }
106
 
 
107
 
  QModelIndex findIndex(QList<int> rows);
108
 
 
109
 
  void setStartRow(int row) { m_startRow = row; }
110
 
 
111
 
  void setEndRow(int row) { m_endRow = row; }
112
 
 
113
 
  void setNumCols(int cols) { m_numCols = cols; }
114
 
 
115
 
  virtual void doCommand() = 0;
116
 
 
117
 
protected:
118
 
  DynamicTreeModel* m_model;
119
 
  QList<int> m_rowNumbers;
120
 
  int m_numCols;
121
 
  int m_startRow;
122
 
  int m_endRow;
123
 
 
124
 
};
125
 
 
126
 
typedef QList<ModelChangeCommand*> ModelChangeCommandList;
127
 
 
128
 
class ModelInsertCommand : public ModelChangeCommand
129
 
{
130
 
  Q_OBJECT
131
 
 
132
 
public:
133
 
 
134
 
  ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0 );
135
 
  virtual ~ModelInsertCommand() {}
136
 
 
137
 
  virtual void doCommand();
138
 
};
139
 
 
140
 
 
141
 
class ModelMoveCommand : public ModelChangeCommand
142
 
{
143
 
  Q_OBJECT
144
 
public:
145
 
  ModelMoveCommand(DynamicTreeModel *model, QObject *parent);
146
 
 
147
 
  virtual ~ModelMoveCommand() {}
148
 
 
149
 
  virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
150
 
 
151
 
  virtual void doCommand();
152
 
 
153
 
  virtual void emitPostSignal();
154
 
 
155
 
  void setDestAncestors( QList<int> rows ) { m_destRowNumbers = rows; }
156
 
 
157
 
  void setDestRow(int row) { m_destRow = row; }
158
 
 
159
 
protected:
160
 
  QList<int> m_destRowNumbers;
161
 
  int m_destRow;
162
 
};
163
 
 
164
 
/**
165
 
  A command which does a move and emits a reset signal.
166
 
*/
167
 
class ModelResetCommand : public ModelMoveCommand
168
 
{
169
 
  Q_OBJECT
170
 
public:
171
 
  ModelResetCommand(DynamicTreeModel* model, QObject* parent = 0);
172
 
 
173
 
  virtual ~ModelResetCommand();
174
 
 
175
 
  virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
176
 
  virtual void emitPostSignal();
177
 
 
178
 
};
179
 
 
180
 
/**
181
 
  A command which does a move and emits a beginResetModel and endResetModel signals.
182
 
*/
183
 
class ModelResetCommandFixed : public ModelMoveCommand
184
 
{
185
 
  Q_OBJECT
186
 
public:
187
 
  ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent = 0);
188
 
 
189
 
  virtual ~ModelResetCommandFixed();
190
 
 
191
 
  virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
192
 
  virtual void emitPostSignal();
193
 
 
194
 
};
195
 
 
196
 
 
197
 
#endif