Qt 4.8
Public Functions | Private Types | Private Functions | Properties | Friends | List of all members
QWidgetItemV2 Class Reference

#include <qlayoutitem.h>

Inheritance diagram for QWidgetItemV2:
QWidgetItem QLayoutItem

Public Functions

int heightForWidth (int width) const
 Reimplemented Function More...
 
QSize maximumSize () const
 Reimplemented Function More...
 
QSize minimumSize () const
 Reimplemented Function More...
 
 QWidgetItemV2 (QWidget *widget)
 
QSize sizeHint () const
 Reimplemented Function More...
 
 ~QWidgetItemV2 ()
 
- Public Functions inherited from QWidgetItem
Qt::Orientations expandingDirections () const
 Reimplemented Function More...
 
QRect geometry () const
 Reimplemented Function More...
 
bool hasHeightForWidth () const
 Reimplemented Function More...
 
bool isEmpty () const
 Returns true if the widget is hidden; otherwise returns false. More...
 
 QWidgetItem (QWidget *w)
 Creates an item containing the given widget. More...
 
void setGeometry (const QRect &)
 Reimplemented Function More...
 
virtual QWidgetwidget ()
 Returns the widget managed by this item. More...
 
- Public Functions inherited from QLayoutItem
Qt::Alignment alignment () const
 Returns the alignment of this item. More...
 
QSizePolicy::ControlTypes controlTypes () const
 Returns the control type(s) for the layout item. More...
 
virtual void invalidate ()
 Invalidates any cached information in this layout item. More...
 
virtual QLayoutlayout ()
 If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned. More...
 
virtual int minimumHeightForWidth (int) const
 Returns the minimum height this widget needs for the given width, w. More...
 
 QLayoutItem (Qt::Alignment alignment=0)
 Constructs a layout item with an alignment. More...
 
void setAlignment (Qt::Alignment a)
 Sets the alignment of this item to alignment. More...
 
virtual QSpacerItemspacerItem ()
 If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise 0 is returned. More...
 
virtual ~QLayoutItem ()
 Destroys the QLayoutItem. More...
 

Private Types

enum  { Dirty = -123, HfwCacheMaxSize = 3 }
 

Private Functions

void invalidateSizeCache ()
 
void updateCacheIfNecessary () const
 
bool useSizeCache () const
 

Properties

void * d
 
QSize q_cachedHfws [HfwCacheMaxSize]
 
QSize q_cachedMaximumSize
 
QSize q_cachedMinimumSize
 
QSize q_cachedSizeHint
 
short q_firstCachedHfw
 
short q_hfwCacheSize
 

Friends

class QWidgetPrivate
 

Additional Inherited Members

- Protected Variables inherited from QWidgetItem
QWidgetwid
 
- Protected Variables inherited from QLayoutItem
Qt::Alignment align
 

Detailed Description

Warning
This function is not part of the public interface.

Definition at line 144 of file qlayoutitem.h.

Enumerations

◆ anonymous enum

anonymous enum
private
Enumerator
Dirty 
HfwCacheMaxSize 

Definition at line 156 of file qlayoutitem.h.

Constructors and Destructors

◆ QWidgetItemV2()

QWidgetItemV2::QWidgetItemV2 ( QWidget widget)
explicit

Definition at line 771 of file qlayoutitem.cpp.

772  : QWidgetItem(widget),
776  q_firstCachedHfw(0),
777  q_hfwCacheSize(0),
778  d(0)
779 {
780  QWidgetPrivate *wd = wid->d_func();
781  if (!wd->widgetItem)
782  wd->widgetItem = this;
783 }
QWidgetItem(QWidget *w)
Creates an item containing the given widget.
Definition: qlayoutitem.h:127
short q_firstCachedHfw
Definition: qlayoutitem.h:169
QSize q_cachedMaximumSize
Definition: qlayoutitem.h:167
QWidgetItemV2 * widgetItem
Definition: qwidget_p.h:707
QWidget * wid
Definition: qlayoutitem.h:141
short q_hfwCacheSize
Definition: qlayoutitem.h:170
QSize q_cachedSizeHint
Definition: qlayoutitem.h:166
QSize q_cachedMinimumSize
Definition: qlayoutitem.h:165

◆ ~QWidgetItemV2()

QWidgetItemV2::~QWidgetItemV2 ( )

Definition at line 785 of file qlayoutitem.cpp.

