Qt 4.8
Public Types | Public Functions | Static Public Functions | Public Variables | List of all members
QGraphicsLayoutItemPrivate Class Reference

#include <qgraphicslayoutitem_p.h>

Inheritance diagram for QGraphicsLayoutItemPrivate:
QGraphicsLayoutPrivate QGraphicsAnchorLayoutPrivate QGraphicsGridLayoutPrivate QGraphicsLinearLayoutPrivate

Public Types

enum  SizeComponent { Width, Height }
 

Public Functions

QSizeFeffectiveSizeHints (const QSizeF &constraint) const
 
void ensureUserSizeHints ()
 Ensures that userSizeHints is allocated. More...
 
bool hasHeightForWidth () const
 
bool hasWidthForHeight () const
 
void init ()
 
QGraphicsItemparentItem () const
 Returns the parent item of this layout, or 0 if this layout is not installed on any widget. More...
 
 QGraphicsLayoutItemPrivate (QGraphicsLayoutItem *parent, bool isLayout)
 
void setSize (Qt::SizeHint which, const QSizeF &size)
 Sets the user size hint which to size. More...
 
void setSizeComponent (Qt::SizeHint which, SizeComponent component, qreal value)
 Sets the width of the user size hint which to width. More...
 
virtual ~QGraphicsLayoutItemPrivate ()
 

Static Public Functions

static QGraphicsLayoutItemPrivateget (QGraphicsLayoutItem *q)
 
static const QGraphicsLayoutItemPrivateget (const QGraphicsLayoutItem *q)
 

Public Variables

QSizeF cachedConstraint
 
QSizeF cachedSizeHints [Qt::NSizeHints]
 
QSizeF cachedSizeHintsWithConstraints [Qt::NSizeHints]
 
QRectF geom
 
QGraphicsItemgraphicsItem
 
quint32 isLayout: 1
 
quint32 ownedByLayout: 1
 
QGraphicsLayoutItemparent
 
QGraphicsLayoutItemq_ptr
 
quint32 sizeHintCacheDirty: 1
 
quint32 sizeHintWithConstraintCacheDirty: 1
 
QSizePolicy sizePolicy
 
QSizeFuserSizeHints
 

Detailed Description

Definition at line 62 of file qgraphicslayoutitem_p.h.

Enumerations

◆ SizeComponent

Constructors and Destructors

◆ ~QGraphicsLayoutItemPrivate()

QGraphicsLayoutItemPrivate::~QGraphicsLayoutItemPrivate ( )
virtual
Warning
This function is not part of the public interface.

Definition at line 119 of file qgraphicslayoutitem.cpp.

120 {
121  // Remove any lazily allocated data
122  delete[] userSizeHints;
123 }

◆ QGraphicsLayoutItemPrivate()

QGraphicsLayoutItemPrivate::QGraphicsLayoutItemPrivate ( QGraphicsLayoutItem par,
bool  layout 
)
Warning
This function is not part of the public interface.

Definition at line 111 of file qgraphicslayoutitem.cpp.

Functions

◆ effectiveSizeHints()

QSizeF * QGraphicsLayoutItemPrivate::effectiveSizeHints ( const QSizeF constraint) const
Warning
This function is not part of the public interface.

effectiveSizeHint has a quirky behavior, one of the quirkinesses is when the hfw function is combined with user-specified min/max sizes. The input to hfw function (e.g width) must be within the min/max width constraint, and the output must be within the min/max height. This sets up a loose dependency between minimum width and maximum height (or minimum height, depending on the type of hfw function). Note that its only the concrete subclass that implements that hfw function that knows if this dependency means that the height will increase or decrease when the width is increased.

The application should try to ensure that the user-defined sizes are within the range so that they don't conflict with the hfw function.

Suppose, for instance that the hfw function is:

height = 2000/width

and the item has these user-defined sizes:

min  ( 5,  5)
pref(100, 10)
max (500,100)

what is the return value if one calls item->effectiveSizeHint(Qt::MinimumSize, QSizeF(10, -1)); ? The sizeHint() function would return QSizeF(10, 200), but it would be bounded down to 100 due to the max value, so it would return (10, 100). This is not what the item expects, since it really wants that its hfw is respected. If this is a label with wrapped text, this would most likely lead to that some text is clipped. This is certainly not what the app developer wants. Now, it would be better if the user changed those constraints to match the hfw function:

min ( 20,  5)
pref(100, 10)
max (500,100)

here, it says that the width cannot be smaller than 20. This is because if it becomes smaller than 20 the result of the hfw function would violate the max height (100).

However, there is a similar problem if the width passed to the hfw function reaches max width:

the sizeHint() function would now return QSizeF(500, 4), but 4 is smaller than the minimum height (5), so effectiveSizeHint() would return (500, 5), which would leave too much space. In this case, setting the max width to 400 fixes the problem:

