[Development] Extending Qt::AlignmentFlag

Knoll Lars Lars.Knoll at digia.com
Mon Aug 5 10:48:45 CEST 2013


On 02.08.13 15:23, "Saether Jan-Arve" <Jan-Arve.Saether at digia.com> wrote:

>I have recently been trying to add support for baseline alignment in Qt
>Quick Layouts.
>
>I therefore want to add another enum value to the Qt::AlignmentFlag enum
>in qnamespace.h
>
>However, as the comment above the AlignmentFlag enum says, it should be
>possible to combine the flags in Qt::AlignmentFlag with the flags in
>Qt::TextFlag. This is done in for instance QPainter::drawText()[1].
>Therefore, none of the flags overlap with each other.
>
>The natural choice would be to just extend the Qt::AlignmentFlag with
>AlignBaseline = 0x0100, but this could cause ambiguities with
>Qt::TextSingleLine = 0x0100
>
>As I really want to add AlignBaseline to Qt::AlignmentFlag, I see two
>alternatives:
>1. Add AlignBaseline = 0x80000000
>This will not cause any ambiguity, but would need some commenting in
>order to avoid that Qt::TextFlag will claim its value at some point in
>the future. We could even add a ReservedByAlignBaseline = 0x80000000 to
>Qt::TextFlag to reduce the risk further.
>
>2. Add AlignBaseline = 0x0100
>This should in fact also not cause any ambiguity thanks to some
>restrictions in the API's that combines these two sets of flags. For
>instance, QPainter::drawText() [1] explicitly lists all valid values.
>Therefore it would be wrong to pass Qt::AlignBaseline to it, and when
>Qt::TextSingleLine is passed it shouldn't cause any ambiguity.
>
>Which alternative would be the preferred? Is there any obstacles I
>haven't foreseen with alternative 2?
>
>Here's the patch, which currently uses alternative 2 (which I'm currently
>leaning towards).
>https://codereview.qt-project.org/61632

I'm ok with alternative 2, but make sure it's properly documented in the
relevant places in the code.

Cheers,
Lars

>
>
>[1] http://qt-project.org/doc/qt-5.1/qtgui/qpainter.html#drawText-4
>
>_______________________________________________
>Development mailing list
>Development at qt-project.org
>http://lists.qt-project.org/mailman/listinfo/development




More information about the Development mailing list