Port KReport from Kross to QJSEngine
ClosedPublic

Authored by piggz on Aug 8 2015, 8:41 AM.

Details

Summary

Replaced Kross with QJSEngine and added example script to the test application.

Script code is compatible with Kexi 2 JS code

Removed the 'interpreter' property from a report as there is now only one interpreter

Test code will color alternate sections, set the caption of an item named 'label1' and print
a debug line on open and section render.

Test Plan
  1. run kreportexmple
  2. add a label
  3. select report properties
  4. set ;script' proerty to 'example'
  5. observe in the render window the effects

Diff Detail

Repository
R14 KReport
Branch
kreport-scripting-piggz
Lint
No Linters Available
Unit
No Unit Test Coverage
piggz updated this revision to Diff 528.Aug 8 2015, 8:41 AM
piggz retitled this revision from to Port KReport from Kross to QJSEngine.
piggz edited the test plan for this revision. (Show Details)
piggz added a reviewer: staniek.
piggz updated this object.
piggz updated this object.
piggz added a comment.Aug 8 2015, 8:48 AM

Attached image shows a script interacting with report objects (section and label). Code is visible in the output pane of QtCreator

This revision was automatically updated to reflect the committed changes.
piggz reopened this revision.Aug 8 2015, 12:56 PM
piggz updated this revision to Diff 531.Aug 8 2015, 12:57 PM
  • Remove the language parameter from KoReportData
piggz updated this object.Aug 8 2015, 1:03 PM
staniek requested changes to this revision.Aug 8 2015, 11:10 PM
staniek edited edge metadata.
staniek added inline comments.
src/CMakeLists.txt
6–7

find_package(Qt5Qml REQUIRED) needed too

src/items/check/KoReportScriptCheck.cpp
20

Preferred is #include <KProperty> for the current KProperty

src/items/image/krscriptimage.cpp
21

staniekUnsubmitted
Not Done

Preferred is #include <KProperty> for the current KProperty

src/renderer/scripting/krscripthandler.cpp
32

Convention is I guess that we don't use prefixes

src/renderer/scripting/krscriptline.cpp
21

staniekUnsubmitted
Not Done

Preferred is #include <KProperty> for the current KProperty

This revision now requires changes to proceed.Aug 8 2015, 11:10 PM

One observation: if we want to integrate my SDC-based explicitly shared classes, please don't port all the elements. (to avoid unnecessary repeated work).

Despite of using Qt 5.5 I have not found better solution for making objects scriptable than using a wrapper QObject. That said, the branch scripting-T517-staniek of ssh://git@git.kde.org/clones/kreport/staniek/work shows that the wrapping is slightly different and SDC may be able to generate script methods for use (getters, setters).

Summing up we need to synchronize the efforts.

I conducted experiments with SDC also because of KDb APIs. For example DCount() function is so frequently used (also in reports) so we may want a globally consistent scripting approach.

piggz added a comment.Aug 9 2015, 6:57 AM

There is no porting of elements required! :)

As of now, they work as in kexi2 with no changes to the wrapper classes. So you are happy to push this to master with above changes?

Please give me some time, hopefully before tomorrow morning ;)

piggz marked 3 inline comments as done.Aug 9 2015, 2:29 PM

Fized all except #include <QtQml/....> as it the build doesnt find the headers otherwise

piggz added a comment.Aug 9 2015, 5:33 PM

Fized all except #include <QtQml/....> as it the build doesnt find the headers otherwise

In D238#4160, @piggz wrote:

Fized all except #include <QtQml/....> as it the build doesnt find the headers otherwise

Do you have Qt5::Qml in target_link_libraries? Cmake will then add proper includes.
find_package(Qt5Qml REQUIRED) finds them, you need to have this line too.

Reviewed entire diff against kreport.git master. Comments below.

src/common/KoReportData.cpp
73

Needed?

src/renderer/KoReportPreRenderer.cpp
509

Don't we want to check result of trigger() and fail on errors? We're never sure if the report is valid if there's any error in scripts.

621

So the owner is responsible for deleting the prev. version?

src/renderer/scripting/krscripthandler.cpp
31

+ please clean up the order of includes: separate local from Qt

91

Check if code.isEmpty(), if so return immediately

91

-> kreportDebug()

92

Add m_reportData->script() as the 'const QString & fileName' arg. This can make the error message better.

98–99

Do we want to call this also if m_scriptValue.isError()?

105

Maybe it's better to destroy the engine first and then the exposed objects?

143

Check result, display errors?

177

Always true, isn't it?

src/renderer/scripting/krscripthandler.h
50–51

change to bool trigger()

src/renderer/scripting/krscriptreport.cpp
103

Is this property always present?

109

Is this property always present?

115

Is this property always present?

src/renderer/scripting/krscriptreport.h
46

