mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-25 04:54:40 +03:00
Merge branch 'master' into 1.4
Conflicts: limereport/items/lrtextitem.cpp limereport/items/lrtextitem.h
This commit is contained in:
commit
a2346bc6aa
@ -63,6 +63,7 @@ class DataHeaderBand : public BandDesignIntf
|
|||||||
Q_PROPERTY(bool reprintOnEachPage READ reprintOnEachPage WRITE setReprintOnEachPage)
|
Q_PROPERTY(bool reprintOnEachPage READ reprintOnEachPage WRITE setReprintOnEachPage)
|
||||||
Q_PROPERTY(int columnsCount READ columnsCount WRITE setColumnsCount)
|
Q_PROPERTY(int columnsCount READ columnsCount WRITE setColumnsCount)
|
||||||
Q_PROPERTY(bool printAlways READ printAlways() WRITE setPrintAlways())
|
Q_PROPERTY(bool printAlways READ printAlways() WRITE setPrintAlways())
|
||||||
|
Q_PROPERTY(bool repeatOnEachRow READ repeatOnEachRow WRITE setRepeatOnEachRow)
|
||||||
public:
|
public:
|
||||||
DataHeaderBand(QObject* owner=0, QGraphicsItem* parent=0);
|
DataHeaderBand(QObject* owner=0, QGraphicsItem* parent=0);
|
||||||
bool isUnique() const {return false;}
|
bool isUnique() const {return false;}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
#include <QtScript/QScriptEngine>
|
#include <QtScript/QScriptEngine>
|
||||||
|
#include <QLocale>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "lrpagedesignintf.h"
|
#include "lrpagedesignintf.h"
|
||||||
@ -215,6 +216,7 @@ void TextItem::Init()
|
|||||||
m_adaptFontToSize = false;
|
m_adaptFontToSize = false;
|
||||||
m_underlineLineSize = 1;
|
m_underlineLineSize = 1;
|
||||||
m_lineSpacing = 1;
|
m_lineSpacing = 1;
|
||||||
|
m_valueType = Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItem::setContent(const QString &value)
|
void TextItem::setContent(const QString &value)
|
||||||
@ -379,6 +381,86 @@ void TextItem::initText()
|
|||||||
m_textSize=m_text->size();
|
m_textSize=m_text->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TextItem::formatDateTime(const QDateTime &value)
|
||||||
|
{
|
||||||
|
if (m_format.isEmpty())
|
||||||
|
{
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.toString(m_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TextItem::formatNumber(const double value)
|
||||||
|
{
|
||||||
|
QString str = QString::number(value);
|
||||||
|
|
||||||
|
if (m_format.contains("%"))
|
||||||
|
{
|
||||||
|
str.sprintf(m_format.toStdString().c_str(), value);
|
||||||
|
str = str.replace(",", QLocale::system().groupSeparator());
|
||||||
|
str = str.replace(".", QLocale::system().decimalPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TextItem::formatFieldValue()
|
||||||
|
{
|
||||||
|
if (m_format.isEmpty()) {
|
||||||
|
return m_varValue.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant value = m_varValue;
|
||||||
|
|
||||||
|
if (m_valueType != Default) {
|
||||||
|
switch (m_valueType) {
|
||||||
|
case DateTime:
|
||||||
|
{
|
||||||
|
QDateTime dt = QDateTime::fromString(value.toString(), Qt::ISODate);
|
||||||
|
value = (dt.isValid() ? QVariant(dt) : m_varValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Double:
|
||||||
|
{
|
||||||
|
bool bOk = false;
|
||||||
|
double dbl = value.toDouble(&bOk);
|
||||||
|
value = (bOk ? QVariant(dbl) : m_varValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (value.type()) {
|
||||||
|
case QVariant::Date:
|
||||||
|
case QVariant::DateTime:
|
||||||
|
return formatDateTime(value.toDateTime());
|
||||||
|
case QVariant::Double:
|
||||||
|
return formatNumber(value.toDouble());
|
||||||
|
default:
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextItem::ValueType TextItem::valueType() const
|
||||||
|
{
|
||||||
|
return m_valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextItem::setValueType(const ValueType valueType)
|
||||||
|
{
|
||||||
|
m_valueType = valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TextItem::format() const
|
||||||
|
{
|
||||||
|
return m_format;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextItem::setFormat(const QString &format)
|
||||||
|
{
|
||||||
|
m_format = format;
|
||||||
|
}
|
||||||
|
|
||||||
bool TextItem::allowHTMLInFields() const
|
bool TextItem::allowHTMLInFields() const
|
||||||
{
|
{
|
||||||
return m_allowHTMLInFields;
|
return m_allowHTMLInFields;
|
||||||
@ -474,7 +556,12 @@ void TextItem::expandContent(DataSourceManager* dataManager, RenderPass pass)
|
|||||||
context=expandUserVariables(context, pass, expandType, dataManager);
|
context=expandUserVariables(context, pass, expandType, dataManager);
|
||||||
context=expandScripts(context, dataManager);
|
context=expandScripts(context, dataManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expandType == NoEscapeSymbols) {
|
||||||
|
setContent(formatFieldValue());
|
||||||
|
} else {
|
||||||
setContent(context);
|
setContent(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItem::setAutoHeight(bool value)
|
void TextItem::setAutoHeight(bool value)
|
||||||
|
@ -44,6 +44,7 @@ class TextItem : public LimeReport::ContentItemDesignIntf {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_ENUMS(AutoWidth)
|
Q_ENUMS(AutoWidth)
|
||||||
Q_ENUMS(AngleType)
|
Q_ENUMS(AngleType)
|
||||||
|
Q_ENUMS(ValueType)
|
||||||
Q_PROPERTY(QString content READ content WRITE setContent)
|
Q_PROPERTY(QString content READ content WRITE setContent)
|
||||||
Q_PROPERTY(int margin READ marginSize WRITE setMarginSize)
|
Q_PROPERTY(int margin READ marginSize WRITE setMarginSize)
|
||||||
Q_PROPERTY(Qt::Alignment alignment READ alignment() WRITE setAlignment)
|
Q_PROPERTY(Qt::Alignment alignment READ alignment() WRITE setAlignment)
|
||||||
@ -63,10 +64,13 @@ class TextItem : public LimeReport::ContentItemDesignIntf {
|
|||||||
Q_PROPERTY(int underlineLineSize READ underlineLineSize WRITE setUnderlineLineSize)
|
Q_PROPERTY(int underlineLineSize READ underlineLineSize WRITE setUnderlineLineSize)
|
||||||
Q_PROPERTY(bool allowHTML READ allowHTML WRITE setAllowHTML)
|
Q_PROPERTY(bool allowHTML READ allowHTML WRITE setAllowHTML)
|
||||||
Q_PROPERTY(bool allowHTMLInFields READ allowHTMLInFields WRITE setAllowHTMLInFields)
|
Q_PROPERTY(bool allowHTMLInFields READ allowHTMLInFields WRITE setAllowHTMLInFields)
|
||||||
|
Q_PROPERTY(QString format READ format WRITE setFormat)
|
||||||
|
Q_PROPERTY(ValueType valueType READ valueType WRITE setValueType)
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum AutoWidth{NoneAutoWidth,MaxWordLength,MaxStringLength};
|
enum AutoWidth{NoneAutoWidth,MaxWordLength,MaxStringLength};
|
||||||
enum AngleType{Angle0,Angle90,Angle180,Angle270,Angle45,Angle315};
|
enum AngleType{Angle0,Angle90,Angle180,Angle270,Angle45,Angle315};
|
||||||
|
enum ValueType{Default,DateTime,Double};
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
TextItem(QObject* owner=0, QGraphicsItem* parent=0);
|
TextItem(QObject* owner=0, QGraphicsItem* parent=0);
|
||||||
@ -130,6 +134,12 @@ public:
|
|||||||
bool allowHTMLInFields() const;
|
bool allowHTMLInFields() const;
|
||||||
void setAllowHTMLInFields(bool allowHTMLInFields);
|
void setAllowHTMLInFields(bool allowHTMLInFields);
|
||||||
|
|
||||||
|
QString format() const;
|
||||||
|
void setFormat(const QString &format);
|
||||||
|
|
||||||
|
ValueType valueType() const;
|
||||||
|
void setValueType(const ValueType valueType);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateLayout();
|
void updateLayout();
|
||||||
bool isNeedExpandContent() const;
|
bool isNeedExpandContent() const;
|
||||||
@ -140,6 +150,9 @@ private:
|
|||||||
void initText();
|
void initText();
|
||||||
void setTextFont(const QFont &value);
|
void setTextFont(const QFont &value);
|
||||||
void adaptFontSize();
|
void adaptFontSize();
|
||||||
|
QString formatDateTime(const QDateTime &value);
|
||||||
|
QString formatNumber(const double value);
|
||||||
|
QString formatFieldValue();
|
||||||
private:
|
private:
|
||||||
QString m_strText;
|
QString m_strText;
|
||||||
|
|
||||||
@ -158,6 +171,9 @@ private:
|
|||||||
int m_underlineLineSize;
|
int m_underlineLineSize;
|
||||||
bool m_allowHTML;
|
bool m_allowHTML;
|
||||||
bool m_allowHTMLInFields;
|
bool m_allowHTMLInFields;
|
||||||
|
|
||||||
|
QString m_format;
|
||||||
|
ValueType m_valueType;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,8 @@ BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, Q
|
|||||||
m_reprintOnEachPage(false),
|
m_reprintOnEachPage(false),
|
||||||
m_startNewPage(false),
|
m_startNewPage(false),
|
||||||
m_startFromNewPage(false),
|
m_startFromNewPage(false),
|
||||||
m_printAlways(false)
|
m_printAlways(false),
|
||||||
|
m_repeatOnEachRow(false)
|
||||||
{
|
{
|
||||||
setPosibleResizeDirectionFlags(ResizeBottom);
|
setPosibleResizeDirectionFlags(ResizeBottom);
|
||||||
setPosibleMoveFlags(TopBotom);
|
setPosibleMoveFlags(TopBotom);
|
||||||
@ -725,6 +726,16 @@ void BandDesignIntf::childBandDeleted(QObject *band)
|
|||||||
m_childBands.removeAt(m_childBands.indexOf(reinterpret_cast<BandDesignIntf*>(band)));
|
m_childBands.removeAt(m_childBands.indexOf(reinterpret_cast<BandDesignIntf*>(band)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BandDesignIntf::repeatOnEachRow() const
|
||||||
|
{
|
||||||
|
return m_repeatOnEachRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BandDesignIntf::setRepeatOnEachRow(bool repeatOnEachRow)
|
||||||
|
{
|
||||||
|
m_repeatOnEachRow = repeatOnEachRow;
|
||||||
|
}
|
||||||
|
|
||||||
bool BandDesignIntf::printAlways() const
|
bool BandDesignIntf::printAlways() const
|
||||||
{
|
{
|
||||||
return m_printAlways;
|
return m_printAlways;
|
||||||
|
@ -213,7 +213,8 @@ public:
|
|||||||
bool canContainChildren(){ return true;}
|
bool canContainChildren(){ return true;}
|
||||||
bool printAlways() const;
|
bool printAlways() const;
|
||||||
void setPrintAlways(bool printAlways);
|
void setPrintAlways(bool printAlways);
|
||||||
|
bool repeatOnEachRow() const;
|
||||||
|
void setRepeatOnEachRow(bool repeatOnEachRow);
|
||||||
signals:
|
signals:
|
||||||
void bandRendered(BandDesignIntf* band);
|
void bandRendered(BandDesignIntf* band);
|
||||||
protected:
|
protected:
|
||||||
@ -266,6 +267,7 @@ private:
|
|||||||
bool m_startNewPage;
|
bool m_startNewPage;
|
||||||
bool m_startFromNewPage;
|
bool m_startFromNewPage;
|
||||||
bool m_printAlways;
|
bool m_printAlways;
|
||||||
|
bool m_repeatOnEachRow;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DataBandDesignIntf : public BandDesignIntf{
|
class DataBandDesignIntf : public BandDesignIntf{
|
||||||
|
@ -123,11 +123,12 @@ QString ContentItemDesignIntf::expandDataFields(QString context, ExpandType expa
|
|||||||
|
|
||||||
if (dataManager->containsField(field)) {
|
if (dataManager->containsField(field)) {
|
||||||
QString fieldValue;
|
QString fieldValue;
|
||||||
|
m_varValue = dataManager->fieldData(field);
|
||||||
if (expandType == EscapeSymbols) {
|
if (expandType == EscapeSymbols) {
|
||||||
if (dataManager->fieldData(field).isNull()) {
|
if (dataManager->fieldData(field).isNull()) {
|
||||||
fieldValue="\"\"";
|
fieldValue="\"\"";
|
||||||
} else {
|
} else {
|
||||||
fieldValue = escapeSimbols(dataManager->fieldData(field).toString());
|
fieldValue = escapeSimbols(m_varValue.toString());
|
||||||
switch (dataManager->fieldData(field).type()) {
|
switch (dataManager->fieldData(field).type()) {
|
||||||
case QVariant::Char:
|
case QVariant::Char:
|
||||||
case QVariant::String:
|
case QVariant::String:
|
||||||
@ -142,8 +143,8 @@ QString ContentItemDesignIntf::expandDataFields(QString context, ExpandType expa
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (expandType == ReplaceHTMLSymbols)
|
if (expandType == ReplaceHTMLSymbols)
|
||||||
fieldValue = replaceHTMLSymbols(dataManager->fieldData(field).toString());
|
fieldValue = replaceHTMLSymbols(m_varValue.toString());
|
||||||
else fieldValue = dataManager->fieldData(field).toString();
|
else fieldValue = m_varValue.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
context.replace(rx.cap(0),fieldValue);
|
context.replace(rx.cap(0),fieldValue);
|
||||||
@ -172,15 +173,16 @@ QString ContentItemDesignIntf::expandUserVariables(QString context, RenderPass p
|
|||||||
pos += rx.matchedLength();
|
pos += rx.matchedLength();
|
||||||
if (dataManager->containsVariable(variable) ){
|
if (dataManager->containsVariable(variable) ){
|
||||||
if (pass==dataManager->variablePass(variable)){
|
if (pass==dataManager->variablePass(variable)){
|
||||||
|
m_varValue = dataManager->variable(variable);
|
||||||
switch (expandType){
|
switch (expandType){
|
||||||
case EscapeSymbols:
|
case EscapeSymbols:
|
||||||
context.replace(rx.cap(0),escapeSimbols(dataManager->variable(variable).toString()));
|
context.replace(rx.cap(0),escapeSimbols(m_varValue.toString()));
|
||||||
break;
|
break;
|
||||||
case NoEscapeSymbols:
|
case NoEscapeSymbols:
|
||||||
context.replace(rx.cap(0),dataManager->variable(variable).toString());
|
context.replace(rx.cap(0),m_varValue.toString());
|
||||||
break;
|
break;
|
||||||
case ReplaceHTMLSymbols:
|
case ReplaceHTMLSymbols:
|
||||||
context.replace(rx.cap(0),replaceHTMLSymbols(dataManager->variable(variable).toString()));
|
context.replace(rx.cap(0),replaceHTMLSymbols(m_varValue.toString()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pos=0;
|
pos=0;
|
||||||
@ -222,6 +224,7 @@ QString ContentItemDesignIntf::expandScripts(QString context, DataSourceManager*
|
|||||||
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, dataManager);
|
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, dataManager);
|
||||||
QScriptValue value = se->evaluate(scriptBody);
|
QScriptValue value = se->evaluate(scriptBody);
|
||||||
if (!se->hasUncaughtException()) {
|
if (!se->hasUncaughtException()) {
|
||||||
|
m_varValue = value.toVariant();
|
||||||
context.replace(scriptExtractor.scriptAt(i),value.toString());
|
context.replace(scriptExtractor.scriptAt(i),value.toString());
|
||||||
} else {
|
} else {
|
||||||
context.replace(scriptExtractor.scriptAt(i),se->uncaughtException().toString());
|
context.replace(scriptExtractor.scriptAt(i),se->uncaughtException().toString());
|
||||||
|
@ -82,6 +82,8 @@ protected:
|
|||||||
virtual QString expandUserVariables(QString context, RenderPass pass, ExpandType expandType, DataSourceManager *dataManager);
|
virtual QString expandUserVariables(QString context, RenderPass pass, ExpandType expandType, DataSourceManager *dataManager);
|
||||||
virtual QString expandDataFields(QString context, ExpandType expandType, DataSourceManager *dataManager);
|
virtual QString expandDataFields(QString context, ExpandType expandType, DataSourceManager *dataManager);
|
||||||
virtual QString expandScripts(QString context, DataSourceManager *dataManager);
|
virtual QString expandScripts(QString context, DataSourceManager *dataManager);
|
||||||
|
|
||||||
|
QVariant m_varValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LayoutDesignIntf : public ItemDesignIntf{
|
class LayoutDesignIntf : public ItemDesignIntf{
|
||||||
|
@ -441,6 +441,9 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
|
|||||||
datasources()->updateChildrenData(dataBand->datasourceName());
|
datasources()->updateChildrenData(dataBand->datasourceName());
|
||||||
m_lastDataBand = dataBand;
|
m_lastDataBand = dataBand;
|
||||||
|
|
||||||
|
if (header && !firstTime && header->repeatOnEachRow())
|
||||||
|
renderBand(header,StartNewPageAsNeeded);
|
||||||
|
|
||||||
renderBand(dataBand,StartNewPageAsNeeded,!bandDatasource->hasNext());
|
renderBand(dataBand,StartNewPageAsNeeded,!bandDatasource->hasNext());
|
||||||
renderChildBands(dataBand);
|
renderChildBands(dataBand);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user