30 #include <QtWidgets/qgraphicsanchorlayout.h>
31 #include <private/qgraphicsanchorlayout_p.h>
32 #include <QtWidgets/qgraphicswidget.h>
33 #include <QtWidgets/qgraphicsproxywidget.h>
34 #include <QtWidgets/qgraphicsview.h>
35 #include <QtWidgets/qstylefactory.h>
36 #include <QtWidgets/qproxystyle.h>
44 hasSimplification = qgetenv(
"QT_ANCHORLAYOUT_NO_SIMPLIFICATION").isEmpty();
48 bool hasSimplification;
53 void simple_semifloat();
54 void layoutDirection();
59 void snakeOppositeDirections();
60 void fairDistribution();
61 void fairDistributionOppositeDirections();
62 void proportionalPreferred();
66 void hardComplexS60();
72 void infiniteMaxSizes();
73 void simplifiableUnfeasible();
74 void simplificationVsOrder();
75 void parallelSimplificationOfCenter();
76 void simplificationVsRedundance();
77 void spacingPersistency();
78 void snakeParallelWithLayout();
79 void parallelToHalfLayout();
81 void graphicsAnchorHandling();
82 void invalidHierarchyCheck();
107 w->setPreferredSize(preferred);
108 w->setMaximumSize(maximum);
120 QGraphicsAnchor *anchor =
l->addAnchor(firstItem, firstEdge, secondItem, secondEdge);
141 const QRectF rightToLeftGeometry =
item->geometry();
143 QRectF expectedGeometry = leftToRightGeometry;
145 if (expectedGeometry != rightToLeftGeometry) {
146 qDebug() <<
"layout->geometry():" << layoutGeometry
147 <<
"expected:" << expectedGeometry
148 <<
"actual:" << rightToLeftGeometry;
165 void tst_QGraphicsAnchorLayout::simple()
171 l->setContentsMargins(0, 0, 0, 0);
188 if (hasSimplification) {
194 void tst_QGraphicsAnchorLayout::simple_center()
205 l->setContentsMargins(0, 0, 0, 0);
231 if (hasSimplification) {
239 void tst_QGraphicsAnchorLayout::simple_semifloat()
254 l->setContentsMargins(0, 0, 0, 0);
288 void tst_QGraphicsAnchorLayout::layoutDirection()
304 l->setContentsMargins(0, 5, 10, 15);
332 QCOMPARE(checkReverseDirection(
p),
true);
334 if (hasSimplification) {
343 void tst_QGraphicsAnchorLayout::diagonal()
356 l->setContentsMargins(0, 0, 0, 0);
394 p.resize(layoutMinimumSize);
402 p.resize(layoutPreferredSize);
410 p.resize(layoutMaximumSize);
418 QSizeF testA(175.0, 300.0);
427 if (hasSimplification) {
433 QCOMPARE(checkReverseDirection(&
p),
true);
435 c->setMinimumWidth(300);
439 void tst_QGraphicsAnchorLayout::parallel()
466 l->setContentsMargins(0, 0, 0, 0);
500 p.resize(layoutMinimumSize);
509 if (!hasSimplification)
512 p.resize(layoutPreferredSize);
524 p.resize(layoutMaximumSize);
537 void tst_QGraphicsAnchorLayout::parallel2()
541 QSizeF(200.0, 100.0),
"A");
545 QSizeF(190.0, 100.0),
"B");
548 l->setContentsMargins(0, 0, 0, 0);
572 p.resize(layoutMinimumSize);
575 p.resize(layoutPreferredSize);
578 p.resize(layoutMaximumSize);
581 if (hasSimplification) {
587 void tst_QGraphicsAnchorLayout::snake()
591 QSizeF(100.0, 100.0),
"A");
595 QSizeF(40.0, 100.0),
"B");
599 QSizeF(100.0, 100.0),
"C");
602 l->setContentsMargins(0, 0, 0, 0);
628 p.resize(layoutMinimumSize);
634 p.resize(layoutPreferredSize);
640 p.resize(layoutMaximumSize);
656 QCOMPARE(layoutMinimumSize, newLayoutMinimumSize);
657 QCOMPARE(layoutMaximumSize, newLayoutMaximumSize);
658 QCOMPARE(layoutPreferredSize, newLayoutPreferredSize);
661 void tst_QGraphicsAnchorLayout::snakeOppositeDirections()
665 QSizeF(100.0, 100.0),
"A");
669 QSizeF(40.0, 100.0),
"B");
673 QSizeF(100.0, 100.0),
"C");
676 l->setContentsMargins(0, 0, 0, 0);
705 p.resize(layoutMinimumSize);
711 p.resize(layoutPreferredSize);
717 p.resize(layoutMaximumSize);
724 QCOMPARE(checkReverseDirection(&
p),
true);
727 void tst_QGraphicsAnchorLayout::fairDistribution()
731 QSizeF(100.0, 100.0),
"A");
735 QSizeF(100.0, 100.0),
"B");
739 QSizeF(100.0, 100.0),
"C");
743 QSizeF(600.0, 100.0),
"D");
747 l->setContentsMargins(0, 0, 0, 0);
776 p.resize(layoutMinimumSize);
777 if (!hasSimplification)
778 QEXPECT_FAIL(
"",
"Without simplification there is no fair distribution.",
Abort);
785 p.resize(layoutPreferredSize);
792 p.resize(layoutMaximumSize);
799 if (hasSimplification) {
805 void tst_QGraphicsAnchorLayout::fairDistributionOppositeDirections()
809 QSizeF(100.0, 100.0),
"A");
813 QSizeF(100.0, 100.0),
"B");
817 QSizeF(100.0, 100.0),
"C");
821 QSizeF(100.0, 100.0),
"D");
825 QSizeF(600.0, 100.0),
"E");
829 l->setContentsMargins(0, 0, 0, 0);
859 if (!hasSimplification)
862 p.resize(layoutMinimumSize);
866 QCOMPARE(
e->size().width(), 4 *
a->size().width());
869 p.resize(layoutPreferredSize);
873 QCOMPARE(
e->size().width(), 4 *
a->size().width());
876 p.resize(layoutMaximumSize);
880 QCOMPARE(
e->size().width(), 4 *
a->size().width());
887 void tst_QGraphicsAnchorLayout::proportionalPreferred()
897 l->setContentsMargins(0, 0, 0, 0);
927 p.resize(layoutMinimumSize);
930 p.resize(layoutPreferredSize);
931 QCOMPARE(
c->size().width(),
d->size().width());
934 p.resize(layoutMaximumSize);
943 QCOMPARE(
c->size().width(),
d->size().width());
948 if (hasSimplification) {
954 void tst_QGraphicsAnchorLayout::example()
969 l->setContentsMargins(0, 0, 0, 0);
1018 p.resize(layoutMinimumSize);
1024 p.resize(layoutPreferredSize);
1025 QCOMPARE(
p.size(), layoutPreferredSize);
1030 p.resize(layoutMaximumSize);
1036 if (hasSimplification) {
1042 void tst_QGraphicsAnchorLayout::setSpacing()
1068 l->setContentsMargins(0, 0, 0, 0);
1087 l->setHorizontalSpacing(4);
1094 l->setVerticalSpacing(0);
1129 #define CT1(c) CT2(c, c)
1130 #define CT2(c1, c2) ((uint)c1 << 16) | (uint)c2
1139 switch (
CT2(control1, control2)) {
1146 switch (
CT2(control1, control2)) {
1183 void tst_QGraphicsAnchorLayout::styleDefaults()
1203 a->setSizePolicy(spRadioButton);
1206 b->setSizePolicy(spRadioButton);
1211 c->setSizePolicy(spPushButton);
1214 d->setSizePolicy(spPushButton);
1220 style->hspacing = -1;
1221 style->vspacing = -1;
1237 view.resize(200, 200);
1251 style->hspacing = 1;
1252 style->vspacing = 2;
1284 l->setContentsMargins(0, 0, 0, 0);
1331 void tst_QGraphicsAnchorLayout::hardComplexS60()
1354 <<
"The layout has several solutions, but which solution it picks is not stable ("
1355 << actual <<
"!=" << expected <<
", iteration" << pass <<
", item" <<
item <<
')';
1356 return result.toLocal8Bit();
1359 void tst_QGraphicsAnchorLayout::stability()
1365 for (
int pass = 0; pass < 20; ++pass) {
1377 for (
int i =
l->count() - 1;
i >=0; --
i) {
1378 const QRectF actualGeom =
l->itemAt(
i)->geometry();
1380 if (actualGeom != geometries[
i])
1384 geometries[
i] = actualGeom;
1391 void tst_QGraphicsAnchorLayout::delete_anchor()
1396 QSizeF maxSize(100, 100);
1403 l->setContentsMargins(0, 0, 0, 0);
1456 void tst_QGraphicsAnchorLayout::sizePolicy()
1461 QSizeF maxSize(100, 100);
1466 l->setContentsMargins(0, 0, 0, 0);
1469 l->addAnchors(
l,
w1);
1561 if (hasSimplification) {
1576 void tst_QGraphicsAnchorLayout::conflicts()
1586 l->setContentsMargins(0, 0, 0, 0);
1608 a->setMinimumSize(
QSizeF(29,10));
1611 a->setMinimumSize(
QSizeF(30,10));
1617 void tst_QGraphicsAnchorLayout::floatConflict()
1626 l->setContentsMargins(0, 0, 0, 0);
1665 void tst_QGraphicsAnchorLayout::infiniteMaxSizes()
1667 if (
sizeof(
qreal) <= 4)
1668 QSKIP(
"qreal has too little precision, result will be wrong");
1670 l->setContentsMargins(0, 0, 0, 0);
1710 p.resize(40000, 10);
1717 void tst_QGraphicsAnchorLayout::simplifiableUnfeasible()
1721 QSizeF(100.0, 100.0),
"A");
1725 QSizeF(190.0, 100.0),
"B");
1728 l->setContentsMargins(0, 0, 0, 0);
1746 if (hasSimplification)
1750 b->setMinimumWidth(100);
1754 if (hasSimplification)
1758 a->setPreferredWidth(70);
1759 a->setMaximumWidth(70);
1763 if (hasSimplification)
1771 void tst_QGraphicsAnchorLayout::simplificationVsOrder()
1795 if (hasSimplification) {
1806 if (hasSimplification) {
1812 void tst_QGraphicsAnchorLayout::parallelSimplificationOfCenter()
1823 l->setContentsMargins(0, 0, 0, 0);
1841 void tst_QGraphicsAnchorLayout::simplificationVsRedundance()
1869 if (!hasSimplification)
1880 void tst_QGraphicsAnchorLayout::spacingPersistency()
1906 void tst_QGraphicsAnchorLayout::snakeParallelWithLayout()
1918 l->setContentsMargins(0, 0, 0, 0);
1956 void tst_QGraphicsAnchorLayout::parallelToHalfLayout()
1962 l->setContentsMargins(10, 10, 10, 10);
1983 void tst_QGraphicsAnchorLayout::globalSpacing()
1996 qreal vSpacing =
b->geometry().top() -
a->geometry().bottom();
1997 qreal hSpacing =
b->geometry().left() -
a->geometry().right();
2000 l->setVerticalSpacing(vSpacing + 10);
2001 l->setHorizontalSpacing(hSpacing + 5);
2004 qreal newVSpacing =
b->geometry().top() -
a->geometry().bottom();
2005 qreal newHSpacing =
b->geometry().left() -
a->geometry().right();
2007 QCOMPARE(newVSpacing, vSpacing + 10);
2008 QCOMPARE(newHSpacing, hSpacing + 5);
2015 newVSpacing =
b->geometry().top() -
a->geometry().bottom();
2016 newHSpacing =
b->geometry().left() -
a->geometry().right();
2022 void tst_QGraphicsAnchorLayout::graphicsAnchorHandling()
2027 l->addAnchors(
l,
a);
2059 void tst_QGraphicsAnchorLayout::invalidHierarchyCheck()
2067 "You cannot add the parent of the layout to the layout.");
2070 "You cannot add the parent of the layout to the layout.");
2073 "You cannot add the parent of the layout to the layout.");
2079 #include "tst_qgraphicsanchorlayout.moc"
small capitals from c petite p scientific i
[1]
int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
int count() const override
QLayoutItem * itemAt(int) const override
The QByteArray class provides an array of bytes.
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
The QDebug class provides an output stream for debugging information.
The QGraphicsAnchor class represents an anchor between two items in a QGraphicsAnchorLayout.
void setSizePolicy(QSizePolicy::Policy policy)
qreal spacing
the preferred space between items in the QGraphicsAnchorLayout.
void setSpacing(qreal spacing)
The QGraphicsAnchorLayout class provides a layout where one can anchor widgets together in Graphics V...
bool hasConflicts() const
static QGraphicsAnchorLayoutPrivate * get(QGraphicsAnchorLayout *q)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.
void setMinimumSize(const QSizeF &size)
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.
QRect geometry() const override
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
void resize(qsizetype size)
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
The QObject class is the base class of all Qt objects.
const QObjectList & children() const
void setParent(QObject *parent)
The QPainter class performs low-level painting on widgets and other paint devices.
void drawLine(const QLineF &line)
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
The QPointF class defines a point in the plane using floating point precision.
The QProxyStyle class is a convenience class that simplifies dynamically overriding QStyle elements.
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
The QRectF class defines a finite rectangle in the plane using floating point precision.
constexpr void moveRight(qreal pos) noexcept
constexpr qreal left() const noexcept
constexpr qreal right() const noexcept
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
The QSizeF class defines the size of a two-dimensional object using floating point precision.
The QSize class defines the size of a two-dimensional object using integer point precision.
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
void setControlType(ControlType type) noexcept
The QString class provides a Unicode character string.
The QStyleFactory class creates QStyle objects.
@ PM_LayoutVerticalSpacing
@ PM_LayoutHorizontalSpacing
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
The QStyleOption class stores the parameters used by QStyle functions.
tst_QGraphicsAnchorLayout()
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message)
Q_CORE_EXPORT void qWait(int ms)
QT_END_INCLUDE_NAMESPACE typedef double qreal
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
#define QTEST_MAIN(TestObject)
#define QSKIP(statement,...)
#define QEXPECT_FAIL(dataIndex, comment, mode)
#define QVERIFY(statement)