File indexing completed on 2024-12-01 03:40:21
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef FORMAT_ENUM_H 0008 #define FORMAT_ENUM_H 0009 0010 #include <QImage> 0011 #include <QMetaEnum> 0012 0013 QImage::Format formatFromString(const QString &str) 0014 { 0015 const QMetaEnum metaEnum = QMetaEnum::fromType<QImage::Format>(); 0016 const QString enumString = QStringLiteral("Format_") + str; 0017 0018 bool ok; 0019 const int res = metaEnum.keyToValue(enumString.toLatin1().constData(), &ok); 0020 0021 return ok ? static_cast<QImage::Format>(res) : QImage::Format_Invalid; 0022 } 0023 0024 QString formatToString(QImage::Format format) 0025 { 0026 const QMetaEnum metaEnum = QMetaEnum::fromType<QImage::Format>(); 0027 return QString::fromLatin1(metaEnum.valueToKey(format)).remove(QStringLiteral("Format_")); 0028 } 0029 0030 #endif