786 {
787  if (wid) {
788  QWidgetPrivate *wd = wid->d_func();
789  if (wd->widgetItem == this)
790  wd->widgetItem = 0;
791  }
792 }
QWidgetItemV2 * widgetItem
Definition: qwidget_p.h:707
QWidget * wid
Definition: qlayoutitem.h:141

Functions

◆ heightForWidth()

int QWidgetItemV2::heightForWidth ( int  w) const
virtual

Reimplemented Function

Reimplemented from QWidgetItem.

Definition at line 848 of file qlayoutitem.cpp.

849 {
850  if (isEmpty())
851  return -1;
852 
853  for (int i = 0; i < q_hfwCacheSize; ++i) {
854  int offset = q_firstCachedHfw + i;
855  const QSize &size = q_cachedHfws[offset % HfwCacheMaxSize];
856  if (size.width() == width) {
857  if (q_hfwCacheSize == HfwCacheMaxSize)
858  q_firstCachedHfw = offset;
859  return size.height();
860  }
861  }
862 
863  if (q_hfwCacheSize < HfwCacheMaxSize)
864  ++q_hfwCacheSize;
866 
867  int height = QWidgetItem::heightForWidth(width);
868  q_cachedHfws[q_firstCachedHfw] = QSize(width, height);
869  return height;
870 }
short q_firstCachedHfw
Definition: qlayoutitem.h:169
int heightForWidth(int) const
Reimplemented Function
int width() const
Returns the width.
Definition: qsize.h:126
bool isEmpty() const
Returns true if the widget is hidden; otherwise returns false.
int height() const
Returns the height.
Definition: qsize.h:129
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
short q_hfwCacheSize
Definition: qlayoutitem.h:170
QSize q_cachedHfws[HfwCacheMaxSize]
Definition: qlayoutitem.h:168

◆ invalidateSizeCache()

void QWidgetItemV2::invalidateSizeCache ( )
inlineprivate

Definition at line 160 of file qlayoutitem.h.

160  {
162  q_hfwCacheSize = 0;
163  }
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
short q_hfwCacheSize
Definition: qlayoutitem.h:170
QSize q_cachedMinimumSize
Definition: qlayoutitem.h:165

◆ maximumSize()

QSize QWidgetItemV2::maximumSize ( ) const
virtual

Reimplemented Function

Reimplemented from QWidgetItem.

Definition at line 820 of file qlayoutitem.cpp.

821 {
822  if (isEmpty())
823  return QSize(0, 0);
824 
825  if (useSizeCache()) {
827  return q_cachedMaximumSize;
828  } else {
829  return QWidgetItem::maximumSize();
830  }
831 }
QSize maximumSize() const
Reimplemented Function
bool useSizeCache() const
QSize q_cachedMaximumSize
Definition: qlayoutitem.h:167
bool isEmpty() const
Returns true if the widget is hidden; otherwise returns false.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateCacheIfNecessary() const

◆ minimumSize()

QSize QWidgetItemV2::minimumSize ( ) const
virtual

Reimplemented Function

Reimplemented from QWidgetItem.

Definition at line 807 of file qlayoutitem.cpp.

808 {
809  if (isEmpty())
810  return QSize(0, 0);
811 
812  if (useSizeCache()) {
814  return q_cachedMinimumSize;
815  } else {
816  return QWidgetItem::minimumSize();
817  }
818 }
bool useSizeCache() const
bool isEmpty() const
Returns true if the widget is hidden; otherwise returns false.
QSize minimumSize() const
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateCacheIfNecessary() const
QSize q_cachedMinimumSize
Definition: qlayoutitem.h:165

◆ sizeHint()

QSize QWidgetItemV2::sizeHint ( ) const
virtual

Reimplemented Function

Reimplemented from QWidgetItem.

Definition at line 794 of file qlayoutitem.cpp.

795 {
796  if (isEmpty())
797  return QSize(0, 0);
798 
799  if (useSizeCache()) {
801  return q_cachedSizeHint;
802  } else {
803  return QWidgetItem::sizeHint();
804  }
805 }
QSize sizeHint() const
Reimplemented Function
bool useSizeCache() const
bool isEmpty() const
Returns true if the widget is hidden; otherwise returns false.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize q_cachedSizeHint
Definition: qlayoutitem.h:166
void updateCacheIfNecessary() const

◆ updateCacheIfNecessary()

void QWidgetItemV2::updateCacheIfNecessary ( ) const
private

Definition at line 733 of file qlayoutitem.cpp.

Referenced by maximumSize(), minimumSize(), and sizeHint().

