diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-09-04 19:21:58 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-11-01 21:28:55 +0100 |
commit | 1022b0d111ea401a9aee719f89c75ff0ddb4fe9b (patch) | |
tree | 8df9faaab1749a5889fccefe9be47be356015fdd /examples/corelib/serialization/convert/converter.cpp | |
parent | 8b8fc42f2c6b08097bcd04038ed7f12667a90875 (diff) |
Eliminate duplicate overrides of Converter methods in example
The Out-only converters shouldn't need to implement loadFile(), as it
shouldn't be called - a converter is not used for input unless it says
it supports input. At the same time, provide the "ground state"
implementations for optionsHelp(), outputOptions() and probeFile() to
save the trivial implementations the need to duplicate one another.
In the process, make the handling of loadFile()'s outputConverter more
consistent among those that do implement it. Always set
outputConverter if it's initially null (the caller does assert this).
Pick-to: 6.6 6.5
Task-number: QTBUG-111228
Change-Id: I856d12c791d1f8e0accdb7dd1412d493117b2302
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'examples/corelib/serialization/convert/converter.cpp')
-rw-r--r-- | examples/corelib/serialization/convert/converter.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/examples/corelib/serialization/convert/converter.cpp b/examples/corelib/serialization/convert/converter.cpp index 7ecd4134e9..231d0d51cd 100644 --- a/examples/corelib/serialization/convert/converter.cpp +++ b/examples/corelib/serialization/convert/converter.cpp @@ -23,3 +23,20 @@ const QList<const Converter *> &Converter::allConverters() { return converters(); } + +// Some virtual methods that Converter classes needn't override, when not relevant: +Converter::Options Converter::outputOptions() const { return {}; } +const char *Converter::optionsHelp() const { return nullptr; } +bool Converter::probeFile(QIODevice *) const { return false; } + +// The virtual method they should override if they claim to support In: +QVariant Converter::loadFile(QIODevice *, const Converter *&outputConverter) const +{ + Q_ASSERT(!directions().testFlag(Converter::Direction::In)); + // For those that don't, this should never be called. + Q_UNIMPLEMENTED(); + // But every implementation should at least do this: + if (!outputConverter) + outputConverter = this; + return QVariant(); +} |