Qt 4.8
Public Types | Public Functions | Public Variables | List of all members
QFormLayoutPrivate Class Reference
Inheritance diagram for QFormLayoutPrivate:
QLayoutPrivate QObjectPrivate QObjectData

Public Types

typedef FixedColumnMatrix< QFormLayoutItem *, ColumnCountItemMatrix
 
- Public Types inherited from QLayoutPrivate
typedef QSpacerItem *(* QSpacerItemFactoryMethod) (const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy)
 
typedef QWidgetItem *(* QWidgetItemFactoryMethod) (const QLayout *layout, QWidget *widget)
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Public Functions

void arrangeWidgets (const QVector< QLayoutStruct > &layouts, QRect &rect)
 
void calcSizeHints ()
 
QStylegetStyle () const
 
bool haveHfwCached (int width) const
 
int insertRow (int row)
 
void insertRows (int row, int count)
 
 QFormLayoutPrivate ()
 
void recalcHFW (int w)
 
void setItem (int row, QFormLayout::ItemRole role, QLayoutItem *item)
 
void setLayout (int row, QFormLayout::ItemRole role, QLayout *layout)
 
void setupHfwLayoutData ()
 
void setupHorizontalLayoutData (int width)
 
void setupVerticalLayoutData (int width)
 
void setWidget (int row, QFormLayout::ItemRole role, QWidget *widget)
 
void updateSizes ()
 
 ~QFormLayoutPrivate ()
 
- Public Functions inherited from QLayoutPrivate
void doResize (const QSize &)
 
void getMargin (int *result, int userMargin, QStyle::PixelMetric pm) const
 
 QLayoutPrivate ()
 
void reparentChildWidgets (QWidget *mw)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

uint dirty: 2
 
uint expandHorizontal: 1
 
uint expandVertical: 1
 
uint fieldGrowthPolicy: 8
 
Qt::Alignment formAlignment
 
int formMaxWidth
 
uint has_hfw: 2
 
int hfw_height
 
int hfw_minheight
 
int hfw_sh_height
 
int hfw_sh_minheight
 
int hfw_width
 
QVector< QLayoutStructhfwLayouts
 
int hSpacing
 
Qt::Alignment labelAlignment
 
int layoutWidth
 
ItemMatrix m_matrix
 
QList< QFormLayoutItem * > m_things
 
int maxLabelWidth
 
int min_width
 
QSize minSize
 
QSize prefSize
 
uint rowWrapPolicy: 8
 
int sh_width
 
uint sizesDirty: 2
 
int thresh_width
 
int vLayoutCount
 
QVector< QLayoutStructvLayouts
 
int vSpacing
 
- Public Variables inherited from QLayoutPrivate
uint activated: 1
 
uint autoNewChild: 1
 
QLayout::SizeConstraint constraint
 
uint enabled: 1
 
int insideSpacing
 
QWidgetmenubar
 
QRect rect
 
uint topLevel: 1
 
int userBottomMargin
 
int userLeftMargin
 
int userRightMargin
 
int userTopMargin
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Static Public Functions inherited from QLayoutPrivate
static QSpacerItemcreateSpacerItem (const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy=QSizePolicy::Minimum, QSizePolicy::Policy vPolicy=QSizePolicy::Minimum)
 
static QWidgetItemcreateWidgetItem (const QLayout *layout, QWidget *widget)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 
- Static Public Variables inherited from QLayoutPrivate
static QSpacerItemFactoryMethod spacerItemFactoryMethod = 0
 
static QWidgetItemFactoryMethod widgetItemFactoryMethod = 0
 

Detailed Description

Definition at line 178 of file qformlayout.cpp.

Typedefs

◆ ItemMatrix

Definition at line 183 of file qformlayout.cpp.

Constructors and Destructors

◆ QFormLayoutPrivate()

QFormLayoutPrivate::QFormLayoutPrivate ( )

Definition at line 251 of file qformlayout.cpp.

255  layoutWidth(-1), hfw_width(-1), hfw_sh_height(-1), min_width(-1),
257 {
258 }
const uint DefaultFieldGrowthPolicy
const uint DefaultRowWrapPolicy
Qt::Alignment formAlignment
Qt::Alignment labelAlignment
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56

◆ ~QFormLayoutPrivate()

QFormLayoutPrivate::~QFormLayoutPrivate ( )
inline

Definition at line 186 of file qformlayout.cpp.

186 { }

Functions

◆ arrangeWidgets()

void QFormLayoutPrivate::arrangeWidgets ( const QVector< QLayoutStruct > &  layouts,
QRect rect 
)

Definition at line 1961 of file qformlayout.cpp.

