PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 606 - add function to convert QPoint/QPointF/QSize/... to (and from) tuple
: add function to convert QPoint/QPointF/QSize/... to (and from) tuple
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: PySide
: HEAD
: All All
: P3 enhancement
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2011-01-11 14:54 EET by Farsmo
Modified: 2011-05-26 17:04 EEST (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Farsmo 2011-01-11 14:54:50 EET
A message by Thomas Perl reminded me that it would be very useful to have a
function that converts a QPoint p to the tuple (p.x(), p.y()). It doesn't sound
like much, but if p is not a variable but a complex expression you either have
to define your own helper function or duplicate the code for p.

For converting from tuple, we already have QSize(*tuple), but I think there are
no harmful consequences to defining a QSize(sequence) constructor that would
allow QSize(max(42,x) for x in mysize), which is much more elegant than
QSize(*(max(42,x) for x in mysize)).

Converting to a tuple is more delicate because it could be implemented in
several ways:
- make QPoint iterable. This would allow for some very nifty things like p2 =
QPoint(complicated_function(x) for x in p1), but it might be argued that it
could make things harder to debug because incorrect code will fail later.
- implement a new function, such as p.xy() or p.coords()
- does Python provide a way to implement tuple(x) without x being iterable?
Comment 1 Matti Airas 2011-01-12 06:33:43 EET
Thanks for the bug report.

Could you please define an exact set of classes for which you would like this
modification to be done. Since the report is a bit vague, I'm leaving it
UNCONFIRMED for now.
Comment 2 Farsmo 2011-01-13 14:59:25 EET
I think it would only be necessary for the following types:
- QPoint/QPointF/QSize/QSizeF/QVector2D/QVector3D/QVector4D, as well as
QLine/QLineF when considered as a sequence of 2 QPoint(F)
  Conversion from tuple: QFoo(sequence)
  Conversion to tuple:   make QFoo a sequence type
- QColor
  Conversion from tuple: QColor.fromRgbF(sequence)/fromHsl..., with sequence
having 3 or 4 items
  Conversion to tuple:   .getRgbF() already exists to obtain an RGBA tuple, but
it might be useful to define .getRgbF(False) to drop the alpha channel (in the
C++ version the alpha parameter is optional because it usually is not needed,
or is processed in a different way)


Also, this was not what I had in mind when reporting the bug but these types
might be able to use conversion to tuple, even though the values of the tuple
would not be homogeneous:
- QDate/QTime/QDateTime
  Conversion from tuple: not necessary
  Conversion to tuple:   .ymd(), .hms(), .hmsm(), .ymdhms(), .ymdhmsm()
- maybe QUrl too?
  Conversion from tuple: QUrl(tuple)
  Conversion to tuple:   something like .toTuple() or .components()
Comment 3 Matti Airas 2011-03-31 11:38:46 EEST
This was deprioritized to P4 because the bug was regarded as post-1.0 material.
Now that 1.0 has been published for one month already, I'd like to see this
bumped to P3.

Also, I'd like to verify that the bug scope should be about the following:

QPoint/QPointF/QSize/QSizeF/QVector2D/QVector3D/QVector4D
QLine/QLineF
QColor

The rest of the classes Farsmo mentioned (QDate/QTime/QDateTime/QUrl) should
preferably be handled in separate bug reports because they're getting pretty
much separated from the original report.
Comment 4 Hugo Parente Lima 2011-03-31 15:43:09 EEST
This not really a bug, it's a feature request, but P4 bugs sometimes sounds
like forgotten bugs that will never be done... bumping to P3.
Comment 5 renato filho 2011-05-13 22:54:41 EEST
fixed on pyside commit:

commit a8b02e046bdf09886972712d201be553d32cedaf
Author: Paulo Alcantara <paulo.alcantara@openbossa.org>
Date:   Tue May 10 15:36:03 2011 -0300
Comment 6 renato filho 2011-05-26 17:04:00 EEST
PySide release 1.0.3