diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-12-18 00:56:37 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-02 04:10:35 +0000 |
commit | 355ecfb11c838b4c9facc9a631e04a52531a2127 (patch) | |
tree | 5b59ec8df2690601b8e5d33252f8ba2dc45a534c /tests/auto/widgets/itemviews | |
parent | 0df30ff22e50aa301791fc72f106ab15ce385a6a (diff) | |
download | qtbase-355ecfb11c838b4c9facc9a631e04a52531a2127.tar.gz |
Add QTextMarkdownWriter::writeTable(QAbstractTableModel)
This provides the ability to write live data from a table to Markdown,
which can be useful to load it into a text document or a wiki.
But so far QTextMarkdownWriter is still a private class, intended to be
used experimentally from QtQuick and perhaps later exposed in other ways.
Change-Id: I0de4673987e4172178604e49b5a024a05d4486ba
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r-- | tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index b1ddc6e7a2..e7822ef7de 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -32,6 +32,9 @@ #include <private/qtablewidget_p.h> #include <QtTest/QtTest> #include "private/qapplication_p.h" +#if QT_CONFIG(textmarkdownwriter) +#include "private/qtextmarkdownwriter_p.h" +#endif #include <algorithm> @@ -196,6 +199,10 @@ private slots: void viewOptions(); void taskQTBUG_7232_AllowUserToControlSingleStep(); + +#if QT_CONFIG(textmarkdownwriter) + void markdownWriter(); +#endif }; // Testing get/set functions @@ -4560,5 +4567,33 @@ void tst_QTableView::taskQTBUG_50171_selectRowAfterSwapColumns() } } +// This has nothing to do with QTableView, but it's convenient to reuse the QtTestTableModel +#if QT_CONFIG(textmarkdownwriter) + +// #define DEBUG_WRITE_OUTPUT + +void tst_QTableView::markdownWriter() +{ + QtTestTableModel model(2, 3); + QString md; + { + QTextStream stream(&md); + QTextMarkdownWriter writer(stream, QTextDocument::MarkdownDialectGitHub); + writer.writeTable(model); + } + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/table.md"); + out.open(QFile::WriteOnly); + out.write(md.toUtf8()); + out.close(); + } +#endif + + QCOMPARE(md, QString::fromLatin1("|1 |2 |3 |\n|-------|-------|-------|\n|[0,0,0]|[0,1,0]|[0,2,0]|\n|[1,0,0]|[1,1,0]|[1,2,0]|\n")); +} +#endif + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" |