mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-03-13 22:03:54 +03:00
Merge branch '1.4_scriptingBand' into 1.4
This commit is contained in:
commit
f72f1a743e
@ -357,6 +357,7 @@ bool BandDesignIntf::canBeSplitted(int height) const
|
||||
|
||||
bool BandDesignIntf::isEmpty() const
|
||||
{
|
||||
if (!isVisible()) return true;
|
||||
foreach(QGraphicsItem* qgItem,childItems()){
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(qgItem);
|
||||
if ((item)&&(!item->isEmpty())) return false;
|
||||
|
@ -818,7 +818,7 @@ void BaseDesignIntf::turnOnSelectionMarker(bool value)
|
||||
|
||||
QString BaseDesignIntf::patternName() const
|
||||
{
|
||||
return m_patternName;
|
||||
return (m_patternName.isEmpty()) ? objectName() : m_patternName;
|
||||
}
|
||||
|
||||
void BaseDesignIntf::setPatternName(const QString &patternName)
|
||||
|
@ -387,6 +387,10 @@ signals:
|
||||
void propertyesChanged(QVector<QString> propertyNames);
|
||||
void itemAlignChanged(BaseDesignIntf* item, const ItemAlign& oldValue, const ItemAlign& newValue);
|
||||
void itemVisibleHasChanged(BaseDesignIntf* item);
|
||||
|
||||
void beforeRender();
|
||||
void afterData();
|
||||
void afterRender();
|
||||
};
|
||||
|
||||
} //namespace LimeReport
|
||||
|
@ -167,8 +167,17 @@ void ReportRender::setScriptContext(ScriptEngineContext* scriptContext)
|
||||
|
||||
bool ReportRender::runInitScript(){
|
||||
if (m_scriptEngineContext){
|
||||
QScriptValue res = ScriptEngineManager::instance().scriptEngine()->evaluate(m_scriptEngineContext->initScript());
|
||||
QScriptEngine* engine = ScriptEngineManager::instance().scriptEngine();
|
||||
engine->pushContext();
|
||||
QScriptValue res = engine->evaluate(m_scriptEngineContext->initScript());
|
||||
if (res.isBool()) return res.toBool();
|
||||
if (engine->hasUncaughtException()) {
|
||||
QMessageBox::critical(0,tr("Error"),
|
||||
QString("Line %1: %2 ").arg(engine->uncaughtExceptionLineNumber())
|
||||
.arg(engine->uncaughtException().toString())
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -213,6 +222,14 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
|
||||
#ifdef HAVE_UI_LOADER
|
||||
initDialogs();
|
||||
#endif
|
||||
|
||||
if (m_scriptEngineContext){
|
||||
|
||||
foreach (BaseDesignIntf* item, patternPage->pageItem()->childBaseItems()){
|
||||
baseDesignIntfToScript(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (runInitScript()){
|
||||
|
||||
clearPageMap();
|
||||
@ -224,6 +241,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
|
||||
QMessageBox::critical(0,tr("Error"),exception.what());
|
||||
return;
|
||||
}
|
||||
|
||||
clearPageMap();
|
||||
startNewPage();
|
||||
|
||||
@ -242,12 +260,13 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
|
||||
if (lastRenderedBand && lastRenderedBand->keepFooterTogether())
|
||||
closeFooterGroup(lastRenderedBand);
|
||||
|
||||
BandDesignIntf* tearOffBand = m_patternPageItem->bandByType(BandDesignIntf::TearOffBand);
|
||||
if (tearOffBand)
|
||||
renderBand(tearOffBand, 0, StartNewPageAsNeeded);
|
||||
BandDesignIntf* tearOffBand = m_patternPageItem->bandByType(BandDesignIntf::TearOffBand);
|
||||
if (tearOffBand)
|
||||
renderBand(tearOffBand, 0, StartNewPageAsNeeded);
|
||||
|
||||
savePage(true);
|
||||
|
||||
ScriptEngineManager::instance().scriptEngine()->popContext();
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,14 +383,6 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
|
||||
QApplication::processEvents();
|
||||
if (patternBand){
|
||||
|
||||
if (mode == ForcedStartPage){
|
||||
savePage();
|
||||
startNewPage();
|
||||
}
|
||||
|
||||
if (patternBand->isFooter())
|
||||
m_lastRenderedFooter = patternBand;
|
||||
|
||||
BandDesignIntf* bandClone = 0;
|
||||
|
||||
if (bandData){
|
||||
@ -380,13 +391,24 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
|
||||
bandClone=renderData(patternBand);
|
||||
}
|
||||
|
||||
if (mode == ForcedStartPage){
|
||||
savePage();
|
||||
startNewPage();
|
||||
}
|
||||
|
||||
if (patternBand->isFooter())
|
||||
m_lastRenderedFooter = patternBand;
|
||||
|
||||
|
||||
bandClone->setBackgroundColor(
|
||||
(datasources()->variable(QLatin1String("line_")+patternBand->objectName().toLower()).toInt()%2!=0 ?
|
||||
patternBand->backgroundColor():
|
||||
patternBand->alternateBackgroundColor()
|
||||
bandClone->backgroundColor():
|
||||
bandClone->alternateBackgroundColor()
|
||||
)
|
||||
);
|
||||
|
||||
patternBand->emitBandRendered(bandClone);
|
||||
emit(patternBand->afterRender());
|
||||
|
||||
if ( isLast && bandClone->keepFooterTogether() && bandClone->sliceLastRow() ){
|
||||
if (m_maxHeightByColumn[m_currentColumn] < (bandClone->height()+m_reportFooterHeight))
|
||||
@ -960,10 +982,18 @@ BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, i
|
||||
BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand)
|
||||
{
|
||||
BandDesignIntf* bandClone = dynamic_cast<BandDesignIntf*>(patternBand->cloneItem(PreviewMode));
|
||||
|
||||
baseDesignIntfToScript(bandClone);
|
||||
emit(patternBand->beforeRender());
|
||||
|
||||
if (patternBand->isFooter()){
|
||||
replaceGroupsFunction(bandClone);
|
||||
}
|
||||
bandClone->updateItemSize(m_datasources);
|
||||
|
||||
baseDesignIntfToScript(bandClone);
|
||||
emit(patternBand->afterData());
|
||||
|
||||
return bandClone;
|
||||
}
|
||||
|
||||
@ -1194,4 +1224,29 @@ void ReportRender::cancelRender(){
|
||||
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:
|
||||
void cancelRender();
|
||||
private:
|
||||
|
||||
void baseDesignIntfToScript(BaseDesignIntf* item);
|
||||
|
||||
void renderPage(PageDesignIntf *patternPage);
|
||||
void initDatasources();
|
||||
void initDatasource(const QString &name);
|
||||
|
@ -220,6 +220,28 @@ QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){
|
||||
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){
|
||||
QVariant value = pcontext->argument(0).toVariant();
|
||||
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")+"\")");
|
||||
#endif
|
||||
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);
|
||||
m_scriptEngine->globalObject().setProperty("QColor", colorCtor);
|
||||
|
Loading…
Reference in New Issue
Block a user