diff --git a/limereport/items/lrimageitem.cpp b/limereport/items/lrimageitem.cpp index a58531b..a685579 100644 --- a/limereport/items/lrimageitem.cpp +++ b/limereport/items/lrimageitem.cpp @@ -106,20 +106,6 @@ void ImageItem::processPopUpAction(QAction *action) ItemDesignIntf::processPopUpAction(action); } -QImage getFileByResourcePath(QString resourcePath){ - QFileInfo resourceFile(resourcePath); - if (resourceFile.exists()) - return QImage(resourcePath); - return QImage(); -} - -QImage ImageItem::drawImage() -{ - if (image().isNull()) - return getFileByResourcePath(m_resourcePath); - return image(); -} - bool ImageItem::useExternalPainter() const { return m_useExternalPainter; @@ -165,7 +151,6 @@ QString ImageItem::fileFilter() const void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight) { - if (m_picture.isNull()){ if (!m_datasource.isEmpty() && !m_field.isEmpty()){ IDataSource* ds = dataManager->dataSource(m_datasource); @@ -176,7 +161,7 @@ void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, } else if (!m_resourcePath.isEmpty()){ m_resourcePath = expandUserVariables(m_resourcePath, pass, NoEscapeSymbols, dataManager); m_resourcePath = expandDataFields(m_resourcePath, NoEscapeSymbols, dataManager); - m_picture = QImage(m_resourcePath); + m_picture = QImage::fromData(dataManager->getResource(m_resourcePath)); } else if (!m_variable.isEmpty()){ QVariant data = dataManager->variable(m_variable); if (data.type() == QVariant::String){ @@ -273,8 +258,8 @@ void ImageItem::setAutoSize(bool autoSize) if (m_autoSize != autoSize){ m_autoSize = autoSize; if (m_autoSize && !m_picture.isNull()){ - setWidth(drawImage().width()); - setHeight(drawImage().height()); + setWidth(image().width()); + setHeight(image().height()); setPossibleResizeDirectionFlags(Fixed); } else { setPossibleResizeDirectionFlags(AllDirections); @@ -324,10 +309,10 @@ void ImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QPointF point = rect().topLeft(); QImage img; - if (m_scale && !drawImage().isNull()){ - img = drawImage().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + if (m_scale && !image().isNull()){ + img = image().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } else { - img = drawImage(); + img = image(); } qreal shiftHeight = rect().height() - img.height(); @@ -402,7 +387,8 @@ void ImageItem::setResourcePath(const QString &value){ if (m_resourcePath != value){ QString oldValue = m_resourcePath; m_resourcePath = value; - update(); + //m_picture = getFileByResourcePath(value); + //update(); notify("resourcePath", oldValue, value); } } diff --git a/limereport/items/lrimageitem.h b/limereport/items/lrimageitem.h index bf36257..db34869 100644 --- a/limereport/items/lrimageitem.h +++ b/limereport/items/lrimageitem.h @@ -108,7 +108,6 @@ protected: void loadPictureFromVariant(QVariant& data); void preparePopUpMenu(QMenu &menu); void processPopUpAction(QAction *action); - QImage drawImage(); private: QImage m_picture; bool m_useExternalPainter; @@ -121,8 +120,7 @@ private: bool m_keepAspectRatio; bool m_center; Format m_format; - QString m_variable; - + QString m_variable; }; } diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 4517ff7..8cba622 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #ifdef BUILD_WITH_EASY_PROFILER @@ -854,6 +856,37 @@ void DataSourceManager::setReportSettings(ReportSettings *reportSettings) m_reportSettings = reportSettings; } +QByteArray DataSourceManager::getResource(const QString &path) +{ + QFile file(path); + if (file.exists()){ + file.open(QIODevice::ReadOnly); + return file.readAll(); + } + + QUrl url(path); + if (url.isValid()){ + QNetworkAccessManager manager; + QNetworkRequest request(url); + QNetworkReply *reply = manager.get(request); + + QEventLoop loop; + QTimer::singleShot(20000, &loop, SLOT(quit())); + connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + + if (reply->error() == QNetworkReply::NoError){ + QByteArray result = reply->readAll(); + reply->deleteLater(); + return result; + } else { + putError(reply->errorString()); + } + } + + return QByteArray(); +} + bool DataSourceManager::checkConnection(QSqlDatabase db){ QSqlQuery query("Select 1",db); return query.first(); diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 9c8518f..73ad0cc 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -32,6 +32,9 @@ #include #include +#include +#include + #include "lrdatadesignintf.h" #include "lrcollection.h" #include "lrglobal.h" @@ -222,6 +225,7 @@ public: bool hasChanges(){ return m_hasChanges; } void dropChanges(){ m_hasChanges = false; } + QByteArray getResource(const QString& url); signals: void loadCollectionFinished(const QString& collectionName); void cleared(); @@ -281,8 +285,7 @@ private: QVector m_groupFunctionsExpressions; IDbCredentialsProvider* m_dbCredentialsProvider; - QMap< QString, QVector > m_varToDataSource; - + QMap< QString, QVector > m_varToDataSource; bool m_hasChanges; };