From add12675cce0a5c97a4a6e9f11d39ed4c9ad3582 Mon Sep 17 00:00:00 2001 From: Andrzej Woronko Date: Fri, 10 May 2019 12:52:17 +0200 Subject: [PATCH] Adding barcode field from the data source --- limereport/items/lrbarcodeitem.cpp | 58 ++++++++++++++++++- limereport/items/lrbarcodeitem.h | 8 +++ .../propertyItems/lrdatasourcepropitem.cpp | 6 ++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/limereport/items/lrbarcodeitem.cpp b/limereport/items/lrbarcodeitem.cpp index fac67d7..a0fee56 100644 --- a/limereport/items/lrbarcodeitem.cpp +++ b/limereport/items/lrbarcodeitem.cpp @@ -115,6 +115,36 @@ void BarcodeItem::setContent(const QString &content) } } +QString BarcodeItem::datasource() const +{ + return m_datasource; +} + +void BarcodeItem::setDatasource(const QString &datasource) +{ + if (m_datasource != datasource){ + QString oldValue = m_datasource; + m_datasource = datasource; + update(); + notify("datasource", oldValue, datasource); + } +} + +QString BarcodeItem::field() const +{ + return m_field; +} + +void BarcodeItem::setField(const QString &field) +{ + if (m_field != field){ + QString oldValue = m_field; + m_field = field; + update(); + notify("field", oldValue, field); + } +} + void BarcodeItem::setBarcodeType(BarcodeItem::BarcodeType value) { if (m_barcodeType!=value){ @@ -268,12 +298,38 @@ void BarcodeItem::setHideText(bool hideText) void BarcodeItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight) { - switch(pass){ + if (content().isEmpty()) + { + if (!m_datasource.isEmpty() && !m_field.isEmpty()) + { + IDataSource* ds = dataManager->dataSource(m_datasource); + if (ds) + { + QVariant data = ds->data(m_field); + if (data.isValid()) + { + switch(pass) + { + case FirstPass: + setContent(expandUserVariables(data.toString(),pass,NoEscapeSymbols, dataManager)); + setContent(expandDataFields(data.toString(), NoEscapeSymbols, dataManager)); + break; + default:; + } + } + } + } + } + else + { + switch(pass) + { case FirstPass: setContent(expandUserVariables(content(),pass,NoEscapeSymbols, dataManager)); setContent(expandDataFields(content(), NoEscapeSymbols, dataManager)); break; default:; + } } BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight); } diff --git a/limereport/items/lrbarcodeitem.h b/limereport/items/lrbarcodeitem.h index cfd6265..cdf9971 100644 --- a/limereport/items/lrbarcodeitem.h +++ b/limereport/items/lrbarcodeitem.h @@ -41,6 +41,8 @@ class BarcodeItem : public LimeReport::ContentItemDesignIntf { Q_ENUMS(InputMode) Q_PROPERTY(QString content READ content WRITE setContent) Q_PROPERTY(BarcodeType barcodeType READ barcodeType WRITE setBarcodeType ) + Q_PROPERTY(QString datasource READ datasource WRITE setDatasource) + Q_PROPERTY(QString field READ field WRITE setField) Q_PROPERTY(QString testValue READ designTestValue WRITE setDesignTestValue) Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor) Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) @@ -148,6 +150,10 @@ public: QString content() const {return m_content;} void setBarcodeType(BarcodeType value); BarcodeType barcodeType(){return m_barcodeType;} + QString datasource() const; + void setDatasource(const QString &datasource); + QString field() const; + void setField(const QString &field); void setDesignTestValue(QString value); QString designTestValue(){return m_designTestValue;} QColor foregroundColor(){return m_foregroundColor;} @@ -174,6 +180,8 @@ public: private: Zint::QZint m_bc; QString m_content; + QString m_datasource; + QString m_field; QString m_designTestValue; BarcodeType m_barcodeType; QColor m_foregroundColor; diff --git a/limereport/objectinspector/propertyItems/lrdatasourcepropitem.cpp b/limereport/objectinspector/propertyItems/lrdatasourcepropitem.cpp index 4463051..4f0dd11 100644 --- a/limereport/objectinspector/propertyItems/lrdatasourcepropitem.cpp +++ b/limereport/objectinspector/propertyItems/lrdatasourcepropitem.cpp @@ -54,6 +54,12 @@ namespace{ bool VARIABLE_IS_NOT_USED registredImageFieldProp = LimeReport::ObjectPropFactory::instance().registerCreator( LimeReport::APropIdent("field","LimeReport::ImageItem"),QObject::tr("field"),createFieldPropItem ); + bool VARIABLE_IS_NOT_USED registredBarcodeDatasouceProp = LimeReport::ObjectPropFactory::instance().registerCreator( + LimeReport::APropIdent("datasource","LimeReport::BarcodeItem"),QObject::tr("datasource"),createDatasourcePropItem + ); + bool VARIABLE_IS_NOT_USED registredBarcodeFieldProp = LimeReport::ObjectPropFactory::instance().registerCreator( + LimeReport::APropIdent("field","LimeReport::BarcodeItem"),QObject::tr("field"),createFieldPropItem + ); } QWidget* LimeReport::DatasourcePropItem::createProperyEditor(QWidget *parent) const{