[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kexi/plugins/reportspgz/backend
From: Adam Pigg <adam () piggz ! co ! uk>
Date: 2008-11-11 22:08:09
Message-ID: 1226441289.320714.25220.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 883024 by piggz:
Scripting Improvements:
Removed internal editor dialog in favour of existing script editor.
Renamed math object to field so as not to clash with existing javascript math.
Scripting now works by associating a an 'object' in the script with a report object \
using Kross::Object 's, and then defining in the script objects the event handlers. \
Added a messasgebox debug function for scripts. The script handler will load all \
scripts which match the report's interpreter type. This may be extended when/if \
scripts gain an 'executable' property, in which case, only non-executable scripts \
will be loaded.
M +5 -1 renderer/scripting/krscriptdebug.cpp
M +1 -0 renderer/scripting/krscriptdebug.h
M +64 -6 renderer/scripting/krscripthandler.cpp
M +9 -2 renderer/scripting/krscripthandler.h
M +23 -0 renderer/scripting/krscriptreport.cpp
M +8 -0 renderer/scripting/krscriptreport.h
M +11 -0 renderer/scripting/krscriptsection.cpp
M +6 -1 renderer/scripting/krscriptsection.h
M +2 -48 wrtembed/reportdesigner.cpp
M +0 -15 wrtembed/reportdesigner.h
M +0 -6 wrtembed/reportsection.cpp
M +0 -1 wrtembed/reportsection.h
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptdebug.cpp \
#883023:883024 @@ -19,6 +19,7 @@
*/
#include "krscriptdebug.h"
#include <kdebug.h>
+#include <kmessagebox.h>
KRScriptDebug::KRScriptDebug(QObject *parent)
: QObject(parent)
@@ -35,4 +36,7 @@
kDebug() << s;
}
-
+void KRScriptDebug::message(const QString &t, const QString &m)
+{
+ KMessageBox::information(0, m, t);
+}
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptdebug.h \
#883023:883024 @@ -35,6 +35,7 @@
public slots:
void print(const QString&);
+ void message(const QString &, const QString&);
};
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscripthandler.cpp \
#883023:883024 @@ -21,8 +21,12 @@
#include <kdebug.h>
#include <kexidb/cursor.h>
+#include <KexiMainWindowIface.h>
+#include <kexiproject.h>
+#include <kexipart.h>
+#include <kexiutils/tristate.h>
+
#include "krscriptfunctions.h"
-
#include <parsexmlutils.h>
#include <krsectiondata.h>
#include "krscriptsection.h"
@@ -57,7 +61,7 @@
//Add math functions to the script
_functions = new KRScriptFunctions(_curs);
- _action->addObject(_functions, "math");
+ _action->addObject(_functions, "field");
//Add constants object
_constants = new KRScriptConstants();
@@ -72,15 +76,17 @@
_action->addObject(_draw, "draw");
//Add a general report object
- _action->addObject(new Scripting::Report(_data), "report");
+ _report = new Scripting::Report(_data);
+ _action->addObject(_report, "report");
//Add the sections
QList<KRSectionData*> secs = _data->sections();
foreach(KRSectionData *sec, secs) {
- _action->addObject(new Scripting::Section(sec), sec->name());
+ _sectionMap[sec] = new Scripting::Section(sec);
+ _action->addObject(_sectionMap[sec], sec->name());
}
- _action->setCode((_data->script() + "\n" + fieldFunctions()).toLocal8Bit());
+ _action->setCode((_data->script() + "\n" + fieldFunctions()).toLocal8Bit() + \
scriptCode().toLocal8Bit());
kDebug() << _action->code();
@@ -91,15 +97,18 @@
} else {
kDebug() << "Function Names:" << _action->functionNames();
}
+
+ _report->eventOnOpen();
}
KRScriptHandler::~KRScriptHandler()
{
- delete _action;
+ delete _report;
delete _functions;
delete _constants;
delete _debug;
delete _draw;
+ delete _action;
}
void KRScriptHandler::setSource(const QString &s)
@@ -126,6 +135,14 @@
_draw->setPage(cp);
_draw->setOffset(off);
+ Scripting::Section *ss = _sectionMap[section];
+ if (ss)
+ {
+ ss->eventOnRender();
+ }
+
+ return;
+
if (!_action->hadError() && _action->functionNames().contains(section->name() + \
"_onrender")) {
QVariant result = _action->callFunction(section->name() + "_onrender");
displayErrors();
@@ -199,3 +216,44 @@
kDebug() << w;
return w;
}
+
+QString KRScriptHandler::scriptCode()
+{
+ QList<int> scriptids = \
KexiMainWindowIface::global()->project()->dbConnection()->objectIds(KexiPart::ScriptObjectType);
+ QString scripts;
+
+ int id;
+ QString script;
+
+ foreach (id, scriptids) {
+ kDebug() << "ID:" << id;
+ tristate res;
+ res = KexiMainWindowIface::global()->project()->dbConnection()->loadDataBlock(id, \
script, QString()); + if (res == true){
+ QDomDocument domdoc;
+ bool parsed = domdoc.setContent(script, false);
+
+ if (! parsed) {
+ kDebug() << "XML parsing error";
+ return false;
+ }
+
+ QDomElement scriptelem = domdoc.namedItem("script").toElement();
+ if (scriptelem.isNull()) {
+ kDebug() << "script domelement is null";
+ return false;
+ }
+
+ QString interpretername = scriptelem.attribute("language");
+ kDebug() << interpretername;
+ if (_data->interpreter() == interpretername) {
+ scripts += '\n' + scriptelem.text().toUtf8();
+ }
+ }
+ else{
+ kDebug() << "Unable to loadDataBlock";
+ }
+ }
+
+ return scripts;
+}
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscripthandler.h \
#883023:883024 @@ -28,11 +28,14 @@
class KRScriptFunctions;
class KRScriptConstants;
class KRScriptDebug;
-class QScriptEngine;
class KRReportData;
class OROPage;
class KRScriptDraw;
+namespace Scripting{
+ class Report;
+ class Section;
+}
class KRScriptHandler : public QObject
{
Q_OBJECT
@@ -57,8 +60,11 @@
KRScriptDebug *_debug;
KRScriptDraw *_draw;
+ Scripting::Report *_report;
+
QString fieldFunctions();
-
+ QString scriptCode();
+
KexiDB::Connection *_conn;
const KexiDB::Cursor *_curs;
@@ -68,6 +74,7 @@
Kross::Action* _action;
QMap<QString, QVariant> _groups;
+ QMap<KRSectionData*, Scripting::Section*> _sectionMap;
QString where();
};
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptreport.cpp \
#883023:883024 @@ -36,16 +36,20 @@
Report::Report(KRReportData *r)
{
_reportdata = r;
+ _scriptObject = 0;
}
Report::~Report()
{
+
}
+
QString Report::title()
{
return _reportdata->title;
}
+
QString Report::recordSource()
{
return _reportdata->query();
@@ -95,4 +99,23 @@
return new QObject();
}
}
+
+void Report::initialize(Kross::Object::Ptr ptr)
+{
+ _scriptObject = ptr;
}
+
+void Report::eventOnOpen()
+{
+ if (_scriptObject)
+ _scriptObject->callMethod("OnOpen");
+}
+
+void Report::eventOnClose()
+{
+ if (_scriptObject)
+ _scriptObject->callMethod("OnClose");
+}
+
+
+}
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptreport.h \
#883023:883024 @@ -21,6 +21,8 @@
#define SCRIPTINGKRSCRIPTREPORT_H
#include <QObject>
+#include <kross/core/object.h>
+
class KRReportData;
class KRObjectData;
namespace Scripting
@@ -43,8 +45,14 @@
QObject* objectByName(const QString &);
QObject* sectionByName(const QString &);
+
+ void initialize(Kross::Object::Ptr);
+ void eventOnOpen();
+ void eventOnClose();
+
private:
KRReportData *_reportdata;
+ Kross::Object::Ptr _scriptObject;
};
}
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptsection.cpp \
#883023:883024 @@ -32,6 +32,7 @@
Section::Section(KRSectionData* sec)
{
_section = sec;
+ _scriptObject = 0;
}
@@ -105,4 +106,14 @@
return 0;
}
+void Section::initialize(Kross::Object::Ptr p)
+{
+ _scriptObject = p;
}
+
+void Section::eventOnRender()
+{
+ if (_scriptObject)
+ _scriptObject->callMethod("OnRender");
+}
+}
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/scripting/krscriptsection.h \
#883023:883024 @@ -22,6 +22,7 @@
#include <QObject>
#include <krsectiondata.h>
+#include <kross/core/object.h>
/**
@author Adam Pigg <adam@piggz.co.uk>
@@ -56,9 +57,13 @@
QObject* objectByNumber(int);
/**Returns an object in the section, by name*/
QObject* objectByName(const QString&);
-
+
+ void initialize(Kross::Object::Ptr);
+ void eventOnRender();
+
private:
KRSectionData *_section;
+ Kross::Object::Ptr _scriptObject;
};
}
#endif
--- trunk/koffice/kexi/plugins/reportspgz/backend/wrtembed/reportdesigner.cpp \
#883023:883024 @@ -93,20 +93,7 @@
virtual ~ReportWriterSectionData() {
selected_items_rw = 0;
}
-/*
- enum ItemType {
- NoItem = 0,
- LabelItem,
- FieldItem,
- TextItem,
- LineItem,
- BarcodeItem,
- ImageItem,
- ChartItem,
- ShapeItem,
- CheckItem
- };
-*/
+
enum MouseAction {
MA_None = 0,
MA_Insert = 1,
@@ -150,8 +137,6 @@
QVBoxLayout *vboxlayout;
KexiSectionHeader *head;
QPushButton *pageButton;
- KexiEditor *editor;
- KDialog *editorDialog;
};
ReportDesigner::ReportDesigner(QWidget * parent, KexiDB::Connection *cn)
@@ -165,8 +150,6 @@
_modified = false;
detail = 0;
d->hruler = 0;
- d->editorDialog = 0;
- d->editor = 0;
sectionData = new ReportWriterSectionData();
createProperties();
@@ -212,7 +195,6 @@
setLayout(d->grid);
-
connect(d->pageButton, SIGNAL(pressed()), this, SLOT(slotPageButton_Pressed()));
emit pagePropertyChanged(*set);
@@ -252,7 +234,7 @@
} else if (n == "datasource") {
setReportDataSource(it.firstChild().nodeValue());
} else if (n == "script") {
- _script = it.firstChild().nodeValue();
+ _interpreter->setValue(it.toElement().attribute("interpreter"));
} else if (n == "grid") {
setGridOptions(it.toElement().attribute("visible").toInt() == 0 ? \
false : true, it.toElement().attribute("divisions").toInt()); }
@@ -625,7 +607,6 @@
root.appendChild(rds);
QDomElement scr = doc.createElement("script");
- scr.appendChild(doc.createTextNode(_script));
scr.setAttribute("interpreter", _interpreter->value().toString());
root.appendChild(scr);
@@ -1359,33 +1340,6 @@
return d->zoom;
}
-QString ReportDesigner::editorText(const QString& orig)
-{
- QString old = orig;
- if (!d->editorDialog) {
- d->editorDialog = new KDialog(this);
- d->editorDialog->setCaption(i18n("Script Editor"));
- d->editorDialog->setButtons(KDialog::Ok | KDialog::Cancel);
-
- d->editor = new KexiEditor(d->editorDialog);
- d->editorDialog->setMainWidget(d->editor);
- d->editorDialog->setMinimumSize(600, 500);
-
- }
- d->editor->setHighlightMode(_interpreter->value().toString());
- d->editor->setText(orig);
- if (d->editorDialog->exec()) {
- setModified(true);
- return d->editor->text();
- }
-
- return old;
-}
-void ReportDesigner::showScriptEditor()
-{
- _script = editorText(_script);
-}
-
QString ReportDesigner::suggestEntityName(const QString &n) const
{
ReportSection *sec;
--- trunk/koffice/kexi/plugins/reportspgz/backend/wrtembed/reportdesigner.h \
#883023:883024 @@ -135,8 +135,6 @@
void setModified(bool = true);
- void showScriptEditor();
-
/**Return a unique name that can be used by the entity*/
QString suggestEntityName(const QString &) const;
@@ -150,16 +148,6 @@
void slotEditPaste();
void slotEditPaste(QGraphicsScene *, const QPointF &);
-/*
- void slotItemLabel();
- void slotItemField();
- void slotItemText();
- void slotItemLine();
- void slotItemBarcode();
- void slotItemImage();
- void slotItemChart();
- void slotItemShape();
- void slotItemCheck();*/
void slotItem(KRObjectData::EntityTypes);
void slotSectionEditor();
@@ -217,9 +205,6 @@
KoProperty::Property* _labelType;
KoProperty::Property* _interpreter;
- QString editorText(const QString&);
- QString _script;
-
ReportWriterSectionData * sectionData;
unsigned int selectionCount();
--- trunk/koffice/kexi/plugins/reportspgz/backend/wrtembed/reportsection.cpp \
#883023:883024 @@ -91,7 +91,6 @@
QObject::connect(scene, SIGNAL(clicked()), this, (SLOT(slotSceneClicked())));
QObject::connect(scene, SIGNAL(lostFocus()), this, \
(SLOT(slotSceneLostFocus())));
- QObject::connect(title, SIGNAL(doubleClicked()), this, \
(SLOT(slotTitleDoubleClicked()))); glayout->addWidget(title, 0, 0, 1, 2);
glayout->addWidget(sectionRuler, 1, 0);
glayout->addWidget(sceneview , 1, 1);
@@ -245,11 +244,6 @@
title->setFrameStyle(QFrame::Panel | QFrame::Raised);
}
-void ReportSection::slotTitleDoubleClicked()
-{
- _rd->showScriptEditor();
-}
-
void ReportSection::slotPropertyChanged(KoProperty::Set &s, KoProperty::Property &p)
{
kDebug();
--- trunk/koffice/kexi/plugins/reportspgz/backend/wrtembed/reportsection.h \
#883023:883024 @@ -79,7 +79,6 @@
void slotSceneClicked();
void slotPropertyChanged(KoProperty::Set &, KoProperty::Property &);
void slotSceneLostFocus();
- void slotTitleDoubleClicked();
protected:
ReportSectionTitle * title;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic