Refactor using Fable
This commit is contained in:
90 files changed
+2080
-2267
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class FormatReader;
|
||||
class IByteSource;
|
||||
class IImageLoader;
|
||||
class IImageProvider;
|
||||
class QQmlEngine;
|
||||
|
||||
// One row per supported format. Everything a format needs — reader, image
|
||||
// byte source, provider scheme — is declared in one place; adding a format
|
||||
// means adding one row to the table built in main().
|
||||
struct FormatSpec {
|
||||
QString extension; // lowercase, without dot; unused when matchesDirectory
|
||||
bool matchesDirectory = false;
|
||||
QString scheme; // image:// scheme; empty = format has no images
|
||||
std::function<std::unique_ptr<FormatReader>()> makeReader;
|
||||
std::function<std::unique_ptr<IByteSource>()> makeSource; // required when scheme is set
|
||||
bool loaderIncludesWeb = false; // formats whose content may reference web images (epub)
|
||||
};
|
||||
|
||||
class FormatRegistry {
|
||||
public:
|
||||
explicit FormatRegistry(QVector<FormatSpec> specs);
|
||||
|
||||
std::unique_ptr<FormatReader> createReader(const QString &filePath) const;
|
||||
|
||||
// New provider for the format, or nullptr for formats without images.
|
||||
// Caller owns the pointer (the QML engine takes ownership on registration).
|
||||
IImageProvider *createImageProvider(const QString &filePath) const;
|
||||
|
||||
// Synchronous loader for measurement, or nullptr for formats without images.
|
||||
std::unique_ptr<IImageLoader> createImageLoader(const QString &filePath) const;
|
||||
|
||||
QStringList supportedExtensions() const;
|
||||
|
||||
// Register one provider per scheme with the QML engine (engine takes ownership).
|
||||
void registerImageProviders(QQmlEngine &engine) const;
|
||||
|
||||
private:
|
||||
const FormatSpec *specFor(const QString &filePath) const;
|
||||
|
||||
QVector<FormatSpec> m_specs;
|
||||
};
|
||||
Reference in new issue
Block a user