diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-10-21 15:14:53 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-10-24 20:58:44 +0200 |
commit | d377d1f3a921488525f6e75c850632f559707747 (patch) | |
tree | e351fc46db44119a6499f1c4543084b1c83c27dd /src/gui/text/qtextdocument.cpp | |
parent | 5edf34848a51c7678031aeb9576b8f3b7b5fceab (diff) |
Enforce QTextDocument::MarkdownFeature compatibility at compile time
We use md4c for parsing markdown. It provides flags to control the
feature set that will be supported when parsing particular documents.
QTextMarkdownImporter::Feature is a fine-grained set of flags that
exactly match the md4c feature flags that we support in Qt so far.
QTextMarkdownImporter is a private exported class (new in 5.14).
We don't expect the corresponding flags in md4c to change in
incompatible ways in the future: the md4c authors have as much respect
for avoiding compatibility issues as we do, and likely will only add
features, not remove them.
We now enforce QTextMarkdownImporter::Features compatibility with
QTextDocument::MarkdownFeatures by setting them directly. We check
QTextMarkdownImporter::Features compatibility with md4c's #define'd
feature flags using static asserts, so that any hypothetical
incompatibility would be detected at compile time.
The enum conversion from QTextDocument::MarkdownFeatures to
QTextMarkdownImporter::Features is moved to a new QTextMarkdownImporter
constructor; thus the conversions from QTextDocument::MarkdownFeatures
to QTextMarkdownImporter::Features, and then to unsigned (in
QTextMarkdownImporter::import()) are adjacent in the same private class
implementation. If incompatibility ever occurred, we would need to
replace one or both of those with another suitable conversion function.
Change-Id: I0bf8a21eb7559df1d38406b948ef657f9060c67b
Reviewed-by: Vitaly Fanaskov <vitaly.fanaskov@qt.io>
Diffstat (limited to 'src/gui/text/qtextdocument.cpp')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 22c249d604..e94f635651 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -3420,7 +3420,7 @@ QString QTextDocument::toMarkdown(QTextDocument::MarkdownFeatures features) cons #if QT_CONFIG(textmarkdownreader) void QTextDocument::setMarkdown(const QString &markdown, QTextDocument::MarkdownFeatures features) { - QTextMarkdownImporter(static_cast<QTextMarkdownImporter::Features>(int(features))).import(this, markdown); + QTextMarkdownImporter(features).import(this, markdown); } #endif |