From e2405dd63fae0eb6c3b6feb0d2979ab4bf1a64d2 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 20 Mar 2015 10:36:16 +0100 Subject: QStateMachine: replaced Q_FOREACH with foreach. Change-Id: I2bd0f9d7ef1d6f236e2afa9fc5b75c5a6f61a250 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstatemachine.cpp | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index eec3febbfe..dd0ba9260e 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -198,7 +198,7 @@ static inline bool isDescendant(const QAbstractState *state1, const QAbstractSta static bool containsDecendantOf(const QSet &states, const QAbstractState *node) { - Q_FOREACH (QAbstractState *s, states) + foreach (QAbstractState *s, states) if (isDescendant(s, node)) return true; @@ -490,11 +490,11 @@ void QStateMachinePrivate::removeConflictingTransitions(QList transitionsToRemove; QSet exitSetT1 = computeExitSet_Unordered(QList() << t1); - Q_FOREACH (QAbstractTransition *t2, filteredTransitions) { + foreach (QAbstractTransition *t2, filteredTransitions) { QSet exitSetT2 = computeExitSet_Unordered(QList() << t2); if (!exitSetT1.intersect(exitSetT2).isEmpty()) { if (isDescendant(t1->sourceState(), t2->sourceState())) { @@ -506,7 +506,7 @@ void QStateMachinePrivate::removeConflictingTransitions(QList QStateMachinePrivate::computeExitSet_Unordered(const QList Q_ASSERT(domain != 0); } - Q_FOREACH (QAbstractState* s, configuration) { + foreach (QAbstractState* s, configuration) { if (isDescendant(s, domain)) statesToExit.insert(s); } @@ -685,14 +685,14 @@ QList QStateMachinePrivate::computeEntrySet(const QList statesToEnter; if (pendingErrorStates.isEmpty()) { - Q_FOREACH (QAbstractTransition *t, enabledTransitions) { - Q_FOREACH (QAbstractState *s, t->targetStates()) { + foreach (QAbstractTransition *t, enabledTransitions) { + foreach (QAbstractState *s, t->targetStates()) { addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); } QList effectiveTargetStates = getEffectiveTargetStates(t).toList(); QAbstractState *ancestor = getTransitionDomain(t, effectiveTargetStates); - Q_FOREACH (QAbstractState *s, effectiveTargetStates) { + foreach (QAbstractState *s, effectiveTargetStates) { addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry); } } @@ -738,7 +738,7 @@ QAbstractState *QStateMachinePrivate::getTransitionDomain(QAbstractTransition *t if (QState *tSource = t->sourceState()) { if (isCompound(tSource)) { bool allDescendants = true; - Q_FOREACH (QAbstractState *s, effectiveTargetStates) { + foreach (QAbstractState *s, effectiveTargetStates) { if (!isDescendant(s, tSource)) { allDescendants = false; break; @@ -970,9 +970,9 @@ void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state, if (QHistoryState *h = toHistoryState(state)) { QList historyConfiguration = QHistoryStatePrivate::get(h)->configuration; if (!historyConfiguration.isEmpty()) { - Q_FOREACH (QAbstractState *s, historyConfiguration) + foreach (QAbstractState *s, historyConfiguration) addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); - Q_FOREACH (QAbstractState *s, historyConfiguration) + foreach (QAbstractState *s, historyConfiguration) addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry); #ifdef QSTATEMACHINE_DEBUG @@ -988,9 +988,9 @@ void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state, if (defaultHistoryContent.isEmpty()) { setError(QStateMachine::NoDefaultStateInHistoryStateError, h); } else { - Q_FOREACH (QAbstractState *s, defaultHistoryContent) + foreach (QAbstractState *s, defaultHistoryContent) addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); - Q_FOREACH (QAbstractState *s, defaultHistoryContent) + foreach (QAbstractState *s, defaultHistoryContent) addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry); #ifdef QSTATEMACHINE_DEBUG qDebug() << q_func() << ": initial history targets for" << state << ':' << defaultHistoryContent; @@ -1021,7 +1021,7 @@ void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state, } } else if (isParallel(state)) { QState *grp = toStandardState(state); - Q_FOREACH (QAbstractState *child, QStatePrivate::get(grp)->childStates()) { + foreach (QAbstractState *child, QStatePrivate::get(grp)->childStates()) { if (!containsDecendantOf(statesToEnter, child)) addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry); } @@ -1044,12 +1044,12 @@ void QStateMachinePrivate::addAncestorStatesToEnter(QAbstractState *s, QAbstract QSet &statesToEnter, QSet &statesForDefaultEntry) { - Q_FOREACH (QState *anc, getProperAncestors(s, ancestor)) { + foreach (QState *anc, getProperAncestors(s, ancestor)) { if (!anc->parentState()) continue; statesToEnter.insert(anc); if (isParallel(anc)) { - Q_FOREACH (QAbstractState *child, QStatePrivate::get(anc)->childStates()) { + foreach (QAbstractState *child, QStatePrivate::get(anc)->childStates()) { if (!containsDecendantOf(statesToEnter, child)) addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry); } -- cgit v1.2.3 From e0c83fb658bb352974f5485dd09df2de02ae8d92 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 Apr 2015 18:02:56 +0200 Subject: qsystemdetection.h: Check existence of define WINAPI_FAMILY_PHONE_APP. It is missing in MinGW and causes warnings like: src/corelib/global/qsystemdetection.h:109:24: error: "WINAPI_FAMILY_PHONE_APP" is not defined [-Werror=undef] in QtScript and headersclean failures in Active Qt. Task-number: QTBUG-45666 Change-Id: I167d9d5b33faddfbbcf44bdcce5e86fb43614fa9 Reviewed-by: Thiago Macieira --- src/corelib/global/qsystemdetection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qsystemdetection.h b/src/corelib/global/qsystemdetection.h index eb9c4ff04f..64f9d91ec7 100644 --- a/src/corelib/global/qsystemdetection.h +++ b/src/corelib/global/qsystemdetection.h @@ -106,7 +106,7 @@ # if defined(WINCE) || defined(_WIN32_WCE) # define Q_OS_WINCE # elif defined(WINAPI_FAMILY) -# if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP +# if defined(WINAPI_FAMILY_PHONE_APP) && WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP # define Q_OS_WINPHONE # define Q_OS_WINRT # elif WINAPI_FAMILY==WINAPI_FAMILY_APP -- cgit v1.2.3 From 6545404afad30b60d1a8e9a2abaf301abaf8f6a5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 Apr 2015 10:57:20 +0200 Subject: Windows: Fix QLockFile hanging when file cannot be created. Return QLockFile::PermissionError when file does not exist, preventing the stale file detection logic from triggering. Add Windows-only autotest trying to create a lock file in a system folder guarded with checks for elevated processes and UAC virtualization. Task-number: QTBUG-45631 Change-Id: I1790f8f925660f6bf1df94c2ced901e6ec57cbb0 Reviewed-by: Joerg Bornemann Reviewed-by: Oliver Wolff --- src/corelib/io/qlockfile_win.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qlockfile_win.cpp b/src/corelib/io/qlockfile_win.cpp index a36e6e93b8..9fe86e1ad8 100644 --- a/src/corelib/io/qlockfile_win.cpp +++ b/src/corelib/io/qlockfile_win.cpp @@ -48,6 +48,12 @@ static inline QByteArray localHostName() return qgetenv("COMPUTERNAME"); } +static inline bool fileExists(const wchar_t *fileName) +{ + WIN32_FILE_ATTRIBUTE_DATA data; + return GetFileAttributesEx(fileName, GetFileExInfoStandard, &data); +} + QLockFile::LockError QLockFilePrivate::tryLock_sys() { const QFileSystemEntry fileEntry(fileName); @@ -79,8 +85,13 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys() case ERROR_SHARING_VIOLATION: case ERROR_ALREADY_EXISTS: case ERROR_FILE_EXISTS: - case ERROR_ACCESS_DENIED: // readonly file, or file still in use by another process. Assume the latter, since we don't create it readonly. return QLockFile::LockFailedError; + case ERROR_ACCESS_DENIED: + // readonly file, or file still in use by another process. + // Assume the latter if the file exists, since we don't create it readonly. + return fileExists((const wchar_t*)fileEntry.nativeFilePath().utf16()) + ? QLockFile::LockFailedError + : QLockFile::PermissionError; default: qWarning() << "Got unexpected locking error" << lastError; return QLockFile::UnknownError; -- cgit v1.2.3 From 1c33c37d4c237a1e43b431f95a827dd219a1f10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Tue, 21 Apr 2015 21:32:19 +0100 Subject: QVector: Save one copy-CTOR call if we don't realloc Change-Id: Ie0f2eb922500bc3d76852939cf2c5d28d65a43ae Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qvector.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 9d5b749e79..eed5d17cad 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -600,16 +600,23 @@ Q_OUTOFLINE_TEMPLATE T QVector::value(int i, const T &defaultValue) const template void QVector::append(const T &t) { - const T copy(t); const bool isTooSmall = uint(d->size + 1) > d->alloc; if (!isDetached() || isTooSmall) { + const T copy(t); QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default); reallocData(d->size, isTooSmall ? d->size + 1 : d->alloc, opt); + + if (QTypeInfo::isComplex) + new (d->end()) T(copy); + else + *d->end() = copy; + + } else { + if (QTypeInfo::isComplex) + new (d->end()) T(t); + else + *d->end() = t; } - if (QTypeInfo::isComplex) - new (d->end()) T(copy); - else - *d->end() = copy; ++d->size; } -- cgit v1.2.3 From b089579dc32a3893ad89c9c180933339e387627a Mon Sep 17 00:00:00 2001 From: Nikita Baryshnikov Date: Tue, 21 Apr 2015 13:28:19 +0300 Subject: QDir: sort-by-size remove two unconditional branches recent change ad03511256a8279a8f55069e5a3a3465a9e122ec made r be arbitrary, not just -1, 0, +1, and now it doesn't make sense to have two unneeded unconditional branches in the sort-by-size case Change-Id: I9d80210846e89e3e8c574f0c32e04b05202b8a5b Reviewed-by: Marc Mutz --- src/corelib/io/qdir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 3a9ae2ee6d..9b1ec3917a 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -239,7 +239,7 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt break; } case QDir::Size: - r = int(qBound(-1, f2->item.size() - f1->item.size(), 1)); + r = f2->item.size() - f1->item.size(); break; case QDir::Type: { -- cgit v1.2.3 From b71535a9236a33371da36d89d38872d3ae91fbf0 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Fri, 17 Apr 2015 14:32:02 +0200 Subject: Doc: Bring QSizeF/QPointF::isNull() documentation up to date Since Qt 5.0 (commit 09dd19df) sign is ignored when testing whether a QPointF or QSizeF is null. This updates the documentation accordingly. Change-Id: I3de1c748f3caa63b8bd8990006de5ba572eac83e Task-number: QTBUG-45669 Reviewed-by: Mitch Curtis Reviewed-by: Venugopal Shivashankar --- src/corelib/tools/qpoint.cpp | 8 ++------ src/corelib/tools/qsize.cpp | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index dc2a2d9739..94a245375b 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -528,12 +528,8 @@ QDebug operator<<(QDebug dbg, const QPointF &p) /*! \fn bool QPointF::isNull() const - Returns \c true if both the x and y coordinates are set to +0.0; - otherwise returns \c false. - - \note Since this function treats +0.0 and -0.0 differently, points - with zero-valued coordinates where either or both values have a - negative sign are not defined to be null points. + Returns \c true if both the x and y coordinates are set to 0.0 (ignoring + the sign); otherwise returns \c false. */ diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp index 19227432f2..24a29f0213 100644 --- a/src/corelib/tools/qsize.cpp +++ b/src/corelib/tools/qsize.cpp @@ -517,12 +517,8 @@ QDebug operator<<(QDebug dbg, const QSize &s) /*! \fn bool QSizeF::isNull() const - Returns \c true if both the width and height are +0.0; otherwise returns - false. - - \note Since this function treats +0.0 and -0.0 differently, sizes with - zero width and height where either or both values have a negative - sign are not defined to be null sizes. + Returns \c true if both the width and height are 0.0 (ignoring the sign); + otherwise returns \c false. \sa isValid(), isEmpty() */ -- cgit v1.2.3