mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-23 16:22:58 +03:00
Added support for URLs as resource paths for ImageItem.
This commit is contained in:
parent
1f327e2a8c
commit
31c031aa01
@ -106,20 +106,6 @@ void ImageItem::processPopUpAction(QAction *action)
|
|||||||
ItemDesignIntf::processPopUpAction(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
|
bool ImageItem::useExternalPainter() const
|
||||||
{
|
{
|
||||||
return m_useExternalPainter;
|
return m_useExternalPainter;
|
||||||
@ -165,7 +151,6 @@ QString ImageItem::fileFilter() const
|
|||||||
|
|
||||||
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_picture.isNull()){
|
if (m_picture.isNull()){
|
||||||
if (!m_datasource.isEmpty() && !m_field.isEmpty()){
|
if (!m_datasource.isEmpty() && !m_field.isEmpty()){
|
||||||
IDataSource* ds = dataManager->dataSource(m_datasource);
|
IDataSource* ds = dataManager->dataSource(m_datasource);
|
||||||
@ -176,7 +161,7 @@ void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass,
|
|||||||
} else if (!m_resourcePath.isEmpty()){
|
} else if (!m_resourcePath.isEmpty()){
|
||||||
m_resourcePath = expandUserVariables(m_resourcePath, pass, NoEscapeSymbols, dataManager);
|
m_resourcePath = expandUserVariables(m_resourcePath, pass, NoEscapeSymbols, dataManager);
|
||||||
m_resourcePath = expandDataFields(m_resourcePath, 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()){
|
} else if (!m_variable.isEmpty()){
|
||||||
QVariant data = dataManager->variable(m_variable);
|
QVariant data = dataManager->variable(m_variable);
|
||||||
if (data.type() == QVariant::String){
|
if (data.type() == QVariant::String){
|
||||||
@ -273,8 +258,8 @@ void ImageItem::setAutoSize(bool autoSize)
|
|||||||
if (m_autoSize != autoSize){
|
if (m_autoSize != autoSize){
|
||||||
m_autoSize = autoSize;
|
m_autoSize = autoSize;
|
||||||
if (m_autoSize && !m_picture.isNull()){
|
if (m_autoSize && !m_picture.isNull()){
|
||||||
setWidth(drawImage().width());
|
setWidth(image().width());
|
||||||
setHeight(drawImage().height());
|
setHeight(image().height());
|
||||||
setPossibleResizeDirectionFlags(Fixed);
|
setPossibleResizeDirectionFlags(Fixed);
|
||||||
} else {
|
} else {
|
||||||
setPossibleResizeDirectionFlags(AllDirections);
|
setPossibleResizeDirectionFlags(AllDirections);
|
||||||
@ -324,10 +309,10 @@ void ImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
QPointF point = rect().topLeft();
|
QPointF point = rect().topLeft();
|
||||||
QImage img;
|
QImage img;
|
||||||
|
|
||||||
if (m_scale && !drawImage().isNull()){
|
if (m_scale && !image().isNull()){
|
||||||
img = drawImage().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
img = image().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
} else {
|
} else {
|
||||||
img = drawImage();
|
img = image();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal shiftHeight = rect().height() - img.height();
|
qreal shiftHeight = rect().height() - img.height();
|
||||||
@ -402,7 +387,8 @@ void ImageItem::setResourcePath(const QString &value){
|
|||||||
if (m_resourcePath != value){
|
if (m_resourcePath != value){
|
||||||
QString oldValue = m_resourcePath;
|
QString oldValue = m_resourcePath;
|
||||||
m_resourcePath = value;
|
m_resourcePath = value;
|
||||||
update();
|
//m_picture = getFileByResourcePath(value);
|
||||||
|
//update();
|
||||||
notify("resourcePath", oldValue, value);
|
notify("resourcePath", oldValue, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,6 @@ protected:
|
|||||||
void loadPictureFromVariant(QVariant& data);
|
void loadPictureFromVariant(QVariant& data);
|
||||||
void preparePopUpMenu(QMenu &menu);
|
void preparePopUpMenu(QMenu &menu);
|
||||||
void processPopUpAction(QAction *action);
|
void processPopUpAction(QAction *action);
|
||||||
QImage drawImage();
|
|
||||||
private:
|
private:
|
||||||
QImage m_picture;
|
QImage m_picture;
|
||||||
bool m_useExternalPainter;
|
bool m_useExternalPainter;
|
||||||
@ -121,8 +120,7 @@ private:
|
|||||||
bool m_keepAspectRatio;
|
bool m_keepAspectRatio;
|
||||||
bool m_center;
|
bool m_center;
|
||||||
Format m_format;
|
Format m_format;
|
||||||
QString m_variable;
|
QString m_variable;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include <QSqlQueryModel>
|
#include <QSqlQueryModel>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QTimer>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#ifdef BUILD_WITH_EASY_PROFILER
|
#ifdef BUILD_WITH_EASY_PROFILER
|
||||||
@ -854,6 +856,37 @@ void DataSourceManager::setReportSettings(ReportSettings *reportSettings)
|
|||||||
m_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){
|
bool DataSourceManager::checkConnection(QSqlDatabase db){
|
||||||
QSqlQuery query("Select 1",db);
|
QSqlQuery query("Select 1",db);
|
||||||
return query.first();
|
return query.first();
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
#include "lrdatadesignintf.h"
|
#include "lrdatadesignintf.h"
|
||||||
#include "lrcollection.h"
|
#include "lrcollection.h"
|
||||||
#include "lrglobal.h"
|
#include "lrglobal.h"
|
||||||
@ -222,6 +225,7 @@ public:
|
|||||||
|
|
||||||
bool hasChanges(){ return m_hasChanges; }
|
bool hasChanges(){ return m_hasChanges; }
|
||||||
void dropChanges(){ m_hasChanges = false; }
|
void dropChanges(){ m_hasChanges = false; }
|
||||||
|
QByteArray getResource(const QString& url);
|
||||||
signals:
|
signals:
|
||||||
void loadCollectionFinished(const QString& collectionName);
|
void loadCollectionFinished(const QString& collectionName);
|
||||||
void cleared();
|
void cleared();
|
||||||
@ -281,8 +285,7 @@ private:
|
|||||||
QVector<QString> m_groupFunctionsExpressions;
|
QVector<QString> m_groupFunctionsExpressions;
|
||||||
IDbCredentialsProvider* m_dbCredentialsProvider;
|
IDbCredentialsProvider* m_dbCredentialsProvider;
|
||||||
|
|
||||||
QMap< QString, QVector<QString> > m_varToDataSource;
|
QMap< QString, QVector<QString> > m_varToDataSource;
|
||||||
|
|
||||||
bool m_hasChanges;
|
bool m_hasChanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user