summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2018-04-13 09:19:48 +0200
committerAndy Shaw <andy.shaw@qt.io>2019-03-15 12:24:02 +0000
commitedf2e699856e0385746ea03fea23ec20c08c0b2c (patch)
treede4b6b0df07ce91c024fb2298996baab8336a781 /tests
parent11228e54b6f0799a1ed432db98de19de0c6f792a (diff)
Don't increase the size of the layout unnecessarily when moving toolbars
When the toolbar was moved from one position to another it could end up increasing the size of the saveState data due to extra lines. This removes any needless ones that should not be included. Change-Id: I1c5d094ae1405d6a82db5fcdc3cd081904706837 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/widgets/widgets/qmainwindow/saveStateSize/main.cpp111
-rw-r--r--tests/manual/widgets/widgets/qmainwindow/saveStateSize/saveStateSize.pro4
2 files changed, 115 insertions, 0 deletions
diff --git a/tests/manual/widgets/widgets/qmainwindow/saveStateSize/main.cpp b/tests/manual/widgets/widgets/qmainwindow/saveStateSize/main.cpp
new file mode 100644
index 0000000000..dbca6df454
--- /dev/null
+++ b/tests/manual/widgets/widgets/qmainwindow/saveStateSize/main.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2019 The Qt Company Ltd.
+ ** Contact: https://www.qt.io/licensing/
+ **
+ ** This file is part of the test suite of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+ ** Commercial License Usage
+ ** Licensees holding valid commercial Qt licenses may use this file in
+ ** accordance with the commercial license agreement provided with the
+ ** Software or, alternatively, in accordance with the terms contained in
+ ** a written agreement between you and The Qt Company. For licensing terms
+ ** and conditions see https://www.qt.io/terms-conditions. For further
+ ** information use the contact form at https://www.qt.io/contact-us.
+ **
+ ** GNU General Public License Usage
+ ** Alternatively, this file may be used under the terms of the GNU
+ ** General Public License version 3 as published by the Free Software
+ ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+ ** included in the packaging of this file. Please review the following
+ ** information to ensure the GNU General Public License requirements will
+ ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+// Test that the size of the saved state bytearray does not change due to moving a
+// toolbar from one area to another. It should stay the same size as the first time
+// it had that toolbar in it
+
+#include <QApplication>
+#include <QMainWindow>
+#include <QToolBar>
+#include <QPushButton>
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QMessageBox>
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+public:
+ MainWindow() : QMainWindow()
+ {
+ auto *tb = new QToolBar(this);
+ tb->setObjectName("Toolbar");
+ tb->addAction("Test action");
+ tb->addAction("Test action");
+ addToolBar(Qt::TopToolBarArea, tb);
+ auto *movableTb = new QToolBar(this);
+ movableTb->setObjectName("Movable Toolbar");
+ movableTb->addAction("Test action");
+ movableTb->addAction("Test action");
+ addToolBar(Qt::TopToolBarArea, movableTb);
+ auto *widget = new QWidget;
+ auto *vbox = new QVBoxLayout;
+ auto *label = new QLabel;
+ label->setText("1. Click on check state size to save initial state\n"
+ "2. Drag the movable toolbar in the top dock area to the left area."
+ " Click on check state size to save moved state\n"
+ "3. Drag the movable toolbar from the left dock area to the top area."
+ " Click on check state size to compare the state sizes.\n"
+ "4. Drag the movable toolbar in the top dock area to the left area."
+ " Click on check state size to compare the state sizes.\n"
+ "5. Drag the movable toolbar from the left dock area to the top area."
+ " Click on check state size to compare the state sizes.\n");
+ vbox->addWidget(label);
+ auto *pushButton = new QPushButton("Check state size");
+ connect(pushButton, &QPushButton::clicked, this, &MainWindow::checkState);
+ vbox->addWidget(pushButton);
+ widget->setLayout(vbox);
+ setCentralWidget(widget);
+ }
+public slots:
+ void checkState()
+ {
+ stepCounter++;
+ QString messageText;
+ if (stepCounter == 1) {
+ beforeMoveStateData = saveState();
+ messageText = QLatin1String("Initial state saved");
+ } else if (stepCounter == 2) {
+ afterMoveStateData = saveState();
+ messageText = QLatin1String("Moved state saved");
+ } else {
+ const int currentSaveSize = saveState().size();
+ const int compareValue = (stepCounter == 4) ? afterMoveStateData.size() : beforeMoveStateData.size();
+ messageText = QString::fromLatin1("%1 step %2")
+ .arg((currentSaveSize == compareValue) ? QLatin1String("SUCCESS") : QLatin1String("FAIL"))
+ .arg(stepCounter);
+ }
+ QMessageBox::information(this, "Step done", messageText);
+ }
+private:
+ int stepCounter = 0;
+ QByteArray beforeMoveStateData;
+ QByteArray afterMoveStateData;
+};
+
+#include "main.moc"
+
+int main(int argc, char **argv)
+{
+ QApplication a(argc, argv);
+ MainWindow mw;
+ mw.show();
+ return a.exec();
+}
+
diff --git a/tests/manual/widgets/widgets/qmainwindow/saveStateSize/saveStateSize.pro b/tests/manual/widgets/widgets/qmainwindow/saveStateSize/saveStateSize.pro
new file mode 100644
index 0000000000..6ee128ed3b
--- /dev/null
+++ b/tests/manual/widgets/widgets/qmainwindow/saveStateSize/saveStateSize.pro
@@ -0,0 +1,4 @@
+QT += widgets
+TEMPLATE = app
+TARGET = saveStateSize
+SOURCES += main.cpp