1962 {
1963  Q_Q(QFormLayout);
1964 
1965  int i;
1966  const int rr = m_matrix.rowCount();
1967  QWidget *w = q->parentWidget();
1968  Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : QApplication::layoutDirection();
1969 
1970  Qt::Alignment formAlignment = fixedAlignment(q->formAlignment(), layoutDirection);
1971  int leftOffset = 0;
1972  int delta = rect.width() - formMaxWidth;
1973  if (formAlignment & (Qt::AlignHCenter | Qt::AlignRight) && delta > 0) {
1974  leftOffset = delta;
1975  if (formAlignment & Qt::AlignHCenter)
1976  leftOffset >>= 1;
1977  }
1978 
1979  for (i = 0; i < rr; ++i) {
1980  QFormLayoutItem *label = m_matrix(i, 0);
1981  QFormLayoutItem *field = m_matrix(i, 1);
1982 
1983  if (label) {
1984  int height = layouts.at(label->vLayoutIndex).size;
1985  if ((label->expandingDirections() & Qt::Vertical) == 0) {
1986  /*
1987  If the field on the right-hand side is tall,
1988  we want the label to be top-aligned, but not too
1989  much. So we introduce a 7 / 4 factor so that it
1990  gets some extra pixels at the top.
1991  */
1992  height = qMin(height,
1993  qMin(label->sizeHint.height() * 7 / 4,
1994  label->maxSize.height()));
1995  }
1996 
1997  QSize sz(qMin(label->layoutWidth, label->sizeHint.width()), height);
1998  int x = leftOffset + rect.x() + label->layoutPos;
1999  if (fixedAlignment(q->labelAlignment(), layoutDirection) & Qt::AlignRight)
2000  x += label->layoutWidth - sz.width();
2001  QPoint p(x, layouts.at(label->vLayoutIndex).pos);
2002  // ### expansion & sizepolicy stuff
2003 
2004  label->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz)));
2005  }
2006 
2007  if (field) {
2008  QSize sz(field->layoutWidth, layouts.at(field->vLayoutIndex).size);
2009  QPoint p(field->layoutPos + leftOffset + rect.x(), layouts.at(field->vLayoutIndex).pos);
2010 /*
2011  if ((field->widget() && field->widget()->sizePolicy().horizontalPolicy() & (QSizePolicy::GrowFlag | QSizePolicy::ExpandFlag | QSizePolicy::IgnoreFlag))
2012  || (field->layout() && sz.width() < field->maxSize.width())) {
2013  sz.rwidth() = field->layoutWidth;
2014  }
2015 */
2016  if (field->maxSize.isValid())
2017  sz = sz.boundedTo(field->maxSize);
2018 
2019  field->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz)));
2020  }
2021  }
2022 }
static Qt::LayoutDirection layoutDirection()
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Qt::Alignment formAlignment
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
#define Q_Q(Class)
Definition: qglobal.h:2483
int width() const
Returns the width.
Definition: qsize.h:126
LayoutDirection
Definition: qnamespace.h:1580
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Qt::LayoutDirection layoutDirection
the layout direction for this widget
Definition: qwidget.h:216
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
static Qt::Alignment fixedAlignment(Qt::Alignment alignment, Qt::LayoutDirection layoutDirection)
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
Qt::Orientations expandingDirections() const
void setGeometry(const QRect &r)

◆ calcSizeHints()

void QFormLayoutPrivate::calcSizeHints ( )

Definition at line 903 of file qformlayout.cpp.

Referenced by QFormLayout::minimumSize(), and QFormLayout::sizeHint().

