From 9c891bead8c14af0aa2fd10f74275e35af87b16c Mon Sep 17 00:00:00 2001
From: Nils Jeisecke
Date: Mon, 22 Jul 2019 19:06:34 +0200
Subject: QTextDocument: add manual test for table border logic
This adds a manual test for the QTextTable border logic.
Two HTML files are bundled as resources:
table-border-test.html: Contains various test cases for the border
logic.
table-border-test-header.html: Contains a test case for printing a table
with a repeated header.
The test application allows:
- editing
- previewing
- printing
- opening the HTML in the system browser (via temp. file)
It is possible to edit the HTML with "live preview" so new test cases
can easily be implemented.
Change-Id: Ic88488bc8b7dd74d5c03c3363f55840423462325
Reviewed-by: Shawn Rutledge
---
tests/manual/manual.pro | 1 +
tests/manual/qtexttableborders/main.cpp | 39 +++++
.../manual/qtexttableborders/qtexttableborders.pro | 10 ++
tests/manual/qtexttableborders/resources.qrc | 6 +
.../table-border-test-header.html | 129 ++++++++++++++++
.../qtexttableborders/table-border-test.html | 171 +++++++++++++++++++++
tests/manual/qtexttableborders/widget.cpp | 125 +++++++++++++++
tests/manual/qtexttableborders/widget.h | 56 +++++++
tests/manual/qtexttableborders/widget.ui | 79 ++++++++++
9 files changed, 616 insertions(+)
create mode 100644 tests/manual/qtexttableborders/main.cpp
create mode 100644 tests/manual/qtexttableborders/qtexttableborders.pro
create mode 100644 tests/manual/qtexttableborders/resources.qrc
create mode 100644 tests/manual/qtexttableborders/table-border-test-header.html
create mode 100644 tests/manual/qtexttableborders/table-border-test.html
create mode 100644 tests/manual/qtexttableborders/widget.cpp
create mode 100644 tests/manual/qtexttableborders/widget.h
create mode 100644 tests/manual/qtexttableborders/widget.ui
(limited to 'tests/manual')
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro
index e688546374..42f9878e44 100644
--- a/tests/manual/manual.pro
+++ b/tests/manual/manual.pro
@@ -35,6 +35,7 @@ qsslsocket \
qsysinfo \
qtabletevent \
qtexteditlist \
+qtexttableborders \
qtbug-8933 \
qtbug-52641 \
qtouchevent \
diff --git a/tests/manual/qtexttableborders/main.cpp b/tests/manual/qtexttableborders/main.cpp
new file mode 100644
index 0000000000..a8fdf7becc
--- /dev/null
+++ b/tests/manual/qtexttableborders/main.cpp
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include "widget.h"
+#include
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ Widget w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/tests/manual/qtexttableborders/qtexttableborders.pro b/tests/manual/qtexttableborders/qtexttableborders.pro
new file mode 100644
index 0000000000..7e454f978d
--- /dev/null
+++ b/tests/manual/qtexttableborders/qtexttableborders.pro
@@ -0,0 +1,10 @@
+#This project can be used to verify QTBUG-36152 case.
+QT += core gui printsupport
+CONFIG += c++11
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+TARGET = qtexttableborders
+TEMPLATE = app
+SOURCES += main.cpp widget.cpp
+HEADERS += widget.h
+FORMS += widget.ui
+RESOURCES += resources.qrc
diff --git a/tests/manual/qtexttableborders/resources.qrc b/tests/manual/qtexttableborders/resources.qrc
new file mode 100644
index 0000000000..a7000a73e3
--- /dev/null
+++ b/tests/manual/qtexttableborders/resources.qrc
@@ -0,0 +1,6 @@
+
+
+ table-border-test-header.html
+ table-border-test.html
+
+
diff --git a/tests/manual/qtexttableborders/table-border-test-header.html b/tests/manual/qtexttableborders/table-border-test-header.html
new file mode 100644
index 0000000000..cb29d0a41d
--- /dev/null
+++ b/tests/manual/qtexttableborders/table-border-test-header.html
@@ -0,0 +1,129 @@
+
+
+
+ Printable table with repeated header
+
+
+ Please print (to PDF, save the trees) this table and compare this to the
+ print results of Chrome/Firefox.
+
+ - Firefox fails to render the first repeated header correctly
+
- Chrome fails to render the Cell B top edge (should be red, except the first row after header
+
- Qt: Could do slightly better with the last row on each page (although both Firefox and Chrome don't work perfect here as well)
+
+
+
+
+
+
+ Header A |
+ Header B |
+
+
+
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+ Cell A | Cell B |
+
+
+
+
+
diff --git a/tests/manual/qtexttableborders/table-border-test.html b/tests/manual/qtexttableborders/table-border-test.html
new file mode 100644
index 0000000000..0339f80d0f
--- /dev/null
+++ b/tests/manual/qtexttableborders/table-border-test.html
@@ -0,0 +1,171 @@
+
+
+
+ Working Test Cases
+
+ border-collapse: separate
+
+ TC-A1: table no border
+
+
+
+ Cell 1A |
+ Cell 1B |
+
+
+
+
+ TC-A2: table attribute controlled border (1px, red)
+
+
+
+ Cell 1A |
+ Cell 1B |
+
+
+
+
+ TC-A3: table attribute controlled border (4px, blue)
+
+
+
+ Cell 1A |
+ Cell 1B |
+
+
+
+ Note: Real browsers render the inner cells border with 1px, but QTextDocument's rendering has always been like this.
+
+ border-collapse: collapse
+
+ TC-B1: table no border
+
+
+
+ Cell 1A |
+ Cell 1B |
+
+
+
+
+ TC-B2: table attribute + css controlled grid (outer border 1px)
+
+
+
+ Cell 1A |
+ Cell 1B |
+
+
+
+
+ TC-B3: table attribute + css controlled grid (outer border 4px)
+
+
+
+ Cell 1A |
+ Cell 1B |
+
+
+
+
+ TC-B4: table attribute + css controlled grid (one cell with custom edge)
+
+
+
+ Cell 1A |
+ Cell 1B (border-right: 8px solid green) |
+
+
+
+
+ TC-B5: table with single decorated cell
+
+
+
+ Cell 1A |
+ Cell 1B (border: 2px solid red) |
+
+
+
+
+ cells with competing rules
+
+ TC-C1: vertical edge (pink, 6px) wins over horizontal edge (red|blue, 6px)
+
+
+
+ Cell 1A |
+ Cell 2B |
+
+
+
+
+ TC-C2: vertical edge (pink, 6px) loses over horizontal edge (red|blue, 8px)
+
+
+
+ Cell 1A |
+ Cell 2B |
+
+
+
+
+ TC-C3: cells with span and competing rules
+
+
+
+ Cell 1A/B spans over two columns (border-bottom: red) |
+
+
+ Cell 2A (border-top loses -> red) |
+ Cell 2B (border-top wins -> green) |
+
+
+
+
+ Non-Working Test Cases
+
+ border-collapse: separate
+
+ TC-X1: table css border (red via style)
+
+
+
+ Cell 1A |
+ Cell 1B |
+
+
+
+
+ border-collapse: collapse
+
+ TC-X2: tr css border
+
+
+
+ Cell 1A (border-bottom should be red) |
+ Cell 1B (border-bottom should be red) |
+
+
+ Cell 2A (border-left should be red) |
+ Cell 2B |
+
+
+
+
+ TC-X3: cells with competing rules and colspan
+
+
+
+ Cell 1A/B spans over two columns (border-bottom: red, border-right pink) |
+
+
+ Cell 2A (border-top loses -> red) |
+ Cell 2B (border-top wins -> green) |
+
+
+
+ This is currently not 100% correct but admittedly a constructed corner case (and Chrome failes here, too).
+
+
+
diff --git a/tests/manual/qtexttableborders/widget.cpp b/tests/manual/qtexttableborders/widget.cpp
new file mode 100644
index 0000000000..21d958ce81
--- /dev/null
+++ b/tests/manual/qtexttableborders/widget.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include "widget.h"
+#include "ui_widget.h"
+
+#include
+#include
+#include
+#include
+
+#ifndef QT_NO_DESKTOPSERVICES
+#include
+#endif
+
+#ifndef QT_NO_PRINTER
+#include
+#include
+#include
+#endif
+
+// This manual test allows checking the QTextTable border logic (QTBUG-36152)
+
+Widget::Widget(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::Widget)
+{
+ ui->setupUi(this);
+ resize(1400, 800);
+
+ connect(ui->docComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &Widget::onDocumentSelected);
+ connect(ui->printButton, &QPushButton::clicked, this, &Widget::onPrint);
+ connect(ui->previewButton, &QPushButton::clicked, this, &Widget::onPreview);
+ connect(ui->openBrowserButton, &QPushButton::clicked, this, &Widget::onOpenBrowser);
+
+ connect(ui->sourceEdit, &QTextEdit::textChanged, this,
+ [this]() {
+ // make this a world class HTML IDE
+ auto pos = ui->htmlEdit->verticalScrollBar()->value();
+ ui->htmlEdit->setHtml(ui->sourceEdit->toPlainText());
+ ui->htmlEdit->verticalScrollBar()->setValue(pos);
+ });
+
+ ui->docComboBox->addItem(tr("Table Border Test"), ":/table-border-test.html");
+ ui->docComboBox->addItem(tr("Table Border Header Test"), ":/table-border-test-header.html");
+
+ ui->docComboBox->setCurrentIndex(0);
+}
+
+Widget::~Widget()
+{
+ delete ui;
+}
+
+void Widget::onDocumentSelected()
+{
+ QString url = ui->docComboBox->itemData(ui->docComboBox->currentIndex()).toString();
+ QFile f(url);
+ if (f.open(QFile::ReadOnly)) {
+ ui->sourceEdit->setPlainText(QString::fromUtf8(f.readAll()));
+ // preview HTML is set via textChanged signal
+ }
+}
+
+void Widget::onPrint()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintDialog dlg(&printer, this);
+ if (ui->htmlEdit->textCursor().hasSelection())
+ dlg.addEnabledOption(QAbstractPrintDialog::PrintSelection);
+ dlg.setWindowTitle(tr("Print Document"));
+ if (dlg.exec() == QDialog::Accepted) {
+ ui->htmlEdit->print(&printer);
+ }
+#endif
+}
+
+void Widget::onPreview()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintPreviewDialog preview(&printer, this);
+ connect(&preview, &QPrintPreviewDialog::paintRequested, ui->htmlEdit, &QTextEdit::print);
+ preview.exec();
+#endif
+}
+
+void Widget::onOpenBrowser()
+{
+ // write the current html to a temp file and open the system browser
+#ifndef QT_NO_DESKTOPSERVICES
+ auto tf = new QTemporaryFile(QDir::tempPath() + "/XXXXXX.html", this);
+ if (tf->open()) {
+ tf->write(ui->sourceEdit->toPlainText().toUtf8());
+ tf->close();
+ QDesktopServices::openUrl(QUrl::fromLocalFile(tf->fileName()));
+ }
+#endif
+}
diff --git a/tests/manual/qtexttableborders/widget.h b/tests/manual/qtexttableborders/widget.h
new file mode 100644
index 0000000000..9cf459e1cd
--- /dev/null
+++ b/tests/manual/qtexttableborders/widget.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#ifndef WIDGET_H
+#define WIDGET_H
+
+#include
+
+namespace Ui {
+class Widget;
+}
+
+class Widget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit Widget(QWidget *parent = nullptr);
+ ~Widget();
+
+private slots:
+ void onDocumentSelected();
+ void onPrint();
+ void onPreview();
+ void onOpenBrowser();
+
+private:
+ Ui::Widget *ui;
+};
+
+#endif // WIDGET_H
diff --git a/tests/manual/qtexttableborders/widget.ui b/tests/manual/qtexttableborders/widget.ui
new file mode 100644
index 0000000000..95c23be69e
--- /dev/null
+++ b/tests/manual/qtexttableborders/widget.ui
@@ -0,0 +1,79 @@
+
+
+ Widget
+
+
+
+ 0
+ 0
+ 606
+ 522
+
+
+
+ QTextTable Border Manual Test
+
+
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ Print
+
+
+
+ -
+
+
+ Preview
+
+
+
+ -
+
+
+ Open Browser
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Qt::Horizontal
+
+
+
+
+
+
+
+
+
+ docComboBox
+ printButton
+ previewButton
+ openBrowserButton
+ htmlEdit
+
+
+
+
--
cgit v1.2.3