qt6windows7/examples/corelib/serialization/convert/converter.h

46 lines
1.3 KiB
C
Raw Normal View History

2023-10-30 06:33:08 +08:00
// Copyright (C) 2018 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef CONVERTER_H
#define CONVERTER_H
#include <QIODevice>
2023-11-02 01:02:52 +08:00
#include <QList>
2023-12-05 01:42:35 +08:00
#include <QStringList>
2023-10-30 06:33:08 +08:00
#include <QVariant>
2023-12-05 01:42:35 +08:00
//! [0]
2023-10-30 06:33:08 +08:00
class Converter
{
2023-12-05 01:42:35 +08:00
static QList<const Converter *> &converters();
2023-10-30 06:33:08 +08:00
protected:
Converter();
2023-12-05 01:42:35 +08:00
static bool isNull(const Converter *converter); // in nullconverter.cpp
2023-10-30 06:33:08 +08:00
public:
2023-12-05 01:42:35 +08:00
static const QList<const Converter *> &allConverters();
2023-10-30 06:33:08 +08:00
2023-11-02 01:02:52 +08:00
enum class Direction { In = 1, Out = 2, InOut = In | Out };
Q_DECLARE_FLAGS(Directions, Direction)
2023-10-30 06:33:08 +08:00
2023-11-02 01:02:52 +08:00
enum Option { SupportsArbitraryMapKeys = 0x01 };
2023-10-30 06:33:08 +08:00
Q_DECLARE_FLAGS(Options, Option)
virtual ~Converter() = 0;
2023-11-02 01:02:52 +08:00
virtual QString name() const = 0;
virtual Directions directions() const = 0;
2023-12-05 01:42:35 +08:00
virtual Options outputOptions() const;
virtual const char *optionsHelp() const;
virtual bool probeFile(QIODevice *f) const;
virtual QVariant loadFile(QIODevice *f, const Converter *&outputConverter) const;
2023-11-02 01:02:52 +08:00
virtual void saveFile(QIODevice *f, const QVariant &contents,
const QStringList &options) const = 0;
2023-10-30 06:33:08 +08:00
};
2023-11-02 01:02:52 +08:00
Q_DECLARE_OPERATORS_FOR_FLAGS(Converter::Directions)
2023-10-30 06:33:08 +08:00
Q_DECLARE_OPERATORS_FOR_FLAGS(Converter::Options)
2023-12-05 01:42:35 +08:00
//! [0]
2023-10-30 06:33:08 +08:00
#endif // CONVERTER_H