-> const QJSValue &val

src/renderer/scripting/krscriptsection.cpp
106

Is this property always present?

src/renderer/scripting/krscriptsection.h
58

-> const QJSValue &val

src/wrtembed/KoReportDesigner.cpp
288–289

How exactly can we port it?
I guess we have to read the value anyway and check if it's JavaScript. If not, show a warning:
"This report appears to contain a script written in language \"%1\". Current version of Reports only allow to use JavaScript. If you edit any script, previous one will be replaced. If you don't edit any script, previous version will be kept for use in older version of Reports."

Then set d->script but also remember value of report:script-interpreter. On saving save it back.

Change the name obtained from report:script-interpreter to "JavaScript" as soon as scripts are edited so saving updates report:script-interpreter properly.

379–380

Save the script only if it's not empty.
Still save the interpreter name. JavaScript if the script was modified but the name can be also the one loaded from the original XML, see above.

805

Not needed

808

Convention: use prepend()
But why this line is needed?

piggz marked 19 inline comments as done.Aug 10 2015, 10:05 AM
piggz added inline comments.
src/renderer/KoReportPreRenderer.cpp
621

exactly my thinking

src/renderer/scripting/krscriptreport.cpp
103

i guess not!

src/wrtembed/KoReportDesigner.cpp
808

so that the user can always select to have 'no script'

staniek added inline comments.Aug 10 2015, 10:14 AM
src/wrtembed/KoReportDesigner.cpp
808

OK...

piggz updated this revision to Diff 543.Aug 11 2015, 1:34 PM
piggz edited edge metadata.
piggz marked 2 inline comments as done.
piggz updated this object.

Address comments by staniek 2

Need firther testing of loading/saving of interpreter and scripts
perhaps as further work to the example app using load of external report file

This revision was automatically updated to reflect the committed changes.
piggz reopened this revision.Aug 11 2015, 1:51 PM
staniek requested changes to this revision.Aug 13 2015, 8:33 AM
staniek edited edge metadata.
staniek added inline comments.
src/CMakeLists.txt
157

Monir: Please keep order

src/common/renderobjects.cpp
49

It's a c++11 construct. Asked on the list what's our policy for it in Calligra 3.
For kdb/kreport/kproperty I propose to follow https://community.kde.org/Frameworks/Policies#Frameworks_compiler_requirements_and_C.2B.2B11. This means: let's change to Q_NULLPTR.

src/renderer/KoReportScreenRenderer.cpp
49

just (!p) as usual

src/renderer/scripting/krscripthandler.cpp
114

Why are these 3 deletes removed?

src/wrtembed/KoReportDesigner.cpp
200

Not a native speaker but I propose
-> originalInterpreter
-> originalScript

294

Removed \n (better for the GUI)
->
"This report is using a script type other than \"javascript\". To prevent loosing the script, the type of script will not be changed unless the script is changed. Please be aware that the script will not work unless it is changed to a \"javascript\" script."

297

-> Unsupported Script Type

379–380

What about this?
The entire #ifdef KREPORT_SCRIPTING section could be skipped if the script (d->script->value().toString()) is empty (removed), right?

This revision now requires changes to proceed.Aug 13 2015, 8:33 AM
piggz added inline comments.Aug 13 2015, 8:49 AM
src/renderer/scripting/krscripthandler.cpp
114

QJSEngine assumes ownership of the objects and deletes them when it is deleted ... took a while to figure out why double-free was happening!! http://doc.qt.io/qt-5/qjsengine.html#newQObject

staniek added inline comments.Aug 13 2015, 8:50 AM
src/renderer/scripting/krscripthandler.cpp
105

Indeed! Thanks.

piggz edited the test plan for this revision. (Show Details)Aug 13 2015, 8:54 AM
piggz edited edge metadata.
piggz marked 11 inline comments as done.Aug 13 2015, 11:20 AM
piggz added inline comments.
src/CMakeLists.txt
157

was not needed anyway

piggz updated this revision to Diff 547.Aug 13 2015, 11:27 AM
piggz edited edge metadata.
piggz marked an inline comment as done.
  • Remove the language parameter from KoReportData
  • Merge branch 'kreport-scripting-piggz' of git://anongit.kde.org/kreport into kreport-scripting-piggz
  • Addressed staniek comments set 1
  • Address comments by staniek 2
  • Address comments round 3
piggz updated this revision to Diff 548.Aug 13 2015, 11:51 AM
piggz edited edge metadata.

Only save script XML if there is a script
String changes

staniek accepted this revision.Aug 13 2015, 11:58 AM
staniek edited edge metadata.

Minor fix and go!

src/wrtembed/KoReportDesigner.cpp
297

this is a title so All Caps needed -> "Unsupported Script Type"

This revision is now accepted and ready to land.Aug 13 2015, 11:58 AM