summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-02-17 17:51:49 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2016-02-17 19:57:54 +0000
commit86c5a337e3b123f2e41c8b15b416f39655519acd (patch)
treeefa0f720a190889b3d31ddbd07cee0495b8a15d4 /src
parent47ca3f78139ad51a5018dcdad27fa5caf817f08d (diff)
parent6620045fcaada61a2897195f32c0ee35beebc37b (diff)
Merge "Merge dev into 5.7" into refs/staging/5.7
Diffstat (limited to 'src')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp23
-rw-r--r--src/corelib/global/qglobal.cpp43
-rw-r--r--src/corelib/global/qglobal.h60
-rw-r--r--src/corelib/io/qfileselector.cpp1
-rw-r--r--src/corelib/io/qtextstream.cpp5
-rw-r--r--src/corelib/itemmodels/qstringlistmodel.cpp8
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.cpp2
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp46
-rw-r--r--src/corelib/kernel/qmetaobject.cpp10
-rw-r--r--src/corelib/kernel/qobject.cpp16
-rw-r--r--src/corelib/thread/qthread.cpp2
-rw-r--r--src/corelib/thread/qthread_p.h11
-rw-r--r--src/corelib/tools/qhash.cpp13
-rw-r--r--src/corelib/tools/qhash.h35
-rw-r--r--src/corelib/tools/qrect.cpp28
-rw-r--r--src/corelib/tools/qrect.h9
-rw-r--r--src/corelib/xml/qxmlstream.h70
-rw-r--r--src/gui/image/qbitmap.cpp4
-rw-r--r--src/gui/image/qbitmap.h7
-rw-r--r--src/gui/image/qicon.cpp3
-rw-r--r--src/gui/kernel/qsurfaceformat.cpp7
-rw-r--r--src/gui/painting/qregion.cpp10
-rw-r--r--src/gui/painting/qregion.h2
-rw-r--r--src/gui/text/qglyphrun.cpp5
-rw-r--r--src/gui/text/qtextobject.cpp4
-rw-r--r--src/gui/text/qtextobject.h10
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp33
-rw-r--r--src/network/access/qspdyprotocolhandler.cpp2
-rw-r--r--src/network/ssl/qsslconfiguration.cpp5
-rw-r--r--src/opengl/qgl.cpp5
-rw-r--r--src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp5
-rw-r--r--src/platformsupport/input/libinput/qlibinputpointer.cpp5
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenu.mm2
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenuloader.mm2
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm12
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.h2
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp13
-rw-r--r--src/widgets/doc/snippets/javastyle.cpp3
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp10
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.cpp23
-rw-r--r--src/widgets/graphicsview/qgraphicswidget_p.cpp3
-rw-r--r--src/widgets/itemviews/qcolumnview.cpp2
-rw-r--r--src/widgets/itemviews/qlistview.cpp11
-rw-r--r--src/widgets/itemviews/qtableview.cpp5
-rw-r--r--src/widgets/itemviews/qtreeview.cpp38
-rw-r--r--src/widgets/styles/qandroidstyle.cpp29
-rw-r--r--src/widgets/styles/qcommonstyle.cpp4
-rw-r--r--src/widgets/styles/qfusionstyle.cpp8
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm5
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp2
-rw-r--r--src/widgets/styles/qwindowsmobilestyle.cpp2
-rw-r--r--src/widgets/styles/qwindowsstyle.cpp2
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp2
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp2
-rw-r--r--src/widgets/widgets/qcheckbox.cpp5
-rw-r--r--src/widgets/widgets/qgroupbox.cpp6
-rw-r--r--src/widgets/widgets/qlineedit.cpp14
-rw-r--r--src/widgets/widgets/qmainwindow.cpp10
-rw-r--r--src/widgets/widgets/qmainwindowlayout.cpp5
-rw-r--r--src/widgets/widgets/qmdiarea.cpp5
-rw-r--r--src/widgets/widgets/qmdisubwindow.cpp15
-rw-r--r--src/widgets/widgets/qradiobutton.cpp5
62 files changed, 479 insertions, 257 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
index ccf8399e0d..ba02f75963 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -568,6 +568,29 @@ struct A : public B {
template<> class QTypeInfo<A> : public QTypeInfoMerger<A, B, C, D> {};
//! [51]
+//! [52]
+ struct Foo {
+ void overloadedFunction();
+ void overloadedFunction(int, QString);
+ };
+ ... qOverload<>(&Foo:overloadedFunction)
+ ... qOverload<int, QString>(&Foo:overloadedFunction)
+//! [52]
+
+//! [53]
+ ... QOverload<>::of(&Foo:overloadedFunction)
+ ... QOverload<int, QString>::of(&Foo:overloadedFunction)
+//! [53]
+
+//! [54]
+ struct Foo {
+ void overloadedFunction(int, QString);
+ void overloadedFunction(int, QString) const;
+ };
+ ... qConstOverload<>(&Foo:overloadedFunction)
+ ... qNonConstOverload<int, QString>(&Foo:overloadedFunction)
+//! [54]
+
//! [qlikely]
// the condition inside the "if" will be successful most of the times
for (int i = 1; i <= 365; i++) {
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index a7ed29d859..e4fa0f7391 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -921,6 +921,49 @@ Q_STATIC_ASSERT_X(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined in
\sa qMin(), qMax()
*/
+/*! \fn auto qOverload(T functionPointer)
+ \relates <QtGlobal>
+ \since 5.7
+
+ qOverload() returns a pointer to an overloaded function. The template
+ parameter is the list of the argument types of the function.
+ \a functionPointer is the pointer to the (member) function:
+
+ \snippet code/src_corelib_global_qglobal.cpp 52
+
+ If a member function is also const-overladed \l qConstOverload and
+ \l qNonConstOverload needs to be used.
+
+ qOverload() needs C++14 enabled. In C++11 only code the helper
+ classes QOverload, QConstOverload, and QNonConstOverload could be used directly:
+
+ \snippet code/src_corelib_global_qglobal.cpp 53
+
+ \sa qConstOverload(), qNonConstOverload()
+*/
+
+/*! \fn auto qConstOverload(T memberFunctionPointer)
+ \relates <QtGlobal>
+ \since 5.7
+
+ qConstOverload() returns a pointer to an constant member function:
+
+ \snippet code/src_corelib_global_qglobal.cpp 54
+
+ \sa qOverload, qNonConstOverload
+*/
+
+/*! \fn auto qNonConstOverload(T memberFunctionPointer)
+ \relates <QtGlobal>
+ \since 5.7
+
+ qNonConstOverload() eturns a pointer to an non constant member function:
+
+ \snippet code/src_corelib_global_qglobal.cpp 54
+
+ \sa qOverload, qNonConstOverload
+*/
+
/*!
\macro QT_VERSION_CHECK
\relates <QtGlobal>
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 69840996dc..d607b04192 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1018,6 +1018,66 @@ Q_CORE_EXPORT QString qtTrId(const char *id, int n = -1);
{ return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; }
#endif
+
+#ifdef Q_QDOC
+
+// Just for documentation generation
+auto qOverload(T functionPointer);
+auto qConstOverload(T memberFunctionPointer);
+auto qNonConstOverload(T memberFunctionPointer);
+
+#elif defined(Q_COMPILER_VARIADIC_TEMPLATES)
+
+template <typename... Args>
+struct QNonConstOverload
+{
+ template <typename R, typename T>
+ Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
+ { return ptr; }
+
+ template <typename R, typename T>
+ static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
+ { return ptr; }
+};
+
+template <typename... Args>
+struct QConstOverload
+{
+ template <typename R, typename T>
+ Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr)
+ { return ptr; }
+
+ template <typename R, typename T>
+ static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr)
+ { return ptr; }
+};
+
+template <typename... Args>
+struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
+{
+ using QConstOverload<Args...>::of;
+ using QConstOverload<Args...>::operator();
+ using QNonConstOverload<Args...>::of;
+ using QNonConstOverload<Args...>::operator();
+
+ template <typename R>
+ Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
+ { return ptr; }
+
+ template <typename R>
+ static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
+ { return ptr; }
+};
+
+#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14
+template <typename... Args> Q_CONSTEXPR QOverload<Args...> qOverload Q_DECL_UNUSED = {};
+template <typename... Args> Q_CONSTEXPR QConstOverload<Args...> qConstOverload Q_DECL_UNUSED = {};
+template <typename... Args> Q_CONSTEXPR QNonConstOverload<Args...> qNonConstOverload Q_DECL_UNUSED = {};
+#endif
+
+#endif
+
+
class QByteArray;
Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value);
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp
index 7a9a4b581c..4ac12fc9ea 100644
--- a/src/corelib/io/qfileselector.cpp
+++ b/src/corelib/io/qfileselector.cpp
@@ -396,6 +396,7 @@ void QFileSelectorPrivate::addStatics(const QStringList &statics)
{
QMutexLocker locker(&sharedDataMutex);
sharedData->preloadedStatics << statics;
+ sharedData->staticSelectors.clear();
}
QT_END_NAMESPACE
diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp
index 9d3689736c..bc4a5fa538 100644
--- a/src/corelib/io/qtextstream.cpp
+++ b/src/corelib/io/qtextstream.cpp
@@ -3130,10 +3130,7 @@ void QTextStream::setGenerateByteOrderMark(bool generate)
{
Q_D(QTextStream);
if (d->writeBuffer.isEmpty()) {
- if (generate)
- d->writeConverterState.flags &= ~QTextCodec::IgnoreHeader;
- else
- d->writeConverterState.flags |= QTextCodec::IgnoreHeader;
+ d->writeConverterState.flags.setFlag(QTextCodec::IgnoreHeader, !generate);
}
}
diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp
index 61323ad9c7..1a1b2b9fb6 100644
--- a/src/corelib/itemmodels/qstringlistmodel.cpp
+++ b/src/corelib/itemmodels/qstringlistmodel.cpp
@@ -237,8 +237,8 @@ bool QStringListModel::removeRows(int row, int count, const QModelIndex &parent)
beginRemoveRows(QModelIndex(), row, row + count - 1);
- for (int r = 0; r < count; ++r)
- lst.removeAt(row);
+ const auto it = lst.begin() + row;
+ lst.erase(it, it + count);
endRemoveRows();
@@ -274,8 +274,8 @@ void QStringListModel::sort(int, Qt::SortOrder order)
std::sort(list.begin(), list.end(), decendingLessThan);
lst.clear();
- QVector<int> forwarding(list.count());
- for (int i = 0; i < list.count(); ++i) {
+ QVector<int> forwarding(lstCount);
+ for (int i = 0; i < lstCount; ++i) {
lst.append(list.at(i).first);
forwarding[list.at(i).second] = i;
}
diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp
index 31369f9a09..907b3ccf1f 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.cpp
+++ b/src/corelib/kernel/qabstracteventdispatcher.cpp
@@ -458,7 +458,7 @@ bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, vo
if (!d->eventFilters.isEmpty()) {
// Raise the loopLevel so that deleteLater() calls in or triggered
// by event_filter() will be processed from the main event loop.
- QScopedLoopLevelCounter loopLevelCounter(d->threadData);
+ QScopedScopeLevelCounter scopeLevelCounter(d->threadData);
for (int i = 0; i < d->eventFilters.size(); ++i) {
QAbstractNativeEventFilter *filter = d->eventFilters.at(i);
if (!filter)
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 60f3dc0db0..42bda25be5 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -980,7 +980,7 @@ bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event)
// call overhead.
QObjectPrivate *d = receiver->d_func();
QThreadData *threadData = d->threadData;
- QScopedLoopLevelCounter loopLevelCounter(threadData);
+ QScopedScopeLevelCounter scopeLevelCounter(threadData);
if (!selfRequired)
return doNotify(receiver, event);
return self->notify(receiver, event);
@@ -1193,6 +1193,9 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags)
*/
void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime)
{
+ // ### Qt 6: consider splitting this method into a public and a private
+ // one, so that a user-invoked processEvents can be detected
+ // and handled properly.
QThreadData *data = QThreadData::current();
if (!data->hasEventDispatcher())
return;
@@ -1396,8 +1399,24 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority)
if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) {
// remember the current running eventloop for DeferredDelete
- // events posted in the receiver's thread
- static_cast<QDeferredDeleteEvent *>(event)->level = data->loopLevel;
+ // events posted in the receiver's thread.
+
+ // Events sent by non-Qt event handlers (such as glib) may not
+ // have the scopeLevel set correctly. The scope level makes sure that
+ // code like this:
+ // foo->deleteLater();
+ // qApp->processEvents(); // without passing QEvent::DeferredDelete
+ // will not cause "foo" to be deleted before returning to the event loop.
+
+ // If the scope level is 0 while loopLevel != 0, we are called from a
+ // non-conformant code path, and our best guess is that the scope level
+ // should be 1. (Loop level 0 is special: it means that no event loops
+ // are running.)
+ int loopLevel = data->loopLevel;
+ int scopeLevel = data->scopeLevel;
+ if (scopeLevel == 0 && loopLevel != 0)
+ scopeLevel = 1;
+ static_cast<QDeferredDeleteEvent *>(event)->level = loopLevel + scopeLevel;
}
// delete the event on exceptions to protect against memory leaks till the event is
@@ -1474,6 +1493,9 @@ bool QCoreApplication::compressEvent(QEvent *event, QObject *receiver, QPostEven
*/
void QCoreApplication::sendPostedEvents(QObject *receiver, int event_type)
{
+ // ### Qt 6: consider splitting this method into a public and a private
+ // one, so that a user-invoked sendPostedEvents can be detected
+ // and handled properly.
QThreadData *data = QThreadData::current();
QCoreApplicationPrivate::sendPostedEvents(receiver, event_type, data);
@@ -1565,15 +1587,19 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type
}
if (pe.event->type() == QEvent::DeferredDelete) {
- // DeferredDelete events are only sent when we are explicitly asked to
- // (s.a. QEvent::DeferredDelete), and then only if the event loop that
- // posted the event has returned.
- int loopLevel = static_cast<QDeferredDeleteEvent *>(pe.event)->loopLevel();
+ // DeferredDelete events are sent either
+ // 1) when the event loop that posted the event has returned; or
+ // 2) if explicitly requested (with QEvent::DeferredDelete) for
+ // events posted by the current event loop; or
+ // 3) if the event was posted before the outermost event loop.
+
+ int eventLevel = static_cast<QDeferredDeleteEvent *>(pe.event)->loopLevel();
+ int loopLevel = data->loopLevel + data->scopeLevel;
const bool allowDeferredDelete =
- (loopLevel > data->loopLevel
- || (!loopLevel && data->loopLevel > 0)
+ (eventLevel > loopLevel
+ || (!eventLevel && loopLevel > 0)
|| (event_type == QEvent::DeferredDelete
- && loopLevel == data->loopLevel));
+ && eventLevel == loopLevel));
if (!allowDeferredDelete) {
// cannot send deferred delete
if (!event_type && !receiver) {
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index c5a6875a77..1c426225a5 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -333,14 +333,8 @@ const char *QMetaObject::className() const
*/
QObject *QMetaObject::cast(QObject *obj) const
{
- if (obj) {
- const QMetaObject *m = obj->metaObject();
- do {
- if (m == this)
- return obj;
- } while ((m = m->d.superdata));
- }
- return 0;
+ // ### Qt 6: inline
+ return const_cast<QObject*>(cast(const_cast<const QObject*>(obj)));
}
/*!
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index dea8c200ef..e3e536d7e1 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -3713,8 +3713,6 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i
if (receiverInSameThread) {
sw.switchSender(receiver, sender, signal_index);
}
- const QObjectPrivate::StaticMetaCallFunction callFunction = c->callFunction;
- const int method_relative = c->method_relative;
if (c->isSlotObject) {
c->slotObj->ref();
QScopedPointer<QtPrivate::QSlotObjectBase, QSlotObjectBaseDeleter> obj(c->slotObj);
@@ -3727,10 +3725,12 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i
obj.reset();
locker.relock();
- } else if (callFunction && c->method_offset <= receiver->metaObject()->methodOffset()) {
+ } else if (c->callFunction && c->method_offset <= receiver->metaObject()->methodOffset()) {
//we compare the vtable to make sure we are not in the destructor of the object.
- locker.unlock();
const int methodIndex = c->method();
+ const int method_relative = c->method_relative;
+ const auto callFunction = c->callFunction;
+ locker.unlock();
if (qt_signal_spy_callback_set.slot_begin_callback != 0)
qt_signal_spy_callback_set.slot_begin_callback(receiver, methodIndex, argv ? argv : empty_argv);
@@ -3740,7 +3740,7 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i
qt_signal_spy_callback_set.slot_end_callback(receiver, methodIndex);
locker.relock();
} else {
- const int method = method_relative + c->method_offset;
+ const int method = c->method_relative + c->method_offset;
locker.unlock();
if (qt_signal_spy_callback_set.slot_begin_callback != 0) {
@@ -4538,6 +4538,8 @@ void qDeleteInEventHandler(QObject *o)
make sure to declare the argument type with Q_DECLARE_METATYPE
+ Overloaded functions can be resolved with help of \l qOverload.
+
\note The number of arguments in the signal or slot are limited to 6 if
the compiler does not support C++11 variadic templates.
*/
@@ -4573,6 +4575,8 @@ void qDeleteInEventHandler(QObject *o)
However, you should take care that any objects used within the functor
are still alive when the signal is emitted.
+ Overloaded functions can be resolved with help of \l qOverload.
+
\note If the compiler does not support C++11 variadic templates, the number
of arguments in the signal or slot are limited to 6, and the functor object
must not have an overloaded or templated operator().
@@ -4612,6 +4616,8 @@ void qDeleteInEventHandler(QObject *o)
However, you should take care that any objects used within the functor
are still alive when the signal is emitted.
+ Overloaded functions can be resolved with help of \l qOverload.
+
\note If the compiler does not support C++11 variadic templates, the number
of arguments in the signal or slot are limited to 6, and the functor object
must not have an overloaded or templated operator().
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index f689ad4d21..48b94abae5 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE
*/
QThreadData::QThreadData(int initialRefCount)
- : _ref(initialRefCount), loopLevel(0), thread(0), threadId(0),
+ : _ref(initialRefCount), loopLevel(0), scopeLevel(0), thread(0), threadId(0),
eventDispatcher(0),
quitNow(false), canWait(true), isAdopted(false), requiresCoreApplication(true)
{
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 39a41f1ef4..5f7d01f50f 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -280,6 +280,7 @@ private:
public:
int loopLevel;
+ int scopeLevel;
QStack<QEventLoop *> eventLoops;
QPostEventList postEventList;
@@ -295,15 +296,15 @@ public:
bool requiresCoreApplication;
};
-class QScopedLoopLevelCounter
+class QScopedScopeLevelCounter
{
QThreadData *threadData;
public:
- inline QScopedLoopLevelCounter(QThreadData *threadData)
+ inline QScopedScopeLevelCounter(QThreadData *threadData)
: threadData(threadData)
- { ++threadData->loopLevel; }
- inline ~QScopedLoopLevelCounter()
- { --threadData->loopLevel; }
+ { ++threadData->scopeLevel; }
+ inline ~QScopedScopeLevelCounter()
+ { --threadData->scopeLevel; }
};
// thread wrapper for the main() thread
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index c1a1b9715f..b49c9d683a 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -1803,6 +1803,19 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
returns \c false.
*/
+/*! \fn QPair<iterator, iterator> QHash::equal_range(const Key &key)
+ \since 5.7
+
+ Returns a pair of iterators delimiting the range of values \c{[first, second)}, that
+ are stored under \a key. If the range is empty then both iterators will be equal to end().
+*/
+
+/*!
+ \fn QPair<const_iterator, const_iterator> QHash::equal_range(const Key &key) const
+ \overload
+ \since 5.7
+*/
+
/*! \typedef QHash::ConstIterator
Qt-style synonym for QHash::const_iterator.
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 819631932b..5e3016d313 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -458,6 +458,8 @@ public:
inline key_iterator keyBegin() const { return key_iterator(begin()); }
inline key_iterator keyEnd() const { return key_iterator(end()); }
+ QPair<iterator, iterator> equal_range(const Key &key);
+ QPair<const_iterator, const_iterator> equal_range(const Key &key) const Q_DECL_NOTHROW;
iterator erase(iterator it) { return erase(const_iterator(it.i)); }
iterator erase(const_iterator it);
@@ -945,6 +947,39 @@ Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash &other) const
}
template <class Key, class T>
+QPair<typename QHash<Key, T>::iterator, typename QHash<Key, T>::iterator> QHash<Key, T>::equal_range(const Key &akey)
+{
+ detach();
+ auto pair = qAsConst(*this).equal_range(akey);
+ return qMakePair(iterator(pair.first.i), iterator(pair.second.i));
+}
+
+template <class Key, class T>
+QPair<typename QHash<Key, T>::const_iterator, typename QHash<Key, T>::const_iterator> QHash<Key, T>::equal_range(const Key &akey) const Q_DECL_NOTHROW
+{
+ uint h;
+ Node *node = *findNode(akey, &h);
+ const_iterator firstIt = const_iterator(node);
+
+ if (node != e) {
+ // equal keys must hash to the same value and so they all
+ // end up in the same bucket. So we can use node->next,
+ // which only works within a bucket, instead of (out-of-line)
+ // QHashData::nextNode()
+ while (node->next != e && node->next->key == akey)
+ node = node->next;
+
+ // 'node' may be the last node in the bucket. To produce the end iterator, we'd
+ // need to enter the next bucket in this case, so we need to use
+ // QHashData::nextNode() here, which, unlike node->next above, can move between
+ // buckets.
+ node = concrete(QHashData::nextNode(reinterpret_cast<QHashData::Node *>(node)));
+ }
+
+ return qMakePair(firstIt, const_iterator(node));
+}
+
+template <class Key, class T>
class QMultiHash : public QHash<Key, T>
{
public:
diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp
index 6215c534f8..4b6183646b 100644
--- a/src/corelib/tools/qrect.cpp
+++ b/src/corelib/tools/qrect.cpp
@@ -706,6 +706,20 @@ QRect QRect::normalized() const Q_DECL_NOTHROW
current position.
*/
+/*!
+ \fn QRect QRect::transposed() const
+ \since 5.7
+
+ Returns a copy of the rectangle that has its width and height
+ exchanged:
+
+ \code
+ QRect r = {15, 51, 42, 24};
+ r = r.transposed(); // r == {15, 51, 24, 42}
+ \endcode
+
+ \sa QSize::transposed()
+*/
/*!
\fn void QRect::setRect(int x, int y, int width, int height)
@@ -1842,6 +1856,20 @@ QRectF QRectF::normalized() const Q_DECL_NOTHROW
current position.
*/
+/*!
+ \fn QRectF QRectF::transposed() const
+ \since 5.7
+
+ Returns a copy of the rectangle that has its width and height
+ exchanged:
+
+ \code
+ QRectF r = {1.5, 5.1, 4.2, 2.4};
+ r = r.transposed(); // r == {1.5, 5.1, 2.4, 4.2}
+ \endcode
+
+ \sa QSizeF::transposed()
+*/
/*!
\fn void QRectF::setRect(qreal x, qreal y, qreal width, qreal height)
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index e90bb8a21e..31fdc8ce6b 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -102,6 +102,7 @@ public:
Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p) Q_DECL_NOTHROW;
Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRect transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t) Q_DECL_NOTHROW;
Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p) Q_DECL_NOTHROW;
@@ -284,6 +285,9 @@ Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const Q_DECL_NOT
Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const Q_DECL_NOTHROW
{ return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
+Q_DECL_CONSTEXPR inline QRect QRect::transposed() const Q_DECL_NOTHROW
+{ return QRect(topLeft(), size().transposed()); }
+
Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay) Q_DECL_NOTHROW
{
x2 += ax - x1;
@@ -551,6 +555,8 @@ public:
Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRectF transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y) Q_DECL_NOTHROW;
Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p) Q_DECL_NOTHROW;
@@ -751,6 +757,9 @@ Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const Q_DE
Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const Q_DECL_NOTHROW
{ return QRectF(xp + p.x(), yp + p.y(), w, h); }
+Q_DECL_CONSTEXPR inline QRectF QRectF::transposed() const Q_DECL_NOTHROW
+{ return QRectF(topLeft(), size().transposed()); }
+
Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
{
*ax = this->xp;
diff --git a/src/corelib/xml/qxmlstream.h b/src/corelib/xml/qxmlstream.h
index 765b3eeaca..bf6ddefcdd 100644
--- a/src/corelib/xml/qxmlstream.h
+++ b/src/corelib/xml/qxmlstream.h
@@ -99,13 +99,16 @@ class QXmlStreamReaderPrivate;
class QXmlStreamAttributes;
class Q_CORE_EXPORT QXmlStreamAttribute {
QXmlStreamStringRef m_name, m_namespaceUri, m_qualifiedName, m_value;
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void *reserved;
+#endif
uint m_isDefault : 1;
friend class QXmlStreamReaderPrivate;
friend class QXmlStreamAttributes;
public:
QXmlStreamAttribute();
QXmlStreamAttribute(const QString &qualifiedName, const QString &value);
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value);
QXmlStreamAttribute(const QXmlStreamAttribute &);
#ifdef Q_COMPILER_RVALUE_REFS
@@ -132,6 +135,8 @@ public:
#endif
QXmlStreamAttribute& operator=(const QXmlStreamAttribute &);
~QXmlStreamAttribute();
+#endif // < Qt 6
+
inline QStringRef namespaceUri() const { return m_namespaceUri; }
inline QStringRef name() const { return m_name; }
inline QStringRef qualifiedName() const { return m_qualifiedName; }
@@ -185,15 +190,34 @@ public:
class Q_CORE_EXPORT QXmlStreamNamespaceDeclaration {
QXmlStreamStringRef m_prefix, m_namespaceUri;
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void *reserved;
+#endif
friend class QXmlStreamReaderPrivate;
public:
QXmlStreamNamespaceDeclaration();
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QXmlStreamNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &);
+ QXmlStreamNamespaceDeclaration(QXmlStreamNamespaceDeclaration &&other) Q_DECL_NOTHROW // = default
+ : m_prefix(std::move(other.m_prefix)),
+ m_namespaceUri(std::move(other.m_namespaceUri)),
+ reserved(other.reserved)
+ {
+ other.reserved = nullptr;
+ }
+ QXmlStreamNamespaceDeclaration &operator=(QXmlStreamNamespaceDeclaration &&other) Q_DECL_NOTHROW // = default
+ {
+ m_prefix = std::move(other.m_prefix);
+ m_namespaceUri = std::move(other.m_namespaceUri);
+ qSwap(reserved, other.reserved);
+ return *this;
+ }
QXmlStreamNamespaceDeclaration(const QString &prefix, const QString &namespaceUri);
~QXmlStreamNamespaceDeclaration();
QXmlStreamNamespaceDeclaration& operator=(const QXmlStreamNamespaceDeclaration &);
+#endif // < Qt 6
+
inline QStringRef prefix() const { return m_prefix; }
inline QStringRef namespaceUri() const { return m_namespaceUri; }
inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const {
@@ -208,14 +232,35 @@ typedef QVector<QXmlStreamNamespaceDeclaration> QXmlStreamNamespaceDeclarations;
class Q_CORE_EXPORT QXmlStreamNotationDeclaration {
QXmlStreamStringRef m_name, m_systemId, m_publicId;
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void *reserved;
+#endif
friend class QXmlStreamReaderPrivate;
public:
QXmlStreamNotationDeclaration();
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
~QXmlStreamNotationDeclaration();
QXmlStreamNotationDeclaration(const QXmlStreamNotationDeclaration &);
+ QXmlStreamNotationDeclaration(QXmlStreamNotationDeclaration &&other) Q_DECL_NOTHROW // = default
+ : m_name(std::move(other.m_name)),
+ m_systemId(std::move(other.m_systemId)),
+ m_publicId(std::move(other.m_publicId)),
+ reserved(other.reserved)
+ {
+ other.reserved = nullptr;
+ }
QXmlStreamNotationDeclaration& operator=(const QXmlStreamNotationDeclaration &);
+ QXmlStreamNotationDeclaration &operator=(QXmlStreamNotationDeclaration &&other) Q_DECL_NOTHROW // = default
+ {
+ m_name = std::move(other.m_name);
+ m_systemId = std::move(other.m_systemId);
+ m_publicId = std::move(other.m_publicId);
+ qSwap(reserved, other.reserved);
+ return *this;
+ }
+#endif // < Qt 6
+
inline QStringRef name() const { return m_name; }
inline QStringRef systemId() const { return m_systemId; }
inline QStringRef publicId() const { return m_publicId; }
@@ -232,14 +277,39 @@ typedef QVector<QXmlStreamNotationDeclaration> QXmlStreamNotationDeclarations;
class Q_CORE_EXPORT QXmlStreamEntityDeclaration {
QXmlStreamStringRef m_name, m_notationName, m_systemId, m_publicId, m_value;
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void *reserved;
+#endif
friend class QXmlStreamReaderPrivate;
public:
QXmlStreamEntityDeclaration();
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
~QXmlStreamEntityDeclaration();
QXmlStreamEntityDeclaration(const QXmlStreamEntityDeclaration &);
+ QXmlStreamEntityDeclaration(QXmlStreamEntityDeclaration &&other) Q_DECL_NOTHROW // = default
+ : m_name(std::move(other.m_name)),
+ m_notationName(std::move(other.m_notationName)),
+ m_systemId(std::move(other.m_systemId)),
+ m_publicId(std::move(other.m_publicId)),
+ m_value(std::move(other.m_value)),
+ reserved(other.reserved)
+ {
+ other.reserved = nullptr;
+ }
QXmlStreamEntityDeclaration& operator=(const QXmlStreamEntityDeclaration &);
+ QXmlStreamEntityDeclaration &operator=(QXmlStreamEntityDeclaration &&other) Q_DECL_NOTHROW // = default
+ {
+ m_name = std::move(other.m_name);
+ m_notationName = std::move(other.m_notationName);
+ m_systemId = std::move(other.m_systemId);
+ m_publicId = std::move(other.m_publicId);
+ m_value = std::move(other.m_value);
+ qSwap(reserved, other.reserved);
+ return *this;
+ }
+#endif // < Qt 6
+
inline QStringRef name() const { return m_name; }
inline QStringRef notationName() const { return m_notationName; }
inline QStringRef systemId() const { return m_systemId; }
diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp
index 54a4dc646b..e8405a6d11 100644
--- a/src/gui/image/qbitmap.cpp
+++ b/src/gui/image/qbitmap.cpp
@@ -196,6 +196,8 @@ QBitmap &QBitmap::operator=(const QPixmap &pixmap)
return *this;
}
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+
/*!
Destroys the bitmap.
*/
@@ -203,6 +205,8 @@ QBitmap::~QBitmap()
{
}
+#endif
+
/*!
\fn void QBitmap::swap(QBitmap &other)
\since 4.8
diff --git a/src/gui/image/qbitmap.h b/src/gui/image/qbitmap.h
index 878aeaafa3..68727e74b5 100644
--- a/src/gui/image/qbitmap.h
+++ b/src/gui/image/qbitmap.h
@@ -55,7 +55,14 @@ public:
QBitmap(int w, int h);
explicit QBitmap(const QSize &);
explicit QBitmap(const QString &fileName, const char *format = Q_NULLPTR);
+ // ### Qt 6: don't inherit QPixmap
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ QBitmap(const QBitmap &other) : QPixmap(other) {}
+ // QBitmap(QBitmap &&other) : QPixmap(std::move(other)) {} // QPixmap doesn't, yet, have a move ctor
+ QBitmap &operator=(const QBitmap &other) { QPixmap::operator=(other); return *this; }
+ QBitmap &operator=(QBitmap &&other) Q_DECL_NOTHROW { QPixmap::operator=(std::move(other)); return *this; }
~QBitmap();
+#endif
QBitmap &operator=(const QPixmap &);
inline void swap(QBitmap &other) { QPixmap::swap(other); } // prevent QBitmap<->QPixmap swaps
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 2b148383b0..620cbde25d 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -51,6 +51,7 @@
#include "qvariant.h"
#include "qcache.h"
#include "qdebug.h"
+#include "qdir.h"
#include "qpalette.h"
#include "qmath.h"
@@ -1171,6 +1172,8 @@ QIcon QIcon::fromTheme(const QString &name)
if (qtIconCache()->contains(name)) {
icon = *qtIconCache()->object(name);
+ } else if (QDir::isAbsolutePath(name)) {
+ return QIcon(name);
} else {
QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme();
bool hasUserTheme = QIconLoader::instance()->hasUserTheme();
diff --git a/src/gui/kernel/qsurfaceformat.cpp b/src/gui/kernel/qsurfaceformat.cpp
index 83481692ff..d7dc0faceb 100644
--- a/src/gui/kernel/qsurfaceformat.cpp
+++ b/src/gui/kernel/qsurfaceformat.cpp
@@ -282,11 +282,8 @@ QSurfaceFormat::~QSurfaceFormat()
void QSurfaceFormat::setStereo(bool enable)
{
QSurfaceFormat::FormatOptions newOptions = d->opts;
- if (enable) {
- newOptions |= QSurfaceFormat::StereoBuffers;
- } else {
- newOptions &= ~QSurfaceFormat::StereoBuffers;
- }
+ newOptions.setFlag(QSurfaceFormat::StereoBuffers, enable);
+
if (int(newOptions) != int(d->opts)) {
detach();
d->opts = newOptions;
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index 5bfe681e73..d104f9ff5a 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -210,6 +210,16 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn QRegion::QRegion(QRegion &&other)
+ \since 5.7
+
+ Move-constructs a new region from region \a other.
+ After the call, \a other is null.
+
+ \sa isNull()
+*/
+
+/*!
\fn QRegion::QRegion(const QBitmap &bm)
Constructs a region from the bitmap \a bm.
diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h
index 94e2db2648..d66f80fcde 100644
--- a/src/gui/painting/qregion.h
+++ b/src/gui/painting/qregion.h
@@ -68,6 +68,8 @@ public:
QRegion(const QRect &r, RegionType t = Rectangle);
QRegion(const QPolygon &pa, Qt::FillRule fillRule = Qt::OddEvenFill);
QRegion(const QRegion &region);
+ QRegion(QRegion &&other) Q_DECL_NOTHROW
+ : d(other.d) { other.d = const_cast<QRegionData*>(&shared_empty); }
QRegion(const QBitmap &bitmap);
~QRegion();
QRegion &operator=(const QRegion &);
diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp
index 0988454410..bd44e11dce 100644
--- a/src/gui/text/qglyphrun.cpp
+++ b/src/gui/text/qglyphrun.cpp
@@ -414,10 +414,7 @@ void QGlyphRun::setFlag(GlyphRunFlag flag, bool enabled)
return;
detach();
- if (enabled)
- d->flags |= flag;
- else
- d->flags &= ~flag;
+ d->flags.setFlag(flag, enabled);
}
/*!
diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp
index 49cf35ecc0..a756549f3e 100644
--- a/src/gui/text/qtextobject.cpp
+++ b/src/gui/text/qtextobject.cpp
@@ -675,7 +675,7 @@ QTextFrame::iterator::iterator(QTextFrame *frame, int block, int begin, int end)
/*!
Copy constructor. Constructs a copy of the \a other iterator.
*/
-QTextFrame::iterator::iterator(const iterator &other)
+QTextFrame::iterator::iterator(const iterator &other) Q_DECL_NOTHROW
{
f = other.f;
b = other.b;
@@ -688,7 +688,7 @@ QTextFrame::iterator::iterator(const iterator &other)
Assigns \a other to this iterator and returns a reference to
this iterator.
*/
-QTextFrame::iterator &QTextFrame::iterator::operator=(const iterator &other)
+QTextFrame::iterator &QTextFrame::iterator::operator=(const iterator &other) Q_DECL_NOTHROW
{
f = other.f;
b = other.b;
diff --git a/src/gui/text/qtextobject.h b/src/gui/text/qtextobject.h
index 18df53945c..d3f6b3d0ac 100644
--- a/src/gui/text/qtextobject.h
+++ b/src/gui/text/qtextobject.h
@@ -148,10 +148,14 @@ public:
friend class QTextDocumentLayoutPrivate;
iterator(QTextFrame *frame, int block, int begin, int end);
public:
- iterator();
+ iterator(); // ### Qt 6: inline
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
- iterator(const iterator &o);
- iterator &operator=(const iterator &o);
+ iterator(const iterator &o) Q_DECL_NOTHROW; // = default
+ iterator &operator=(const iterator &o) Q_DECL_NOTHROW; // = default
+ iterator(iterator &&other) Q_DECL_NOTHROW // = default
+ { memcpy(this, &other, sizeof(iterator)); }
+ iterator &operator=(iterator &&other) Q_DECL_NOTHROW // = default
+ { memcpy(this, &other, sizeof(iterator)); return *this; }
#endif
QTextFrame *parentFrame() const { return f; }
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 072c5c9ff5..15a886c21d 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -261,15 +261,17 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
// check if Content-Length is provided
QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
if (uploadByteDevice) {
- if (request.contentLength() != -1 && uploadByteDevice->size() != -1) {
+ const qint64 contentLength = request.contentLength();
+ const qint64 uploadDeviceSize = uploadByteDevice->size();
+ if (contentLength != -1 && uploadDeviceSize != -1) {
// both values known, take the smaller one.
- request.setContentLength(qMin(uploadByteDevice->size(), request.contentLength()));
- } else if (request.contentLength() == -1 && uploadByteDevice->size() != -1) {
+ request.setContentLength(qMin(uploadDeviceSize, contentLength));
+ } else if (contentLength == -1 && uploadDeviceSize != -1) {
// content length not supplied by user, but the upload device knows it
- request.setContentLength(uploadByteDevice->size());
- } else if (request.contentLength() != -1 && uploadByteDevice->size() == -1) {
+ request.setContentLength(uploadDeviceSize);
+ } else if (contentLength != -1 && uploadDeviceSize == -1) {
// everything OK, the user supplied us the contentLength
- } else if (Q_UNLIKELY(request.contentLength() == -1 && uploadByteDevice->size() == -1)) {
+ } else if (Q_UNLIKELY(contentLength == -1 && uploadDeviceSize == -1)) {
qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given");
}
}
@@ -1113,11 +1115,12 @@ void QHttpNetworkConnectionPrivate::startHostInfoLookup()
#endif
QHostAddress temp;
if (temp.setAddress(lookupHost)) {
- if (temp.protocol() == QAbstractSocket::IPv4Protocol) {
+ const QAbstractSocket::NetworkLayerProtocol protocol = temp.protocol();
+ if (protocol == QAbstractSocket::IPv4Protocol) {
networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection);
return;
- } else if (temp.protocol() == QAbstractSocket::IPv6Protocol) {
+ } else if (protocol == QAbstractSocket::IPv6Protocol) {
networkLayerState = QHttpNetworkConnectionPrivate::IPv6;
QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection);
return;
@@ -1146,13 +1149,14 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(const QHostInfo &info)
return;
foreach (const QHostAddress &address, info.addresses()) {
- if (address.protocol() == QAbstractSocket::IPv4Protocol) {
+ const QAbstractSocket::NetworkLayerProtocol protocol = address.protocol();
+ if (protocol == QAbstractSocket::IPv4Protocol) {
if (!foundAddress) {
foundAddress = true;
delayIpv4 = false;
}
bIpv4 = true;
- } else if (address.protocol() == QAbstractSocket::IPv6Protocol) {
+ } else if (protocol == QAbstractSocket::IPv6Protocol) {
if (!foundAddress) {
foundAddress = true;
delayIpv4 = true;
@@ -1213,13 +1217,14 @@ void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup()
int timeout = 300;
#ifndef QT_NO_BEARERMANAGEMENT
if (networkSession) {
- if (networkSession->configuration().bearerType() == QNetworkConfiguration::Bearer2G)
+ const QNetworkConfiguration::BearerType bearerType = networkSession->configuration().bearerType();
+ if (bearerType == QNetworkConfiguration::Bearer2G)
timeout = 800;
- else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerCDMA2000)
+ else if (bearerType == QNetworkConfiguration::BearerCDMA2000)
timeout = 500;
- else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerWCDMA)
+ else if (bearerType == QNetworkConfiguration::BearerWCDMA)
timeout = 500;
- else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerHSPA)
+ else if (bearerType == QNetworkConfiguration::BearerHSPA)
timeout = 400;
}
#endif
diff --git a/src/network/access/qspdyprotocolhandler.cpp b/src/network/access/qspdyprotocolhandler.cpp
index d7ca49aa52..f3073dcd3c 100644
--- a/src/network/access/qspdyprotocolhandler.cpp
+++ b/src/network/access/qspdyprotocolhandler.cpp
@@ -476,7 +476,7 @@ QByteArray QSpdyProtocolHandler::composeHeader(const QHttpNetworkRequest &reques
// calculate additional headers first, because we need to know the size
// ### do not partially copy the list, but restrict the set header fields
// in QHttpNetworkConnection
- QList<QPair<QByteArray, QByteArray> > additionalHeaders;
+ QVector<QPair<QByteArray, QByteArray> > additionalHeaders;
for (int a = 0; a < request.header().count(); ++a) {
QByteArray key = request.header().at(a).first;
if (key == "Connection" || key == "Host" || key == "Keep-Alive"
diff --git a/src/network/ssl/qsslconfiguration.cpp b/src/network/ssl/qsslconfiguration.cpp
index 0cc08b9fcc..f9bb28e033 100644
--- a/src/network/ssl/qsslconfiguration.cpp
+++ b/src/network/ssl/qsslconfiguration.cpp
@@ -664,10 +664,7 @@ QList<QSslCertificate> QSslConfiguration::systemCaCertificates()
*/
void QSslConfiguration::setSslOption(QSsl::SslOption option, bool on)
{
- if (on)
- d->sslOptions |= option;
- else
- d->sslOptions &= ~option;
+ d->sslOptions.setFlag(option, on);
}
/*!
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index bf0a2f8dd7..a8409346ba 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -5553,10 +5553,7 @@ QSize QGLTexture::bindCompressedTexturePVR(const char *buf, int len)
// Set the invert flag for the texture. The "vertical flip"
// flag in PVR is the opposite sense to our sense of inversion.
- if ((pvrHeader->flags & PVR_VERTICAL_FLIP) != 0)
- options &= ~QGLContext::InvertedYBindOption;
- else
- options |= QGLContext::InvertedYBindOption;
+ options.setFlag(QGLContext::InvertedYBindOption, !(pvrHeader->flags & PVR_VERTICAL_FLIP));
return QSize(pvrHeader->width, pvrHeader->height);
}
diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
index ce9043c098..7f73a7ef94 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
+++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
@@ -266,10 +266,7 @@ void QEvdevMouseHandler::readMouseData()
case 0x11e: button = Qt::ExtraButton12; break;
case 0x11f: button = Qt::ExtraButton13; break;
}
- if (data->value)
- m_buttons |= button;
- else
- m_buttons &= ~button;
+ m_buttons.setFlag(button, data->value);
btnChanged = true;
} else if (data->type == EV_SYN && data->code == SYN_REPORT) {
if (btnChanged) {
diff --git a/src/platformsupport/input/libinput/qlibinputpointer.cpp b/src/platformsupport/input/libinput/qlibinputpointer.cpp
index 3476235d6b..d5a3a8b437 100644
--- a/src/platformsupport/input/libinput/qlibinputpointer.cpp
+++ b/src/platformsupport/input/libinput/qlibinputpointer.cpp
@@ -76,10 +76,7 @@ void QLibInputPointer::processButton(libinput_event_pointer *e)
case 0x11f: button = Qt::ExtraButton13; break;
}
- if (pressed)
- m_buttons |= button;
- else
- m_buttons &= ~button;
+ m_buttons.setFlag(button, pressed);
QWindowSystemInterface::handleMouseEvent(Q_NULLPTR, m_pos, m_pos, m_buttons, QGuiApplication::keyboardModifiers());
}
diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm
index 8091ba8465..8c576c7cbe 100644
--- a/src/plugins/platforms/cocoa/qcocoamenu.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenu.mm
@@ -128,7 +128,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuDelegate);
- (void) itemFired:(NSMenuItem*) item
{
QCocoaMenuItem *cocoaItem = reinterpret_cast<QCocoaMenuItem *>([item tag]);
- QScopedLoopLevelCounter loopLevelCounter(QGuiApplicationPrivate::instance()->threadData);
+ QScopedScopeLevelCounter scopeLevelCounter(QGuiApplicationPrivate::instance()->threadData);
QGuiApplicationPrivate::modifier_buttons = [QNSView convertKeyModifiers:[NSEvent modifierFlags]];
static QMetaMethod activatedSignal = QMetaMethod::fromSignal(&QCocoaMenuItem::activated);
activatedSignal.invoke(cocoaItem, Qt::QueuedConnection);
diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm
index d73b9a8b7b..e440a9080c 100644
--- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm
@@ -308,7 +308,7 @@ QT_END_NAMESPACE
if ([item tag]) {
QCocoaMenuItem *cocoaItem = reinterpret_cast<QCocoaMenuItem *>([item tag]);
- QScopedLoopLevelCounter loopLevelCounter(QGuiApplicationPrivate::instance()->threadData);
+ QScopedScopeLevelCounter scopeLevelCounter(QGuiApplicationPrivate::instance()->threadData);
cocoaItem->activated();
}
}
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index e707010979..8733116c6f 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -1898,6 +1898,18 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
return NO;
}
+
+- (BOOL)wantsPeriodicDraggingUpdates:(void *)dummy
+{
+ // This method never gets called. It's a workaround for Apple's
+ // bug: they first respondsToSelector : @selector(wantsPeriodicDraggingUpdates:)
+ // (note ':') and then call -wantsPeriodicDraggingUpdate (without colon).
+ // So, let's make them happy.
+ Q_UNUSED(dummy);
+
+ return NO;
+}
+
- (void)updateCursorFromDragResponse:(QPlatformDragQtResponse)response drag:(QCocoaDrag *)drag
{
const QPixmap pixmapCursor = drag->currentDrag()->dragCursor(response.acceptedAction());
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h
index 6a2ecacd77..02dc95e852 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.h
+++ b/src/plugins/platforms/xcb/qxcbconnection.h
@@ -472,7 +472,7 @@ public:
xcb_window_t getSelectionOwner(xcb_atom_t atom) const;
xcb_window_t getQtSelectionOwner();
- void setButton(Qt::MouseButton button, bool down) { if (down) m_buttons |= button; else m_buttons &= ~button; }
+ void setButton(Qt::MouseButton button, bool down) { m_buttons.setFlag(button, down); }
Qt::MouseButtons buttons() const { return m_buttons; }
Qt::MouseButton translateMouseButton(xcb_button_t s);
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index ca2b0c0889..07422f8811 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -787,10 +787,8 @@ void QFileDialog::setOptions(Options options)
if (changed & DontUseCustomDirectoryIcons) {
QFileIconProvider::Options providerOptions = iconProvider()->options();
- if (options & DontUseCustomDirectoryIcons)
- providerOptions |= QFileIconProvider::DontUseCustomDirectoryIcons;
- else
- providerOptions &= ~QFileIconProvider::DontUseCustomDirectoryIcons;
+ providerOptions.setFlag(QFileIconProvider::DontUseCustomDirectoryIcons,
+ options & DontUseCustomDirectoryIcons);
iconProvider()->setOptions(providerOptions);
}
}
@@ -3455,7 +3453,7 @@ void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text)
const QStringList multipleFiles = typedFiles();
if (multipleFiles.count() > 0) {
QModelIndexList oldFiles = qFileDialogUi->listView->selectionModel()->selectedRows();
- QModelIndexList newFiles;
+ QVector<QModelIndex> newFiles;
for (const auto &file : multipleFiles) {
QModelIndex idx = model->index(file);
if (oldFiles.removeAll(idx) == 0)
@@ -3718,10 +3716,7 @@ void QFileDialogPrivate::_q_showHidden()
{
Q_Q(QFileDialog);
QDir::Filters dirFilters = q->filter();
- if (showHiddenAction->isChecked())
- dirFilters |= QDir::Hidden;
- else
- dirFilters &= ~QDir::Hidden;
+ dirFilters.setFlag(QDir::Hidden, showHiddenAction->isChecked());
q->setFilter(dirFilters);
}
diff --git a/src/widgets/doc/snippets/javastyle.cpp b/src/widgets/doc/snippets/javastyle.cpp
index 4997e25ada..cf62c2155e 100644
--- a/src/widgets/doc/snippets/javastyle.cpp
+++ b/src/widgets/doc/snippets/javastyle.cpp
@@ -242,8 +242,7 @@ void JavaStyle::drawControl(ControlElement control, const QStyleOption *option,
QRect rect = docker->rect;
QRect titleRect = rect;
if (docker->verticalTitleBar) {
- QRect r = rect;
- r.setSize(r.size().transposed());
+ QRect r = rect.transposed();
titleRect = QRect(r.left() + rect.bottom()
- titleRect.bottom(),
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index e1b835e727..450d5a7d9c 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -1297,10 +1297,7 @@ void QGraphicsView::setRenderHint(QPainter::RenderHint hint, bool enabled)
{
Q_D(QGraphicsView);
QPainter::RenderHints oldHints = d->renderHints;
- if (enabled)
- d->renderHints |= hint;
- else
- d->renderHints &= ~hint;
+ d->renderHints.setFlag(hint, enabled);
if (oldHints != d->renderHints)
d->updateAll();
}
@@ -1463,10 +1460,7 @@ void QGraphicsView::setOptimizationFlags(OptimizationFlags flags)
void QGraphicsView::setOptimizationFlag(OptimizationFlag flag, bool enabled)
{
Q_D(QGraphicsView);
- if (enabled)
- d->optimizationFlags |= flag;
- else
- d->optimizationFlags &= ~flag;
+ d->optimizationFlags.setFlag(flag, enabled);
}
/*!
diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp
index bb6d867280..e7fca55550 100644
--- a/src/widgets/graphicsview/qgraphicswidget.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget.cpp
@@ -2272,15 +2272,8 @@ void QGraphicsWidget::paintWindowFrame(QPainter *painter, const QStyleOptionGrap
bar.QStyleOption::operator=(*option);
d->initStyleOptionTitleBar(&bar); // this clear flags in bar.state
d->ensureWindowData();
- if (d->windowData->buttonMouseOver)
- bar.state |= QStyle::State_MouseOver;
- else
- bar.state &= ~QStyle::State_MouseOver;
- if (d->windowData->buttonSunken)
- bar.state |= QStyle::State_Sunken;
- else
- bar.state &= ~QStyle::State_Sunken;
-
+ bar.state.setFlag(QStyle::State_MouseOver, d->windowData->buttonMouseOver);
+ bar.state.setFlag(QStyle::State_Sunken, d->windowData->buttonSunken);
bar.rect = windowFrameRect;
// translate painter to make the style happy
@@ -2337,17 +2330,9 @@ void QGraphicsWidget::paintWindowFrame(QPainter *painter, const QStyleOptionGrap
initStyleOption(&frameOptions);
if (!hasBorder)
painter->setClipRect(windowFrameRect.adjusted(0, +height, 0, 0), Qt::IntersectClip);
- if (hasFocus()) {
- frameOptions.state |= QStyle::State_HasFocus;
- } else {
- frameOptions.state &= ~QStyle::State_HasFocus;
- }
+ frameOptions.state.setFlag(QStyle::State_HasFocus, hasFocus());
bool isActive = isActiveWindow();
- if (isActive) {
- frameOptions.state |= QStyle::State_Active;
- } else {
- frameOptions.state &= ~QStyle::State_Active;
- }
+ frameOptions.state.setFlag(QStyle::State_Active, isActive);
frameOptions.palette.setCurrentColorGroup(isActive ? QPalette::Active : QPalette::Normal);
frameOptions.rect = windowFrameRect;
diff --git a/src/widgets/graphicsview/qgraphicswidget_p.cpp b/src/widgets/graphicsview/qgraphicswidget_p.cpp
index 0c40583659..faf1a4c49a 100644
--- a/src/widgets/graphicsview/qgraphicswidget_p.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget_p.cpp
@@ -327,12 +327,11 @@ void QGraphicsWidgetPrivate::initStyleOptionTitleBar(QStyleOptionTitleBar *optio
option->subControls = QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarSysMenu;
option->activeSubControls = windowData->hoveredSubControl;
bool isActive = q->isActiveWindow();
+ option->state.setFlag(QStyle::State_Active, isActive);
if (isActive) {
- option->state |= QStyle::State_Active;
option->titleBarState = Qt::WindowActive;
option->titleBarState |= QStyle::State_Active;
} else {
- option->state &= ~QStyle::State_Active;
option->titleBarState = Qt::WindowNoState;
}
QFont windowTitleFont = QApplication::font("QMdiSubWindowTitleBar");
diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp
index cba7e8aacc..26173b5e92 100644
--- a/src/widgets/itemviews/qcolumnview.cpp
+++ b/src/widgets/itemviews/qcolumnview.cpp
@@ -568,7 +568,7 @@ void QColumnViewPrivate::closeColumns(const QModelIndex &parent, bool build)
bool clearAll = !parent.isValid();
bool passThroughRoot = false;
- QList<QModelIndex> dirsToAppend;
+ QVector<QModelIndex> dirsToAppend;
// Find the last column that matches the parent's tree
int currentColumn = -1;
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index bf6d26dbfe..53a5dcba9c 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -1015,10 +1015,7 @@ void QListView::paintEvent(QPaintEvent *e)
if (viewState == EditingState)
option.state |= QStyle::State_Editing;
}
- if (*it == hover)
- option.state |= QStyle::State_MouseOver;
- else
- option.state &= ~QStyle::State_MouseOver;
+ option.state.setFlag(QStyle::State_MouseOver, *it == hover);
if (alternate) {
int row = (*it).row();
@@ -1033,11 +1030,7 @@ void QListView::paintEvent(QPaintEvent *e)
alternateBase = (row & 1) != 0;
}
}
- if (alternateBase) {
- option.features |= QStyleOptionViewItem::Alternate;
- } else {
- option.features &= ~QStyleOptionViewItem::Alternate;
- }
+ option.features.setFlag(QStyleOptionViewItem::Alternate, alternateBase);
// draw background of the item (only alternate row). rest of the background
// is provided by the delegate
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index 6a669d4a1f..714f09e893 100644
--- a/src/widgets/itemviews/qtableview.cpp
+++ b/src/widgets/itemviews/qtableview.cpp
@@ -824,10 +824,7 @@ void QTableViewPrivate::drawAndClipSpans(const QRegion &area, QPainter *painter,
QStyleOptionViewItem opt = option;
opt.rect = rect;
alternateBase = alternatingColors && (span->top() & 1);
- if (alternateBase)
- opt.features |= QStyleOptionViewItem::Alternate;
- else
- opt.features &= ~QStyleOptionViewItem::Alternate;
+ opt.features.setFlag(QStyleOptionViewItem::Alternate, alternateBase);
drawCell(painter, opt, index);
region -= rect;
for (int r = span->top(); r <= span->bottom(); ++r) {
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index ccc7c34602..95f14bec78 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -1359,11 +1359,7 @@ void QTreeViewPrivate::paintAlternatingRowColors(QPainter *painter, QStyleOption
}
while (y <= bottom) {
option->rect.setRect(0, y, viewport->width(), rowHeight);
- if (current & 1) {
- option->features |= QStyleOptionViewItem::Alternate;
- } else {
- option->features &= ~QStyleOptionViewItem::Alternate;
- }
+ option->features.setFlag(QStyleOptionViewItem::Alternate, current & 1);
++current;
q->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, option, painter, q);
y += rowHeight;
@@ -1709,11 +1705,9 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
else
opt.state |= QStyle::State_HasFocus;
}
- if ((hoverRow || modelIndex == hover)
- && (option.showDecorationSelected || (d->hoverBranch == -1)))
- opt.state |= QStyle::State_MouseOver;
- else
- opt.state &= ~QStyle::State_MouseOver;
+ opt.state.setFlag(QStyle::State_MouseOver,
+ (hoverRow || modelIndex == hover)
+ && (option.showDecorationSelected || d->hoverBranch == -1));
if (enabled) {
QPalette::ColorGroup cg;
@@ -1729,11 +1723,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
}
if (alternate) {
- if (d->current & 1) {
- opt.features |= QStyleOptionViewItem::Alternate;
- } else {
- opt.features &= ~QStyleOptionViewItem::Alternate;
- }
+ opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
}
/* Prior to Qt 4.3, the background of the branch (in selected state and
@@ -1832,11 +1822,7 @@ void QTreeView::drawBranches(QPainter *painter, const QRect &rect,
painter->setBrushOrigin(QPoint(0, verticalOffset()));
if (d->alternatingColors) {
- if (d->current & 1) {
- opt.features |= QStyleOptionViewItem::Alternate;
- } else {
- opt.features &= ~QStyleOptionViewItem::Alternate;
- }
+ opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
}
// When hovering over a row, pass State_Hover for painting the branch
@@ -1862,10 +1848,8 @@ void QTreeView::drawBranches(QPainter *painter, const QRect &rect,
| (moreSiblings ? QStyle::State_Sibling : QStyle::State_None)
| (children ? QStyle::State_Children : QStyle::State_None)
| (expanded ? QStyle::State_Open : QStyle::State_None);
- if (hoverRow || item == d->hoverBranch)
- opt.state |= QStyle::State_MouseOver;
- else
- opt.state &= ~QStyle::State_MouseOver;
+ opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
+
style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this);
}
// then go out level by level
@@ -1890,10 +1874,8 @@ void QTreeView::drawBranches(QPainter *painter, const QRect &rect,
}
if (moreSiblings)
opt.state |= QStyle::State_Sibling;
- if (hoverRow || item == d->hoverBranch)
- opt.state |= QStyle::State_MouseOver;
- else
- opt.state &= ~QStyle::State_MouseOver;
+ opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
+
style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this);
current = ancestor;
ancestor = current.parent();
diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp
index d97201c601..e59c35ed68 100644
--- a/src/widgets/styles/qandroidstyle.cpp
+++ b/src/widgets/styles/qandroidstyle.cpp
@@ -1233,30 +1233,21 @@ const QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidStateDrawable::best
int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value)
{
- int state = QStyle::State_Enabled | QStyle::State_Active;;
+ QStyle::State state = QStyle::State_Enabled | QStyle::State_Active;;
foreach (const QString &key, value.keys()) {
bool val = value.value(key).toString() == QLatin1String("true");
if (key == QLatin1String("enabled")) {
- if (val)
- state |= QStyle::State_Enabled;
- else
- state &= ~QStyle::State_Enabled;
+ state.setFlag(QStyle::State_Enabled, val);
continue;
}
if (key == QLatin1String("window_focused")) {
- if (val)
- state |= QStyle::State_Active;
- else
- state &= ~QStyle::State_Active;
+ state.setFlag(QStyle::State_Active, val);
continue;
}
if (key == QLatin1String("focused")) {
- if (val)
- state |= QStyle::State_HasFocus;
- else
- state &= ~QStyle::State_HasFocus;
+ state.setFlag(QStyle::State_HasFocus, val);
continue;
}
@@ -1271,18 +1262,12 @@ int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value)
}
if (key == QLatin1String("selected")) {
- if (val)
- state |= QStyle::State_Selected;
- else
- state &= ~QStyle::State_Selected;
+ state.setFlag(QStyle::State_Selected, val);
continue;
}
if (key == QLatin1String("active")) {
- if (val)
- state |= QStyle::State_Active;
- else
- state &= ~QStyle::State_Active;
+ state.setFlag(QStyle::State_Active, val);
continue;
}
@@ -1292,7 +1277,7 @@ int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value)
if (key == QLatin1String("background") && val)
return -1;
}
- return state;
+ return static_cast<int>(state);
}
void QAndroidStyle::AndroidStateDrawable::setPaddingLeftToSizeWidth()
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index c28a70e3f9..c26da68ac9 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -2036,7 +2036,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
const bool verticalTitleBar = dwOpt->verticalTitleBar;
if (verticalTitleBar) {
- r.setSize(r.size().transposed());
+ r = r.transposed();
p->save();
p->translate(r.left(), r.top() + r.width());
@@ -2924,7 +2924,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
// horizontal, then transpose again.
if (verticalTitleBar)
- rect.setSize(rect.size().transposed());
+ rect = rect.transposed();
do {
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp
index 92c065e138..1cd91a26ee 100644
--- a/src/widgets/styles/qfusionstyle.cpp
+++ b/src/widgets/styles/qfusionstyle.cpp
@@ -684,10 +684,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
{
QStyleOption dockWidgetHandle = *option;
bool horizontal = option->state & State_Horizontal;
- if (horizontal)
- dockWidgetHandle.state &= ~State_Horizontal;
- else
- dockWidgetHandle.state |= State_Horizontal;
+ dockWidgetHandle.state.setFlag(State_Horizontal, !horizontal);
proxy()->drawControl(CE_Splitter, &dockWidgetHandle, painter, widget);
}
break;
@@ -1228,8 +1225,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
if (verticalTitleBar) {
QRect rect = dwOpt->rect;
- QRect r = rect;
- r.setSize(r.size().transposed());
+ QRect r = rect.transposed();
titleRect = QRect(r.left() + rect.bottom()
- titleRect.bottom(),
r.top() + titleRect.left() - rect.left(),
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 74554f6d3d..3490d09fdf 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -4342,8 +4342,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, w);
if (verticalTitleBar) {
QRect rect = dwOpt->rect;
- QRect r = rect;
- r.setSize(r.size().transposed());
+ QRect r = rect.transposed();
titleRect = QRect(r.left() + rect.bottom()
- titleRect.bottom(),
@@ -5167,7 +5166,7 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt,
// If this is a vertical titlebar, we transpose and work as if it was
// horizontal, then transpose again.
if (verticalTitleBar)
- srect.setSize(srect.size().transposed());
+ srect = srect.transposed();
do {
int right = srect.right();
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 55b91714cf..053820e459 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -4130,7 +4130,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
if (!dwOpt->title.isEmpty()) {
QRect r = subElementRect(SE_DockWidgetTitleBarText, opt, w);
if (dwOpt->verticalTitleBar) {
- r.setSize(r.size().transposed());
+ r = r.transposed();
p->save();
p->translate(r.left(), r.top() + r.width());
p->rotate(-90);
diff --git a/src/widgets/styles/qwindowsmobilestyle.cpp b/src/widgets/styles/qwindowsmobilestyle.cpp
index 93da8d42f0..45323d1d15 100644
--- a/src/widgets/styles/qwindowsmobilestyle.cpp
+++ b/src/widgets/styles/qwindowsmobilestyle.cpp
@@ -5690,7 +5690,7 @@ void QWindowsMobileStyle::drawControl(ControlElement element, const QStyleOption
QRect r = rect;
if (verticalTitleBar) {
- r.setSize(r.size().transposed());
+ r = r.transposed();
painter->save();
painter->translate(r.left(), r.top() + r.width());
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp
index 34b281a36f..d8af8c5de8 100644
--- a/src/widgets/styles/qwindowsstyle.cpp
+++ b/src/widgets/styles/qwindowsstyle.cpp
@@ -1779,7 +1779,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
QRect r = rect;
if (verticalTitleBar) {
- r.setSize(r.size().transposed());
+ r = r.transposed();
p->save();
p->translate(r.left(), r.top() + r.width());
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index c8ecc3f192..a48417677a 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -1383,7 +1383,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
const bool verticalTitleBar = dwOpt->verticalTitleBar;
if (verticalTitleBar) {
- rect.setSize(rect.size().transposed());
+ rect = rect.transposed();
painter->translate(rect.left() - 1, rect.top() + rect.width());
painter->rotate(-90);
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index fecfb02782..cda7dff509 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -2383,7 +2383,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op
const bool verticalTitleBar = dwOpt->verticalTitleBar;
if (verticalTitleBar) {
- rect.setSize(rect.size().transposed());
+ rect = rect.transposed();
p->translate(rect.left() - 1, rect.top() + rect.width());
p->rotate(-90);
diff --git a/src/widgets/widgets/qcheckbox.cpp b/src/widgets/widgets/qcheckbox.cpp
index 6ce6d288ff..ad2d019c4a 100644
--- a/src/widgets/widgets/qcheckbox.cpp
+++ b/src/widgets/widgets/qcheckbox.cpp
@@ -177,10 +177,7 @@ void QCheckBox::initStyleOption(QStyleOptionButton *option) const
else
option->state |= d->checked ? QStyle::State_On : QStyle::State_Off;
if (testAttribute(Qt::WA_Hover) && underMouse()) {
- if (d->hovering)
- option->state |= QStyle::State_MouseOver;
- else
- option->state &= ~QStyle::State_MouseOver;
+ option->state.setFlag(QStyle::State_MouseOver, d->hovering);
}
option->text = d->text;
option->icon = d->icon;
diff --git a/src/widgets/widgets/qgroupbox.cpp b/src/widgets/widgets/qgroupbox.cpp
index 0b4add4eb3..5bdd6f20e6 100644
--- a/src/widgets/widgets/qgroupbox.cpp
+++ b/src/widgets/widgets/qgroupbox.cpp
@@ -103,11 +103,7 @@ void QGroupBox::initStyleOption(QStyleOptionGroupBox *option) const
option->activeSubControls |= d->pressedControl;
option->subControls = QStyle::SC_GroupBoxFrame;
- if (d->hover)
- option->state |= QStyle::State_MouseOver;
- else
- option->state &= ~QStyle::State_MouseOver;
-
+ option->state.setFlag(QStyle::State_MouseOver, d->hover);
if (d->flat)
option->features |= QStyleOptionFrame::Flat;
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index fb2818de83..3cdd7dc0f0 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -568,16 +568,10 @@ void QLineEdit::setEchoMode(EchoMode mode)
if (mode == (EchoMode)d->control->echoMode())
return;
Qt::InputMethodHints imHints = inputMethodHints();
- if (mode == Password || mode == NoEcho) {
- imHints |= Qt::ImhHiddenText;
- } else {
- imHints &= ~Qt::ImhHiddenText;
- }
- if (mode != Normal) {
- imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
- } else {
- imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
- }
+ imHints.setFlag(Qt::ImhHiddenText, mode == Password || mode == NoEcho);
+ imHints.setFlag(Qt::ImhNoAutoUppercase, mode != Normal);
+ imHints.setFlag(Qt::ImhNoPredictiveText, mode != Normal);
+ imHints.setFlag(Qt::ImhSensitiveData, mode != Normal);
setInputMethodHints(imHints);
d->control->setEchoMode(mode);
update();
diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp
index a448f2fe72..4ee22dc235 100644
--- a/src/widgets/widgets/qmainwindow.cpp
+++ b/src/widgets/widgets/qmainwindow.cpp
@@ -922,10 +922,7 @@ void QMainWindow::setAnimated(bool enabled)
Q_D(QMainWindow);
DockOptions opts = d->layout->dockOptions;
- if (enabled)
- opts |= AnimatedDocks;
- else
- opts &= ~AnimatedDocks;
+ opts.setFlag(AnimatedDocks, enabled);
d->layout->setDockOptions(opts);
}
@@ -961,10 +958,7 @@ void QMainWindow::setDockNestingEnabled(bool enabled)
Q_D(QMainWindow);
DockOptions opts = d->layout->dockOptions;
- if (enabled)
- opts |= AllowNestedDocks;
- else
- opts &= ~AllowNestedDocks;
+ opts.setFlag(AllowNestedDocks, enabled);
d->layout->setDockOptions(opts);
}
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp
index b695918406..ae87ea526d 100644
--- a/src/widgets/widgets/qmainwindowlayout.cpp
+++ b/src/widgets/widgets/qmainwindowlayout.cpp
@@ -375,10 +375,7 @@ void QDockWidgetGroupWindow::adjustFlags()
Qt::WindowFlags flags = oldFlags;
if (nativeDeco) {
flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint;
- if (top->features() & QDockWidget::DockWidgetClosable)
- flags |= Qt::WindowCloseButtonHint;
- else
- flags &= ~Qt::WindowCloseButtonHint;
+ flags.setFlag(Qt::WindowCloseButtonHint, top->features() & QDockWidget::DockWidgetClosable);
flags &= ~Qt::FramelessWindowHint;
} else {
flags |= Qt::FramelessWindowHint;
diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp
index bb43abf34c..2b734b603f 100644
--- a/src/widgets/widgets/qmdiarea.cpp
+++ b/src/widgets/widgets/qmdiarea.cpp
@@ -2104,10 +2104,7 @@ void QMdiArea::setActivationOrder(WindowOrder order)
void QMdiArea::setOption(AreaOption option, bool on)
{
Q_D(QMdiArea);
- if (on && !(d->options & option))
- d->options |= option;
- else if (!on && (d->options & option))
- d->options &= ~option;
+ d->options.setFlag(option, on);
}
/*!
diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp
index cda61e8181..610cb1201f 100644
--- a/src/widgets/widgets/qmdisubwindow.cpp
+++ b/src/widgets/widgets/qmdisubwindow.cpp
@@ -575,10 +575,7 @@ void ControllerWidget::setControlVisible(QMdiSubWindowPrivate::WindowStateAction
if (subControl == QStyle::SC_None)
return;
- if (visible && !(visibleControls & subControl))
- visibleControls |= subControl;
- else if (!visible && (visibleControls & subControl))
- visibleControls &= ~subControl;
+ visibleControls.setFlag(subControl, visible && !(visibleControls & subControl));
}
/*
@@ -2417,10 +2414,7 @@ bool QMdiSubWindow::isShaded() const
void QMdiSubWindow::setOption(SubWindowOption option, bool on)
{
Q_D(QMdiSubWindow);
- if (on && !(d->options & option))
- d->options |= option;
- else if (!on && (d->options & option))
- d->options &= ~option;
+ d->options.setFlag(option, on);
#ifndef QT_NO_RUBBERBAND
if ((option & (RubberBandResize | RubberBandMove)) && !on && d->isInRubberBandMode)
@@ -3172,10 +3166,7 @@ void QMdiSubWindow::paintEvent(QPaintEvent *paintEvent)
QStyleOptionFrame frameOptions;
frameOptions.initFrom(this);
frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, this);
- if (d->isActive)
- frameOptions.state |= QStyle::State_Active;
- else
- frameOptions.state &= ~QStyle::State_Active;
+ frameOptions.state.setFlag(QStyle::State_Active, d->isActive);
// ### Ensure that we do not require setting the cliprect for 4.4
if (!isMinimized() && !d->hasBorder(d->cachedStyleOptions))
diff --git a/src/widgets/widgets/qradiobutton.cpp b/src/widgets/widgets/qradiobutton.cpp
index 37f8c2eef2..125182f79f 100644
--- a/src/widgets/widgets/qradiobutton.cpp
+++ b/src/widgets/widgets/qradiobutton.cpp
@@ -182,10 +182,7 @@ void QRadioButton::initStyleOption(QStyleOptionButton *option) const
option->state |= QStyle::State_Sunken;
option->state |= (d->checked) ? QStyle::State_On : QStyle::State_Off;
if (testAttribute(Qt::WA_Hover) && underMouse()) {
- if (d->hovering)
- option->state |= QStyle::State_MouseOver;
- else
- option->state &= ~QStyle::State_MouseOver;
+ option->state.setFlag(QStyle::State_MouseOver, d->hovering);
}
}