904 {
905  Q_Q(QFormLayout);
906 
907  int leftMargin, topMargin, rightMargin, bottomMargin;
908  q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
909 
910  updateSizes();
912  // Don't need to call setupHorizontal here
913 
914  int h = topMargin + bottomMargin;
915  int mh = topMargin + bottomMargin;
916 
917  // The following are set in updateSizes
918  int w = sh_width + leftMargin + rightMargin;
919  int mw = min_width + leftMargin + rightMargin;
920 
921  for (int i = 0; i < vLayoutCount; ++i) {
922  int spacing = vLayouts.at(i).spacing;
923  h += vLayouts.at(i).sizeHint + spacing;
924  mh += vLayouts.at(i).minimumSize + spacing;
925  }
926 
931 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void setupVerticalLayoutData(int width)
#define Q_Q(Class)
Definition: qglobal.h:2483
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
QVector< QLayoutStruct > vLayouts
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141

◆ getStyle()

QStyle * QFormLayoutPrivate::getStyle ( ) const

Definition at line 993 of file qformlayout.cpp.

994 {
995  Q_Q(const QFormLayout);
996 
997  // ### cache
998  if (QWidget *parentWidget = q->parentWidget())
999  return parentWidget->style();
1000  else
1001  return QApplication::style();
1002 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QStyle * style()
Returns the application&#39;s style object.
QStyle * style() const
Definition: qwidget.cpp:2742
#define Q_Q(Class)
Definition: qglobal.h:2483
static QWidget * parentWidget(const QWidget *w)
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55

◆ haveHfwCached()

bool QFormLayoutPrivate::haveHfwCached ( int  width) const
inline

Definition at line 203 of file qformlayout.cpp.

204  {
205  return (hfw_width == width) || (width == sh_width && hfw_sh_height >= 0);
206  }

◆ insertRow()

int QFormLayoutPrivate::insertRow ( int  row)

Definition at line 933 of file qformlayout.cpp.

934 {
935  int rowCnt = m_matrix.rowCount();
936  if (uint(row) > uint(rowCnt))
937  row = rowCnt;
938 
939  insertRows(row, 1);
940  return row;
941 }
void insertRows(int row, int count)
unsigned int uint
Definition: qglobal.h:996

◆ insertRows()

void QFormLayoutPrivate::insertRows ( int  row,
int  count 
)

Definition at line 943 of file qformlayout.cpp.

Referenced by insertRow().

944 {
945  while (count > 0) {
946  m_matrix.insertRow(row, 0);
947  --count;
948  }
949 }

◆ recalcHFW()

void QFormLayoutPrivate::recalcHFW ( int  w)

Definition at line 484 of file qformlayout.cpp.

Referenced by QFormLayout::heightForWidth().

485 {
487 
488  int h = 0;
489  int mh = 0;
490 
491  for (int r = 0; r < vLayoutCount; ++r) {
492  int spacing = hfwLayouts.at(r).spacing;
493  h += hfwLayouts.at(r).sizeHint + spacing;
494  mh += hfwLayouts.at(r).minimumSize + spacing;
495  }
496 
497  if (sh_width > 0 && sh_width == w) {
500  } else {
501  hfw_width = w;
504  }
505 }
QVector< QLayoutStruct > hfwLayouts
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56

◆ setItem()

void QFormLayoutPrivate::setItem ( int  row,
QFormLayout::ItemRole  role,
QLayoutItem item 
)

Definition at line 951 of file qformlayout.cpp.

Referenced by setLayout(), and setWidget().

952 {
953  const bool fullRow = role == QFormLayout::SpanningRole;
954  const int column = role == QFormLayout::SpanningRole ? 1 : static_cast<int>(role);
955  if (uint(row) >= uint(m_matrix.rowCount()) || uint(column) > 1U) {
956  qWarning("QFormLayoutPrivate::setItem: Invalid cell (%d, %d)", row, column);
957  return;
958  }
959 
960  if (!item)
961  return;
962 
963  if (m_matrix(row, column)) {
964  qWarning("QFormLayoutPrivate::setItem: Cell (%d, %d) already occupied", row, column);
965  return;
966  }
967 
968  QFormLayoutItem *i = new QFormLayoutItem(item);
969  i->fullRow = fullRow;
970  m_matrix(row, column) = i;
971 
972  m_things.append(i);
973 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QFormLayoutItem * > m_things
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996

◆ setLayout()

void QFormLayoutPrivate::setLayout ( int  row,
QFormLayout::ItemRole  role,
QLayout layout 
)

Definition at line 975 of file qformlayout.cpp.

976 {
977  if (layout) {
978  Q_Q(QFormLayout);
979  if (q->adoptLayout(layout))
980  setItem(row, role, layout);
981  }
982 }
#define Q_Q(Class)
Definition: qglobal.h:2483
void setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item)
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55

◆ setupHfwLayoutData()

void QFormLayoutPrivate::setupHfwLayoutData ( )

Definition at line 507 of file qformlayout.cpp.

Referenced by recalcHFW().

508 {
509  // setupVerticalLayoutData must be called before this
510  // setupHorizontalLayoutData must also be called before this
511  // copies non hfw data into hfw
512  // then updates size and min
513 
514 
515  // Note: QGridLayout doesn't call minimumHeightForWidth,
516  // but instead uses heightForWidth for both min and sizeHint.
517  // For the common case where minimumHeightForWidth just calls
518  // heightForWidth, we do the calculation twice, which can be
519  // very expensive for word wrapped QLabels/QTextEdits, for example.
520  // So we just use heightForWidth as well.
521  int i;
522  int rr = m_matrix.rowCount();
523 
524  hfwLayouts.clear();
526  for (i = 0; i < vLayoutCount; ++i)
527  hfwLayouts[i] = vLayouts.at(i);
528 
529  for (i = 0; i < rr; ++i) {
530  QFormLayoutItem *label = m_matrix(i, 0);
531  QFormLayoutItem *field = m_matrix(i, 1);
532 
533  if (label) {
534  if (label->isHfw) {
535  // We don't check sideBySide here, since a label is only
536  // ever side by side with its field
537  int hfw = label->heightForWidth(label->layoutWidth);
538  hfwLayouts[label->vLayoutIndex].minimumSize = hfw;
539  hfwLayouts[label->vLayoutIndex].sizeHint = hfw;
540  } else {
541  // Reset these here, so the field can do a qMax below (the previous value may have
542  // been the fields non-hfw values, which are often larger than hfw)
543  hfwLayouts[label->vLayoutIndex].sizeHint = label->sizeHint.height();
544  hfwLayouts[label->vLayoutIndex].minimumSize = label->minSize.height();
545  }
546  }
547 
548  if (field) {
549  int hfw = field->isHfw ? field->heightForWidth(field->layoutWidth) : 0;
550  int h = field->isHfw ? hfw : field->sizeHint.height();
551  int mh = field->isHfw ? hfw : field->minSize.height();
552 
553  if (field->sideBySide) {
554  int oh = hfwLayouts.at(field->vLayoutIndex).sizeHint;
555  int omh = hfwLayouts.at(field->vLayoutIndex).minimumSize;
556 
557  hfwLayouts[field->vLayoutIndex].sizeHint = qMax(h, oh);
558  hfwLayouts[field->vLayoutIndex].minimumSize = qMax(mh, omh);
559  } else {
560  hfwLayouts[field->vLayoutIndex].sizeHint = h;
561  hfwLayouts[field->vLayoutIndex].minimumSize = mh;
562  }
563  }
564  }
565 }
QVector< QLayoutStruct > hfwLayouts
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int heightForWidth(int width) const
int height() const
Returns the height.
Definition: qsize.h:129
QVector< QLayoutStruct > vLayouts

◆ setupHorizontalLayoutData()

void QFormLayoutPrivate::setupHorizontalLayoutData ( int  width)

Definition at line 849 of file qformlayout.cpp.

Referenced by QFormLayout::heightForWidth().

850 {
851  Q_Q(QFormLayout);
852 
853  // requires setupVerticalLayoutData to be called first
854 
855  int fieldMaxWidth = 0;
856 
857  int rr = m_matrix.rowCount();
858  bool wrapAllRows = (q->rowWrapPolicy() == QFormLayout::WrapAllRows);
859 
860  for (int i = 0; i < rr; ++i) {
861  QFormLayoutItem *label = m_matrix(i, 0);
862  QFormLayoutItem *field = m_matrix(i, 1);
863 
864  // Totally ignore empty rows...
865  if (!label && !field)
866  continue;
867 
868  if (label) {
869  // if there is a field, and we're side by side, we use maxLabelWidth
870  // otherwise we just use the sizehint
871  label->layoutWidth = (field && label->sideBySide) ? maxLabelWidth : label->sizeHint.width();
872  label->layoutPos = 0;
873  }
874 
875  if (field) {
876  // This is the default amount allotted to fields in sbs
877  int fldwidth = width - maxLabelWidth - field->sbsHSpace;
878 
879  // If we've split a row, we still decide to align
880  // the field with all the other field if it will fit
881  // Fields in sbs mode get the remnants of the maxLabelWidth
882  if (!field->sideBySide) {
883  if (wrapAllRows || (!label && field->fullRow) || field->sizeHint.width() > fldwidth) {
884  field->layoutWidth = width;
885  field->layoutPos = 0;
886  } else {
887  field->layoutWidth = fldwidth;
888  field->layoutPos = width - fldwidth;
889  }
890  } else {
891  // We're sbs, so we should have a label
892  field->layoutWidth = fldwidth;
893  field->layoutPos = width - fldwidth;
894  }
895 
896  fieldMaxWidth = qMax(fieldMaxWidth, field->maxSize.width());
897  }
898  }
899 
900  formMaxWidth = maxLabelWidth + fieldMaxWidth;
901 }
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define Q_Q(Class)
Definition: qglobal.h:2483
int width() const
Returns the width.
Definition: qsize.h:126
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55

◆ setupVerticalLayoutData()

void QFormLayoutPrivate::setupVerticalLayoutData ( int  width)

Definition at line 655 of file qformlayout.cpp.

Referenced by calcSizeHints(), and QFormLayout::heightForWidth().

656 {
657  Q_Q(QFormLayout);
658 
659  // Early out if we have no changes that would cause a change in vertical layout
660  if ((width == layoutWidth || (width >= thresh_width && layoutWidth >= thresh_width)) && !dirty && !sizesDirty)
661  return;
662 
663  layoutWidth = width;
664 
665  int rr = m_matrix.rowCount();
666  int vidx = 1;
667  QFormLayout::RowWrapPolicy rowWrapPolicy = q->rowWrapPolicy();
668  bool wrapAllRows = (rowWrapPolicy == QFormLayout::WrapAllRows);
669  bool addTopBottomStretch = true;
670 
671  vLayouts.clear();
672  vLayouts.resize((2 * rr) + 2); // a max, some may be unused
673 
674  QStyle *style = 0;
675 
676  int userVSpacing = q->verticalSpacing();
677 
678  if (userVSpacing < 0) {
679  if (QWidget *widget = q->parentWidget())
680  style = widget->style();
681  }
682 
683  // make sure our sizes are up to date
684  updateSizes();
685 
686  // Grab the widest label width here
687  // This might be different from the value computed during
688  // sizeHint/minSize, since we don't count label/field pairs that
689  // are split.
690  maxLabelWidth = 0;
691  if (!wrapAllRows) {
692  for (int i = 0; i < rr; ++i) {
693  const QFormLayoutItem *label = m_matrix(i, 0);
694  const QFormLayoutItem *field = m_matrix(i, 1);
695  if (label && (label->sizeHint.width() + (field ? field->minSize.width() : 0) <= width))
697  }
698  } else {
699  maxLabelWidth = width;
700  }
701 
702  QFormLayoutItem *prevItem1 = 0;
703  QFormLayoutItem *prevItem2 = 0;
704  bool prevRowSplit = false;
705 
706  for (int i = 0; i < rr; ++i) {
707  QFormLayoutItem *label = m_matrix(i, 0);
708  QFormLayoutItem *field = m_matrix(i, 1);
709 
710  // Totally ignore empty rows...
711  if (!label && !field)
712  continue;
713 
714  QSize min1;
715  QSize min2;
716  QSize sh1;
717  QSize sh2;
718  if (label) {
719  min1 = label->minSize;
720  sh1 = label->sizeHint;
721  }
722  if (field) {
723  min2 = field->minSize;
724  sh2 = field->sizeHint;
725  }
726 
727  // In separate lines, we make a vLayout for everything that isn't null
728  // in side by side, we only separate label/field if we're going to wrap it
729  bool splitSideBySide = (rowWrapPolicy == QFormLayout::WrapLongRows)
730  && ((maxLabelWidth < sh1.width()) || (width < (maxLabelWidth + min2.width())));
731 
732  if (wrapAllRows || splitSideBySide) {
733  if (label) {
734  initLayoutStruct(vLayouts[vidx], label);
735 
736  if (vidx > 1)
737  vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, 0, prevItem1, prevItem2);
738 
739  label->vLayoutIndex = vidx;
740  label->sideBySide = false;
741 
742  prevItem1 = label;
743  prevItem2 = 0;
744 
745  if (vLayouts[vidx].stretch > 0)
746  addTopBottomStretch = false;
747 
748  ++vidx;
749  }
750 
751  if (field) {
752  initLayoutStruct(vLayouts[vidx], field);
753 
754  if (vidx > 1)
755  vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, 0, prevItem1, prevItem2);
756 
757  field->vLayoutIndex = vidx;
758  field->sideBySide = false;
759 
760  prevItem1 = field;
761  prevItem2 = 0;
762 
763  if (vLayouts[vidx].stretch > 0)
764  addTopBottomStretch = false;
765 
766  ++vidx;
767  }
768 
769  prevRowSplit = splitSideBySide;
770  } else {
771  // we're in side by side mode, and we have enough space to do that
774 
775  int stretch1 = 0;
776  int stretch2 = 0;
777  bool expanding = false;
778 
779  if (label) {
780  max1 = label->maxSize;
781  if (label->expandingDirections() & Qt::Vertical)
782  expanding = true;
783 
784  label->sideBySide = (field != 0);
785  label->vLayoutIndex = vidx;
786  stretch1 = label->vStretch();
787  }
788 
789  if (field) {
790  max2 = field->maxSize;
791  if (field->expandingDirections() & Qt::Vertical)
792  expanding = true;
793 
794  field->sideBySide = (label || !field->fullRow);
795  field->vLayoutIndex = vidx;
796  stretch2 = field->vStretch();
797  }
798 
799  vLayouts[vidx].init(qMax(stretch1, stretch2), qMax(min1.height(), min2.height()));
800  vLayouts[vidx].sizeHint = qMax(sh1.height(), sh2.height());
801  vLayouts[vidx].maximumSize = qMin(max1.height(), max2.height());
802  vLayouts[vidx].expansive = expanding || (vLayouts[vidx].stretch > 0);
803  vLayouts[vidx].empty = false;
804 
805  if (vLayouts[vidx].stretch > 0)
806  addTopBottomStretch = false;
807 
808  if (vidx > 1)
809  vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, prevRowSplit, label, field, prevItem1, prevItem2);
810 
811  if (label) {
812  prevItem1 = label;
813  prevItem2 = field;
814  } else {
815  prevItem1 = field;
816  prevItem2 = 0;
817  }
818 
819  prevRowSplit = false;
820  ++vidx;
821  }
822  }
823 
824  if (addTopBottomStretch) {
825  Qt::Alignment formAlignment = q->formAlignment();
826 
827  if (!(formAlignment & Qt::AlignBottom)) {
828  // AlignTop (default if unspecified) or AlignVCenter: We add a stretch at the bottom
829  vLayouts[vidx].init(1, 0);
830  vLayouts[vidx].expansive = true;
831  ++vidx;
832  }
833 
834  if (formAlignment & (Qt::AlignVCenter | Qt::AlignBottom)) {
835  // AlignVCenter or AlignBottom: We add a stretch at the top
836  vLayouts[0].init(1, 0);
837  vLayouts[0].expansive = true;
838  } else {
839  vLayouts[0].init(0, 0);
840  }
841  } else {
842  vLayouts[0].init(0, 0);
843  }
844 
845  vLayoutCount = vidx;
846  dirty = false;
847 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QPointer< QWidget > widget
Qt::Alignment formAlignment
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool empty() const
This function is provided for STL compatibility.
Definition: qvector.h:285
static void initLayoutStruct(QLayoutStruct &sl, QFormLayoutItem *item)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
QStyle * style() const
Definition: qwidget.cpp:2742
#define Q_Q(Class)
Definition: qglobal.h:2483
int width() const
Returns the width.
Definition: qsize.h:126
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
int vStretch() const
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
int height() const
Returns the height.
Definition: qsize.h:129
static int spacingHelper(QWidget *parent, QStyle *style, int userVSpacing, bool recalculate, QFormLayoutItem *item1, QFormLayoutItem *item2, QFormLayoutItem *prevItem1, QFormLayoutItem *prevItem2)
QVector< QLayoutStruct > vLayouts
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
Qt::Orientations expandingDirections() const
RowWrapPolicy
This enum specifies the different policies that can be used to control the way in which the form&#39;s ro...
Definition: qformlayout.h:74

◆ setWidget()

void QFormLayoutPrivate::setWidget ( int  row,
QFormLayout::ItemRole  role,
QWidget widget 
)

Definition at line 984 of file qformlayout.cpp.

985 {
986  if (widget) {
987  Q_Q(QFormLayout);
988  q->addChildWidget(widget);
989  setItem(row, role, QLayoutPrivate::createWidgetItem(q, widget));
990  }
991 }
#define Q_Q(Class)
Definition: qglobal.h:2483
static QWidgetItem * createWidgetItem(const QLayout *layout, QWidget *widget)
Definition: qlayout.cpp:190
void setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item)
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55

◆ updateSizes()

void QFormLayoutPrivate::updateSizes ( )

Definition at line 305 of file qformlayout.cpp.

Referenced by calcSizeHints(), QFormLayout::expandingDirections(), QFormLayout::hasHeightForWidth(), and setupVerticalLayoutData().

306 {
307  Q_Q(QFormLayout);
308 
309  if (sizesDirty) {
310  QFormLayout::RowWrapPolicy wrapPolicy = q->rowWrapPolicy();
311  bool wrapAllRows = (wrapPolicy == QFormLayout::WrapAllRows);
312  bool dontWrapRows = (wrapPolicy == QFormLayout::DontWrapRows);
313  int rr = m_matrix.rowCount();
314 
315  has_hfw = false;
316 
317  // If any control can expand, so can this layout
318  // Wrapping doesn't affect expansion, though, just the minsize
319  bool expandH = false;
320  bool expandV = false;
321 
322  QFormLayoutItem *prevLbl = 0;
323  QFormLayoutItem *prevFld = 0;
324 
325  QWidget *parent = q->parentWidget();
326  QStyle *style = parent ? parent->style() : 0;
327 
328  int userVSpacing = q->verticalSpacing();
329  int userHSpacing = wrapAllRows ? 0 : q->horizontalSpacing();
330 
331  int maxMinLblWidth = 0;
332  int maxMinFldWidth = 0; // field with label
333  int maxMinIfldWidth = 0; // independent field
334 
335  int maxShLblWidth = 0;
336  int maxShFldWidth = 0;
337  int maxShIfldWidth = 0;
338 
339  for (int i = 0; i < rr; ++i) {
340  QFormLayoutItem *label = m_matrix(i, 0);
341  QFormLayoutItem *field = m_matrix(i, 1);
342 
343  // Skip empty rows
344  if (!label && !field)
345  continue;
346 
347  if (label) {
348  updateFormLayoutItem(label, userVSpacing, q->fieldGrowthPolicy(), false);
349  if (label->isHfw)
350  has_hfw = true;
351  Qt::Orientations o = label->expandingDirections();
352 
353  if (o & Qt::Vertical)
354  expandV = true;
355  if (o & Qt::Horizontal)
356  expandH = true;
357  }
358  if (field) {
359  updateFormLayoutItem(field, userVSpacing, q->fieldGrowthPolicy(), !label && field->fullRow);
360  field->sbsHSpace = (!label && field->fullRow) ? 0 : userHSpacing;
361  if (field->isHfw)
362  has_hfw = true;
363 
364  Qt::Orientations o = field->expandingDirections();
365 
366  if (o & Qt::Vertical)
367  expandV = true;
368  if (o & Qt::Horizontal)
369  expandH = true;
370  }
371 
372  // See if we need to calculate default spacings
373  if ((userHSpacing < 0 || userVSpacing < 0) && style) {
374  QSizePolicy::ControlTypes lbltypes =
375  QSizePolicy::ControlTypes(label ? label->controlTypes() : QSizePolicy::DefaultType);
376  QSizePolicy::ControlTypes fldtypes =
377  QSizePolicy::ControlTypes(field ? field->controlTypes() : QSizePolicy::DefaultType);
378 
379  // VSpacing
380  if (userVSpacing < 0) {
381  if (wrapAllRows) {
382  // label spacing is to a previous item
383  QFormLayoutItem *lbltop = prevFld ? prevFld : prevLbl;
384  // field spacing is to the label (or a previous item)
385  QFormLayoutItem *fldtop = label ? label : lbltop;
386  QSizePolicy::ControlTypes lbltoptypes =
387  QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType);
388  QSizePolicy::ControlTypes fldtoptypes =
389  QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType);
390  if (label && lbltop)
391  label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
392  if (field && fldtop)
393  field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
394  } else {
395  // Side by side.. we have to also consider the spacings to empty cells, which can strangely be more than
396  // non empty cells..
397  QFormLayoutItem *lbltop = prevLbl ? prevLbl : prevFld;
398  QFormLayoutItem *fldtop = prevFld;
399  QSizePolicy::ControlTypes lbltoptypes =
400  QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType);
401  QSizePolicy::ControlTypes fldtoptypes =
402  QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType);
403 
404  // To be compatible to QGridLayout, we have to compare solitary labels & fields with both predecessors
405  if (label) {
406  if (!field) {
407  int lblspacing = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
408  int fldspacing = style->combinedLayoutSpacing(fldtoptypes, lbltypes, Qt::Vertical, 0, parent);
409  label->vSpace = qMax(lblspacing, fldspacing);
410  } else
411  label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent);
412  }
413 
414  if (field) {
415  // check spacing against both the previous label and field
416  if (!label) {
417  int lblspacing = style->combinedLayoutSpacing(lbltoptypes, fldtypes, Qt::Vertical, 0, parent);
418  int fldspacing = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
419  field->vSpace = qMax(lblspacing, fldspacing);
420  } else
421  field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent);
422  }
423  }
424  }
425 
426  // HSpacing
427  // hard-coded the left and right control types so that all the rows have the same
428  // inter-column spacing (otherwise the right column isn't always left aligned)
429  if (userHSpacing < 0 && !wrapAllRows && (label || !field->fullRow) && field)
431  }
432 
433  // Now update our min/sizehint widths
434  // We choose to put the spacing in the field side in sbs, so
435  // the right edge of the labels will align, but fields may
436  // be a little ragged.. since different controls may have
437  // different appearances, a slight raggedness in the left
438  // edges of fields can be tolerated.
439  // (Note - field->sbsHSpace is 0 for WrapAllRows mode)
440  if (label) {
441  maxMinLblWidth = qMax(maxMinLblWidth, label->minSize.width());
442  maxShLblWidth = qMax(maxShLblWidth, label->sizeHint.width());
443  if (field) {
444  maxMinFldWidth = qMax(maxMinFldWidth, field->minSize.width() + field->sbsHSpace);
445  maxShFldWidth = qMax(maxShFldWidth, field->sizeHint.width() + field->sbsHSpace);
446  }
447  } else if (field) {
448  maxMinIfldWidth = qMax(maxMinIfldWidth, field->minSize.width());
449  maxShIfldWidth = qMax(maxShIfldWidth, field->sizeHint.width());
450  }
451 
452  prevLbl = label;
453  prevFld = field;
454  }
455 
456  // Now, finally update the min/sizeHint widths
457  if (wrapAllRows) {
458  sh_width = qMax(maxShLblWidth, qMax(maxShIfldWidth, maxShFldWidth));
459  min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth));
460  // in two line, we don't care as much about the threshold width
461  thresh_width = 0;
462  } else if (dontWrapRows) {
463  // This is just the max widths glommed together
464  sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth);
465  min_width = qMax(maxMinLblWidth + maxMinFldWidth, maxMinIfldWidth);
467  } else {
468  // This is just the max widths glommed together
469  sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth);
470  // min width needs to be the min when everything is wrapped,
471  // otherwise we'll never get set with a width that causes wrapping
472  min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth));
473  // We split a pair at label sh + field min (### for now..)
474  thresh_width = maxShLblWidth + maxMinFldWidth;
475  }
476 
477  // Update the expansions
478  expandVertical = expandV;
479  expandHorizontal = expandH;
480  }
481  sizesDirty = false;
482 }
QSizePolicy::ControlTypes controlTypes() const
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
#define Q_Q(Class)
Definition: qglobal.h:2483
int width() const
Returns the width.
Definition: qsize.h:126
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
static void updateFormLayoutItem(QFormLayoutItem *item, int userVSpacing, QFormLayout::FieldGrowthPolicy fieldGrowthPolicy, bool fullRow)
QObject * parent
Definition: qobject.h:92
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55
Qt::Orientations expandingDirections() const
int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=0, QWidget *widget=0) const
Returns the spacing that should be used between controls1 and controls2 in a layout.
Definition: qstyle.cpp:2438
RowWrapPolicy
This enum specifies the different policies that can be used to control the way in which the form&#39;s ro...
Definition: qformlayout.h:74

