Commit f5a17233 authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

Using image provider as a container for SVG images.

Removed global record management log byte array.
parent fe8bdbef
......@@ -318,7 +318,13 @@ int main(int argc, char *argv[])
/* get main handle of appliaction and QML */
QQmlApplicationEngine engine;
QQmlContext *ctx = engine.rootContext();
engine.addImageProvider(QLatin1String("images"), new ImageProvider);
globImgProvPtr = new (std::nothrow) ImageProvider;
if (Q_NULLPTR == globImgProvPtr) {
qCritical("Cannot create image provider.");
return EXIT_FAILURE;
}
engine.addImageProvider(IMAGE_PROVIDER_ID, globImgProvPtr);
/* Register application pages to QML */
registerQmlTypes(uri, QML_PAGE_LOC, qmlPages);
......
......@@ -28,16 +28,24 @@
#define LOGO_EDGE 64
ImageProvider::ImageProvider(void)
: QQuickImageProvider(QQuickImageProvider::Pixmap)
: QQuickImageProvider(QQuickImageProvider::Pixmap),
m_svgImgs()
{
}
QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size,
const QSize& requestedSize)
QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size,
const QSize &requestedSize)
{
Q_UNUSED(id);
if (Q_UNLIKELY(id.isEmpty())) {
return QPixmap();
}
QByteArray svgData(svg(id));
if (svgData.isEmpty()) {
return QPixmap();
}
QPixmap pixmap(Graphics::pixmapFromSvg(globRmLogoSvg, LOGO_EDGE));
QPixmap pixmap(Graphics::pixmapFromSvg(svgData, LOGO_EDGE));
QPixmap result;
if (requestedSize.isValid()) {
......@@ -45,6 +53,37 @@ QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size,
} else {
result = pixmap;
}
*size = result.size();
if (size != Q_NULLPTR) {
*size = result.size();
}
return result;
}
QByteArray ImageProvider::svg(const QString &id) const
{
if (id.isEmpty()) {
return QByteArray();
}
QMap<QString, QByteArray>::const_iterator it(m_svgImgs.find(id));
if (it != m_svgImgs.end()) {
return it.value();
}
return QByteArray();
}
bool ImageProvider::setSvg(const QString &id, const QByteArray &svgData)
{
if (Q_UNLIKELY(id.isEmpty())) {
return false;
}
if (!svgData.isEmpty()) {
m_svgImgs[id] = svgData;
} else {
m_svgImgs.remove(id);
}
return true;
}
ImageProvider *globImgProvPtr = Q_NULLPTR;
......@@ -26,6 +26,9 @@
#include <QPixmap>
#include <QQuickImageProvider>
#define IMAGE_PROVIDER_ID QLatin1String("images")
#define RM_SVG_LOGO_ID QLatin1String("rmlogo.svg") /* Records management logo. */
/*!
* @brief Class provides an interface for supporting pixmaps
* and threaded image requests in QML.
......@@ -39,14 +42,39 @@ public:
ImageProvider(void);
/*!
* @brief Transform image from stored bytearray and show it as QML image.
* @brief Transform image from stored byte array and return a pixmap.
*
* @param[in] id String that identify image file.
* @param[in] id String identifying the image data.
* @param[in,out] size Output image size.
* @param[in] requestedSize Input image size (may be NULL).
* @return Plain pixmap image for QML.
*/
virtual
QPixmap requestPixmap(const QString &id, QSize *size,
const QSize& requestedSize);
const QSize &requestedSize) Q_DECL_OVERRIDE;
/*!
* @brief Get SVG image data.
*
* @param[in] id Image data identifier.
* @return Non-empty image data if id present.
*/
QByteArray svg(const QString &id) const;
/*!
* @brief Set SVG image data.
*
* @param[in] id Image data identifier.
* @param[in] svgData Image data in SVG format.
* @return True if value inserted.
*/
bool setSvg(const QString &id, const QByteArray &svgData);
private:
QMap<QString, QByteArray> m_svgImgs; /*!< Map of images in SVG format. */
};
/*!
* @brief Globally accessible image provider.
*/
extern ImageProvider *globImgProvPtr;
......@@ -27,14 +27,16 @@
#include "src/datovka_shared/records_management/json/service_info.h"
#include "src/datovka_shared/records_management/json/upload_file.h"
#include "src/datovka_shared/records_management/json/upload_hierarchy.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/models/accountmodel.h"
#include "src/qml_interaction/image_provider.h"
#include "src/records_management/models/upload_hierarchy_list_model.h"
#include "src/records_management.h"
#include "src/settings.h"
#include "src/sqlite/zfo_db.h"
#include "src/worker/emitter.h"
#include "src/worker/pool.h"
#include "src/worker/task_records_management_stored_messages.h"
#include "src/sqlite/zfo_db.h"
/*!
* @brief Process upload file service response.
......@@ -126,7 +128,10 @@ bool RecordsManagement::callServiceInfo(const QString &urlStr,
ServiceInfoResp siRes(
ServiceInfoResp::fromJson(response, &ok));
if (ok && siRes.isValid()) {
globRmLogoSvg = siRes.logoSvg();
if (globImgProvPtr != Q_NULLPTR) {
globImgProvPtr->setSvg(RM_SVG_LOGO_ID,
siRes.logoSvg());
}
emit serviceInfo(siRes.name(), siRes.tokenName());
emit statusBarTextChanged(tr("Done"), false, true);
return true;
......@@ -256,7 +261,9 @@ void RecordsManagement::loadStoredServiceInfo(void)
return;
}
globRmLogoSvg = entry.logoSvg;
if (globImgProvPtr != Q_NULLPTR) {
globImgProvPtr->setSvg(RM_SVG_LOGO_ID, entry.logoSvg);
}
emit serviceInfo(entry.name, entry.tokenName);
}
......@@ -318,7 +325,8 @@ bool RecordsManagement::updateServiceInfo(const QString &newUrlStr,
entry.url = cUrlStr;
entry.name = srName;
entry.tokenName = srToken;
entry.logoSvg = globRmLogoSvg;
entry.logoSvg = (globImgProvPtr != Q_NULLPTR) ?
globImgProvPtr->svg(RM_SVG_LOGO_ID) : QByteArray();
globRecordsManagementDbPtr->updateServiceInfo(entry);
if (oldUrlStr != cUrlStr) {
return globRecordsManagementDbPtr->deleteAllStoredMsg();
......@@ -384,5 +392,3 @@ bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
emit statusBarTextChanged(tr("Communication error"), false, true);
return false;
}
QByteArray globRmLogoSvg;
......@@ -25,9 +25,8 @@
#include <QObject>
#include "src/sqlite/message_db_container.h"
#include "src/datovka_shared/records_management/io/records_management_connection.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/messages.h"
class RecordsManagement : public QObject {
Q_OBJECT
......@@ -163,8 +162,3 @@ private:
RecordsManagementConnection m_rmc; /*!< Connection to records management service. */
};
/*!
* @brief Global SVG data.
*/
extern QByteArray globRmLogoSvg; /*!< Raw SVG data. */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment