1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
48
class QtTestTableModel: public QAbstractTableModel
54
QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
55
: QAbstractTableModel(parent),
57
column_count(columns) {}
59
int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; }
60
int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; }
61
bool isEditable(const QModelIndex &) const { return true; }
63
QVariant data(const QModelIndex &idx, int role) const
65
if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
66
qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
70
if (role == Qt::DisplayRole || role == Qt::EditRole)
71
return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0);
76
bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex())
78
if (start < 0 || start > row_count)
81
beginInsertRows(parent, start, start + count - 1);
87
bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex())
89
if (start < 0 || start >= row_count || row_count < count)
92
beginRemoveRows(parent, start, start + count - 1);
98
bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex())
100
if (start < 0 || start > column_count)
103
beginInsertColumns(parent, start, start + count - 1);
104
column_count += count;
109
bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex())
111
if (start < 0 || start >= column_count || column_count < count)
114
beginRemoveColumns(parent, start, start + count - 1);
115
column_count -= count;
127
class tst_QTableView : public QObject
133
virtual ~tst_QTableView();
142
void spanSelectColumn();
143
void spanSelectAll();
144
void rowInsertion_data();
146
void rowRemoval_data();
148
void columnInsertion_data();
149
void columnInsertion();
150
void columnRemoval_data();
151
void columnRemoval();
153
static inline void spanInit_helper(QTableView *);
156
tst_QTableView::tst_QTableView()
160
tst_QTableView::~tst_QTableView()
164
void tst_QTableView::init()
168
void tst_QTableView::cleanup()
172
void tst_QTableView::spanInit_helper(QTableView *view)
174
for (int i=0; i < 40; i++) {
175
view->setSpan(1+i%2, 1+4*i, 1+i%3, 2);
178
for (int i=1; i < 40; i++) {
179
view->setSpan(6 + i*7, 4, 4, 50);
183
void tst_QTableView::spanInit()
185
QtTestTableModel model(500, 500);
194
void tst_QTableView::spanDraw()
196
QtTestTableModel model(500, 500);
205
QImage image(500, 500, QImage::Format_ARGB32_Premultiplied);
206
QPainter painter(&image);
212
void tst_QTableView::spanSelectAll()
214
QtTestTableModel model(500, 500);
227
void tst_QTableView::spanSelectColumn()
229
QtTestTableModel model(500, 500);
242
typedef QVector<QRect> SpanList;
243
Q_DECLARE_METATYPE(SpanList)
247
QTest::addColumn<SpanList>("spans");
249
QTest::newRow("Without spans")
252
QTest::newRow("With spans")
261
<< QRect(6, 7, 1, 3));
264
void tst_QTableView::rowInsertion_data()
269
void tst_QTableView::rowInsertion()
271
QFETCH(SpanList, spans);
273
QtTestTableModel model(10, 10);
275
view.setModel(&model);
277
foreach (QRect span, spans)
278
view.setSpan(span.top(), span.left(), span.height(), span.width());
283
view.model()->insertRows(0, 2);
284
view.model()->insertRows(5, 2);
285
view.model()->insertRows(8, 2);
286
view.model()->insertRows(12, 2);
290
void tst_QTableView::rowRemoval_data()
295
void tst_QTableView::rowRemoval()
297
QFETCH(SpanList, spans);
299
QtTestTableModel model(10, 10);
301
view.setModel(&model);
303
foreach (QRect span, spans)
304
view.setSpan(span.top(), span.left(), span.height(), span.width());
309
view.model()->removeRows(3, 3);
313
void tst_QTableView::columnInsertion_data()
318
void tst_QTableView::columnInsertion()
320
QFETCH(SpanList, spans);
322
QtTestTableModel model(10, 10);
324
view.setModel(&model);
326
// Same set as for rowInsertion, just swapping columns and rows.
327
foreach (QRect span, spans)
328
view.setSpan(span.left(), span.top(), span.width(), span.height());
333
view.model()->insertColumns(0, 2);
334
view.model()->insertColumns(5, 2);
335
view.model()->insertColumns(8, 2);
336
view.model()->insertColumns(12, 2);
340
void tst_QTableView::columnRemoval_data()
345
void tst_QTableView::columnRemoval()
347
QFETCH(SpanList, spans);
349
QtTestTableModel model(10, 10);
351
view.setModel(&model);
353
// Same set as for rowRemoval, just swapping columns and rows.
354
foreach (QRect span, spans)
355
view.setSpan(span.left(), span.top(), span.width(), span.height());
360
view.model()->removeColumns(3, 3);
364
QTEST_MAIN(tst_QTableView)
365
#include "tst_qtableview.moc"