sebasgo

a blog about my KDE adventures

New QML Model Types in kqtquickcharts

| Comments

The plugin now provides three new QML types: ChartModel and Record. The first type implements QAbstractTableModel, so it can directly hooked up with a chart as its source model. The other allows to easily describe the model’s data in QML making it trivial to draft a simple QML chart demonstration:

demo/minimal/main.qmllink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import QtQuick 1.1
import org.kde.charts 0.1

Rectangle {
    color: "white"
    width: 800
    height: 400

    ChartModel {
        id: chartModel
        columns: 2

        Record {
            values: [0.1, 0.2]
        }
        Record {
            values: [0.25, 0.3]
        }
        Record {
            values: [0.5, 0.5]
        }
        Record {
            values: [1.0, 0.75]
        }
    }

    Column {
        anchors.fill: parent
        anchors.margins: 20
        spacing: 20

        LineChart {
            model: chartModel
            width: parent.width
            height: parent.height - legend.height - parent.spacing
            pitch: 180
            dimensions: [
                Dimension {
                    id: funDimension
                    color: "#ffd500"
                    dataColumn: 0
                    minimumValue: 0.0
                    maximumValue: 1.0
                    label: "Fun"
                    precision: 0
                    unit: " %"
                    unitFactor: 100.0
                },
                Dimension {
                    id: profitDimension
                    color: "#ff0000"
                    dataColumn: 1
                    minimumValue: 0.0
                    maximumValue: 1.0
                    label: "Profit"
                    precision: 0
                    unit: " %"
                    unitFactor: 100.0
                }
            ]
        }

        Row {
            id: legend
            spacing: 30
            anchors.horizontalCenter: parent.horizontalCenter

            LegendItem {
                dimension: funDimension
            }
            LegendItem {
                dimension: profitDimension
            }
        }
    }
}

The file can be directly run with qmlviewer, in fact I have used it to generate the screenshot in the original announcement for this project.1 There are no C++ components required anymore to leverage the charts plugin.2

The way the demo employs ChartModel obviously doesn’t reflect how most applications want to use the charts plugin. Static data isn’t encountered what often after all. For this case ChartModel offers a set of methods to dynamically manage its data. I am currently developing a second, more complex demo illustrating their use.

Update Mar 12th, 2014: The seperate Valuetype is gone by now. I have updated both text and the code sample reflecting changes.

  1. By that time, the model implementation was still in a very early stage and since the demo depends on it, I hadn’t published it yet.

  2. Supplying a C++ model is still an option, though.

Announcing kqtquickcharts

| Comments

kqtquickcharts is a Qt Quick 1 plugin for beautiful and interactive charts. It offers QML elements for line and bar charts to present numeric data from a model implementing the interface of QAbstractTableModel.

The plugin will see its first release as a part of KDE Edu with KDE SC 4.13 on April 16, 2014. Future efforts will be aimed at making the plugin viable for pure QML applications and to port it to Qt Quick 2.

This project is the result of an effort to make the charts originally developed for KTouch available to a greater audience. The first new application to make use of the components will be artikulate, an upcoming KDE Edu application to improve one’s pronunciation skills.

What is new for KTouch in KDE SC 4.12

| Comments

It has been quite a while since my last post. My time available for KDE development has dried up since then considerably, limiting the scope of my work to basic maintenance and user support. Time for actual programming, let alone writing about it, was rather scarce.

Luckily this state has largely come to an end. And on top of that I was invited to attend this year’s KDE Edu sprint in A Coruña. The sprint was, as usual, highly productive and motivating. Many thanks go to the KDE e.V. and GPUL for sponsoring the event, to KDE España for covering my traveling expenses and especially to José Millán Soto for organizing the event.

During the sprint, many discussions were held and plans were made, and there was, of course, a decent amount of time to for some serious hacking. For the most part I worked on KTouch, and the time was well spend. I was able complete my main goal for the next version of KTouch, 2.2 to be released with KDE SC 4.12.

So let’s see what 4.12 will bring for KTouch.

Custom Lesson Support

The probably most missed feature from old version 1.x days returns to KTouch, only in much improved and extended fashion: an easy way to train on arbitrary text.

Technically spoken, this was possible since 2.0, because users could create their own courses and train on them. But the process is still cumbersome and too complex for the task at hand.1 In the old days one could just open a text file and get going. A feature like that is clearly missing.

This solved for the next version by introducing a new special course, the Custom Lessons course, always available right next to the normal built-in courses.

This new special course mostly acts like any other, training and statistics gathering works as usual. Clicking on New Custom Lesson brings up a stripped-down version of the normal lesson editor.

This has the nice side effect that the usual quality checks are also performed for custom lessons. The characters of the lesson text are matched against the current keyboard layout, so the user has a realistic chance to spot special or foreign characters he can’t type before hitting them during training.2

During my work on the custom lesson editor I took also some time to improve the actual lesson text editing experience. Now the editor has a toolbar allowing to load text files and to reformat lesson texts with long lines so they use the recommended line length.