Properties

◆ dirty

uint QFormLayoutPrivate::dirty

Definition at line 214 of file qformlayout.cpp.

Referenced by setupVerticalLayoutData().

◆ expandHorizontal

uint QFormLayoutPrivate::expandHorizontal

Definition at line 217 of file qformlayout.cpp.

Referenced by QFormLayout::expandingDirections(), and updateSizes().

◆ expandVertical

uint QFormLayoutPrivate::expandVertical

Definition at line 216 of file qformlayout.cpp.

Referenced by QFormLayout::expandingDirections(), and updateSizes().

◆ fieldGrowthPolicy

uint QFormLayoutPrivate::fieldGrowthPolicy

Definition at line 211 of file qformlayout.cpp.

◆ formAlignment

Qt::Alignment QFormLayoutPrivate::formAlignment

Definition at line 219 of file qformlayout.cpp.

Referenced by setupVerticalLayoutData().

◆ formMaxWidth

int QFormLayoutPrivate::formMaxWidth

Definition at line 238 of file qformlayout.cpp.

Referenced by setupHorizontalLayoutData().

◆ has_hfw

uint QFormLayoutPrivate::has_hfw

Definition at line 213 of file qformlayout.cpp.

Referenced by updateSizes().

◆ hfw_height

int QFormLayoutPrivate::hfw_height

