File: format-enum.h

package info (click to toggle)
kimageformats 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 36,256 kB
  • sloc: cpp: 13,535; makefile: 9
file content (30 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
    SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#ifndef FORMAT_ENUM_H
#define FORMAT_ENUM_H

#include <QImage>
#include <QMetaEnum>

QImage::Format formatFromString(const QString &str)
{
    const QMetaEnum metaEnum = QMetaEnum::fromType<QImage::Format>();
    const QString enumString = QStringLiteral("Format_") + str;

    bool ok;
    const int res = metaEnum.keyToValue(enumString.toLatin1().constData(), &ok);

    return ok ? static_cast<QImage::Format>(res) : QImage::Format_Invalid;
}

QString formatToString(QImage::Format format)
{
    const QMetaEnum metaEnum = QMetaEnum::fromType<QImage::Format>();
    return QString::fromLatin1(metaEnum.valueToKey(format)).remove(QStringLiteral("Format_"));
}

#endif