1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28#include <QAbstractTextDocumentLayout>
29#include <private/qtextdocument_p.h>
30
31#ifndef COMMON_H
32#define COMMON_H
33
34class QTestDocumentLayout : public QAbstractTextDocumentLayout
35{
36 Q_OBJECT
37public:
38 QTestDocumentLayout(QTextDocument *doc) : QAbstractTextDocumentLayout(doc), f(-1), called(false) {}
39 virtual void draw(QPainter *, const PaintContext &) {}
40 virtual int hitTest(const QPointF &, Qt::HitTestAccuracy ) const { return 0; }
41
42 virtual void documentChanged(int from, int oldLength, int length)
43 {
44 called = true;
45 lastDocumentLengths.append(t: document()->docHandle()->length());
46
47 if (f < 0)
48 return;
49
50 if(from != f ||
51 o != oldLength ||
52 l != length) {
53 qDebug(msg: "checkDocumentChanged: got %d %d %d, expected %d %d %d", from, oldLength, length, f, o, l);
54 error = true;
55 }
56 }
57
58 virtual int pageCount() const { return 1; }
59 virtual QSizeF documentSize() const { return QSizeF(); }
60
61 virtual QRectF frameBoundingRect(QTextFrame *) const { return QRectF(); }
62 virtual QRectF blockBoundingRect(const QTextBlock &) const { return QRectF(); }
63
64 int f;
65 int o;
66 int l;
67
68 void expect(int from, int oldLength, int length) {
69 f = from;
70 o = oldLength;
71 l = length;
72 error = false;
73 called = false;
74 }
75 bool error;
76 bool called;
77 QList<int> lastDocumentLengths;
78};
79
80#endif
81

source code of qtbase/tests/auto/gui/text/qtextdocument/common.h