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>
parent
76716c4a9a
commit
82b26444a4
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ QString tst_QTextMarkdownWriter::documentToUnixMarkdown()
|
|||
QString ret;
|
||||
QTextStream ts(&ret, QIODevice::WriteOnly);
|
||||
QTextMarkdownWriter writer(ts, QTextDocument::MarkdownDialectGitHub);
|
||||
writer.writeAll(*document);
|
||||
writer.writeAll(document);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4579,7 +4579,7 @@ void tst_QTableView::markdownWriter()
|
|||
{
|
||||
QTextStream stream(&md);
|
||||
QTextMarkdownWriter writer(stream, QTextDocument::MarkdownDialectGitHub);
|
||||
writer.writeTable(model);
|
||||
writer.writeTable(&model);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_WRITE_OUTPUT
|
||||
|
|
|
|||
Loading…
Reference in New Issue