#pragma once #include #include #include #include #include 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()> makeReader; std::function()> makeSource; // required when scheme is set bool loaderIncludesWeb = false; // formats whose content may reference web images (epub) }; class FormatRegistry { public: explicit FormatRegistry(QVector specs); std::unique_ptr 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 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 m_specs; };