diff --git a/kexi/plugins/reports/kexidbreportdata.h b/kexi/plugins/reports/kexidbreportdata.h --- a/kexi/plugins/reports/kexidbreportdata.h +++ b/kexi/plugins/reports/kexidbreportdata.h @@ -25,6 +25,7 @@ #include #include +#include #include /** @@ -66,8 +67,8 @@ //Utility Functions #ifdef KREPORT_SCRIPTING - virtual QStringList scriptList(const QString& language) const; - virtual QString scriptCode(const QString& script, const QString& language) const; + virtual QStringList scriptList() const; + virtual QString scriptCode(const QString& script) const; #endif virtual QStringList dataSources() const; virtual KoReportData* data(const QString&); diff --git a/kexi/plugins/reports/kexidbreportdata.cpp b/kexi/plugins/reports/kexidbreportdata.cpp --- a/kexi/plugins/reports/kexidbreportdata.cpp +++ b/kexi/plugins/reports/kexidbreportdata.cpp @@ -286,16 +286,15 @@ } #ifdef KREPORT_SCRIPTING -QStringList KexiDBReportData::scriptList(const QString& interpreter) const +QStringList KexiDBReportData::scriptList() const { QStringList scripts; if( d->connection) { QList scriptids = d->connection->objectIds(KexiPart::ScriptObjectType); QStringList scriptnames = d->connection->objectNames(KexiPart::ScriptObjectType); qDebug() << scriptids << scriptnames; - qDebug() << interpreter; //A blank entry scripts << ""; @@ -311,7 +310,7 @@ QDomElement scriptelem = domdoc.namedItem("script").toElement(); if (parsed && !scriptelem.isNull()) { - if (interpreter == scriptelem.attribute("language") && scriptelem.attribute("scripttype") == "object") { + if (scriptelem.attribute("scripttype") == "object" && (scriptelem.attribute("language").toLower() == QLatin1String("javascript") || scriptelem.attribute("language").toLower() == QLatin1String("qtscript"))) { scripts << scriptnames[i]; } } else { @@ -328,7 +327,7 @@ return scripts; } -QString KexiDBReportData::scriptCode(const QString& scriptname, const QString& language) const +QString KexiDBReportData::scriptCode(const QString& scriptname) const { QString scripts; @@ -358,11 +357,10 @@ } QString interpretername = scriptelem.attribute("language"); - qDebug() << language << interpretername; qDebug() << scriptelem.attribute("scripttype"); qDebug() << scriptname << scriptnames[i]; - if (language == interpretername && (scriptelem.attribute("scripttype") == "module" || scriptname == scriptnames[i])) { + if ((interpretername == QLatin1String("javascript") || interpretername == QLatin1String("qtscript")) && (scriptelem.attribute("scripttype") == "module" || scriptname == scriptnames[i])) { scripts += '\n' + scriptelem.text().toUtf8(); } ++i; diff --git a/kexi/plugins/reports/kexireportview.h b/kexi/plugins/reports/kexireportview.h --- a/kexi/plugins/reports/kexireportview.h +++ b/kexi/plugins/reports/kexireportview.h @@ -23,6 +23,7 @@ #include +#include #include #include @@ -33,7 +34,7 @@ class ORODocument; class KReportView; #ifdef KREPORT_SCRIPTING -class KexiScriptAdaptor; +//class KexiScriptAdaptor; class KRScriptFunctions; #endif #ifndef KEXI_MOBILE @@ -75,7 +76,7 @@ KexiReportPart::TempData* tempData() const; KoReportData* sourceData(QDomElement e); #ifdef KREPORT_SCRIPTING - KexiScriptAdaptor *m_kexi; + //KexiScriptAdaptor *m_kexi; KRScriptFunctions *m_functions; #endif KoReportRendererFactory m_factory; diff --git a/kexi/plugins/reports/kexireportview.cpp b/kexi/plugins/reports/kexireportview.cpp --- a/kexi/plugins/reports/kexireportview.cpp +++ b/kexi/plugins/reports/kexireportview.cpp @@ -32,7 +32,7 @@ #include #ifdef KREPORT_SCRIPTING -#include "../scripting/kexiscripting/kexiscriptadaptor.h" +//#include "../scripting/kexiscripting/kexiscriptadaptor.h" #endif #include @@ -168,8 +168,8 @@ qDebug(); delete m_preRenderer; #ifdef KREPORT_SCRIPTING - delete m_kexi; - delete m_functions; +// delete m_kexi; +// delete m_functions; #endif delete m_reportDocument; } @@ -404,17 +404,12 @@ #ifdef KREPORT_SCRIPTING //Add a kexi object to provide kexidb and extra functionality - if(!m_kexi) { - m_kexi = new KexiScriptAdaptor(); - } - m_preRenderer->registerScriptObject(m_kexi, "Kexi"); +//TODO if we want this if(!m_kexi) { +// m_kexi = new KexiScriptAdaptor(); +// } +// m_preRenderer->registerScriptObject(m_kexi, "Kexi"); //If using a kexidb source, add a functions scripting object if (tempData()->connectionDefinition.attribute("type") == "internal") { - //Delete old functions - if (m_functions) { - delete m_functions; - } - m_functions = new KRScriptFunctions(reportData, KexiMainWindowIface::global()->project()->dbConnection()); m_preRenderer->registerScriptObject(m_functions, "field"); } diff --git a/kexi/plugins/reports/krscriptfunctions.cpp b/kexi/plugins/reports/krscriptfunctions.cpp --- a/kexi/plugins/reports/krscriptfunctions.cpp +++ b/kexi/plugins/reports/krscriptfunctions.cpp @@ -28,7 +28,10 @@ { m_cursor = kodata; m_connection = conn; - m_source = kodata->sourceName(); + + if (kodata) { + m_source = kodata->sourceName(); + } } KRScriptFunctions::~KRScriptFunctions() @@ -43,6 +46,11 @@ qreal KRScriptFunctions::math(const QString &function, const QString &field) { qreal ret; + + if (!m_cursor) { + return 0; + } + KDbEscapedString sql = KDbEscapedString("SELECT " + function + "(" + field + ") FROM (" + m_source + ")"); if (!m_where.isEmpty()) {