Ariya Hidayat
Qt Script
Graphics Dojo
Posted by Ariya Hidayat
 in Qt Script, Graphics Dojo
 on Tuesday, January 06, 2009 @ 14:29

It is just bound to happen, isn’t it? Since I share the office with Kent, our QtScript guru, it is indeed a matter of time before a QtScript-based Graphics Dojo example falling from the sky. Here it is: a bar chart.

There are many ways to create your bar chart. You can use an office suite like OpenOffice.org. You can use the web-based API, such as Google Chart. You can also use insert-your-favorite-tool-here. What is shown below is the QtScript-based solution. Due to the nature of a scripting language, the data for the chart is actually inside the script, or rather it is one important piece of the script itself. Thus, creating a new chart is a matter of editing or adding new chart data and relaunch it. This eliminates the need for a routine that parses the input. Quite a time saver, isn’t it? Combined with the lack of compiling step, resistance is futile.

chart.png

As an example, for the chart above (which is just the SquirrelFish benchmark result redone with the tool), here is the relevant script fragment:

chart.windowTitle = "SquirrelFish Performance";
chart.suffix = "runs";
chart.data = {
          "WebKit 3.0" :  5.4,
          "WebKit 3.1" : 18.8,
        "SquirrelFish" : 29.9,
"SquirrelFish Extreme" : 63.6 };

The colors for each bar are generated automatically, see Helder’s QQ 26 Adaptive Coloring for Syntax Highlighting for the general idea. If you do not favor the automatically picked colors, use the mouse wheel to change them (at once). Resizing the window allows you to find the optimum overall dimension for your chart. And once you are satisfied with the result, mouse click to save it to an image file.

The code is available from our brand new git repository for Graphics Dojo under the subdirectory barchart. Here is a way to get it:

git clone git://labs.trolltech.com/GraphicsDojo

To run the script, you need the bindings. Just grab that QtScript binding generator, build and run it (see its README), and the use the built qs_eval like:

/path/to/qtbindings/qs_eval/qs_eval barchart.qs

Finally, if you want to creat a lot of bar charts, just split out the actual chart instantiation (line 122 onwards) into its own script file. This way, you can create a new chart with touching barchart.qs very often.

PS: I thank Kent for his help which made my first QtScript endeavor as smooth as it could be.

5 Responses to “Simple QtScript-based bar chart”

» Posted by Scorp1us
 on Tuesday, January 06, 2009 @ 14:49

I am confused by QtScript. Since few of the non slots are not decorated with the Q_INVOKE (sp?) macro, doesn’t that leave Qt toScript pretty useless. I hear you can run a utility on the class to expose the member functions to QtScript, but why isn’t that done by default? It would be cool to be able to download Qt and start developing in ECMA or C++, immediately, without having to run the utulity every time you go to use a class.

Or am I mistaken?

» Posted by ariya
 on Wednesday, January 07, 2009 @ 11:39
Ariya Hidayat

@ Scorp1us: You download+install Qt and then grab+build+run the binding generator, each of these exactly one time only. After that, you can develop tons of QtScript-based tools (which use Qt classes) as many times as you want.

» Posted by sukzhong
 on Thursday, January 08, 2009 @ 06:25

HI ariya:

we’re porting QtWebKit in Qt Embeded linux to embed device.we have some problems,hope you can give us some advices.

we have compiled the Qt4.4.3(include QtWebKit) on blackfin or arm platform,it runs ok,it can visit normal website for example gmail etc,but it doesn’t support any plugin, and we want it to support.

so we checkout the current webkit source code, and compile it on ubuntu, we find it can run ok, it can load adobe flash plugin normally.

and we view the implemation of pluginviewQt.cpp etc in webkit source code,and find that the implemation only supports the xembed style to setwindow for plugin, but the current Qt Embeded linux4.4.3 can’t support xembed protocol.

my questions are:
1.can you give some ideas about the plugin implemation of QtWebKit supportting not only xembed but also shared window like firefox.

2.can qt embeded linux support xembed protocol in future?

3.do you know what time Qt4.5 release will publish?

Thanks!

» Posted by ariya
 on Monday, January 12, 2009 @ 16:15
Ariya Hidayat

@sukzhong: Please refrain from hijacking this blog post with unrelated topic. As I wrote in a private email, use webkit-dev list for this kind of questions.

» Posted by test
 on Tuesday, January 13, 2009 @ 14:29

test



© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.