[Issue N108897] Dangerous, subtle change to QRect::normalize()

Clarence Dang dang at kde.org
Fri Mar 31 11:51:36 BST 2006


[CC'ing kde-core-devel as anyone porting code to Qt4 might want to know]

On Friday 31 March 2006 00:06, qt-bugs at trolltech.com wrote:
> On Thursday, 30. Mar 2006 18:34 Clarence Dang wrote:
> > [Maybe a duplicate of
> > http://www.trolltech.com/developer/tasktracker.html?method=entry&id=80908
> > but it's still not fixed and also "Q_ASSERT(!normRect.isValid());"
> > should not have the "!" to have been a valid bug report]

So N80908 is unrelated?

> > Qt 4.1.1 qt-copy/src/corelib/tools/qrect.cpp:
> >
> > ~~~~
> > QRect QRect::normalized() const
> > {
> >     if (isNull() || width() == 0 || height() == 0)
> >         return *this;
> > ~~~~
> >
> > This check was not in Qt3.  It is also wrong - consider:
> >
> > ~~~~
> > QPoint thisPoint (195, 60);
> > QPoint lastPoint (194, 62);
> > QRect r = QRect (thisPoint, lastPoint);
> > QRect r2 = r.normalize ()
> > ~~~~
> >
> > "r" is emtpy and I want to fix it using normalize() to get "r2". This
> > is something reasonable to attempt and even the docs suggest it:
> >
> > ~~~~
> >   bool QRect::isEmpty () const
> >
> >    Returns true if the rectangle is empty, otherwise returns false.
> >
> >    An empty rectangle has a left() > right() or top() > bottom(). An
> >    empty
> > rectangle is not valid (i.e isEmpty() ==
> >    !isValid()).
> >
> >    Use the normalized() function to retrieve a rectangle where the
> >    corners are
> > swapped.
> > ~~~~
> >
> > But normalize() does nothing because of the check.
>
> We are aware of some special cases with QRect not working the way that
> they should be but unfortunately these cannot be changed for a
> maintanence release.  However, we are looking into accomodating these
> cases for the Qt 4.2 and documenting the ones that cannot be resolved
> directly.

The example above is not a contrived one:

http://websvn.kde.org/trunk/KDE/kdegraphics/kolourpaint/tools/kptoolpen.cpp:
    QRect rect = QRect (thisPoint, lastPoint).normalize ()

This innocent looking line will work for all values of "thisPoint" and 
"lastPoint", _except_ for 4 special cases by my count:

++
+*
+

Where "*" is the topLeft point and "+" are the troublesome bottomRight points.

This is very unexpected!




More information about the kde-core-devel mailing list