Replace QBoolBlocker with QScopedValueRoolback
It was pre-Qt 4.5 (so pre-C++11), while QScopedValueRollback is 4.8. Both are still old, but with Qt 6 and C++17, we can use CTAD. QScopedValueRollback requires a value change to be explicit, which is less surprising. The uses outside of qtbase have also been fixed. Change-Id: Ia930b1a2ed1e465a826ffffd179c1909e16583db Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
45886e6a81
commit
327cfd55b1
@ -436,20 +436,6 @@ private:
|
||||
alignas(void *) char prealloc_[3 * sizeof(void *) + 3 * sizeof(QMetaType)];
|
||||
};
|
||||
|
||||
class QBoolBlocker
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QBoolBlocker)
|
||||
public:
|
||||
Q_NODISCARD_CTOR explicit QBoolBlocker(bool &b, bool value = true)
|
||||
: block(b), reset(b)
|
||||
{ block = value; }
|
||||
inline ~QBoolBlocker() { block = reset; }
|
||||
|
||||
private:
|
||||
bool █
|
||||
bool reset;
|
||||
};
|
||||
|
||||
struct QAbstractDynamicMetaObject;
|
||||
struct Q_CORE_EXPORT QDynamicMetaObjectData
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
// Set 'blockSendPostedEvents' to true if you _really_ need
|
||||
// to make sure that qt events are not posted while calling
|
||||
// low-level cocoa functions (like beginModalForWindow). And
|
||||
// use a QBoolBlocker to be safe:
|
||||
// use a QScopedValueRollback to be safe:
|
||||
bool blockSendPostedEvents;
|
||||
// The following variables help organizing modal sessions:
|
||||
QStack<QCocoaModalSessionInfo> cocoaModalSessionStack;
|
||||
|
@ -296,7 +296,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
|
||||
d->interrupt = true;
|
||||
d->propagateInterrupt = false;
|
||||
});
|
||||
QBoolBlocker interruptBlocker(d->interrupt, false);
|
||||
QScopedValueRollback interruptBlocker(d->interrupt, false);
|
||||
|
||||
bool interruptLater = false;
|
||||
QtCocoaInterruptDispatcher::cancelInterruptLater();
|
||||
@ -342,7 +342,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
|
||||
// interrupted. This is mostly an optimization, but it allow us to use
|
||||
// [NSApp run], which is the normal code path for cocoa applications.
|
||||
if (NSModalSession session = d->currentModalSession()) {
|
||||
QBoolBlocker execGuard(d->currentExecIsNSAppRun, false);
|
||||
QScopedValueRollback execGuard(d->currentExecIsNSAppRun, false);
|
||||
qCDebug(lcEventDispatcher) << "Running modal session" << session;
|
||||
while ([NSApp runModalSession:session] == NSModalResponseContinue && !d->interrupt) {
|
||||
qt_mac_waitForMoreEvents(NSModalPanelRunLoopMode);
|
||||
@ -370,7 +370,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
|
||||
|
||||
} else {
|
||||
d->nsAppRunCalledByQt = true;
|
||||
QBoolBlocker execGuard(d->currentExecIsNSAppRun, true);
|
||||
QScopedValueRollback execGuard(d->currentExecIsNSAppRun, true);
|
||||
[NSApp run];
|
||||
}
|
||||
retVal = true;
|
||||
@ -562,7 +562,7 @@ void QCocoaEventDispatcherPrivate::ensureNSAppInitialized()
|
||||
// Stopping the application will still process runloop sources before
|
||||
// actually stopping, so we need to explicitly guard our sources from
|
||||
// doing anything, deferring their actions until later.
|
||||
QBoolBlocker initializationGuard(initializingNSApplication, true);
|
||||
QScopedValueRollback initializationGuard(initializingNSApplication, true);
|
||||
|
||||
CFRunLoopPerformBlock(mainRunLoop(), kCFRunLoopCommonModes, ^{
|
||||
qCDebug(lcEventDispatcher) << "NSApplication has been initialized; Stopping NSApp";
|
||||
@ -624,7 +624,7 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession()
|
||||
continue;
|
||||
|
||||
ensureNSAppInitialized();
|
||||
QBoolBlocker block1(blockSendPostedEvents, true);
|
||||
QScopedValueRollback block1(blockSendPostedEvents, true);
|
||||
info.nswindow = nswindow;
|
||||
[(NSWindow*) info.nswindow retain];
|
||||
QRect rect = cocoaWindow->geometry();
|
||||
|
@ -84,7 +84,7 @@ void QCocoaScreen::updateScreens()
|
||||
qCInfo(lcQpaScreen) << "Skipping screen update, already updating";
|
||||
return;
|
||||
}
|
||||
QBoolBlocker recursionGuard(updatingScreens);
|
||||
QScopedValueRollback recursionGuard(updatingScreens, true);
|
||||
|
||||
uint32_t displayCount = 0;
|
||||
if (CGGetOnlineDisplayList(0, nullptr, &displayCount) != kCGErrorSuccess)
|
||||
|
@ -215,7 +215,7 @@ void QCocoaWindow::setGeometry(const QRect &rectIn)
|
||||
{
|
||||
qCDebug(lcQpaWindow) << "QCocoaWindow::setGeometry" << window() << rectIn;
|
||||
|
||||
QBoolBlocker inSetGeometry(m_inSetGeometry, true);
|
||||
QScopedValueRollback inSetGeometry(m_inSetGeometry, true);
|
||||
|
||||
QRect rect = rectIn;
|
||||
// This means it is a call from QWindow::setFramePosition() and
|
||||
|
@ -69,7 +69,7 @@ static bool sendAsShortcut(const KeyEvent &keyEvent, QWindow *window)
|
||||
QWindow *window = [self topLevelWindow];
|
||||
|
||||
// We will send a key event unless the input method handles it
|
||||
QBoolBlocker sendKeyEventGuard(m_sendKeyEvent, true);
|
||||
QScopedValueRollback sendKeyEventGuard(m_sendKeyEvent, true);
|
||||
|
||||
// Assume we should send key events with text, unless told
|
||||
// otherwise by doCommandBySelector.
|
||||
|
@ -375,7 +375,7 @@ NSWindow<QNSWindowProtocol> *qnswindow_cast(NSWindow *window)
|
||||
|
||||
- (void)miniaturize:(id)sender
|
||||
{
|
||||
QBoolBlocker miniaturizeTracker(m_isMinimizing, true);
|
||||
QScopedValueRollback miniaturizeTracker(m_isMinimizing, true);
|
||||
[super miniaturize:sender];
|
||||
}
|
||||
|
||||
|
@ -2258,7 +2258,7 @@ static QString msgUnableToSetGeometry(const QWindowsWindow *platformWindow,
|
||||
|
||||
void QWindowsWindow::setGeometry(const QRect &rectIn)
|
||||
{
|
||||
QBoolBlocker b(m_inSetgeometry);
|
||||
QScopedValueRollback b(m_inSetgeometry, true);
|
||||
|
||||
QRect rect = rectIn;
|
||||
// This means it is a call from QWindow::setFramePosition() and
|
||||
|
@ -2885,7 +2885,7 @@ void QComboBox::hidePopup()
|
||||
if (d->hidingPopup)
|
||||
return;
|
||||
d->hidingPopup = true;
|
||||
// can't use QBoolBlocker on a bitfield
|
||||
// can't use QScopedValueRollback on a bitfield
|
||||
auto resetHidingPopup = qScopeGuard([d]{
|
||||
d->hidingPopup = false;
|
||||
});
|
||||
|
@ -189,7 +189,7 @@ void QDialogButtonBoxPrivate::layoutButtons()
|
||||
Q_Q(QDialogButtonBox);
|
||||
const int MacGap = 36 - 8; // 8 is the default gap between a widget and a spacer item
|
||||
|
||||
QBoolBlocker blocker(ignoreShowAndHide);
|
||||
QScopedValueRollback blocker(ignoreShowAndHide, true);
|
||||
for (int i = buttonLayout->count() - 1; i >= 0; --i) {
|
||||
QLayoutItem *item = buttonLayout->takeAt(i);
|
||||
if (QWidget *widget = item->widget())
|
||||
|
@ -1412,7 +1412,7 @@ void QMenuPrivate::activateCausedStack(const QList<QPointer<QWidget>> &causedSta
|
||||
QAction::ActionEvent action_e, bool self)
|
||||
{
|
||||
Q_Q(QMenu);
|
||||
// can't use QBoolBlocker here
|
||||
// can't use QScopedValueRollback here
|
||||
const bool activationRecursionGuardReset = activationRecursionGuard;
|
||||
activationRecursionGuard = true;
|
||||
QPointer<QMenu> guard(q);
|
||||
|
@ -805,7 +805,7 @@ QSplitterLayoutStruct *QSplitterPrivate::findWidget(QWidget *w) const
|
||||
void QSplitterPrivate::insertWidget_helper(int index, QWidget *widget, bool show)
|
||||
{
|
||||
Q_Q(QSplitter);
|
||||
QBoolBlocker b(blockChildAdd);
|
||||
QScopedValueRollback b(blockChildAdd, true);
|
||||
const bool needShow = show && shouldShowWidget(widget);
|
||||
if (widget->parentWidget() != q)
|
||||
widget->setParent(q);
|
||||
@ -1145,7 +1145,7 @@ QWidget *QSplitter::replaceWidget(int index, QWidget *widget)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QBoolBlocker b(d->blockChildAdd);
|
||||
QScopedValueRollback b(d->blockChildAdd, true);
|
||||
|
||||
const QRect geom = current->geometry();
|
||||
const bool wasHidden = current->isHidden();
|
||||
@ -1310,7 +1310,7 @@ void QSplitter::setRubberBand(int pos)
|
||||
const int rBord = 3; // customizable?
|
||||
int hw = handleWidth();
|
||||
if (!d->rubberBand) {
|
||||
QBoolBlocker b(d->blockChildAdd);
|
||||
QScopedValueRollback b(d->blockChildAdd, true);
|
||||
d->rubberBand = new QRubberBand(QRubberBand::Line, this);
|
||||
// For accessibility to identify this special widget.
|
||||
d->rubberBand->setObjectName("qt_rubberband"_L1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user