mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-05-28 00:30:23 -04:00
tests: Remove qimage_format_enum_names and just use QMetaEnum
This commit is contained in:
parent
1acb5a6177
commit
d36c191351
@ -7,56 +7,24 @@
|
|||||||
#ifndef FORMAT_ENUM_H
|
#ifndef FORMAT_ENUM_H
|
||||||
#define FORMAT_ENUM_H
|
#define FORMAT_ENUM_H
|
||||||
|
|
||||||
|
#include <QMetaEnum>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
|
||||||
// Generated from QImage::Format enum
|
|
||||||
static const char * qimage_format_enum_names[] = {
|
|
||||||
"Invalid",
|
|
||||||
"Mono",
|
|
||||||
"MonoLSB",
|
|
||||||
"Indexed8",
|
|
||||||
"RGB32",
|
|
||||||
"ARGB32",
|
|
||||||
"ARGB32_Premultiplied",
|
|
||||||
"RGB16",
|
|
||||||
"ARGB8565_Premultiplied",
|
|
||||||
"RGB666",
|
|
||||||
"ARGB6666_Premultiplied",
|
|
||||||
"RGB555",
|
|
||||||
"ARGB8555_Premultiplied",
|
|
||||||
"RGB888",
|
|
||||||
"RGB444",
|
|
||||||
"ARGB4444_Premultiplied",
|
|
||||||
"RGBX8888",
|
|
||||||
"RGBA8888",
|
|
||||||
"RGBA8888_Premultiplied"
|
|
||||||
};
|
|
||||||
// Never claim there are more than QImage::NImageFormats supported formats.
|
|
||||||
// This is future-proofing against the above list being extended.
|
|
||||||
static const int qimage_format_enum_names_count =
|
|
||||||
(sizeof(qimage_format_enum_names) / sizeof(*qimage_format_enum_names) > int(QImage::NImageFormats))
|
|
||||||
? int(QImage::NImageFormats)
|
|
||||||
: (sizeof(qimage_format_enum_names) / sizeof(*qimage_format_enum_names));
|
|
||||||
|
|
||||||
QImage::Format formatFromString(const QString &str)
|
QImage::Format formatFromString(const QString &str)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < qimage_format_enum_names_count; ++i) {
|
const QMetaEnum metaEnum = QMetaEnum::fromType<QImage::Format>();
|
||||||
if (str.compare(QLatin1String(qimage_format_enum_names[i]), Qt::CaseInsensitive) == 0) {
|
const QString enumString = QStringLiteral("Format_") + str;
|
||||||
return (QImage::Format)(i);
|
|
||||||
}
|
bool ok;
|
||||||
}
|
const int res = metaEnum.keyToValue(enumString.toLatin1().constData(), &ok);
|
||||||
return QImage::Format_Invalid;
|
|
||||||
|
return ok ? static_cast<QImage::Format>(res) : QImage::Format_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString formatToString(QImage::Format format)
|
QString formatToString(QImage::Format format)
|
||||||
{
|
{
|
||||||
int index = int(format);
|
const QMetaEnum metaEnum = QMetaEnum::fromType<QImage::Format>();
|
||||||
if (index > 0 && index < qimage_format_enum_names_count) {
|
return QString::fromLatin1(metaEnum.valueToKey(format)).remove(QStringLiteral("Format_"));
|
||||||
return QLatin1String(qimage_format_enum_names[index]);
|
|
||||||
}
|
|
||||||
return QLatin1String("<unknown:") +
|
|
||||||
QString::number(index) +
|
|
||||||
QLatin1String(">");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,8 +67,8 @@ int main(int argc, char **argv)
|
|||||||
QTextStream out(stdout);
|
QTextStream out(stdout);
|
||||||
out << "QImage formats:\n";
|
out << "QImage formats:\n";
|
||||||
// skip QImage::Format_Invalid
|
// skip QImage::Format_Invalid
|
||||||
for (int i = 1; i < qimage_format_enum_names_count; ++i) {
|
for (int i = 1; i < QImage::NImageFormats; ++i) {
|
||||||
out << " " << qimage_format_enum_names[i] << '\n';
|
out << " " << formatToString(static_cast<QImage::Format>(i)) << '\n';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user