QtBase  v6.3.1
tst_qgraphicslayout.cpp
Go to the documentation of this file.
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 
29 #include <QTest>
30 #include <QGraphicsLayout>
31 #include <QGraphicsLinearLayout>
32 #include <QGraphicsWidget>
33 #include <QGraphicsView>
34 
35 class tst_QGraphicsLayout : public QObject
36 {
37  Q_OBJECT
38 public:
41 
42 private slots:
43  void invalidate();
44 };
45 
46 
47 class RectWidget : public QGraphicsWidget
48 {
49 public:
50  RectWidget(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { }) : QGraphicsWidget(parent, wFlags), setGeometryCalls(0) {}
51 
53  {
57  painter->drawLine(rect().topLeft(), rect().bottomRight());
58  painter->drawLine(rect().bottomLeft(), rect().topRight());
59  }
60 
61  void setGeometry(const QRectF &rect) override
62  {
63  //qDebug() << "setGeometry():" << this->data(0).toString();
66  }
67 
70  }
71 
73 };
74 
84 void tst_QGraphicsLayout::invalidate()
85 {
90 
92  window->setGeometryCalls = setGeometryCalls;
93  window->setData(0, QString(QChar('a')));
94 
96  RectWidget *leaf = 0;
97  const int depth = 100;
99  for (int i = 1; i < depth; ++i) {
101  l->setContentsMargins(0,0,0,0);
102  RectWidget *child = new RectWidget;
103  child->setData(0, QString(QChar('a' + i)));
104  child->setGeometryCalls = setGeometryCalls;
105  l->addItem(child);
106  parent = child;
107  }
108  leaf = parent;
109  leaf->setMinimumSize(QSizeF(1,1));
110 
111  view->show();
112 
114 
115  // ...then measure...
116 
117  // should be as small as possible, to reduce overhead of painting
118  QSizeF size(1, 1);
119  setGeometryCalls->clear();
120  QBENCHMARK {
121  leaf->setMinimumSize(size);
122  leaf->setMaximumSize(size);
123  while (setGeometryCalls->count() < depth) {
125  }
126  // force a resize on each widget, this will ensure
127  // that each iteration will resize all 50 widgets
128  int w = int(size.width());
129  w^=2;
130  size.setWidth(w);
131  }
132  window->setGeometryCalls = nullptr;
133  delete view;
134  delete scene;
136  delete setGeometryCalls;
137 }
138 
140 
141 #include "tst_qgraphicslayout.moc"
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:84
static void sendPostedEvents(QObject *receiver=nullptr, int event_type=0)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
friend class QGraphicsWidget
static void setInstantInvalidatePropagation(bool enable)
void setMaximumSize(const QSizeF &size)
void setMinimumSize(const QSizeF &size)
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
QGraphicsObject * parent
the parent of the item
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
void addItem(QGraphicsItem *item)
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:60
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
QRectF rect() const
void setGeometry(const QRectF &rect) override
void updateGeometry() override
iterator insert(const Key &key, const T &value)
Definition: qmap.h:719
size_type count(const Key &key) const
Definition: qmap.h:439
void clear()
Definition: qmap.h:324
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
QObject * parent() const
Definition: qobject.h:409
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
void drawLine(const QLineF &line)
Definition: qpainter.h:477
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Definition: qpainter.cpp:3924
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
Definition: qstyleoption.h:684
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QMap< RectWidget *, QRectF > * setGeometryCalls
RectWidget(QGraphicsItem *parent=nullptr, Qt::WindowFlags wFlags={ })
void setGeometry(const QRectF &rect) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QOpenGLWidget * widget
[1]
Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout=5000)
@ RelativeSize
Definition: qnamespace.h:1163
@ Window
Definition: qnamespace.h:232
#define QString()
Definition: parse-defines.h:51
#define QBENCHMARK
Definition: qbenchmark.h:76
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLenum option
Definition: qopenglext.h:5929
#define QTEST_MAIN(TestObject)
Definition: qtest.h:664
#define QVERIFY(statement)
Definition: qtestcase.h:64
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define slots
Definition: qtmetamacros.h:76
Q_UNUSED(salary)
[21]
QGraphicsScene scene
[0]
QLayoutItem * child
[0]
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QQuickView * view
[0]