Qt 4.8
Public Functions | Properties | List of all members
QGridLayoutItem Class Reference

#include <qgridlayoutengine_p.h>

Public Functions

Qt::Alignment alignment () const
 
QGridLayoutBox box (Qt::Orientation orientation, qreal constraint=-1.0) const
 
int columnSpan () const
 
int columnSpan (Qt::Orientation orientation) const
 
QSizePolicy::ControlTypes controlTypes (LayoutSide side) const
 
void dump (int indent=0) const
 
Qt::Orientation dynamicConstraintOrientation () const
 
QSizeF effectiveMaxSize (const QSizeF &constraint) const
 
int firstColumn () const
 
int firstColumn (Qt::Orientation orientation) const
 
int firstRow () const
 
int firstRow (Qt::Orientation orientation) const
 
QRectF geometryWithin (qreal x, qreal y, qreal width, qreal height, qreal rowDescent) const
 
bool hasDynamicConstraint () const
 
void insertOrRemoveRows (int row, int delta, Qt::Orientation orientation=Qt::Vertical)
 
int lastColumn () const
 
int lastColumn (Qt::Orientation orientation) const
 
int lastRow () const
 
int lastRow (Qt::Orientation orientation) const
 
QGraphicsLayoutItemlayoutItem () const
 
 QGridLayoutItem (QGridLayoutEngine *engine, QGraphicsLayoutItem *layoutItem, int row, int column, int rowSpan=1, int columnSpan=1, Qt::Alignment alignment=0, int itemAtIndex=-1)
 
int rowSpan () const
 
int rowSpan (Qt::Orientation orientation) const
 
void setAlignment (Qt::Alignment alignment)
 
void setFirstRow (int row, Qt::Orientation orientation=Qt::Vertical)
 
void setGeometry (const QRectF &rect)
 
void setRowSpan (int rowSpan, Qt::Orientation orientation=Qt::Vertical)
 
void setStretchFactor (int stretch, Qt::Orientation orientation)
 
QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
 
QSizePolicy::Policy sizePolicy (Qt::Orientation orientation) const
 
int stretchFactor (Qt::Orientation orientation) const
 
void transpose ()
 

Properties

Qt::Alignment q_alignment
 
QGridLayoutEngineq_engine
 
int q_firstRows [NOrientations]
 
QGraphicsLayoutItemq_layoutItem
 
int q_rowSpans [NOrientations]
 
int q_stretches [NOrientations]
 

Detailed Description

Definition at line 254 of file qgridlayoutengine_p.h.

Constructors and Destructors

◆ QGridLayoutItem()

QGridLayoutItem::QGridLayoutItem ( QGridLayoutEngine engine,
QGraphicsLayoutItem layoutItem,
int  row,
int  column,
int  rowSpan = 1,
int  columnSpan = 1,
Qt::Alignment  alignment = 0,
int  itemAtIndex = -1 
)

Definition at line 487 of file qgridlayoutengine.cpp.

490  : q_engine(engine), q_layoutItem(layoutItem), q_alignment(alignment)
491 {
492  q_firstRows[Hor] = column;
493  q_firstRows[Ver] = row;
496  q_stretches[Hor] = -1;
497  q_stretches[Ver] = -1;
498 
499  q_engine->insertItem(this, itemAtIndex);
500 }
int q_firstRows[NOrientations]
QGridLayoutEngine * q_engine
Qt::Alignment q_alignment
int q_rowSpans[NOrientations]
int q_stretches[NOrientations]
void insertItem(QGridLayoutItem *item, int index)
The index is only used by QGraphicsLinearLayout to ensure that itemAt() reflects the order of visual ...
Qt::Alignment alignment() const
QGraphicsLayoutItem * q_layoutItem

Functions

◆ alignment()

Qt::Alignment QGridLayoutItem::alignment ( ) const
inline

◆ box()

QGridLayoutBox QGridLayoutItem::box ( Qt::Orientation  orientation,
qreal  constraint = -1.0 
) const

Definition at line 600 of file qgridlayoutengine.cpp.

Referenced by QGridLayoutEngine::fillRowData(), and geometryWithin().

601 {
602  QGridLayoutBox result;
603  QSizePolicy::Policy policy = sizePolicy(orientation);
604 
605  if (orientation == Qt::Horizontal) {
606  QSizeF constraintSize(-1.0, constraint);
607 
608  result.q_preferredSize = sizeHint(Qt::PreferredSize, constraintSize).width();
609 
610  if (policy & QSizePolicy::ShrinkFlag) {
611  result.q_minimumSize = sizeHint(Qt::MinimumSize, constraintSize).width();
612  } else {
613  result.q_minimumSize = result.q_preferredSize;
614  }
615 
617  result.q_maximumSize = sizeHint(Qt::MaximumSize, constraintSize).width();
618  } else {
619  result.q_maximumSize = result.q_preferredSize;
620  }
621  } else {
622  QSizeF constraintSize(constraint, -1.0);
623 
624  result.q_preferredSize = sizeHint(Qt::PreferredSize, constraintSize).height();
625 
626  if (policy & QSizePolicy::ShrinkFlag) {
627  result.q_minimumSize = sizeHint(Qt::MinimumSize, constraintSize).height();
628  } else {
629  result.q_minimumSize = result.q_preferredSize;
630  }
631 
633  result.q_maximumSize = sizeHint(Qt::MaximumSize, constraintSize).height();
634  } else {
635  result.q_maximumSize = result.q_preferredSize;
636  }
637 
638  result.q_minimumDescent = sizeHint(Qt::MinimumDescent, constraintSize).height();
639  if (result.q_minimumDescent >= 0.0)
640  result.q_minimumAscent = result.q_minimumSize - result.q_minimumDescent;
641  }
642  if (policy & QSizePolicy::IgnoreFlag)
643  result.q_preferredSize = result.q_minimumSize;
644 
645  return result;
646 }
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QSizePolicy::Policy sizePolicy(Qt::Orientation orientation) const
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const

◆ columnSpan() [1/2]

int QGridLayoutItem::columnSpan ( ) const
inline

◆ columnSpan() [2/2]

int QGridLayoutItem::columnSpan ( Qt::Orientation  orientation) const

Definition at line 527 of file qgridlayoutengine.cpp.

528 {
529  return q_rowSpans[orientation == Qt::Horizontal];
530 }
int q_rowSpans[NOrientations]

◆ controlTypes()

QSizePolicy::ControlTypes QGridLayoutItem::controlTypes ( LayoutSide  side) const

Definition at line 590 of file qgridlayoutengine.cpp.

Referenced by QGridLayoutEngine::fillRowData().

591 {
592  return q_layoutItem->sizePolicy().controlType();
593 }
QSizePolicy sizePolicy() const
Returns the current size policy.
ControlType controlType() const
Definition: qlayout.cpp:1670
QGraphicsLayoutItem * q_layoutItem

◆ dump()

void QGridLayoutItem::dump ( int  indent = 0) const

Definition at line 754 of file qgridlayoutengine.cpp.

