summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-07 17:49:32 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-05-08 20:28:44 +0000
commit82b26444a456d4d5ddf5f483b7766977659bee35 (patch)
treeef9ccb72aca12b1741a75c49101030ced96adf23 /src/gui/text
parent76716c4a9adc3f9aeb251d3ebe4d1d0be38b97ee (diff)
Change QTextMarkdownWriter to pass by const pointer and QAIM
- QObjects are always passed by pointer not by reference, by convention - writeTable() takes QAIM rather than QATM to make testing via QStandardItemModel possible in the future Change-Id: I5bc6b8cd9709da4fb5d57d98fa22e0cb34360944 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextdocument.cpp2
-rw-r--r--src/gui/text/qtextdocumentwriter.cpp2
-rw-r--r--src/gui/text/qtextmarkdownwriter.cpp26
-rw-r--r--src/gui/text/qtextmarkdownwriter_p.h4
4 files changed, 17 insertions, 17 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 0a59bfb838..b5ff72e706 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -3301,7 +3301,7 @@ QString QTextDocument::toMarkdown(QTextDocument::MarkdownFeatures features) cons
QString ret;
QTextStream s(&ret);
QTextMarkdownWriter w(s, features);
- if (w.writeAll(*this))
+ if (w.writeAll(this))
return ret;
return QString();
}
diff --git a/src/gui/text/qtextdocumentwriter.cpp b/src/gui/text/qtextdocumentwriter.cpp
index c82ff873cd..193d2c0dd3 100644
--- a/src/gui/text/qtextdocumentwriter.cpp
+++ b/src/gui/text/qtextdocumentwriter.cpp
@@ -278,7 +278,7 @@ bool QTextDocumentWriter::write(const QTextDocument *document)
}
QTextStream s(d->device);
QTextMarkdownWriter writer(s, QTextDocument::MarkdownDialectGitHub);
- return writer.writeAll(*document);
+ return writer.writeAll(document);
}
#endif // textmarkdownwriter
diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp
index 0634d324b1..a445ee7e83 100644
--- a/src/gui/text/qtextmarkdownwriter.cpp
+++ b/src/gui/text/qtextmarkdownwriter.cpp
@@ -63,26 +63,26 @@ QTextMarkdownWriter::QTextMarkdownWriter(QTextStream &stream, QTextDocument::Mar
{
}
-bool QTextMarkdownWriter::writeAll(const QTextDocument &document)
+bool QTextMarkdownWriter::writeAll(const QTextDocument *document)
{
- writeFrame(document.rootFrame());
+ writeFrame(document->rootFrame());
return true;
}
-void QTextMarkdownWriter::writeTable(const QAbstractTableModel &table)
+void QTextMarkdownWriter::writeTable(const QAbstractItemModel *table)
{
- QVector<int> tableColumnWidths(table.columnCount());
- for (int col = 0; col < table.columnCount(); ++col) {
- tableColumnWidths[col] = table.headerData(col, Qt::Horizontal).toString().length();
- for (int row = 0; row < table.rowCount(); ++row) {
+ QVector<int> tableColumnWidths(table->columnCount());
+ for (int col = 0; col < table->columnCount(); ++col) {
+ tableColumnWidths[col] = table->headerData(col, Qt::Horizontal).toString().length();
+ for (int row = 0; row < table->rowCount(); ++row) {
tableColumnWidths[col] = qMax(tableColumnWidths[col],
- table.data(table.index(row, col)).toString().length());
+ table->data(table->index(row, col)).toString().length());
}
}
// write the header and separator
- for (int col = 0; col < table.columnCount(); ++col) {
- QString s = table.headerData(col, Qt::Horizontal).toString();
+ for (int col = 0; col < table->columnCount(); ++col) {
+ QString s = table->headerData(col, Qt::Horizontal).toString();
m_stream << "|" << s << QString(tableColumnWidths[col] - s.length(), Space);
}
m_stream << "|" << Qt::endl;
@@ -91,9 +91,9 @@ void QTextMarkdownWriter::writeTable(const QAbstractTableModel &table)
m_stream << '|'<< Qt::endl;
// write the body
- for (int row = 0; row < table.rowCount(); ++row) {
- for (int col = 0; col < table.columnCount(); ++col) {
- QString s = table.data(table.index(row, col)).toString();
+ for (int row = 0; row < table->rowCount(); ++row) {
+ for (int col = 0; col < table->columnCount(); ++col) {
+ QString s = table->data(table->index(row, col)).toString();
m_stream << "|" << s << QString(tableColumnWidths[col] - s.length(), Space);
}
m_stream << '|'<< Qt::endl;
diff --git a/src/gui/text/qtextmarkdownwriter_p.h b/src/gui/text/qtextmarkdownwriter_p.h
index 250288bcff..4c07bad2e7 100644
--- a/src/gui/text/qtextmarkdownwriter_p.h
+++ b/src/gui/text/qtextmarkdownwriter_p.h
@@ -64,8 +64,8 @@ class Q_GUI_EXPORT QTextMarkdownWriter
{
public:
QTextMarkdownWriter(QTextStream &stream, QTextDocument::MarkdownFeatures features);
- bool writeAll(const QTextDocument &document);
- void writeTable(const QAbstractTableModel &table);
+ bool writeAll(const QTextDocument *document);
+ void writeTable(const QAbstractItemModel *table);
int writeBlock(const QTextBlock &block, bool table, bool ignoreFormat);
void writeFrame(const QTextFrame *frame);