summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qcompilerdetection.h9
-rw-r--r--src/corelib/global/qnumeric_p.h6
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp33
-rw-r--r--src/widgets/itemviews/qabstractitemview.h6
-rw-r--r--src/widgets/itemviews/qabstractitemview_p.h4
-rw-r--r--src/widgets/styles/qcommonstyle.cpp3
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm3
-rw-r--r--src/widgets/styles/qstyle.cpp4
-rw-r--r--src/widgets/styles/qstyle.h1
9 files changed, 59 insertions, 10 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index e655aace32..7575fe06b2 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -83,6 +83,9 @@
# endif
#elif defined(_MSC_VER)
+# ifdef __clang__
+# define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__)
+# endif
# define Q_CC_MSVC (_MSC_VER)
# define Q_CC_MSVC_NET
# define Q_OUTOFLINE_TEMPLATE inline
@@ -97,7 +100,9 @@
# define Q_UNREACHABLE_IMPL() __assume(0)
# define Q_NORETURN __declspec(noreturn)
# define Q_DECL_DEPRECATED __declspec(deprecated)
-# define Q_DECL_DEPRECATED_X(text) __declspec(deprecated(text))
+# ifndef Q_CC_CLANG
+# define Q_DECL_DEPRECATED_X(text) __declspec(deprecated(text))
+# endif
# define Q_DECL_EXPORT __declspec(dllexport)
# define Q_DECL_IMPORT __declspec(dllimport)
/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */
@@ -1177,7 +1182,7 @@
# define QT_WARNING_DISABLE_MSVC(number)
# define QT_WARNING_DISABLE_CLANG(text)
# define QT_WARNING_DISABLE_GCC(text)
-#elif defined(Q_CC_MSVC) && _MSC_VER >= 1500
+#elif defined(Q_CC_MSVC) && _MSC_VER >= 1500 && !defined(Q_CC_CLANG)
# undef QT_DO_PRAGMA /* not needed */
# define QT_WARNING_PUSH __pragma(warning(push))
# define QT_WARNING_POP __pragma(warning(pop))
diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h
index f58e062dbd..5705bc29c8 100644
--- a/src/corelib/global/qnumeric_p.h
+++ b/src/corelib/global/qnumeric_p.h
@@ -222,7 +222,7 @@ template <> inline bool mul_overflow(unsigned long long v1, unsigned long long v
# define HAVE_MUL64_OVERFLOW
#endif
-#if ((defined(Q_CC_MSVC) && _MSC_VER >= 1800) || defined(Q_CC_INTEL)) && defined(Q_PROCESSOR_X86)
+#if ((defined(Q_CC_MSVC) && _MSC_VER >= 1800) || defined(Q_CC_INTEL)) && defined(Q_PROCESSOR_X86) && !QT_HAS_BUILTIN(__builtin_uadd_overflow)
template <> inline bool add_overflow(unsigned v1, unsigned v2, unsigned *r)
{ return _addcarry_u32(0, v1, v2, r); }
# ifdef Q_CC_MSVC // longs are 32-bit
@@ -230,7 +230,7 @@ template <> inline bool add_overflow(unsigned long v1, unsigned long v2, unsigne
{ return _addcarry_u32(0, v1, v2, reinterpret_cast<unsigned *>(r)); }
# endif
#endif
-#if ((defined(Q_CC_MSVC) && _MSC_VER >= 1800) || defined(Q_CC_INTEL)) && defined(Q_PROCESSOR_X86_64)
+#if ((defined(Q_CC_MSVC) && _MSC_VER >= 1800) || defined(Q_CC_INTEL)) && defined(Q_PROCESSOR_X86_64) && !QT_HAS_BUILTIN(__builtin_uadd_overflow)
template <> inline bool add_overflow(quint64 v1, quint64 v2, quint64 *r)
{ return _addcarry_u64(0, v1, v2, reinterpret_cast<unsigned __int64 *>(r)); }
# ifndef Q_CC_MSVC // longs are 64-bit
@@ -239,7 +239,7 @@ template <> inline bool add_overflow(unsigned long v1, unsigned long v2, unsigne
# endif
#endif
-#if defined(Q_CC_MSVC) && (defined(Q_PROCESSOR_X86_64) || defined(Q_PROCESSOR_IA64))
+#if defined(Q_CC_MSVC) && (defined(Q_PROCESSOR_X86_64) || defined(Q_PROCESSOR_IA64)) && !QT_HAS_BUILTIN(__builtin_uadd_overflow)
#pragma intrinsic(_umul128)
template <> inline bool mul_overflow(quint64 v1, quint64 v2, quint64 *r)
{
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index d98f61b990..9135d1a23c 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -108,7 +108,9 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate()
currentIndexSet(false),
wrapItemText(false),
delayedPendingLayout(true),
- moveCursorUpdatedView(false)
+ moveCursorUpdatedView(false),
+ verticalScrollModeSet(false),
+ horizontalScrollModeSet(false)
{
keyboardInputTime.invalidate();
}
@@ -137,6 +139,9 @@ void QAbstractItemViewPrivate::init()
viewport->setBackgroundRole(QPalette::Base);
q->setAttribute(Qt::WA_InputMethodEnabled);
+
+ verticalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, q, 0));
+ horizontalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, q, 0));
}
void QAbstractItemViewPrivate::setHoverIndex(const QPersistentModelIndex &index)
@@ -1237,12 +1242,14 @@ QAbstractItemView::EditTriggers QAbstractItemView::editTriggers() const
\brief how the view scrolls its contents in the vertical direction
This property controls how the view scroll its contents vertically.
- Scrolling can be done either per pixel or per item.
+ Scrolling can be done either per pixel or per item. Its default value
+ comes from the style via the QStyle::SH_ItemView_ScrollMode style hint.
*/
void QAbstractItemView::setVerticalScrollMode(ScrollMode mode)
{
Q_D(QAbstractItemView);
+ d->verticalScrollModeSet = true;
if (mode == d->verticalScrollMode)
return;
QModelIndex topLeft = indexAt(QPoint(0, 0));
@@ -1261,18 +1268,27 @@ QAbstractItemView::ScrollMode QAbstractItemView::verticalScrollMode() const
return d->verticalScrollMode;
}
+void QAbstractItemView::resetVerticalScrollMode()
+{
+ auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, this, 0));
+ setVerticalScrollMode(sm);
+ d_func()->verticalScrollModeSet = false;
+}
+
/*!
\since 4.2
\property QAbstractItemView::horizontalScrollMode
\brief how the view scrolls its contents in the horizontal direction
This property controls how the view scroll its contents horizontally.
- Scrolling can be done either per pixel or per item.
+ Scrolling can be done either per pixel or per item. Its default value
+ comes from the style via the QStyle::SH_ItemView_ScrollMode style hint.
*/
void QAbstractItemView::setHorizontalScrollMode(ScrollMode mode)
{
Q_D(QAbstractItemView);
+ d->horizontalScrollModeSet = true;
if (mode == d->horizontalScrollMode)
return;
d->horizontalScrollMode = mode;
@@ -1289,6 +1305,13 @@ QAbstractItemView::ScrollMode QAbstractItemView::horizontalScrollMode() const
return d->horizontalScrollMode;
}
+void QAbstractItemView::resetHorizontalScrollMode()
+{
+ auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, this, 0));
+ setHorizontalScrollMode(sm);
+ d_func()->horizontalScrollModeSet = false;
+}
+
#ifndef QT_NO_DRAGANDDROP
/*!
\since 4.2
@@ -1627,6 +1650,10 @@ bool QAbstractItemView::event(QEvent *event)
break;
case QEvent::StyleChange:
doItemsLayout();
+ if (!d->verticalScrollModeSet)
+ resetVerticalScrollMode();
+ if (!d->horizontalScrollModeSet)
+ resetHorizontalScrollMode();
break;
case QEvent::FocusOut:
d->checkPersistentEditorFocus();
diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h
index fb1d222676..b8d386f234 100644
--- a/src/widgets/itemviews/qabstractitemview.h
+++ b/src/widgets/itemviews/qabstractitemview.h
@@ -75,8 +75,8 @@ class Q_WIDGETS_EXPORT QAbstractItemView : public QAbstractScrollArea
Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
- Q_PROPERTY(ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode)
- Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode WRITE setHorizontalScrollMode)
+ Q_PROPERTY(ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode RESET resetVerticalScrollMode)
+ Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode WRITE setHorizontalScrollMode RESET resetHorizontalScrollMode)
public:
enum SelectionMode {
@@ -147,9 +147,11 @@ public:
void setVerticalScrollMode(ScrollMode mode);
ScrollMode verticalScrollMode() const;
+ void resetVerticalScrollMode();
void setHorizontalScrollMode(ScrollMode mode);
ScrollMode horizontalScrollMode() const;
+ void resetHorizontalScrollMode();
void setAutoScroll(bool enable);
bool hasAutoScroll() const;
diff --git a/src/widgets/itemviews/qabstractitemview_p.h b/src/widgets/itemviews/qabstractitemview_p.h
index 4ba24a2786..a3af79abcb 100644
--- a/src/widgets/itemviews/qabstractitemview_p.h
+++ b/src/widgets/itemviews/qabstractitemview_p.h
@@ -461,6 +461,10 @@ public:
mutable bool delayedPendingLayout;
bool moveCursorUpdatedView;
+ // Whether scroll mode has been explicitly set or its value come from SH_ItemView_ScrollMode
+ bool verticalScrollModeSet;
+ bool horizontalScrollModeSet;
+
private:
mutable QBasicTimer delayedLayout;
mutable QBasicTimer fetchMoreTimer;
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 17c2ea2ba8..c28a70e3f9 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -5215,6 +5215,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
case SH_Splitter_OpaqueResize:
ret = true;
break;
+ case SH_ItemView_ScrollMode:
+ ret = QAbstractItemView::ScrollPerItem;
+ break;
default:
ret = 0;
break;
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 009cc1b1b0..74554f6d3d 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -3043,6 +3043,9 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
}
break;
+ case SH_ItemView_ScrollMode:
+ ret = QAbstractItemView::ScrollPerPixel;
+ break;
default:
ret = QCommonStyle::styleHint(sh, opt, w, hret);
break;
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp
index 34d5b49ee1..26bb227e29 100644
--- a/src/widgets/styles/qstyle.cpp
+++ b/src/widgets/styles/qstyle.cpp
@@ -1978,6 +1978,10 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
tab is changed while dragging over the tabbar, in milliseconds. This
enum value has been introduced in Qt 5.4
+ \value SH_ItemView_ScrollMode The default vertical and horizontal scroll mode as specified
+ by the style. Can be overridden with QAbstractItemView::setVerticalScrollMode() and
+ QAbstractItemView::setHorizontalScrollMode(). This enum value has been introduced in Qt 5.7.
+
\sa styleHint()
*/
diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h
index 425acc8301..0f9c9379f5 100644
--- a/src/widgets/styles/qstyle.h
+++ b/src/widgets/styles/qstyle.h
@@ -732,6 +732,7 @@ public:
SH_Menu_SubMenuSloppyCloseTimeout,
SH_Menu_SubMenuResetWhenReenteringParent,
SH_Menu_SubMenuDontStartSloppyOnLeave,
+ SH_ItemView_ScrollMode,
// Add new style hint values here
SH_CustomBase = 0xf0000000