[PULL REQUEST] table print implementation

Lubomir I. Ivanov neolit123 at gmail.com
Thu Jul 11 04:28:43 PDT 2013


On 11 July 2013 13:56, Dirk Hohndel <dirk at hohndel.org> wrote:
> On Thu, 2013-07-11 at 13:17 +0300, Lubomir I. Ivanov wrote:
>> this is a somehow working table print..it currently uses a print preview dialog
>> so that we don't have to export to a file or an actual device while testing.
>
> Nice :-)
>
>> the approach of doing the table print is by using the QTextDocument class
>> with HTML/CSS with table/tr/th tags. it allows some freedom of what can be done
>> in the table, but not as much as if you draw it manually with cairo/pango
>> or with QPainter and this HTML/CSS implementation REALLY is as subset.
>>
>> but as you have already guessed it is much easier to maintain, which
>> perhaps can be seen in printlayout.cpp...
>
> I think I like this approach. If we do this right it should make it
> quite easy to support custom templates that users can create and share.
> I know that almost every country has their own preferred logbook format,
> and often even more than one. So having the ability for users who just
> know a bit of html/css to be able to contribute layouts would be a real
> strength for Subsurface...
>

i was thinking about designing a template based structure, where
programmatically the table columns can be preset.
this could be based on a custom format specified in the preferences
with a parseable string, for example:

nr,15|divemaster,30|location,50|gps,15
would only create a table with these dive properties in columns with
certain width (name, %).

the real problem that i've encountered is the limitation of the Qt
HTML/CSS subset..
a good example would be that the table border and color can only be
controlled via the <table> tag style and not from the inner <th>, <tr>
tags. and there are a lot of missing, common CSS properties which
means that users trying to create a style template will have to be
aware of the Qt specific limitations in this case otherwise their
style sheets will be broken.

the preferred columns to be printed is something that can be done at
this stage, but if we plan to allow table style mods (like colors) we
really need to 'sandbox' the user outside of the actual Qt CSS, with a
list print dialog options/controls i'd think.

>> it detects a new page by a rather expensive (i think) operation, but it seems
>> to work OK, so far.
>
> For 230 or so dives it easily took 13 seconds before the preview came
> up. That seems rather long :-)
>

i found reports on the web that QTextDocument is slow in general.
after each row added, the current algorithm requires passing a new
string to the QTextDocument object (with setHtml()) and then calling
pageCount() to determine if a new page has occurred. this is the only
way i found out how to do it so far, so that table headers are
inserted on that new page.
if someone has tips for a better solution i would be happy to apply it.

>> to test go to File->Print (all 'print types' modes do a table print for now),
>> 'print selected' should work, press 'print'..
>>
>> comments are welcome.
>
> Thanks for the code. This is one of the major missing pieces and I'm
> glad to see progress. It would be really nice to design it early on with
> the idea of reading templates and using those to do the layout...
>

i will start thinking on this part, perhaps after a short discussion /
plan on the direction. if someone is interested, please look at the
above comments.

>> p.s. i think i saw a couple of divelist bugs, in the lines of dives were
>> reported as dive->selected, but weren't selected in the divelist.
>> will try to replicate again later.
>
> That would be great. I've seen and fixed some in the past but I'm sure
> there are many more lurking everywhere.
>

i think i also found some visual glitches in the divelist on ubuntu
and will report in trac soon.

lubomir
--


More information about the subsurface mailing list