min ( 20,  5)
pref(100, 10)
max (400,100)

The implementor of a hfw widget must be aware of this when sizeHint() is reimplemented, so that the default min and max sizes works sensible. (unfortunately the implementor does not have the control over user-set values).

Definition at line 188 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayoutItem::effectiveSizeHint().

189 {
190  Q_Q(const QGraphicsLayoutItem);
191  QSizeF *sizeHintCache;
192  const bool hasConstraint = constraint.width() >= 0 || constraint.height() >= 0;
193  QSizeF adjustedConstraint = constraint;
194  if (hasConstraint) {
197 
198  const QSizeF *hintsWithoutConstraint = effectiveSizeHints(QSizeF(-1,-1));
199 
200  if (adjustedConstraint.width() >= 0)
201  adjustedConstraint.setWidth( qBound( hintsWithoutConstraint[Qt::MinimumSize].width(),
202  adjustedConstraint.width(),
203  hintsWithoutConstraint[Qt::MaximumSize].width()));
204  if (adjustedConstraint.height() >= 0)
205  adjustedConstraint.setHeight( qBound( hintsWithoutConstraint[Qt::MinimumSize].height(),
206  adjustedConstraint.height(),
207  hintsWithoutConstraint[Qt::MaximumSize].height()));
208 
209  if (!sizeHintWithConstraintCacheDirty && adjustedConstraint == cachedConstraint)
211  sizeHintCache = cachedSizeHintsWithConstraints;
212  } else {
213  if (!sizeHintCacheDirty)
214  return cachedSizeHints;
215  sizeHintCache = cachedSizeHints;
216  }
217 
218  for (int i = 0; i < Qt::NSizeHints; ++i) {
219  sizeHintCache[i] = adjustedConstraint;
220  if (userSizeHints)
221  combineSize(sizeHintCache[i], userSizeHints[i]);
222  }
223 
224  QSizeF &minS = sizeHintCache[Qt::MinimumSize];
225  QSizeF &prefS = sizeHintCache[Qt::PreferredSize];
226  QSizeF &maxS = sizeHintCache[Qt::MaximumSize];
227  QSizeF &descentS = sizeHintCache[Qt::MinimumDescent];
228 
229  normalizeHints(minS.rwidth(), prefS.rwidth(), maxS.rwidth(), descentS.rwidth());
230  normalizeHints(minS.rheight(), prefS.rheight(), maxS.rheight(), descentS.rheight());
231 
232  // if the minimum, preferred and maximum sizes contradict each other
233  // (e.g. the minimum is larger than the maximum) we give priority to
234  // the maximum size, then the minimum size and finally the preferred size
235  COMBINE_SIZE(maxS, q->sizeHint(Qt::MaximumSize, maxS));
237  expandSize(maxS, prefS);
238  expandSize(maxS, minS);
240 
241  COMBINE_SIZE(minS, q->sizeHint(Qt::MinimumSize, minS));
242  expandSize(minS, QSizeF(0, 0));
243  boundSize(minS, prefS);
244  boundSize(minS, maxS);
245 
246  COMBINE_SIZE(prefS, q->sizeHint(Qt::PreferredSize, prefS));
247  expandSize(prefS, minS);
248  boundSize(prefS, maxS);
249 
250  // Not supported yet
251  // COMBINE_SIZE(descentS, q->sizeHint(Qt::MinimumDescent, constraint));
252 
253  if (hasConstraint) {
254  cachedConstraint = adjustedConstraint;
256  } else {
257  sizeHintCacheDirty = false;
258  }
259  return sizeHintCache;
260 }
QSizeF cachedSizeHints[Qt::NSizeHints]
#define COMBINE_SIZE(result, size)
QSizeF * effectiveSizeHints(const QSizeF &constraint) const
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
void setWidth(qreal w)
Sets the width to the given width.
Definition: qsize.h:290
static void normalizeHints(qreal &minimum, qreal &preferred, qreal &maximum, qreal &descent)
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
#define Q_Q(Class)
Definition: qglobal.h:2483
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
static void expandSize(QSizeF &result, const QSizeF &size)
static void boundSize(QSizeF &result, const QSizeF &size)
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
QSizeF cachedSizeHintsWithConstraints[Qt::NSizeHints]
static void combineSize(QSizeF &result, const QSizeF &size)
void setHeight(qreal h)
Sets the height to the given height.
Definition: qsize.h:293
qreal & rheight()
Returns a reference to the height.
Definition: qsize.h:302
qreal & rwidth()
Returns a reference to the width.
Definition: qsize.h:299

◆ ensureUserSizeHints()

void QGraphicsLayoutItemPrivate::ensureUserSizeHints ( )