734 {
736  return;
737 
738  const QSize sizeHint(wid->sizeHint());
739  const QSize minimumSizeHint(wid->minimumSizeHint());
740  const QSize minimumSize(wid->minimumSize());
741  const QSize maximumSize(wid->maximumSize());
742  const QSizePolicy sizePolicy(wid->sizePolicy());
743  const QSize expandedSizeHint(sizeHint.expandedTo(minimumSizeHint));
744 
745  const QSize smartMinSize(qSmartMinSize(sizeHint, minimumSizeHint, minimumSize, maximumSize, sizePolicy));
746  const QSize smartMaxSize(qSmartMaxSize(expandedSizeHint, minimumSize, maximumSize, sizePolicy, align));
747 
748  const bool useLayoutItemRect = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect);
749 
750  q_cachedMinimumSize = useLayoutItemRect
751  ? toLayoutItemSize(wid->d_func(), smartMinSize)
752  : smartMinSize;
753 
754  q_cachedSizeHint = expandedSizeHint;
755  q_cachedSizeHint = q_cachedSizeHint.boundedTo(maximumSize)
757  q_cachedSizeHint = useLayoutItemRect
759  : q_cachedSizeHint;
760 
762  q_cachedSizeHint.setWidth(0);
764  q_cachedSizeHint.setHeight(0);
765 
766  q_cachedMaximumSize = useLayoutItemRect
767  ? toLayoutItemSize(wid->d_func(), smartMaxSize)
768  : smartMaxSize;
769 }
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
QSize minimumSize
the widget&#39;s minimum size
Definition: qwidget.h:172
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
Q_GUI_EXPORT QSize qSmartMaxSize(const QSize &sizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy, Qt::Alignment align)
Policy horizontalPolicy() const
Definition: qsizepolicy.h:118
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
QSize sizeHint() const
Reimplemented Function
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
int width() const
Returns the width.
Definition: qsize.h:126
QSize q_cachedMaximumSize
Definition: qlayoutitem.h:167
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static QSize toLayoutItemSize(QWidgetPrivate *priv, const QSize &size)
Definition: qlayoutitem.cpp:72
QSize minimumSizeHint
the recommended minimum size for the widget
Definition: qwidget.h:196
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition: qwidget.h:171
Policy verticalPolicy() const
Definition: qsizepolicy.h:119
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
QWidget * wid
Definition: qlayoutitem.h:141
Qt::Alignment align
Definition: qlayoutitem.h:90
QSize q_cachedSizeHint
Definition: qlayoutitem.h:166
QSize maximumSize() const
Reimplemented Function
QSize minimumSize() const
Reimplemented Function
QSize q_cachedMinimumSize
Definition: qlayoutitem.h:165

◆ useSizeCache()

bool QWidgetItemV2::useSizeCache ( ) const
inlineprivate

Definition at line 728 of file qlayoutitem.cpp.

Referenced by maximumSize(), minimumSize(), and sizeHint().

729 {
730  return wid->d_func()->widgetItem == this;
731 }
QWidget * wid
Definition: qlayoutitem.h:141

Friends and Related Functions

◆ QWidgetPrivate

friend class QWidgetPrivate
friend

Definition at line 173 of file qlayoutitem.h.

Properties

◆ d

void* QWidgetItemV2::d
private

Definition at line 171 of file qlayoutitem.h.

◆ q_cachedHfws

QSize QWidgetItemV2::q_cachedHfws[HfwCacheMaxSize]
mutableprivate

Definition at line 168 of file qlayoutitem.h.

Referenced by heightForWidth().

◆ q_cachedMaximumSize

QSize QWidgetItemV2::q_cachedMaximumSize
mutableprivate

Definition at line 167 of file qlayoutitem.h.

Referenced by maximumSize().

◆ q_cachedMinimumSize

QSize QWidgetItemV2::q_cachedMinimumSize
mutableprivate

Definition at line 165 of file qlayoutitem.h.

Referenced by minimumSize().

◆ q_cachedSizeHint

QSize QWidgetItemV2::q_cachedSizeHint
mutableprivate

Definition at line 166 of file qlayoutitem.h.

Referenced by sizeHint().

◆ q_firstCachedHfw

short QWidgetItemV2::q_firstCachedHfw
mutableprivate

Definition at line 169 of file qlayoutitem.h.

Referenced by heightForWidth().

◆ q_hfwCacheSize

short QWidgetItemV2::q_hfwCacheSize
mutableprivate

Definition at line 170 of file qlayoutitem.h.

Referenced by heightForWidth().


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