Tables GSoC Status

Hi all,

I hope everyone had a nice time on Gran Canaria. It seems like it’s been a really successful event from all the posts I’ve read.

I’m not one of the frequent GSoC bloggers here on p.k.o, but as we are in mid-term now I thought I’d make a little summary of my thoughts around the project so far and give a little status report.

Initially my idea was to divide this post into two sections; “The Good” and “The Bad”, with a summary at the end. But then I realized that for almost every bad thing I could think of, I could find a good side to it, and vice versa. There’s always two sides to a coin. So instead I’ve decided to make a table. How appropriate ;)

(The table is styled and probably looks better at my blog page)
GSoC experiences so far
+
Table layout is hard. There are just so many things to consider, and a lot of side cases to take care of. Just look at Qt Scribe’s implementation. Lord knows I have :) But extremely fun and a very rewarding thing to work on. The feedback is quite immediate, which is very gratifying.
Unit testing is an art. You have to be very careful what you test for and how you go about it. Just writing the tests is not enough, you have to put a lot of thought into it. But it’s an invaluable tool when starting out and trying to focus on a specific aspect of a complex thing such as table layout. By the way, anyone who can recommend a short little book on unit testing? Preferably something as concise and “hands-on” as e.g. Meyers’ Effective C++.
I have probably over-estimated my abilities as a programmer. I tend to try to consider all the consequences of the changes I do at once and look into the future, instead of focusing on the actual problem at hand, and this tend to be a real show stopper for productivity. As my good mentor Thomas put it; perfection is the enemy of productivity. But I’ve learnt a lot about my abilities and limitations, and I feel that I’m improving. I’m confident that by the end of this summer, I will have grown as a programmer.
Git can be confusing. Coming from centralized VCSs like SVN and CVS, wrapping your head around this new-fangled distributed VCS can be quite daunting, especially as the user interface is a veritable swiss army knife of funky names and idioms. A text that really helped me understand how Git works was The Git Parable. And for the more technically inclined I’ve heard good things about Git for Computer Scientists But it is a God-send after all, and I can’t wait until all of KOffice (and KDE) is on Git. Things like cherrypicking, interactive rebasing and extremely easy branching/merging is just too good to say no to. I’d like to make a parallel to when I first learned Vim. No pain no gain right? ;) Recent posts here on the planet, if I understand them correctly, indicates that there are talks about hosting KDE Git repos at Gitorious, which sounds like a good idea to me.
The payment schedule of Summer of Code is kind of unfortunate. At least if you have high fixed expenses every month, as you’ll have to go all through June without any money. This is something to think about if you’re considering participating. I was lucky to be able to loan money for my rent/Internet/electricity/phone bill. But this is definitely understandable. Having monthly payments would mean having monthly evaluations and a lot more work for both mentors and Google staff members. I guess a lot of students in the program live with their parents and don’t have a lot of expenses. But I’m (almost) an old fart as far as students go ;) Just bringing this up, as it can become an extra stress factor.

All in all, I’m having a great GSoC so far, and I think it can only get better.

Progress

Now on to some information about my progress. What I’ve been working on is getting some first basic table layout working. The design is quite simple so far, and looks very roughly something like this:

Table Layout Design Overview
Table Layout Design Overview

The Layout class is the innermost class of the text layout engine in KOffice, and is the one responsible for most of the nitty gritty details of text layout. It is declared as an inner class of KoTextDocumentLayout, which has an instance of this class called m_state.

KoTextDocumentLayout in turn is a higher level class that derives from Qt’s abstract document layout class QAbstractTextDocumentLayout. Qt’s own document layout engine, QTextDocumentLayout, which is not shown in the diagram above, derives from this same ABC. I’ve also included KWTextDocumentLayout, which is a specialized KoTextDocumentLayout used in KWord. It adds support for letting text flow around other shapes, among other things.

What this all means is that KOffice’s layout engine, while still working with an underlying QTextDocument, is completely separate from Qt’s. Now, because of poor research on my part in the weeks leading up to the GSoC start, I actually thought I’d be able to leverage at least some of the built-in support for table layout in Qt. But I have only myself to blame for that, and it’s nothing to cry over now. What I do get is QTextTable, which can be considered a blueprint for a table, and my task is to lay out this table according to its properties, which I’ll later have to extend to support ODF features that don’t have a 1:1 equivalent in QTextTable and its associate classes.

I’ve modified Layout to have an instance of the new class TableLayout, which is responsible for doing layout and drawing of tables. It takes a QTextTable and lays it out, storing the layout information, such as table and cell geometries in an associated TableData instance. It actually caches TableData instances per-table internally. TableLayout offers an API to be used from Layout to obtain cell content rectangles to direct the layout engine into, as well as an API for adjusting cell heights based on the cell contents.

It’s a simple design, but one that I think will work out fine for all the requirements that will come later, and I already have ideas on how e.g. cell spanning should be implemented. Things on my TODO are too many to even enumerate, but what I’m working on right this minute is row heights calculations and finding a good way to let the layout process in Layout notify the TableLayout of cell content height changes. After that comes, among other things:

  • Margins/paddings/borders.
  • Variable column widths.
  • Tests, tests and more tests.

Now let’s see, this post has had a table, a diagram and a list. What’s missing? A video of course :) Take 50 seconds and marvel at me pasting a basic table from Firefox into KWord and editing the cell contents:

Direct link (5.7 MB Ogg/Theora).

Actually I’m cheating in the above video, as the table height is hard coded, but don’t tell anyone! ;)

Finally, I’d like to be honest and admit that progress really haven’t been as fast as I thought it would be, but I do feel that I’m on the right track. And even though the road ahead is longer than what I would have wanted, at least it seems pretty straight, all things considered.

Now if you’ll excuse me, I really need to get back to coding!

Bye ’til next time!

3 thoughts on “Tables GSoC Status

Leave a Reply

Your email address will not be published. Required fields are marked *