755 {
756  qDebug("%*s%p (%d, %d) %d x %d", indent, "", q_layoutItem, firstRow(), firstColumn(),
757  rowSpan(), columnSpan());
758 
759  if (q_stretches[Hor] >= 0)
760  qDebug("%*s Horizontal stretch: %d", indent, "", q_stretches[Hor]);
761  if (q_stretches[Ver] >= 0)
762  qDebug("%*s Vertical stretch: %d", indent, "", q_stretches[Ver]);
763  if (q_alignment != 0)
764  qDebug("%*s Alignment: %x", indent, "", uint(q_alignment));
765  qDebug("%*s Horizontal size policy: %x Vertical size policy: %x",
767 }
Qt::Alignment q_alignment
Q_CORE_EXPORT void qDebug(const char *,...)
QSizePolicy::Policy sizePolicy(Qt::Orientation orientation) const
unsigned int uint
Definition: qglobal.h:996
int q_stretches[NOrientations]
QGraphicsLayoutItem * q_layoutItem

◆ dynamicConstraintOrientation()

Qt::Orientation QGridLayoutItem::dynamicConstraintOrientation ( ) const

Definition at line 582 of file qgridlayoutengine.cpp.

Referenced by QGridLayoutEngine::ensureDynamicConstraint(), QGridLayoutEngine::fillRowData(), and geometryWithin().

583 {
584  if (QGraphicsLayoutItemPrivate::get(q_layoutItem)->hasHeightForWidth())
585  return Qt::Vertical;
586  else //if (QGraphicsLayoutItemPrivate::get(q_layoutItem)->hasWidthForHeight())
587  return Qt::Horizontal;
588 }
static QGraphicsLayoutItemPrivate * get(QGraphicsLayoutItem *q)
QGraphicsLayoutItem * q_layoutItem

◆ effectiveMaxSize()

QSizeF QGridLayoutItem::effectiveMaxSize ( const QSizeF constraint) const
Warning
This function is not part of the public interface. returns the effective maximumSize, will take the sizepolicy into consideration. (i.e. if sizepolicy does not have QSizePolicy::Grow, then maxSizeHint will be the preferredSize) Note that effectiveSizeHint does not take sizePolicy into consideration, (since it only evaluates the hints, as the name implies)

Definition at line 730 of file qgridlayoutengine.cpp.

Referenced by geometryWithin().

731 {
732  QSizeF size = constraint;
735  if (!vGrow || !hGrow) {
736  QSizeF pref = layoutItem()->effectiveSizeHint(Qt::PreferredSize, constraint);
737  if (!vGrow)
738  size.setHeight(pref.height());
739  if (!hGrow)
740  size.setWidth(pref.width());
741  }
742 
743  if (!size.isValid()) {
745  if (size.width() == -1)
746  size.setWidth(maxSize.width());
747  if (size.height() == -1)
748  size.setHeight(maxSize.height());
749  }
750  return size;
751 }
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:281
void setWidth(qreal w)
Sets the width to the given width.
Definition: qsize.h:290
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QSizePolicy::Policy sizePolicy(Qt::Orientation orientation) const
QGraphicsLayoutItem * layoutItem() const
void setHeight(qreal h)
Sets the height to the given height.
Definition: qsize.h:293

◆ firstColumn() [1/2]

int QGridLayoutItem::firstColumn ( ) const
inline

◆ firstColumn() [2/2]

int QGridLayoutItem::firstColumn ( Qt::Orientation  orientation) const

Definition at line 507 of file qgridlayoutengine.cpp.

508 {
509  return q_firstRows[orientation == Qt::Horizontal];
510 }
int q_firstRows[NOrientations]

◆ firstRow() [1/2]

int QGridLayoutItem::firstRow ( ) const
inline

◆ firstRow() [2/2]

int QGridLayoutItem::firstRow ( Qt::Orientation  orientation) const

Definition at line 502 of file qgridlayoutengine.cpp.

503 {
504  return q_firstRows[orientation == Qt::Vertical];
505 }
int q_firstRows[NOrientations]

◆ geometryWithin()

QRectF QGridLayoutItem::geometryWithin ( qreal  x,
qreal  y,
qreal  width,
qreal  height,
qreal  rowDescent 
) const

Definition at line 648 of file qgridlayoutengine.cpp.

Referenced by QGridLayoutEngine::fillRowData(), and QGridLayoutEngine::setGeometries().

650 {
651  rowDescent = -1.0; // ### This disables the descent
652 
654  if (vBox.q_minimumDescent < 0.0 || rowDescent < 0.0) {
655  qreal cellWidth = width;
656  qreal cellHeight = height;
657 
658 
659  QSizeF size = effectiveMaxSize(QSizeF(-1,-1));
660  if (hasDynamicConstraint()) {
662  if (size.width() > cellWidth)
663  size = effectiveMaxSize(QSizeF(cellWidth, -1));
664  } else if (size.height() > cellHeight) {
665  size = effectiveMaxSize(QSizeF(-1, cellHeight));
666  }
667  }
668  size = size.boundedTo(QSizeF(cellWidth, cellHeight));
669  width = size.width();
670  height = size.height();
671 
672  Qt::Alignment align = q_engine->effectiveAlignment(this);
673  switch (align & Qt::AlignHorizontal_Mask) {
674  case Qt::AlignHCenter:
675  x += (cellWidth - width)/2;
676  break;
677  case Qt::AlignRight:
678  x += cellWidth - width;
679  break;
680  default:
681  break;
682  }
683  switch (align & Qt::AlignVertical_Mask) {
684  case Qt::AlignVCenter:
685  y += (cellHeight - height)/2;
686  break;
687  case Qt::AlignBottom:
688  y += cellHeight - height;
689  break;
690  default:
691  break;
692  }
693  return QRectF(x, y, width, height);
694  } else {
695  qreal descent = vBox.q_minimumDescent;
696  qreal ascent = vBox.q_minimumSize - descent;
697  return QRectF(x, y + height - rowDescent - ascent, width, ascent + descent);
698  }
699 }
double qreal
Definition: qglobal.h:1193
Qt::Alignment effectiveAlignment(const QGridLayoutItem *layoutItem) const
QGridLayoutEngine * q_engine
Qt::Orientation dynamicConstraintOrientation() const
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
bool hasDynamicConstraint() const
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QSizeF effectiveMaxSize(const QSizeF &constraint) const
QSizeF boundedTo(const QSizeF &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:350
QGridLayoutBox box(Qt::Orientation orientation, qreal constraint=-1.0) const

◆ hasDynamicConstraint()

bool QGridLayoutItem::hasDynamicConstraint ( ) const

◆ insertOrRemoveRows()

void QGridLayoutItem::insertOrRemoveRows ( int  row,
int  delta,
Qt::Orientation  orientation = Qt::Vertical 
)

Definition at line 713 of file qgridlayoutengine.cpp.

714 {
715  int oldFirstRow = firstRow(orientation);
716  if (oldFirstRow >= row) {
717  setFirstRow(oldFirstRow + delta, orientation);
718  } else if (lastRow(orientation) >= row) {
719  setRowSpan(rowSpan(orientation) + delta, orientation);
720  }
721 }
void setRowSpan(int rowSpan, Qt::Orientation orientation=Qt::Vertical)
void setFirstRow(int row, Qt::Orientation orientation=Qt::Vertical)

◆ lastColumn() [1/2]

int QGridLayoutItem::lastColumn ( ) const
inline

◆ lastColumn() [2/2]

int QGridLayoutItem::lastColumn ( Qt::Orientation  orientation) const

Definition at line 517 of file qgridlayoutengine.cpp.

518 {
519  return firstColumn(orientation) + columnSpan(orientation) - 1;
520 }

◆ lastRow() [1/2]

int QGridLayoutItem::lastRow ( ) const
inline

◆ lastRow() [2/2]

int QGridLayoutItem::lastRow ( Qt::Orientation  orientation) const

Definition at line 512 of file qgridlayoutengine.cpp.

513 {
514  return firstRow(orientation) + rowSpan(orientation) - 1;
515 }

◆ layoutItem()

QGraphicsLayoutItem* QGridLayoutItem::layoutItem ( ) const
inline

Definition at line 293 of file qgridlayoutengine_p.h.

Referenced by effectiveMaxSize(), and QGridLayoutEngine::findLayoutItem().

293 { return q_layoutItem; }
QGraphicsLayoutItem * q_layoutItem

◆ rowSpan() [1/2]

int QGridLayoutItem::rowSpan ( ) const
inline

◆ rowSpan() [2/2]

int QGridLayoutItem::rowSpan ( Qt::Orientation  orientation) const

Definition at line 522 of file qgridlayoutengine.cpp.

523 {
524  return q_rowSpans[orientation == Qt::Vertical];
525 }
int q_rowSpans[NOrientations]

◆ setAlignment()

void QGridLayoutItem::setAlignment ( Qt::Alignment  alignment)
inline

Definition at line 281 of file qgridlayoutengine_p.h.

281 { q_alignment = alignment; }
Qt::Alignment q_alignment
Qt::Alignment alignment() const

◆ setFirstRow()

void QGridLayoutItem::setFirstRow ( int  row,
Qt::Orientation  orientation = Qt::Vertical 
)

Definition at line 532 of file qgridlayoutengine.cpp.

Referenced by insertOrRemoveRows().

533 {
534  q_firstRows[orientation == Qt::Vertical] = row;
535 }
int q_firstRows[NOrientations]

◆ setGeometry()

void QGridLayoutItem::setGeometry ( const QRectF rect)

Definition at line 701 of file qgridlayoutengine.cpp.

Referenced by QGridLayoutEngine::setGeometries().

702 {
703  q_layoutItem->setGeometry(rect);
704 }
virtual void setGeometry(const QRectF &rect)
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordi...
QGraphicsLayoutItem * q_layoutItem

◆ setRowSpan()

void QGridLayoutItem::setRowSpan ( int  rowSpan,
Qt::Orientation  orientation = Qt::Vertical 
)

Definition at line 537 of file qgridlayoutengine.cpp.

Referenced by insertOrRemoveRows().

538 {
539  q_rowSpans[orientation == Qt::Vertical] = rowSpan;
540 }
int q_rowSpans[NOrientations]

◆ setStretchFactor()

void QGridLayoutItem::setStretchFactor ( int  stretch,
Qt::Orientation  orientation 
)

Definition at line 559 of file qgridlayoutengine.cpp.

560 {
561  Q_ASSERT(stretch >= 0); // ### deal with too big stretches
562  q_stretches[orientation == Qt::Vertical] = stretch;
563 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int q_stretches[NOrientations]

◆ sizeHint()

QSizeF QGridLayoutItem::sizeHint ( Qt::SizeHint  which,
const QSizeF constraint = QSizeF() 
) const

Definition at line 595 of file qgridlayoutengine.cpp.

Referenced by box().

596 {
597  return q_layoutItem->effectiveSizeHint(which, constraint);
598 }
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
QGraphicsLayoutItem * q_layoutItem

◆ sizePolicy()

QSizePolicy::Policy QGridLayoutItem::sizePolicy ( Qt::Orientation  orientation) const

Definition at line 565 of file qgridlayoutengine.cpp.

Referenced by box(), dump(), effectiveMaxSize(), QGridLayoutEngine::fillRowData(), and stretchFactor().

566 {
568  return (orientation == Qt::Horizontal) ? sizePolicy.horizontalPolicy()
569  : sizePolicy.verticalPolicy();
570 }
QSizePolicy::Policy sizePolicy(Qt::Orientation orientation) const
QSizePolicy sizePolicy() const
Returns the current size policy.
QGraphicsLayoutItem * q_layoutItem

◆ stretchFactor()

int QGridLayoutItem::stretchFactor ( Qt::Orientation  orientation) const

Definition at line 542 of file qgridlayoutengine.cpp.

Referenced by QGridLayoutEngine::fillRowData().

543 {
544  int stretch = q_stretches[orientation == Qt::Vertical];
545  if (stretch >= 0)
546  return stretch;
547 
548  QSizePolicy::Policy policy = sizePolicy(orientation);
549 
550  if (policy & QSizePolicy::ExpandFlag) {
551  return 1;
552  } else if (policy & QSizePolicy::GrowFlag) {
553  return -1; // because we max it up
554  } else {
555  return 0;
556  }
557 }
QSizePolicy::Policy sizePolicy(Qt::Orientation orientation) const
int q_stretches[NOrientations]

◆ transpose()

void QGridLayoutItem::transpose ( )

Definition at line 706 of file qgridlayoutengine.cpp.

707 {
711 }
int q_firstRows[NOrientations]
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
int q_rowSpans[NOrientations]
int q_stretches[NOrientations]

Properties

◆ q_alignment

Qt::Alignment QGridLayoutItem::q_alignment
private

Definition at line 310 of file qgridlayoutengine_p.h.

Referenced by dump().

◆ q_engine

QGridLayoutEngine* QGridLayoutItem::q_engine
private

Definition at line 305 of file qgridlayoutengine_p.h.

Referenced by geometryWithin(), and QGridLayoutItem().

◆ q_firstRows

int QGridLayoutItem::q_firstRows[NOrientations]
private

Definition at line 307 of file qgridlayoutengine_p.h.

Referenced by firstColumn(), firstRow(), QGridLayoutItem(), setFirstRow(), and transpose().

◆ q_layoutItem

QGraphicsLayoutItem* QGridLayoutItem::q_layoutItem
private

◆ q_rowSpans

int QGridLayoutItem::q_rowSpans[NOrientations]
private

Definition at line 308 of file qgridlayoutengine_p.h.

Referenced by columnSpan(), QGridLayoutItem(), rowSpan(), setRowSpan(), and transpose().

◆ q_stretches

int QGridLayoutItem::q_stretches[NOrientations]
private

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