mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-03-28 05:03:51 +03:00
beforeRender, afterData, afterRender signals have been added
getVariable, getField functions have been added
This commit is contained in:
parent
b9fcf84f30
commit
edd2c43545
@ -357,6 +357,7 @@ bool BandDesignIntf::canBeSplitted(int height) const
|
|||||||
|
|
||||||
bool BandDesignIntf::isEmpty() const
|
bool BandDesignIntf::isEmpty() const
|
||||||
{
|
{
|
||||||
|
if (!isVisible()) return true;
|
||||||
foreach(QGraphicsItem* qgItem,childItems()){
|
foreach(QGraphicsItem* qgItem,childItems()){
|
||||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(qgItem);
|
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(qgItem);
|
||||||
if ((item)&&(!item->isEmpty())) return false;
|
if ((item)&&(!item->isEmpty())) return false;
|
||||||
|
@ -818,7 +818,7 @@ void BaseDesignIntf::turnOnSelectionMarker(bool value)
|
|||||||
|
|
||||||
QString BaseDesignIntf::patternName() const
|
QString BaseDesignIntf::patternName() const
|
||||||
{
|
{
|
||||||
return m_patternName;
|
return (m_patternName.isEmpty()) ? objectName() : m_patternName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseDesignIntf::setPatternName(const QString &patternName)
|
void BaseDesignIntf::setPatternName(const QString &patternName)
|
||||||
|
@ -387,6 +387,10 @@ signals:
|
|||||||
void propertyesChanged(QVector<QString> propertyNames);
|
void propertyesChanged(QVector<QString> propertyNames);
|
||||||
void itemAlignChanged(BaseDesignIntf* item, const ItemAlign& oldValue, const ItemAlign& newValue);
|
void itemAlignChanged(BaseDesignIntf* item, const ItemAlign& oldValue, const ItemAlign& newValue);
|
||||||
void itemVisibleHasChanged(BaseDesignIntf* item);
|
void itemVisibleHasChanged(BaseDesignIntf* item);
|
||||||
|
|
||||||
|
void beforeRender();
|
||||||
|
void afterData();
|
||||||
|
void afterRender();
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace LimeReport
|
} //namespace LimeReport
|
||||||
|
@ -167,6 +167,7 @@ void ReportRender::setScriptContext(ScriptEngineContext* scriptContext)
|
|||||||
|
|
||||||
bool ReportRender::runInitScript(){
|
bool ReportRender::runInitScript(){
|
||||||
if (m_scriptEngineContext){
|
if (m_scriptEngineContext){
|
||||||
|
ScriptEngineManager::instance().scriptEngine()->pushContext();
|
||||||
QScriptValue res = ScriptEngineManager::instance().scriptEngine()->evaluate(m_scriptEngineContext->initScript());
|
QScriptValue res = ScriptEngineManager::instance().scriptEngine()->evaluate(m_scriptEngineContext->initScript());
|
||||||
if (res.isBool()) return res.toBool();
|
if (res.isBool()) return res.toBool();
|
||||||
}
|
}
|
||||||
@ -213,6 +214,14 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
|
|||||||
#ifdef HAVE_UI_LOADER
|
#ifdef HAVE_UI_LOADER
|
||||||
initDialogs();
|
initDialogs();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (m_scriptEngineContext){
|
||||||
|
|
||||||
|
foreach (BaseDesignIntf* item, patternPage->pageItem()->childBaseItems()){
|
||||||
|
baseDesignIntfToScript(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (runInitScript()){
|
if (runInitScript()){
|
||||||
|
|
||||||
clearPageMap();
|
clearPageMap();
|
||||||
@ -224,6 +233,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
|
|||||||
QMessageBox::critical(0,tr("Error"),exception.what());
|
QMessageBox::critical(0,tr("Error"),exception.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearPageMap();
|
clearPageMap();
|
||||||
startNewPage();
|
startNewPage();
|
||||||
|
|
||||||
@ -248,6 +258,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
|
|||||||
|
|
||||||
savePage(true);
|
savePage(true);
|
||||||
|
|
||||||
|
ScriptEngineManager::instance().scriptEngine()->popContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,14 +375,6 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
|
|||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
if (patternBand){
|
if (patternBand){
|
||||||
|
|
||||||
if (mode == ForcedStartPage){
|
|
||||||
savePage();
|
|
||||||
startNewPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (patternBand->isFooter())
|
|
||||||
m_lastRenderedFooter = patternBand;
|
|
||||||
|
|
||||||
BandDesignIntf* bandClone = 0;
|
BandDesignIntf* bandClone = 0;
|
||||||
|
|
||||||
if (bandData){
|
if (bandData){
|
||||||
@ -380,13 +383,24 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
|
|||||||
bandClone=renderData(patternBand);
|
bandClone=renderData(patternBand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode == ForcedStartPage){
|
||||||
|
savePage();
|
||||||
|
startNewPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (patternBand->isFooter())
|
||||||
|
m_lastRenderedFooter = patternBand;
|
||||||
|
|
||||||
|
|
||||||
bandClone->setBackgroundColor(
|
bandClone->setBackgroundColor(
|
||||||
(datasources()->variable(QLatin1String("line_")+patternBand->objectName().toLower()).toInt()%2!=0 ?
|
(datasources()->variable(QLatin1String("line_")+patternBand->objectName().toLower()).toInt()%2!=0 ?
|
||||||
patternBand->backgroundColor():
|
bandClone->backgroundColor():
|
||||||
patternBand->alternateBackgroundColor()
|
bandClone->alternateBackgroundColor()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
patternBand->emitBandRendered(bandClone);
|
patternBand->emitBandRendered(bandClone);
|
||||||
|
emit(patternBand->afterRender());
|
||||||
|
|
||||||
if ( isLast && bandClone->keepFooterTogether() && bandClone->sliceLastRow() ){
|
if ( isLast && bandClone->keepFooterTogether() && bandClone->sliceLastRow() ){
|
||||||
if (m_maxHeightByColumn[m_currentColumn] < (bandClone->height()+m_reportFooterHeight))
|
if (m_maxHeightByColumn[m_currentColumn] < (bandClone->height()+m_reportFooterHeight))
|
||||||
@ -960,10 +974,18 @@ BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, i
|
|||||||
BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand)
|
BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand)
|
||||||
{
|
{
|
||||||
BandDesignIntf* bandClone = dynamic_cast<BandDesignIntf*>(patternBand->cloneItem(PreviewMode));
|
BandDesignIntf* bandClone = dynamic_cast<BandDesignIntf*>(patternBand->cloneItem(PreviewMode));
|
||||||
|
|
||||||
|
baseDesignIntfToScript(bandClone);
|
||||||
|
emit(patternBand->beforeRender());
|
||||||
|
|
||||||
if (patternBand->isFooter()){
|
if (patternBand->isFooter()){
|
||||||
replaceGroupsFunction(bandClone);
|
replaceGroupsFunction(bandClone);
|
||||||
}
|
}
|
||||||
bandClone->updateItemSize(m_datasources);
|
bandClone->updateItemSize(m_datasources);
|
||||||
|
|
||||||
|
baseDesignIntfToScript(bandClone);
|
||||||
|
emit(patternBand->afterData());
|
||||||
|
|
||||||
return bandClone;
|
return bandClone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1194,4 +1216,29 @@ void ReportRender::cancelRender(){
|
|||||||
m_renderCanceled = true;
|
m_renderCanceled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReportRender::baseDesignIntfToScript(BaseDesignIntf *item)
|
||||||
|
{
|
||||||
|
if ( item ) {
|
||||||
|
|
||||||
|
if (item->metaObject()->indexOfSignal("beforeRender()")!=-1)
|
||||||
|
item->disconnect(SIGNAL(beforeRender()));
|
||||||
|
if (item->metaObject()->indexOfSignal("afterData()")!=-1)
|
||||||
|
item->disconnect(SIGNAL(afterData()));
|
||||||
|
if (item->metaObject()->indexOfSignal("afterRender()")!=-1)
|
||||||
|
item->disconnect(SIGNAL(afterRender()));
|
||||||
|
|
||||||
|
QScriptEngine* engine = ScriptEngineManager::instance().scriptEngine();
|
||||||
|
QScriptValue sItem = engine->globalObject().property(item->patternName());
|
||||||
|
if (sItem.isValid()){
|
||||||
|
engine->newQObject(sItem, item);
|
||||||
|
} else {
|
||||||
|
sItem = engine->newQObject(item);
|
||||||
|
engine->globalObject().setProperty(item->patternName(),sItem);
|
||||||
|
}
|
||||||
|
foreach(BaseDesignIntf* child, item->childBaseItems()){
|
||||||
|
baseDesignIntfToScript(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,9 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void cancelRender();
|
void cancelRender();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void baseDesignIntfToScript(BaseDesignIntf* item);
|
||||||
|
|
||||||
void renderPage(PageDesignIntf *patternPage);
|
void renderPage(PageDesignIntf *patternPage);
|
||||||
void initDatasources();
|
void initDatasources();
|
||||||
void initDatasource(const QString &name);
|
void initDatasource(const QString &name);
|
||||||
|
@ -220,6 +220,28 @@ QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){
|
|||||||
return QScriptValue();
|
return QScriptValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptValue getVariable(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
|
|
||||||
|
QString name = pcontext->argument(0).toString();
|
||||||
|
|
||||||
|
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
||||||
|
DataSourceManager* dm = sm->dataManager();
|
||||||
|
QScriptValue res = pengine->newVariant(dm->variable(name));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue getField(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
|
|
||||||
|
QString name = pcontext->argument(0).toString();
|
||||||
|
|
||||||
|
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
||||||
|
DataSourceManager* dm = sm->dataManager();
|
||||||
|
QScriptValue res = pengine->newVariant(dm->fieldData(name));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue numberFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
QScriptValue numberFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
QVariant value = pcontext->argument(0).toVariant();
|
QVariant value = pcontext->argument(0).toVariant();
|
||||||
char format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString()[0].toLatin1():'f';
|
char format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString()[0].toLatin1():'f';
|
||||||
@ -431,6 +453,8 @@ ScriptEngineManager::ScriptEngineManager()
|
|||||||
addFunction("currencyUSBasedFormat",currencyUSBasedFormat,"NUMBER","currencyUSBasedFormat(\""+tr("Value")+",\""+tr("CurrencySymbol")+"\")");
|
addFunction("currencyUSBasedFormat",currencyUSBasedFormat,"NUMBER","currencyUSBasedFormat(\""+tr("Value")+",\""+tr("CurrencySymbol")+"\")");
|
||||||
#endif
|
#endif
|
||||||
addFunction("setVariable", setVariable, "GENERAL", "setVariable(\""+tr("Name")+"\",\""+tr("Value")+"\")");
|
addFunction("setVariable", setVariable, "GENERAL", "setVariable(\""+tr("Name")+"\",\""+tr("Value")+"\")");
|
||||||
|
addFunction("getVariable", getVariable, "GENERAL", "getVariable(\""+tr("Name")+"\")");
|
||||||
|
addFunction("getField", getField, "GENERAL", "getField(\""+tr("Name")+"\")");
|
||||||
|
|
||||||
QScriptValue colorCtor = m_scriptEngine->newFunction(constructColor);
|
QScriptValue colorCtor = m_scriptEngine->newFunction(constructColor);
|
||||||
m_scriptEngine->globalObject().setProperty("QColor", colorCtor);
|
m_scriptEngine->globalObject().setProperty("QColor", colorCtor);
|
||||||
|
Loading…
Reference in New Issue
Block a user