Definition at line 227 of file qformlayout.cpp.

Referenced by recalcHFW().

◆ hfw_minheight

int QFormLayoutPrivate::hfw_minheight

Definition at line 228 of file qformlayout.cpp.

Referenced by recalcHFW().

◆ hfw_sh_height

int QFormLayoutPrivate::hfw_sh_height

Definition at line 230 of file qformlayout.cpp.

Referenced by recalcHFW().

◆ hfw_sh_minheight

int QFormLayoutPrivate::hfw_sh_minheight

Definition at line 231 of file qformlayout.cpp.

Referenced by recalcHFW().

◆ hfw_width

int QFormLayoutPrivate::hfw_width

Definition at line 226 of file qformlayout.cpp.

Referenced by recalcHFW().

◆ hfwLayouts

QVector<QLayoutStruct> QFormLayoutPrivate::hfwLayouts

Definition at line 245 of file qformlayout.cpp.

Referenced by recalcHFW(), and setupHfwLayoutData().

◆ hSpacing

int QFormLayoutPrivate::hSpacing

Definition at line 247 of file qformlayout.cpp.

◆ labelAlignment

Qt::Alignment QFormLayoutPrivate::labelAlignment

Definition at line 218 of file qformlayout.cpp.

◆ layoutWidth

int QFormLayoutPrivate::layoutWidth

