Merge QStyleOption*V{2,3,4} classes together

In order to keep binary compatibility, Qt 4 introduced V{2,3,4}
classes for QStyleOption subclasses. They're simple, low level
containers for various members with public access (no accessors
required).

In Qt 5.0 we can break BC, so this patch moves the members
from the derived classes into the ``base'' ones.
The ``base'' ones get a version bump matching the highest
version available, and the V{2,3,4} classes become typedefs.

This change can cause problems in code that used QStyleOption
directly, especially QStyleOptionViewItem, because the old V4
fields get default initialization but the QStyle subclasses
detect that the option is a V4 option and expect all fields
to be properly initialized. The fix in such places is to
properly initialize all fields.

Task-number: QTBUG-23522
Change-Id: I2f782da09ca5cc8c4cbafc07448fb0d33153a251
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Giuseppe D'Angelo 2012-01-30 00:52:34 +00:00 committed by Qt by Nokia
parent 75711510b1
commit 3578e05b29
5 changed files with 314 additions and 1583 deletions

10
dist/changes-5.0.0 vendored
View File

@ -269,6 +269,16 @@ QtWidgets
* QInputDialog::getInteger() has been obsoleted. Use QInputDialog::getInt() instead.
* In Qt 4, many QStyleOption subclasses were introduced in order to keep
binary compatibility -- QStyleOption was designed to be extended this way,
in fact it embeds a version number. In Qt 5 the various QStyleOption*V{2,3,4}
classes have been removed, and their members merged into the respective
base classes. Those classes were left as typedefs to keep existing code
working. Still, some minor adjustements could be necessary, especially in code
that uses QStyleOption directly and does not initialize all the members using
the proper Qt API: due to the version bump, QStyle will try to use the additional
QStyleOption members, which are left default-initialized.
QtNetwork
---------
* QHostAddress::isLoopback() API added. Returns true if the address is

File diff suppressed because it is too large Load Diff

View File

