mirror of
				https://github.com/fralx/LimeReport.git
				synced 2025-10-31 21:31:21 +03:00 
			
		
		
		
	Added support for URLs as resource paths for ImageItem.
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| }; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -35,6 +35,8 @@ | ||||
| #include <QSqlError> | ||||
| #include <QSqlQueryModel> | ||||
| #include <QFileInfo> | ||||
| #include <QEventLoop> | ||||
| #include <QTimer> | ||||
| #include <stdexcept> | ||||
|  | ||||
| #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(); | ||||
|   | ||||
| @@ -32,6 +32,9 @@ | ||||
|  | ||||
| #include <QObject> | ||||
| #include <QIcon> | ||||
| #include <QNetworkAccessManager> | ||||
| #include <QNetworkReply> | ||||
|  | ||||
| #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<QString> m_groupFunctionsExpressions; | ||||
|     IDbCredentialsProvider* m_dbCredentialsProvider; | ||||
|  | ||||
|     QMap< QString, QVector<QString> > m_varToDataSource; | ||||
|  | ||||
|     QMap< QString, QVector<QString> > m_varToDataSource;     | ||||
|     bool m_hasChanges; | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user