Definition at line 224 of file qformlayout.cpp.

Referenced by setupVerticalLayoutData().

◆ m_matrix

ItemMatrix QFormLayoutPrivate::m_matrix

◆ m_things

QList<QFormLayoutItem *> QFormLayoutPrivate::m_things

Definition at line 222 of file qformlayout.cpp.

Referenced by setItem().

◆ maxLabelWidth

int QFormLayoutPrivate::maxLabelWidth

Definition at line 243 of file qformlayout.cpp.

Referenced by setupHorizontalLayoutData(), and setupVerticalLayoutData().

◆ min_width

int QFormLayoutPrivate::min_width

Definition at line 233 of file qformlayout.cpp.

Referenced by calcSizeHints(), and updateSizes().

◆ minSize

QSize QFormLayoutPrivate::minSize

Definition at line 236 of file qformlayout.cpp.

Referenced by calcSizeHints().

◆ prefSize

QSize QFormLayoutPrivate::prefSize

Definition at line 237 of file qformlayout.cpp.

Referenced by calcSizeHints().

◆ rowWrapPolicy

uint QFormLayoutPrivate::rowWrapPolicy

Definition at line 212 of file qformlayout.cpp.

Referenced by setupVerticalLayoutData().

◆ sh_width

int QFormLayoutPrivate::sh_width

Definition at line 234 of file qformlayout.cpp.

Referenced by calcSizeHints(), recalcHFW(), and updateSizes().

◆ sizesDirty

uint QFormLayoutPrivate::sizesDirty

Definition at line 215 of file qformlayout.cpp.

Referenced by setupVerticalLayoutData(), and updateSizes().

◆ thresh_width

int QFormLayoutPrivate::thresh_width

Definition at line 235 of file qformlayout.cpp.

Referenced by setupVerticalLayoutData(), and updateSizes().

◆ vLayoutCount

int QFormLayoutPrivate::vLayoutCount

◆ vLayouts

QVector<QLayoutStruct> QFormLayoutPrivate::vLayouts

Definition at line 241 of file qformlayout.cpp.

Referenced by calcSizeHints(), setupHfwLayoutData(), and setupVerticalLayoutData().

◆ vSpacing

int QFormLayoutPrivate::vSpacing

Definition at line 248 of file qformlayout.cpp.


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