service/NativeResourceDocument.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QTextDocument> | ||
| 4 | #include <QHash> | ||
| 5 | #include <QImage> | ||
| 6 | #include <QUrl> | ||
| 7 | #include <utility> | ||
| 8 | |||
| 9 | // Only decoded capabilities supplied by the native image pipeline are visible. | ||
| 10 | // Never delegate missing resources to QTextDocument's ambient file/URL loader. | ||
| 11 | class NativeResourceDocument final : public QTextDocument { | ||
| 12 | public: | ||
| 13 | 2871 | explicit NativeResourceDocument(QObject *parent = nullptr, QHash<QUrl, QImage> images = {}) | |
| 14 | 2871 | : QTextDocument(parent), m_images(std::move(images)) {} | |
| 15 | protected: | ||
| 16 | 35 | QVariant loadResource(int type, const QUrl &url) override { | |
| 17 | 35 | const auto found = m_images.constFind(url); | |
| 18 |
7/7✓ Branch 3 → 4 taken 34 times.
✓ Branch 3 → 8 taken 1 time.
✓ Branch 6 → 7 taken 25 times.
✓ Branch 6 → 8 taken 9 times.
✓ Branch 9 → 10 taken 25 times.
✓ Branch 9 → 13 taken 10 times.
✓ Branch 11 → 12 taken 25 times.
|
35 | if (type == QTextDocument::ImageResource && found != m_images.cend()) return *found; |
| 19 | 10 | return QByteArray(); | |
| 20 | } | ||
| 21 | private: | ||
| 22 | const QHash<QUrl, QImage> m_images; | ||
| 23 | }; | ||
| 24 |