The custom lessons are stored per user profile and keyboard layout, so one can train on different lessons depending on the specific situation.

One nice side effect of the re-introduction of this feature that KTouch is now finally at least basically usable under every keyboard layout, even for those it offers no courses for.

New Courses

Thanks to the to a some generous contributions KTouch will ship a few new courses:

  • A new Farsi course including the corresponding keyboard layout data. Contributed by Seyed Ali Akbar Najafian.
  • For the Spanish keyboad layout a new couse in Basque. Contributed by Alexander Gabilondo.
  • And a course for the rather exotic Workman layout. Contributed by Peter Feigl.

Many thanks go to the respective authors!

  1. To do so, one has (1) discover the editor, (2) create a new course, (3) set the keyboard layout for this course to his own and, (4) finally fill it with one or more lessons. Step (3) will scare off any not-so-tech-savvy user, since it requires technical knowledge and failing to do so will render the course inaccessible in the trainer. Also courses are constructed around the assumption that lessons build up on each other. This doesn’t hold true for a collection of random training texts.

  2. This feature depends on the presence of keyboard layout data also used by the keyboard visualization. If missing the checks won’t be performed and all characters will be valid.

February Update for KTouch

| Comments

I have expected the February to become a month full of bug fixing because of the the KTouch’s release at the beginning of the month, but I haven’t received a single valid bug report to date.1 Well, except a few which will be addressed by the the feature I have been busy working on instead.

Lesson Rendering Evolved

For KTouch 2.0 I have employed a rather simple approach to paint the current training line: for each character of the current line KTouch instantiates a dedicated QML Text item. This way it was easy to apply the styling for the individual states any character can have: placeholder text, typed text, contains a tying error and finally being part of the pre-edit text of some input methods. It also allowed my to implement the training screen very fast and works well for for Western languages with their simple Latin alphabet.

But this technique shows its deficiencies when used for more complex scripts like Arabic or Thai. Because of the use of individual Text items for each character it’s impossible to draw typographic ligatures. Both of the aforementioned languages rely heavily on them: Arabic joins most letters of a word together, Thai often stacks consecutive letters on top of each other. And for the former it doesn’t help either that KTouch currently can’t do right-to-left training.

With these issues it is clear KTouch needs new lesson rendering engine.

As of now the new engine is already nearly completed and fixes all the problems outlined above, only a few minor features compared to the old engine and some general code cleanup are still missing. When these are done I will push the changes to the KTouch’s central Git repository.

The new engine is now written in C++ as a new custom declarative type. Actually the old and the new approach doesn’t differ that much technically: both my custom type and the stock QML Text element leverage a QTextDocument to do the actual text rendering, the difference is only that my component gives me the control over it which I need. And that I now use only one single declarative item for the whole lesson text instead of one per character of the active line and one for each other line.

As one can see it is now possible to properly train on Arabic lessons, even though the alignment of the training text is still incorrect.2

One nice side effect of doing all the painting in C++ is that it gives me exact control over the font rendering. KTouch uses scaled font rendering to fit the lesson text into the viewport. In this case it’s important to disable hinting at least horizontally, because the rendering hints are calculated before scaling and this results in incorrect letter-spacing. I consider bad letter-spacing to be a major nuisance, so I was happy being finally able address this issue in the new C++ component.

The first line shows the old, fully hinted font rendering, the second the new font rendering where only vertical hinting is applied. As one can easily observe the letters in the second line are much more evenly spaced out.

  1. This either means there are really no issues (rather unlikely) or the existing issues don’t get reported. So if you experience problems with KTouch please don’t hesitate to report them.

  2. Although the training part of the application has now no problems with right-to-left rendering, the rest of the application has still issues with it. But those are small and easy fix compared to the trainer and will be taken care of soon.

January Update for KTouch

| Comments

This also includes the work done on KTouch in December. With the expected Christmas-related development hiatus I didn’t feel overly compelled to write a dedicated update.

And it is also the very last update before the upcoming KDE SC 4.10 release. The final tag freeze was already yesterday, so this report pretty much reflects the state KTouch will be released in.

Bugfixes

Since November another dozen of different mostly smallish issues have been fixed, among them the very last crash bug I am aware of. It took me forever to get to the bottom of the issue, even if the solution was always right in front of me. In the end it turned out KTouch’s resource editor was another victim of kdelibs Bug 303228, a bug report I have stumbled over very early on during my investigations. Too bad if one can’t match two backtraces.

Another significant fix is that KTouch is now able to render properly under a Plasma theme with light text on dark backgrounds (Bug 312082). No more impossible-to-read labels because of lack of contrast.

Data

Thanks to Ludo Beckers KTouch has gained support for the Belgian keyboard layout. As of now we don’t have matching course for this layout yet, so unfortunately it is difficult for the user to directly profit from it.

I think the overall data situation may improve, though, once the first release of KTouch 2.0 is out. I hope the new training experience combined with the completely overhauled authoring tools are enough of an impetus for new contributors to get some movement in that area.