Ensures that userSizeHints is allocated.

Warning
This function is not part of the public interface.

This function must be called before any dereferencing.

Definition at line 302 of file qgraphicslayoutitem.cpp.

Referenced by setSize(), and setSizeComponent().

303 {
304  if (!userSizeHints)
306 }
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202

◆ get() [1/2]

static QGraphicsLayoutItemPrivate* QGraphicsLayoutItemPrivate::get ( QGraphicsLayoutItem q)
inlinestatic

◆ get() [2/2]

static const QGraphicsLayoutItemPrivate* QGraphicsLayoutItemPrivate::get ( const QGraphicsLayoutItem q)
inlinestatic

Definition at line 69 of file qgraphicslayoutitem_p.h.

69 { return q->d_func();}

◆ hasHeightForWidth()

bool QGraphicsLayoutItemPrivate::hasHeightForWidth ( ) const

Definition at line 355 of file qgraphicslayoutitem.cpp.

Referenced by _q_boundGeometryToSizeConstraints(), QGridLayoutItem::hasDynamicConstraint(), and minimumHeightForWidth().

356 {
357  Q_Q(const QGraphicsLayoutItem);
358  if (isLayout) {
359  const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
360  for (int i = l->count() - 1; i >= 0; --i) {
362  return true;
363  }
364  } else if (QGraphicsItem *item = q->graphicsItem()) {
365  if (item->isWidget()) {
366  QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
367  if (w->layout()) {
369  }
370  }
371  }
372  return q->sizePolicy().hasHeightForWidth();
373 }
static QGraphicsLayoutItemPrivate * get(QGraphicsLayoutItem *q)
QGraphicsLayout * layout
The layout of the widget.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_Q(Class)
Definition: qglobal.h:2483
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
virtual int count() const =0
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return the numbe...
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
QFactoryLoader * l
virtual QGraphicsLayoutItem * itemAt(int i) const =0
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return a pointer...
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ hasWidthForHeight()

bool QGraphicsLayoutItemPrivate::hasWidthForHeight ( ) const

Definition at line 375 of file qgraphicslayoutitem.cpp.

Referenced by _q_boundGeometryToSizeConstraints(), and QGridLayoutItem::hasDynamicConstraint().

376 {
377  Q_Q(const QGraphicsLayoutItem);
378  if (isLayout) {
379  const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
380  for (int i = l->count() - 1; i >= 0; --i) {
382  return true;
383  }
384  } else if (QGraphicsItem *item = q->graphicsItem()) {
385  if (item->isWidget()) {
386  QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
387  if (w->layout()) {
389  }
390  }
391  }
392  return q->sizePolicy().hasWidthForHeight();
393 }
static QGraphicsLayoutItemPrivate * get(QGraphicsLayoutItem *q)
QGraphicsLayout * layout
The layout of the widget.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_Q(Class)
Definition: qglobal.h:2483
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
virtual int count() const =0
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return the numbe...
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
QFactoryLoader * l
virtual QGraphicsLayoutItem * itemAt(int i) const =0
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return a pointer...
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ init()

void QGraphicsLayoutItemPrivate::init ( )
Warning
This function is not part of the public interface.

Definition at line 128 of file qgraphicslayoutitem.cpp.

◆ parentItem()

QGraphicsItem * QGraphicsLayoutItemPrivate::parentItem ( ) const

Returns the parent item of this layout, or 0 if this layout is not installed on any widget.

Warning
This function is not part of the public interface.

If this is the item that the layout is installed on, it will return "itself".

If the layout is a sub-layout, this function returns the parent widget of the parent layout.

Note that it will traverse up the layout item hierarchy instead of just calling QGraphicsItem::parentItem(). This is on purpose.

See also
parent()

Definition at line 282 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayoutPrivate::addChildLayoutItem(), QGraphicsLayoutPrivate::getMargin(), QGraphicsGridLayoutPrivate::styleInfo(), QGraphicsLinearLayoutPrivate::styleInfo(), QGraphicsAnchorLayoutPrivate::styleInfo(), and QGraphicsLayoutPrivate::visualDirection().

283 {
284  Q_Q(const QGraphicsLayoutItem);
285 
286  const QGraphicsLayoutItem *parent = q;
287  while (parent && parent->isLayout()) {
288  parent = parent->parentLayoutItem();
289  }
290  return parent ? parent->graphicsItem() : 0;
291 }
QGraphicsItem * graphicsItem() const
Returns the QGraphicsItem that this layout item represents.
#define Q_Q(Class)
Definition: qglobal.h:2483
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
bool isLayout() const
Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges o...
QGraphicsLayoutItem * parentLayoutItem() const
Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not...
QGraphicsLayoutItem * parent

◆ setSize()

