37 #include <QtWidgets/qstyle.h>
38 #include <QtWidgets/qproxystyle.h>
45 void qgraphicslinearlayout_data();
46 void qgraphicslinearlayout();
48 void alignment_data();
56 void insertItem_data();
58 void insertStretch_data();
60 void invalidate_data();
64 void itemAt_visualOrder();
65 void orientation_data();
69 void removeItem_data();
71 void setGeometry_data();
73 void defaultSpacing();
74 void setSpacing_data();
76 void setItemSpacing_data();
77 void setItemSpacing();
79 void setStretchFactor_data();
80 void setStretchFactor();
82 void defaultStretchFactors_data();
83 void defaultStretchFactors();
86 void updateGeometry();
87 void layoutDirection();
89 void avoidRecursionInInsertItem();
91 void testAlignmentInLargerLayout();
92 void testOffByOneInLargerLayout();
93 void testDefaultAlignment();
94 void combineSizePolicies();
98 void task218400_insertStretchCrash();
136 void tst_QGraphicsLinearLayout::initTestCase()
176 void tst_QGraphicsLinearLayout::qgraphicslinearlayout_data()
178 QTest::addColumn<Qt::Orientation>(
"orientation");
183 void tst_QGraphicsLinearLayout::qgraphicslinearlayout()
189 qApp->processEvents();
223 void tst_QGraphicsLinearLayout::alignment_data()
225 QTest::addColumn<Qt::Orientation>(
"orientation");
226 QTest::addColumn<QSize>(
"newSize");
233 void tst_QGraphicsLinearLayout::alignment()
242 view.setSceneRect(0, 0, 320, 240);
269 for (
size_t i = 0;
i <
sizeof(alignmentsToTest)/
sizeof(
Qt::Alignment); ++
i) {
282 w->setMinimumSize(
QSizeF(10,10));
283 w->setMaximumSize(
QSizeF(10,10));
285 w->setMinimumSize(
QSizeF(50,50));
286 w->setMaximumSize(
QSizeF(50,50));
305 if (newSize.isValid())
368 void tst_QGraphicsLinearLayout::count_data()
370 QTest::addColumn<int>(
"itemCount");
371 QTest::addColumn<int>(
"layoutCount");
379 void tst_QGraphicsLinearLayout::count()
387 for (
int i = 0;
i < itemCount; ++
i)
391 for (
int i = 0;
i < layoutCount; ++
i)
398 void tst_QGraphicsLinearLayout::dump_data()
400 QTest::addColumn<int>(
"itemCount");
401 QTest::addColumn<int>(
"layoutCount");
402 for (
int i = -1;
i < 3; ++
i) {
412 void tst_QGraphicsLinearLayout::dump()
417 for (
int i = 0;
i < itemCount; ++
i)
419 for (
int i = 0;
i < layoutCount; ++
i)
423 void tst_QGraphicsLinearLayout::geometry_data()
425 QTest::addColumn<int>(
"itemCount");
426 QTest::addColumn<int>(
"layoutCount");
427 QTest::addColumn<int>(
"itemSpacing");
428 QTest::addColumn<int>(
"spacing");
429 QTest::addColumn<Qt::Orientation>(
"orientation");
430 QTest::addColumn<QRectF>(
"rect");
447 void tst_QGraphicsLinearLayout::geometry()
462 for (
int i = 0;
i < itemCount; ++
i)
464 for (
int i = 0;
i < layoutCount; ++
i)
469 item->setMaximumSize(10, 10);
470 item->setMinimumSize(10, 10);
472 layout.setItemSpacing(0, itemSpacing);
483 void tst_QGraphicsLinearLayout::insertItem_data()
485 QTest::addColumn<int>(
"itemCount");
486 QTest::addColumn<int>(
"layoutCount");
487 QTest::addColumn<int>(
"insertItemAt");
488 QTest::addColumn<bool>(
"isWidget");
489 for (
int i = -1;
i < 4; ++
i) {
491 for (
int j = 0;
j < 2; ++
j) {
493 QTest::newRow((
"0, 0, " + postFix).constData()) << 0 << 0 <<
i << (bool)
j;
494 QTest::newRow((
"1, 0, " + postFix).constData()) << 1 << 0 <<
i << (bool)
j;
495 QTest::newRow((
"0, 1, " + postFix).constData()) << 0 << 1 <<
i << (bool)
j;
496 QTest::newRow((
"2, 2, " + postFix).constData()) << 2 << 2 <<
i << (bool)
j;
502 void tst_QGraphicsLinearLayout::insertItem()
506 QFETCH(
int, insertItemAt);
508 if (insertItemAt > layoutCount + itemCount)
512 for (
int i = 0;
i < itemCount; ++
i)
514 for (
int i = 0;
i < layoutCount; ++
i)
527 if (insertItemAt >= 0 && (itemCount + layoutCount >= 0)) {
535 else if (itemCount + layoutCount > 0)
539 void tst_QGraphicsLinearLayout::insertStretch_data()
541 QTest::addColumn<int>(
"itemCount");
542 QTest::addColumn<int>(
"layoutCount");
543 QTest::addColumn<int>(
"insertItemAt");
544 QTest::addColumn<int>(
"stretch");
545 for (
int i = -1;
i < 4; ++
i) {
547 for (
int j = 0;
j < 2; ++
j) {
558 void tst_QGraphicsLinearLayout::insertStretch()
562 QFETCH(
int, insertItemAt);
564 if (insertItemAt > layoutCount + itemCount)
575 for (
int i = 0;
i < itemCount; ++
i) {
577 item->setMinimumSize(10, 10);
578 item->setPreferredSize(25, 25);
579 item->setMaximumSize(50, 50);
582 for (
int i = 0;
i < layoutCount; ++
i) {
584 item->setMinimumSize(10, 10);
585 item->setPreferredSize(25, 25);
586 item->setMaximumSize(50, 50);
599 int prevStretch = -2;
601 widget->
resize((layoutCount + itemCount) * 25 + 25, 25);
604 if (prevStretch != -2) {
605 if (
layout->stretchFactor(
item) >= prevStretch) {
612 prevWidth = (int)(
item->geometry().width());
619 void tst_QGraphicsLinearLayout::invalidate_data()
621 QTest::addColumn<int>(
"count");
629 void tst_QGraphicsLinearLayout::invalidate()
643 qApp->processEvents();
661 void tst_QGraphicsLinearLayout::itemAt_data()
663 QTest::addColumn<int>(
"index");
670 void tst_QGraphicsLinearLayout::itemAt()
675 for (
int i = 0;
i < 3; ++
i)
681 void tst_QGraphicsLinearLayout::itemAt_visualOrder()
692 l->insertItem(0, w0);
695 l->insertItem(2,
w2);
703 void tst_QGraphicsLinearLayout::orientation_data()
705 QTest::addColumn<Qt::Orientation>(
"orientation");
711 void tst_QGraphicsLinearLayout::orientation()
726 for (
i = 0;
i < itemCount; ++
i)
733 qApp->processEvents();
735 for (
i = 0;
i < itemCount; ++
i) {
746 layout.setOrientation(orientation);
750 qApp->processEvents();
751 for (
i = 0;
i < positions.
count(); ++
i) {
760 void tst_QGraphicsLinearLayout::removeAt_data()
762 QTest::addColumn<int>(
"itemCount");
763 QTest::addColumn<int>(
"layoutCount");
764 QTest::addColumn<int>(
"removeItemAt");
765 QTest::addColumn<Qt::Orientation>(
"orientation");
766 for (
int i = -1;
i < 4; ++
i) {
768 for (
int k = 0; k < 2; ++k) {
770 QTest::newRow((
"0, 0, " + iB).constData()) << 0 << 0 <<
i << orientation;
771 QTest::newRow((
"1, 0, " + iB).constData()) << 1 << 0 <<
i << orientation;
772 QTest::newRow((
"0, 1, " + iB).constData()) << 0 << 1 <<
i << orientation;
773 QTest::newRow((
"2, 2, " + iB).constData()) << 2 << 2 <<
i << orientation;
779 void tst_QGraphicsLinearLayout::removeAt()
783 QFETCH(
int, removeItemAt);
785 if (removeItemAt >= layoutCount + itemCount)
789 for (
int i = 0;
i < itemCount; ++
i)
791 for (
int i = 0;
i < layoutCount; ++
i)
796 if (removeItemAt >= 0 && removeItemAt <
layout.
count())
801 layout.removeAt(removeItemAt);
816 void tst_QGraphicsLinearLayout::removeItem_data()
818 QTest::addColumn<int>(
"itemCount");
819 QTest::addColumn<int>(
"layoutCount");
820 QTest::addColumn<int>(
"removeItemAt");
821 for (
int i = -1;
i < 4; ++
i) {
831 void tst_QGraphicsLinearLayout::removeItem()
835 QFETCH(
int, removeItemAt);
836 if (removeItemAt >= layoutCount + itemCount)
840 for (
int i = 0;
i < itemCount; ++
i)
842 for (
int i = 0;
i < layoutCount; ++
i)
846 if (removeItemAt >= 0 && removeItemAt <
layout.
count())
860 void tst_QGraphicsLinearLayout::setGeometry_data()
862 QTest::addColumn<QRectF>(
"rect");
868 void tst_QGraphicsLinearLayout::setGeometry()
879 layout.setMaximumSize(100, 100);
910 void tst_QGraphicsLinearLayout::defaultSpacing()
915 style->horizontalSpacing = 5;
916 style->verticalSpacing = 3;
932 for (
int i = 0;
i < 2; ++
i) {
942 style->horizontalSpacing = 15;
961 style->verticalSpacing = 13;
977 void tst_QGraphicsLinearLayout::setSpacing_data()
979 QTest::addColumn<qreal>(
"spacing");
987 void tst_QGraphicsLinearLayout::setSpacing()
1001 if (oldSpacing != -1) {
1002 for (
int i = 0;
i < 3; ++
i)
1019 void tst_QGraphicsLinearLayout::setItemSpacing_data()
1021 QTest::addColumn<int>(
"index");
1022 QTest::addColumn<int>(
"spacing");
1030 void tst_QGraphicsLinearLayout::setItemSpacing()
1042 for (
int i = 0;
i < 5; ++
i) {
1047 qreal oldSpacing = 0;
1059 if (oldSpacing >= 0) {
1065 void tst_QGraphicsLinearLayout::itemSpacing()
1074 for (
int i = 0;
i < 5; ++
i) {
1081 if (defaultSpacing >= 0) {
1088 layout->setItemSpacing(1, 42);
1092 layout->setItemSpacing(1, -1);
1122 void tst_QGraphicsLinearLayout::setStretchFactor_data()
1124 QTest::addColumn<qreal>(
"totalSize");
1125 QTest::addColumn<IntList>(
"stretches");
1133 void tst_QGraphicsLinearLayout::setStretchFactor()
1149 for (
i = 0;
i < stretches.count(); ++
i) {
1151 item->setMinimumSize(5,5);
1152 item->setPreferredSize(10,5);
1153 item->setMaximumSize(50,5);
1164 qreal firstStretch = -1;
1165 qreal firstExtent = -1.;
1166 qreal sumExtent = 0;
1167 for (
i = 0;
i < stretches.count(); ++
i) {
1171 if (firstStretch != -1 && firstExtent != -1) {
1173 if (stretch == firstStretch)
1175 else if (stretch > firstStretch)
1176 QVERIFY(extent > firstExtent);
1178 QVERIFY(extent < firstExtent);
1180 firstStretch = (
qreal)stretch;
1181 firstExtent = extent;
1190 void tst_QGraphicsLinearLayout::testStretch()
1225 void tst_QGraphicsLinearLayout::defaultStretchFactors_data()
1227 QTest::addColumn<Qt::Orientation>(
"orientation");
1228 QTest::addColumn<int>(
"count");
1229 QTest::addColumn<IntList>(
"preferredSizeHints");
1230 QTest::addColumn<IntList>(
"stretches");
1231 QTest::addColumn<IntList>(
"ignoreFlag");
1232 QTest::addColumn<QSizeF>(
"newSize");
1233 QTest::addColumn<IntList>(
"expectedSizes");
1236 << (
IntList() << 20 << 40 << 60)
1240 << (
IntList() << 20 << 40 << 60);
1243 << (
IntList() << 20 << 40 << 60)
1247 << (
IntList() << 20 << 40 << 60);
1250 << (
IntList() << 20 << 40 << 60)
1254 << (
IntList() << 0 << 0 << 0);
1257 << (
IntList() << 10 << 10 << 10)
1264 << (
IntList() << 10 << 10 << 10)
1268 << (
IntList() << 10 << 0 << 10);
1272 void tst_QGraphicsLinearLayout::defaultStretchFactors()
1296 if (preferredSizeHints.value(
i, -1) >= 0) {
1299 if (stretches.value(
i, -1) >= 0) {
1302 if (ignoreFlag.value(
i, 0) != 0) {
1316 view.resize(400,300);
1317 if (newSize.isValid())
1325 if (
i < expectedSizes.count())
1333 void tst_QGraphicsLinearLayout::sizeHint_data()
1335 QTest::addColumn<Qt::SizeHint>(
"which");
1336 QTest::addColumn<QSizeF>(
"constraint");
1337 QTest::addColumn<qreal>(
"spacing");
1338 QTest::addColumn<qreal>(
"layoutMargin");
1339 QTest::addColumn<QSizeF>(
"sizeHint");
1350 void tst_QGraphicsLinearLayout::sizeHint()
1366 for (
int i = 0;
i < 3; ++
i) {
1368 item->setMinimumSize(10, 10);
1369 item->setPreferredSize(25, 25);
1370 item->setMaximumSize(50, 50);
1378 void tst_QGraphicsLinearLayout::updateGeometry()
1385 w1->setMinimumSize(100, 40);
1397 w1->setMinimumSize(110, 60);
1407 w1->setMinimumSize(110, 50);
1413 window->setLayout(layout2);
1420 w1->setMinimumSize(120, 60);
1431 w1->setMinimumSize(100, 50);
1437 window->setLayout(layout2);
1449 w1->setMinimumSize(100, 50);
1456 window->setLayout(layout2);
1464 void tst_QGraphicsLinearLayout::layoutDirection()
1504 void tst_QGraphicsLinearLayout::removeLayout()
1533 void tst_QGraphicsLinearLayout::avoidRecursionInInsertItem()
1543 void tst_QGraphicsLinearLayout::styleInfoLeak()
1549 void tst_QGraphicsLinearLayout::task218400_insertStretchCrash()
1564 void tst_QGraphicsLinearLayout::testAlignmentInLargerLayout()
1611 void tst_QGraphicsLinearLayout::testOffByOneInLargerLayout() {
1622 b->setMaximumSize(100,100);
1646 void tst_QGraphicsLinearLayout::testDefaultAlignment()
1655 w->setMaximumSize(50,50);
1662 layout->setMinimumSize(100,100);
1666 layout->setMinimumSize(-1,-1);
1671 w2->setMaximumSize(100,100);
1679 void tst_QGraphicsLinearLayout::combineSizePolicies()
1699 w2->setMaximumHeight(50);
1704 void tst_QGraphicsLinearLayout::hiddenItems()
1729 sp.setRetainSizeWhenHidden(
true);
1730 w2->setSizePolicy(
sp);
1734 sp.setRetainSizeWhenHidden(
false);
1735 w2->setSizePolicy(
sp);
1740 #include "tst_qgraphicslinearlayout.moc"
small capitals from c petite p scientific i
[1]
virtual int pixelMetric(QStyle::PixelMetric pm, const QStyleOption *option=0, const QWidget *widget=0) const override
LayoutStyle(const QString &key)
static void setStyle(QStyle *)
void setGeometry(const QRect &) override
void invalidate() override
int count() const override
void insertStretch(int index, int stretch=0)
int spacing() const override
QSize sizeHint() const override
QSize maximumSize() const override
bool setStretchFactor(QWidget *w, int stretch)
void addItem(QLayoutItem *) override
void insertItem(int index, QLayoutItem *)
void addStretch(int stretch=0)
QLayoutItem * itemAt(int) const override
void setSpacing(int spacing) override
The QBrush class defines the fill pattern of shapes drawn by QPainter.
The QByteArray class provides an array of bytes.
static QByteArray number(int, int base=10)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
static void sendPostedEvents(QObject *receiver=nullptr, int event_type=0)
The QEvent class is the base class of all event classes. Event objects contain event parameters.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
virtual void widgetEvent(QEvent *e)
void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const override
void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.
void setMaximumSize(const QSizeF &size)
void setSizePolicy(const QSizePolicy &policy)
void setPreferredSize(const QSizeF &size)
QGraphicsLayoutItem * parentLayoutItem() const
void setMinimumSize(const QSizeF &size)
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void addItem(QGraphicsLayoutItem *item)
Qt::Orientation orientation() const
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)
QGraphicsProxyWidget * addWidget(QWidget *widget, Qt::WindowFlags wFlags=Qt::WindowFlags())
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
QRect geometry() const override
bool setAlignment(QWidget *w, Qt::Alignment alignment)
void removeItem(QLayoutItem *)
void setContentsMargins(int left, int top, int right, int bottom)
virtual QRect geometry() const =0
Qt::Alignment alignment() const
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
void append(parameter_type t)
The QObject class is the base class of all Qt objects.
The QPainter class performs low-level painting on widgets and other paint devices.
void setBrush(const QBrush &brush)
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
constexpr qreal x() const noexcept
constexpr qreal y() const noexcept
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 QSizeF size() const noexcept
constexpr QSize size() const noexcept
The QSizeF class defines the size of a two-dimensional object using floating point precision.
constexpr qreal width() const noexcept
constexpr qreal height() const noexcept
void transpose() noexcept
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.
The QString class provides a Unicode character string.
@ 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.
void widgetEvent(QEvent *e) override
int layoutDirectionChange
SubQGraphicsLinearLayout(Qt::Orientation orientation=Qt::Horizontal)
union Alignment_ Alignment
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout=5000)
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message)
QT_END_INCLUDE_NAMESPACE typedef double qreal
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLfloat GLfloat GLfloat GLfloat h
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 QFETCH(Type, name)
#define QVERIFY(statement)
QGraphicsWidget * textEdit