0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +03:00

Adding barcode field from the data source

This commit is contained in:
Andrzej Woronko 2019-05-10 12:52:17 +02:00
parent f7e2dc1697
commit add12675cc
3 changed files with 71 additions and 1 deletions

View File

@ -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) void BarcodeItem::setBarcodeType(BarcodeItem::BarcodeType value)
{ {
if (m_barcodeType!=value){ if (m_barcodeType!=value){
@ -268,12 +298,38 @@ void BarcodeItem::setHideText(bool hideText)
void BarcodeItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight) 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: case FirstPass:
setContent(expandUserVariables(content(),pass,NoEscapeSymbols, dataManager)); setContent(expandUserVariables(content(),pass,NoEscapeSymbols, dataManager));
setContent(expandDataFields(content(), NoEscapeSymbols, dataManager)); setContent(expandDataFields(content(), NoEscapeSymbols, dataManager));
break; break;
default:; default:;
}
} }
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight); BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
} }

View File

@ -41,6 +41,8 @@ class BarcodeItem : public LimeReport::ContentItemDesignIntf {
Q_ENUMS(InputMode) Q_ENUMS(InputMode)
Q_PROPERTY(QString content READ content WRITE setContent) Q_PROPERTY(QString content READ content WRITE setContent)
Q_PROPERTY(BarcodeType barcodeType READ barcodeType WRITE setBarcodeType ) 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(QString testValue READ designTestValue WRITE setDesignTestValue)
Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor) Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
@ -148,6 +150,10 @@ public:
QString content() const {return m_content;} QString content() const {return m_content;}
void setBarcodeType(BarcodeType value); void setBarcodeType(BarcodeType value);
BarcodeType barcodeType(){return m_barcodeType;} 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); void setDesignTestValue(QString value);
QString designTestValue(){return m_designTestValue;} QString designTestValue(){return m_designTestValue;}
QColor foregroundColor(){return m_foregroundColor;} QColor foregroundColor(){return m_foregroundColor;}
@ -174,6 +180,8 @@ public:
private: private:
Zint::QZint m_bc; Zint::QZint m_bc;
QString m_content; QString m_content;
QString m_datasource;
QString m_field;
QString m_designTestValue; QString m_designTestValue;
BarcodeType m_barcodeType; BarcodeType m_barcodeType;
QColor m_foregroundColor; QColor m_foregroundColor;

View File

@ -54,6 +54,12 @@ namespace{
bool VARIABLE_IS_NOT_USED registredImageFieldProp = LimeReport::ObjectPropFactory::instance().registerCreator( bool VARIABLE_IS_NOT_USED registredImageFieldProp = LimeReport::ObjectPropFactory::instance().registerCreator(
LimeReport::APropIdent("field","LimeReport::ImageItem"),QObject::tr("field"),createFieldPropItem 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{ QWidget* LimeReport::DatasourcePropItem::createProperyEditor(QWidget *parent) const{