QLayoutItem - make controlTypes a virtual function.
Just implementing the ### Qt5 suggestion about making controlTypes a virtual function. Change-Id: Ic1db47fe488f089de965438e456e9b48e0b96f32 Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
aec8bac313
commit
03dbba9a62
@ -524,6 +524,19 @@ bool QLayout::isEmpty() const
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
QSizePolicy::ControlTypes QLayout::controlTypes() const
|
||||
{
|
||||
if (count() == 0)
|
||||
return QSizePolicy::DefaultType;
|
||||
QSizePolicy::ControlTypes types;
|
||||
for (int i = count() - 1; i >= 0; --i)
|
||||
types |= itemAt(i)->controlTypes();
|
||||
return types;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
|
@ -131,6 +131,7 @@ public:
|
||||
virtual int indexOf(QWidget *) const;
|
||||
virtual int count() const = 0;
|
||||
bool isEmpty() const;
|
||||
QSizePolicy::ControlTypes controlTypes() const;
|
||||
|
||||
int totalHeightForWidth(int w) const;
|
||||
QSize totalMinimumSize() const;
|
||||
|
@ -414,17 +414,6 @@ int QLayoutItem::heightForWidth(int /* w */) const
|
||||
*/
|
||||
QSizePolicy::ControlTypes QLayoutItem::controlTypes() const
|
||||
{
|
||||
// ### Qt 5: This function should probably be virtual instead
|
||||
if (const QWidget *widget = const_cast<QLayoutItem*>(this)->widget()) {
|
||||
return widget->sizePolicy().controlType();
|
||||
} else if (const QLayout *layout = const_cast<QLayoutItem*>(this)->layout()) {
|
||||
if (layout->count() == 0)
|
||||
return QSizePolicy::DefaultType;
|
||||
QSizePolicy::ControlTypes types;
|
||||
for (int i = layout->count() - 1; i >= 0; --i)
|
||||
types |= layout->itemAt(i)->controlTypes();
|
||||
return types;
|
||||
}
|
||||
return QSizePolicy::DefaultType;
|
||||
}
|
||||
|
||||
@ -688,6 +677,11 @@ bool QWidgetItem::isEmpty() const
|
||||
return wid->isHidden() || wid->isWindow();
|
||||
}
|
||||
|
||||
QSizePolicy::ControlTypes QWidgetItem::controlTypes() const
|
||||
{
|
||||
return wid->sizePolicy().controlType();
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QWidgetItemV2
|
||||
\internal
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
|
||||
Qt::Alignment alignment() const { return align; }
|
||||
void setAlignment(Qt::Alignment a);
|
||||
QSizePolicy::ControlTypes controlTypes() const;
|
||||
virtual QSizePolicy::ControlTypes controlTypes() const;
|
||||
|
||||
protected:
|
||||
Qt::Alignment align;
|
||||
@ -135,7 +135,7 @@ public:
|
||||
|
||||
bool hasHeightForWidth() const;
|
||||
int heightForWidth(int) const;
|
||||
|
||||
QSizePolicy::ControlTypes controlTypes() const;
|
||||
protected:
|
||||
QWidget *wid;
|
||||
};
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include <QtWidgets/QFrame>
|
||||
#include <QtWidgets/QWindowsStyle>
|
||||
#include <QtWidgets/QSizePolicy>
|
||||
#include <QtWidgets/QComboBox>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <private/qlayoutengine_p.h>
|
||||
@ -77,6 +78,7 @@ private slots:
|
||||
void layoutItemRect();
|
||||
void warnIfWrongParent();
|
||||
void controlTypes();
|
||||
void controlTypes2();
|
||||
void adjustSizeShouldMakeSureLayoutIsActivated();
|
||||
};
|
||||
|
||||
@ -310,7 +312,16 @@ void tst_QLayout::controlTypes()
|
||||
QCOMPARE(layout.controlTypes(), QSizePolicy::DefaultType);
|
||||
QSizePolicy p;
|
||||
QCOMPARE(p.controlType(),QSizePolicy::DefaultType);
|
||||
}
|
||||
|
||||
void tst_QLayout::controlTypes2()
|
||||
{
|
||||
QWidget main;
|
||||
QVBoxLayout *const layout = new QVBoxLayout(&main);
|
||||
layout->setMargin(0);
|
||||
QComboBox *combo = new QComboBox(&main);
|
||||
layout->addWidget(combo);
|
||||
QCOMPARE(layout->controlTypes(), QSizePolicy::ComboBox);
|
||||
}
|
||||
|
||||
void tst_QLayout::adjustSizeShouldMakeSureLayoutIsActivated()
|
||||
|
Loading…
Reference in New Issue
Block a user