@ -118,10 +118,17 @@ class Q_WIDGETS_EXPORT QStyleOptionFrame : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_Frame };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 3 };
int lineWidth;
int midLineWidth;
enum FrameFeature {
None = 0x00,
Flat = 0x01
};
Q_DECLARE_FLAGS(FrameFeatures, FrameFeature)
FrameFeatures features;
QFrame::Shape frameShape;
QStyleOptionFrame();
QStyleOptionFrame(const QStyleOptionFrame &other) : QStyleOption(Version, Type) { *this = other; }
@ -130,52 +137,17 @@ protected:
QStyleOptionFrame(int version);
};
class Q_WIDGETS_EXPORT QStyleOptionFrameV2 : public QStyleOptionFrame
{
public:
enum StyleOptionVersion { Version = 2 };
enum FrameFeature {
None = 0x00,
Flat = 0x01
};
Q_DECLARE_FLAGS(FrameFeatures, FrameFeature)
FrameFeatures features;
QStyleOptionFrameV2();
QStyleOptionFrameV2(const QStyleOptionFrameV2 &other) : QStyleOptionFrame(Version) { *this = other; }
QStyleOptionFrameV2(const QStyleOptionFrame &other);
QStyleOptionFrameV2 &operator=(const QStyleOptionFrame &other);
protected:
QStyleOptionFrameV2(int version);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionFrameV2::FrameFeatures)
class Q_WIDGETS_EXPORT QStyleOptionFrameV3 : public QStyleOptionFrameV2
{
public:
enum StyleOptionVersion { Version = 3 };
QFrame::Shape frameShape : 4;
uint unused : 28;
QStyleOptionFrameV3();
QStyleOptionFrameV3(const QStyleOptionFrameV3 &other) : QStyleOptionFrameV2(Version) { *this = other; }
QStyleOptionFrameV3(const QStyleOptionFrame &other);
QStyleOptionFrameV3 &operator=(const QStyleOptionFrame &other);
protected:
QStyleOptionFrameV3(int version);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionFrame::FrameFeatures)
typedef QStyleOptionFrame QStyleOptionFrameV2;
typedef QStyleOptionFrame QStyleOptionFrameV3;
#ifndef QT_NO_TABWIDGET
class Q_WIDGETS_EXPORT QStyleOptionTabWidgetFrame : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_TabWidgetFrame };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 2 };
int lineWidth;
int midLineWidth;
@ -183,6 +155,8 @@ public:
QSize tabBarSize;
QSize rightCornerWidgetSize;
QSize leftCornerWidgetSize;
QRect tabBarRect;
QRect selectedTabRect;
QStyleOptionTabWidgetFrame();
inline QStyleOptionTabWidgetFrame(const QStyleOptionTabWidgetFrame &other)
@ -192,25 +166,8 @@ protected:
QStyleOptionTabWidgetFrame(int version);
};
class Q_WIDGETS_EXPORT QStyleOptionTabWidgetFrameV2 : public QStyleOptionTabWidgetFrame
{
public:
enum StyleOptionVersion { Version = 2 };
QRect tabBarRect;
QRect selectedTabRect;
QStyleOptionTabWidgetFrameV2();
QStyleOptionTabWidgetFrameV2(const QStyleOptionTabWidgetFrameV2 &other) :
QStyleOptionTabWidgetFrame(Version) { *this = other; }
QStyleOptionTabWidgetFrameV2(const QStyleOptionTabWidgetFrame &other);
QStyleOptionTabWidgetFrameV2 &operator=(const QStyleOptionTabWidgetFrame &other);
protected:
QStyleOptionTabWidgetFrameV2(int version);
};
#endif
typedef QStyleOptionTabWidgetFrame QStyleOptionTabWidgetFrameV2;
#endif // QT_NO_TABWIDGET
#ifndef QT_NO_TABBAR
@ -218,11 +175,12 @@ class Q_WIDGETS_EXPORT QStyleOptionTabBarBase : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_TabBarBase };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 2 };
QTabBar::Shape shape;
QRect tabBarRect;
QRect selectedTabRect;
bool documentMode;
QStyleOptionTabBarBase();
QStyleOptionTabBarBase(const QStyleOptionTabBarBase &other) : QStyleOption(Version, Type) { *this = other; }
@ -231,21 +189,8 @@ protected:
QStyleOptionTabBarBase(int version);
};
class Q_WIDGETS_EXPORT QStyleOptionTabBarBaseV2 : public QStyleOptionTabBarBase
{
public:
enum StyleOptionVersion { Version = 2 };
bool documentMode;
QStyleOptionTabBarBaseV2();
QStyleOptionTabBarBaseV2(const QStyleOptionTabBarBaseV2 &other) : QStyleOptionTabBarBase(Version) { *this = other; }
QStyleOptionTabBarBaseV2(const QStyleOptionTabBarBase &other);
QStyleOptionTabBarBaseV2 &operator=(const QStyleOptionTabBarBase &other);
protected:
QStyleOptionTabBarBaseV2(int version);
};
#endif
typedef QStyleOptionTabBarBase QStyleOptionTabBarBaseV2;
#endif // QT_NO_TABBAR
class Q_WIDGETS_EXPORT QStyleOptionHeader : public QStyleOption
{
@ -304,7 +249,7 @@ class Q_WIDGETS_EXPORT QStyleOptionTab : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_Tab };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 3 };
enum TabPosition { Beginning, Middle, End, OnlyOneTab };
enum SelectedPosition { NotAdjacent, NextIsSelected, PreviousIsSelected };
@ -319,6 +264,10 @@ public:
TabPosition position;
SelectedPosition selectedPosition;
CornerWidgets cornerWidgets;
QSize iconSize;
bool documentMode;
QSize leftButtonSize;
QSize rightButtonSize;
QStyleOptionTab();
QStyleOptionTab(const QStyleOptionTab &other) : QStyleOption(Version, Type) { *this = other; }
@ -329,38 +278,9 @@ protected:
Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionTab::CornerWidgets)
class Q_WIDGETS_EXPORT QStyleOptionTabV2 : public QStyleOptionTab
{
public:
enum StyleOptionVersion { Version = 2 };
QSize iconSize;
QStyleOptionTabV2();
QStyleOptionTabV2(const QStyleOptionTabV2 &other) : QStyleOptionTab(Version) { *this = other; }
QStyleOptionTabV2(const QStyleOptionTab &other);
QStyleOptionTabV2 &operator=(const QStyleOptionTab &other);
protected:
QStyleOptionTabV2(int version);
};
class Q_WIDGETS_EXPORT QStyleOptionTabV3 : public QStyleOptionTabV2
{
public:
enum StyleOptionVersion { Version = 3 };
bool documentMode;
QSize leftButtonSize;
QSize rightButtonSize;
QStyleOptionTabV3();
QStyleOptionTabV3(const QStyleOptionTabV3 &other) : QStyleOptionTabV2(Version) { *this = other; }
QStyleOptionTabV3(const QStyleOptionTabV2 &other) : QStyleOptionTabV2(Version) { *this = other; }
QStyleOptionTabV3(const QStyleOptionTab &other);
QStyleOptionTabV3 &operator=(const QStyleOptionTab &other);
protected:
QStyleOptionTabV3(int version);
};
#endif
typedef QStyleOptionTab QStyleOptionTabV2;
typedef QStyleOptionTab QStyleOptionTabV3;
#endif // QT_NO_TABBAR
#ifndef QT_NO_TOOLBAR
@ -388,15 +308,13 @@ protected:
Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionToolBar::ToolBarFeatures)
#endif
#endif // QT_NO_TOOLBAR
class Q_WIDGETS_EXPORT QStyleOptionProgressBar : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_ProgressBar };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 2 };
int minimum;
int maximum;
@ -404,6 +322,9 @@ public:
QString text;
Qt::Alignment textAlignment;
bool textVisible;
Qt::Orientation orientation;
bool invertedAppearance;
bool bottomToTop;
QStyleOptionProgressBar();
QStyleOptionProgressBar(const QStyleOptionProgressBar &other) : QStyleOption(Version, Type) { *this = other; }
@ -412,24 +333,7 @@ protected:
QStyleOptionProgressBar(int version);
};
// Adds style info for vertical progress bars
class Q_WIDGETS_EXPORT QStyleOptionProgressBarV2 : public QStyleOptionProgressBar
{
public:
enum StyleOptionType { Type = SO_ProgressBar };
enum StyleOptionVersion { Version = 2 };
Qt::Orientation orientation;
bool invertedAppearance;
bool bottomToTop;
QStyleOptionProgressBarV2();
QStyleOptionProgressBarV2(const QStyleOptionProgressBar &other);
QStyleOptionProgressBarV2(const QStyleOptionProgressBarV2 &other);
QStyleOptionProgressBarV2 &operator=(const QStyleOptionProgressBar &other);
protected:
QStyleOptionProgressBarV2(int version);
};
typedef QStyleOptionProgressBar QStyleOptionProgressBarV2;
class Q_WIDGETS_EXPORT QStyleOptionMenuItem : public QStyleOption
{
@ -504,12 +408,13 @@ class Q_WIDGETS_EXPORT QStyleOptionDockWidget : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_DockWidget };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 2 };
QString title;
bool closable;
bool movable;
bool floatable;
bool verticalTitleBar;
QStyleOptionDockWidget();
QStyleOptionDockWidget(const QStyleOptionDockWidget &other) : QStyleOption(Version, Type) { *this = other; }
@ -518,28 +423,15 @@ protected:
QStyleOptionDockWidget(int version);
};
class Q_WIDGETS_EXPORT QStyleOptionDockWidgetV2 : public QStyleOptionDockWidget
{
public:
enum StyleOptionVersion { Version = 2 };
typedef QStyleOptionDockWidget QStyleOptionDockWidgetV2;
bool verticalTitleBar;
QStyleOptionDockWidgetV2();
QStyleOptionDockWidgetV2(const QStyleOptionDockWidgetV2 &other)
: QStyleOptionDockWidget(Version) { *this = other; }
QStyleOptionDockWidgetV2(const QStyleOptionDockWidget &other);
QStyleOptionDockWidgetV2 &operator = (const QStyleOptionDockWidget &other);
protected:
QStyleOptionDockWidgetV2(int version);
};
#ifndef QT_NO_ITEMVIEWS
class Q_WIDGETS_EXPORT QStyleOptionViewItem : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_ViewItem };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 4 };
enum Position { Left, Right, Top, Bottom };
@ -551,18 +443,6 @@ public:
QFont font;
bool showDecorationSelected;
QStyleOptionViewItem();
QStyleOptionViewItem(const QStyleOptionViewItem &other) : QStyleOption(Version, Type) { *this = other; }
protected:
QStyleOptionViewItem(int version);
};
class Q_WIDGETS_EXPORT QStyleOptionViewItemV2 : public QStyleOptionViewItem
{
public:
enum StyleOptionVersion { Version = 2 };
enum ViewItemFeature {
None = 0x00,
WrapText = 0x01,
@ -575,40 +455,9 @@ public:
ViewItemFeatures features;
QStyleOptionViewItemV2();
QStyleOptionViewItemV2(const QStyleOptionViewItemV2 &other) : QStyleOptionViewItem(Version) { *this = other; }
QStyleOptionViewItemV2(const QStyleOptionViewItem &other);
QStyleOptionViewItemV2 &operator=(const QStyleOptionViewItem &other);
protected:
QStyleOptionViewItemV2(int version);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionViewItemV2::ViewItemFeatures)
class Q_WIDGETS_EXPORT QStyleOptionViewItemV3 : public QStyleOptionViewItemV2
{
public:
enum StyleOptionVersion { Version = 3 };
QLocale locale;
const QWidget *widget;
QStyleOptionViewItemV3();
QStyleOptionViewItemV3(const QStyleOptionViewItemV3 &other)
: QStyleOptionViewItemV2(Version) { *this = other; }
QStyleOptionViewItemV3(const QStyleOptionViewItem &other);
QStyleOptionViewItemV3 &operator = (const QStyleOptionViewItem &other);
protected:
QStyleOptionViewItemV3(int version);
};
#ifndef QT_NO_ITEMVIEWS
class Q_WIDGETS_EXPORT QStyleOptionViewItemV4 : public QStyleOptionViewItemV3
{
public:
enum StyleOptionVersion { Version = 4 };
enum ViewItemPosition { Invalid, Beginning, Middle, End, OnlyOne };
QModelIndex index;
@ -618,26 +467,36 @@ public:
ViewItemPosition viewItemPosition;
QBrush backgroundBrush;
QStyleOptionViewItemV4();
QStyleOptionViewItemV4(const QStyleOptionViewItemV4 &other)
: QStyleOptionViewItemV3(Version) { *this = other; }
QStyleOptionViewItemV4(const QStyleOptionViewItem &other);
QStyleOptionViewItemV4 &operator = (const QStyleOptionViewItem &other);
QStyleOptionViewItem();
QStyleOptionViewItem(const QStyleOptionViewItem &other) : QStyleOption(Version, Type) { *this = other; }
protected:
QStyleOptionViewItemV4(int version);
QStyleOptionViewItem(int version);
};
#endif
Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionViewItem::ViewItemFeatures)
typedef QStyleOptionViewItem QStyleOptionViewItemV2;
typedef QStyleOptionViewItem QStyleOptionViewItemV3;
typedef QStyleOptionViewItem QStyleOptionViewItemV4;
#endif // QT_NO_ITEMVIEWS
class Q_WIDGETS_EXPORT QStyleOptionToolBox : public QStyleOption
{
public:
enum StyleOptionType { Type = SO_ToolBox };
enum StyleOptionVersion { Version = 1 };
enum StyleOptionVersion { Version = 2 };
QString text;
QIcon icon;
enum TabPosition { Beginning, Middle, End, OnlyOneTab };
enum SelectedPosition { NotAdjacent, NextIsSelected, PreviousIsSelected };
TabPosition position;
SelectedPosition selectedPosition;
QStyleOptionToolBox();
QStyleOptionToolBox(const QStyleOptionToolBox &other) : QStyleOption(Version, Type) { *this = other; }
@ -645,24 +504,7 @@ protected:
QStyleOptionToolBox(int version);
};
class Q_WIDGETS_EXPORT QStyleOptionToolBoxV2 : public QStyleOptionToolBox
{
public:
enum StyleOptionVersion { Version = 2 };
enum TabPosition { Beginning, Middle, End, OnlyOneTab };
enum SelectedPosition { NotAdjacent, NextIsSelected, PreviousIsSelected };
TabPosition position;
SelectedPosition selectedPosition;
QStyleOptionToolBoxV2();
QStyleOptionToolBoxV2(const QStyleOptionToolBoxV2 &other) : QStyleOptionToolBox(Version) { *this = other; }
QStyleOptionToolBoxV2(const QStyleOptionToolBox &other);
QStyleOptionToolBoxV2 &operator=(const QStyleOptionToolBox &other);
protected:
QStyleOptionToolBoxV2(int version);
};
typedef QStyleOptionToolBox QStyleOptionToolBoxV2;
#ifndef QT_NO_RUBBERBAND
class Q_WIDGETS_EXPORT QStyleOptionRubberBand : public QStyleOption

