QTextEditMimeData: add a hasFormat() override
This is potentially faster in the `!fragment.isEmpty()` code path. Put the supported mimetypes list in a QOffsetStringArray, as requested in code review. Also while touching these lines, use QT_CONFIG(textodfwriter) instead of the double negative `#ifndef QT_NO_TEXTODFWRITER`. Change-Id: Ibf5e6eb5ef8df604bafa7d646c305589c58eee5b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
fc9af57050
commit
6cd8f1fbef
@ -58,6 +58,8 @@
|
||||
#include <QtGui/qaccessible.h>
|
||||
#include <QtCore/qmetaobject.h>
|
||||
|
||||
#include <private/qoffsetstringarray_p.h>
|
||||
|
||||
#if QT_CONFIG(shortcut)
|
||||
#include "private/qapplication_p.h"
|
||||
#include "private/qshortcutmap_p.h"
|
||||
@ -3456,19 +3458,50 @@ void QUnicodeControlCharacterMenu::menuActionTriggered()
|
||||
}
|
||||
#endif // QT_NO_CONTEXTMENU
|
||||
|
||||
static constexpr auto supportedMimeTypes = qOffsetStringArray(
|
||||
"text/plain",
|
||||
"text/html",
|
||||
#if QT_CONFIG(textmarkdownwriter)
|
||||
"text/markdown",
|
||||
#endif
|
||||
#if QT_CONFIG(textodfwriter)
|
||||
"application/vnd.oasis.opendocument.text"
|
||||
#endif
|
||||
);
|
||||
|
||||
/*! \internal
|
||||
\reimp
|
||||
*/
|
||||
QStringList QTextEditMimeData::formats() const
|
||||
{
|
||||
if (!fragment.isEmpty())
|
||||
return QStringList() << u"text/plain"_s << u"text/html"_s
|
||||
#if QT_CONFIG(textmarkdownwriter)
|
||||
<< u"text/markdown"_s
|
||||
#endif
|
||||
#ifndef QT_NO_TEXTODFWRITER
|
||||
<< u"application/vnd.oasis.opendocument.text"_s
|
||||
#endif
|
||||
;
|
||||
else
|
||||
return QMimeData::formats();
|
||||
if (!fragment.isEmpty()) {
|
||||
constexpr auto size = supportedMimeTypes.count();
|
||||
QStringList ret;
|
||||
ret.reserve(size);
|
||||
for (int i = 0; i < size; ++i)
|
||||
ret.emplace_back(QLatin1StringView(supportedMimeTypes.at(i)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return QMimeData::formats();
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
\reimp
|
||||
*/
|
||||
bool QTextEditMimeData::hasFormat(const QString &format) const
|
||||
{
|
||||
if (!fragment.isEmpty()) {
|
||||
constexpr auto size = supportedMimeTypes.count();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (format == QLatin1StringView(supportedMimeTypes.at(i)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return QMimeData::hasFormat(format);
|
||||
}
|
||||
|
||||
QVariant QTextEditMimeData::retrieveData(const QString &mimeType, QMetaType type) const
|
||||
|
@ -268,6 +268,8 @@ public:
|
||||
inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
|
||||
|
||||
virtual QStringList formats() const override;
|
||||
bool hasFormat(const QString &format) const override;
|
||||
|
||||
protected:
|
||||
virtual QVariant retrieveData(const QString &mimeType, QMetaType type) const override;
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user