QtBase  v6.3.1
tst_qgraphicslinearlayout.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 <QGraphicsLinearLayout>
31 #include <QGraphicsWidget>
32 #include <QGraphicsView>
33 
35 {
36  Q_OBJECT
37 public:
40 
41 private slots:
42  void heightForWidth_data();
43  void heightForWidth();
44 };
45 
46 
48 {
50  QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override
51  {
52  if (which != Qt::PreferredSize)
53  return QGraphicsWidget::sizeHint(which, constraint);
54  if (constraint.width() < 0)
55  return QGraphicsWidget::sizeHint(which, constraint);
56  return QSizeF(constraint.width(), constraint.width());
57  }
58 };
59 
60 void tst_QGraphicsLinearLayout::heightForWidth_data()
61 {
62  QTest::addColumn<bool>("hfw");
63  QTest::addColumn<bool>("nested");
64 
65  QTest::newRow("hfw") << true << false;
66  QTest::newRow("hfw, nested") << true << true;
67  QTest::newRow("not hfw") << false << false;
68  QTest::newRow("not hfw, nested") << false << true;
69 }
70 
71 void tst_QGraphicsLinearLayout::heightForWidth()
72 {
73  QFETCH(bool, hfw);
74  QFETCH(bool, nested);
75 
79 
80  QGraphicsLinearLayout *outerlayout = 0;
81  if (nested) {
82  outerlayout = new QGraphicsLinearLayout(form);
83  for (int i = 0; i < 8; i++) {
85  outerlayout->addItem(layout);
86  outerlayout = layout;
87  }
88  }
89 
90  QGraphicsLinearLayout *qlayout = 0;
91  qlayout = new QGraphicsLinearLayout(Qt::Vertical);
92  if (nested)
93  outerlayout->addItem(qlayout);
94  else
95  form->setLayout(qlayout);
96 
98  for (int i = 0; i < 1; i++) {
99  widget = new MySquareWidget;
100  QSizePolicy sizepolicy = widget->sizePolicy();
101  sizepolicy.setHeightForWidth(hfw);
102  widget->setSizePolicy(sizepolicy);
103  qlayout->addItem(widget);
104  }
105  // make sure only one iteration is done.
106  // run with tst_QGraphicsLinearLayout.exe "heightForWidth" -tickcounter -iterations 6
107  // this will iterate 6 times the whole test, (not only the benchmark)
108  // which should reduce warmup time and give a realistic picture of the performance of
109  // effectiveSizeHint()
110  QSizeF constraint(hfw ? 100 : -1, -1);
111  QBENCHMARK {
113  }
114 
115 }
116 
117 
119 
120 #include "tst_qgraphicslinearlayout.moc"
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void addItem(QGraphicsLayoutItem *item)
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
void addItem(QGraphicsItem *item)
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setLayout(QGraphicsLayout *layout)
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const override
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition: qsizepolicy.h:54
constexpr void setHeightForWidth(bool b) noexcept
Definition: qsizepolicy.h:116
void setSizePolicy(QSizePolicy)
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition: qwidget.h:153
QOpenGLWidget * widget
[1]
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Definition: qtestcase.cpp:2658
@ Vertical
Definition: qnamespace.h:125
SizeHint
Definition: qnamespace.h:1589
@ PreferredSize
Definition: qnamespace.h:1591
void
Definition: png.h:1080
#define QBENCHMARK
Definition: qbenchmark.h:76
#define QTEST_MAIN(TestObject)
Definition: qtest.h:664
#define QFETCH(Type, name)
Definition: qtestcase.h:230
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define slots
Definition: qtmetamacros.h:76
QVBoxLayout * layout
QGraphicsWidget * form
QGraphicsScene scene
[0]
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const override