View File

@ -1033,6 +1033,9 @@ void tst_QItemDelegate::editorEvent()
QStyleOptionViewItem option;
option.rect = rect;
option.state |= QStyle::State_Enabled;
// mimic QStyledItemDelegate::initStyleOption logic
option.features |= QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDisplay;
option.checkState = Qt::CheckState(checkState);
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
QPoint pos = inCheck ? qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0) : QPoint(200,200);
@ -1181,6 +1184,9 @@ void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck()
QTest::qWaitForWindowShown(&view);
QStyleOptionViewItem option;
option.rect = view.visualRect(model.index(0, 0));
// mimic QStyledItemDelegate::initStyleOption logic
option.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator;
option.checkState = Qt::CheckState(model.index(0, 0).data(Qt::CheckStateRole).toInt());
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center()
+ QPoint(checkMargin, 0);

View File

@ -2978,6 +2978,10 @@ void tst_QTreeWidget::task191552_rtl()
QStyleOptionViewItem opt;
opt.initFrom(&tw);
opt.rect = tw.visualItemRect(item);
// mimic QStyledItemDelegate::initStyleOption logic
opt.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator;
opt.checkState = Qt::Checked;
opt.widget = &tw;
const QRect checkRect = tw.style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, &tw);
QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::NoModifier, checkRect.center());
QTest::qWait(200);