void QGraphicsLayoutItemPrivate::setSize ( Qt::SizeHint  which,
const QSizeF size 
)

Sets the user size hint which to size.

Warning
This function is not part of the public interface.

Use an invalid size to unset the size hint.

Definition at line 316 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayoutItem::setMaximumSize(), QGraphicsLayoutItem::setMinimumSize(), and QGraphicsLayoutItem::setPreferredSize().

317 {
319 
320  if (userSizeHints) {
321  if (size == userSizeHints[which])
322  return;
323  } else if (size.width() < 0 && size.height() < 0) {
324  return;
325  }
326 
328  userSizeHints[which] = size;
329  q->updateGeometry();
330 }
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
#define Q_Q(Class)
Definition: qglobal.h:2483
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
void ensureUserSizeHints()
Ensures that userSizeHints is allocated.

◆ setSizeComponent()

void QGraphicsLayoutItemPrivate::setSizeComponent ( Qt::SizeHint  which,
SizeComponent  component,
qreal  value 
)

Sets the width of the user size hint which to width.

Warning
This function is not part of the public interface.

Definition at line 340 of file qgraphicslayoutitem.cpp.

Referenced by QGraphicsLayoutItem::setMaximumHeight(), QGraphicsLayoutItem::setMaximumWidth(), QGraphicsLayoutItem::setMinimumHeight(), QGraphicsLayoutItem::setMinimumWidth(), QGraphicsLayoutItem::setPreferredHeight(), and QGraphicsLayoutItem::setPreferredWidth().

342 {
345  qreal &userValue = (component == Width)
346  ? userSizeHints[which].rwidth()
347  : userSizeHints[which].rheight();
348  if (value == userValue)
349  return;
350  userValue = value;
351  q->updateGeometry();
352 }
double qreal
Definition: qglobal.h:1193
#define Q_Q(Class)
Definition: qglobal.h:2483
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
static qreal component(const QPointF &point, unsigned int i)
void ensureUserSizeHints()
Ensures that userSizeHints is allocated.
qreal & rheight()
Returns a reference to the height.
Definition: qsize.h:302

Properties

◆ cachedConstraint

QSizeF QGraphicsLayoutItemPrivate::cachedConstraint
mutable

Definition at line 87 of file qgraphicslayoutitem_p.h.

Referenced by effectiveSizeHints().

◆ cachedSizeHints

QSizeF QGraphicsLayoutItemPrivate::cachedSizeHints[Qt::NSizeHints]
mutable

Definition at line 86 of file qgraphicslayoutitem_p.h.

Referenced by effectiveSizeHints().

◆ cachedSizeHintsWithConstraints

QSizeF QGraphicsLayoutItemPrivate::cachedSizeHintsWithConstraints[Qt::NSizeHints]
mutable

Definition at line 88 of file qgraphicslayoutitem_p.h.

Referenced by effectiveSizeHints().

◆ geom

QRectF QGraphicsLayoutItemPrivate::geom

Definition at line 96 of file qgraphicslayoutitem_p.h.

Referenced by QGraphicsWidget::setGeometry().

◆ graphicsItem

QGraphicsItem* QGraphicsLayoutItemPrivate::graphicsItem

Definition at line 97 of file qgraphicslayoutitem_p.h.

◆ isLayout

quint32 QGraphicsLayoutItemPrivate::isLayout

Definition at line 92 of file qgraphicslayoutitem_p.h.

Referenced by hasHeightForWidth(), and hasWidthForHeight().

◆ ownedByLayout

quint32 QGraphicsLayoutItemPrivate::ownedByLayout

Definition at line 93 of file qgraphicslayoutitem_p.h.

◆ parent

QGraphicsLayoutItem* QGraphicsLayoutItemPrivate::parent

◆ q_ptr

QGraphicsLayoutItem* QGraphicsLayoutItemPrivate::q_ptr

Definition at line 95 of file qgraphicslayoutitem_p.h.

◆ sizeHintCacheDirty

quint32 QGraphicsLayoutItemPrivate::sizeHintCacheDirty
mutable

Definition at line 90 of file qgraphicslayoutitem_p.h.

Referenced by effectiveSizeHints(), and init().

◆ sizeHintWithConstraintCacheDirty

quint32 QGraphicsLayoutItemPrivate::sizeHintWithConstraintCacheDirty
mutable

Definition at line 91 of file qgraphicslayoutitem_p.h.

Referenced by effectiveSizeHints(), and init().

◆ sizePolicy

QSizePolicy QGraphicsLayoutItemPrivate::sizePolicy

Definition at line 82 of file qgraphicslayoutitem_p.h.

◆ userSizeHints

QSizeF* QGraphicsLayoutItemPrivate::userSizeHints

The documentation for this class was generated from the following files: