From a6aafe3c45cb1f23290adc99d7d0a8cbb85d153e Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 15 Apr 2016 15:21:26 +0200 Subject: [PATCH] Add QTC_GUARD Similar to QTC_CHECK, but has the boolean result of the condition as value. Use it in the form if (QTC_GUARD(condition)) { ... } Replace some occurrences of QTC_CHECK(condition) if (condition) { .... } Change-Id: I8eea02f869eb7a183dfbf4810dace48097880519 Reviewed-by: Orgad Shaneh Reviewed-by: Tobias Hunger Reviewed-by: hjk --- src/libs/utils/checkablemessagebox.cpp | 3 +-- src/libs/utils/qtcassert.h | 1 + src/plugins/coreplugin/dialogs/newdialog.cpp | 3 +-- src/plugins/coreplugin/editormanager/editormanager.cpp | 6 ++---- src/plugins/cpptools/semantichighlighter.cpp | 3 +-- src/plugins/help/helpwidget.cpp | 3 +-- src/plugins/modeleditor/pxnodecontroller.cpp | 3 +-- .../texteditor/codeassist/functionhintproposalwidget.cpp | 3 +-- 8 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/libs/utils/checkablemessagebox.cpp b/src/libs/utils/checkablemessagebox.cpp index 3654425133a..8813db0bea9 100644 --- a/src/libs/utils/checkablemessagebox.cpp +++ b/src/libs/utils/checkablemessagebox.cpp @@ -280,8 +280,7 @@ QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButt bool askAgain(QSettings *settings, const QString &settingsSubKey) { - QTC_CHECK(settings); - if (settings) { + if (QTC_GUARD(settings)) { settings->beginGroup(QLatin1String(kDoNotAskAgainKey)); bool shouldNotAsk = settings->value(settingsSubKey, false).toBool(); settings->endGroup(); diff --git a/src/libs/utils/qtcassert.h b/src/libs/utils/qtcassert.h index 544221ee8c7..bf4b28ba4d5 100644 --- a/src/libs/utils/qtcassert.h +++ b/src/libs/utils/qtcassert.h @@ -39,3 +39,4 @@ namespace Utils { QTCREATOR_UTILS_EXPORT void writeAssertLocation(const char *ms #define QTC_ASSERT(cond, action) if (cond) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0) #define QTC_CHECK(cond) if (cond) {} else { QTC_ASSERT_STRING(#cond); } do {} while (0) +#define QTC_GUARD(cond) ((cond) ? true : (QTC_ASSERT_STRING(#cond), false)) diff --git a/src/plugins/coreplugin/dialogs/newdialog.cpp b/src/plugins/coreplugin/dialogs/newdialog.cpp index 013779f83da..5506b067a1c 100644 --- a/src/plugins/coreplugin/dialogs/newdialog.cpp +++ b/src/plugins/coreplugin/dialogs/newdialog.cpp @@ -471,8 +471,7 @@ void NewDialog::accept() saveState(); if (m_ui->templatesView->currentIndex().isValid()) { IWizardFactory *wizard = currentWizardFactory(); - QTC_CHECK(wizard); - if (wizard) { + if (QTC_GUARD(wizard)) { QTimer::singleShot(0, std::bind(&runWizard, wizard, m_defaultLocation, selectedPlatform(), m_extraVariables)); } diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 470e623d45d..ec70f60f378 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1674,10 +1674,9 @@ void EditorManagerPrivate::gotoNextSplit() if (nextIndex >= d->m_editorAreas.size()) nextIndex = 0; nextView = d->m_editorAreas.at(nextIndex)->findFirstView(); - QTC_CHECK(nextView); } - if (nextView) + if (QTC_GUARD(nextView)) activateView(nextView); } @@ -1698,10 +1697,9 @@ void EditorManagerPrivate::gotoPreviousSplit() if (nextIndex < 0) nextIndex = d->m_editorAreas.count() - 1; prevView = d->m_editorAreas.at(nextIndex)->findLastView(); - QTC_CHECK(prevView); } - if (prevView) + if (QTC_GUARD(prevView)) activateView(prevView); } diff --git a/src/plugins/cpptools/semantichighlighter.cpp b/src/plugins/cpptools/semantichighlighter.cpp index 711996e57f7..df0107ba63c 100644 --- a/src/plugins/cpptools/semantichighlighter.cpp +++ b/src/plugins/cpptools/semantichighlighter.cpp @@ -103,8 +103,7 @@ void SemanticHighlighter::onHighlighterFinished() QTC_ASSERT(m_watcher, return); if (!m_watcher->isCanceled() && documentRevision() == m_revision) { SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter(); - QTC_CHECK(highlighter); - if (highlighter) { + if (QTC_GUARD(highlighter)) { qCDebug(log) << "onHighlighterFinished() - clearing formats"; clearExtraAdditionalFormatsUntilEnd(highlighter, m_watcher->future()); } diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp index 4def75dd980..f5848fb38a8 100644 --- a/src/plugins/help/helpwidget.cpp +++ b/src/plugins/help/helpwidget.cpp @@ -222,8 +222,7 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget connect(m_copy, &QAction::triggered, this, &HelpWidget::copy); Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED); - QTC_CHECK(advancedMenu); - if (advancedMenu) { + if (QTC_GUARD(advancedMenu)) { // reuse TextEditor constants to avoid a second pair of menu actions m_scaleUp = new QAction(tr("Increase Font Size"), this); cmd = Core::ActionManager::registerAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE, diff --git a/src/plugins/modeleditor/pxnodecontroller.cpp b/src/plugins/modeleditor/pxnodecontroller.cpp index 4ae41c1acf5..ecac98854cd 100644 --- a/src/plugins/modeleditor/pxnodecontroller.cpp +++ b/src/plugins/modeleditor/pxnodecontroller.cpp @@ -319,8 +319,7 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio if (!action->packageStereotype.isEmpty()) package->setStereotypes(QStringList() << action->packageStereotype); auto folderNode = dynamic_cast(node); - QTC_CHECK(folderNode); - if (folderNode) { + if (QTC_GUARD(folderNode)) { d->diagramSceneController->modelController()->undoController()->beginMergeSequence(tr("Create Component Model")); QStringList relativeElements = qmt::NameController::buildElementsPath( d->pxnodeUtilities->calcRelativePath(folderNode, d->anchorFolder), true); diff --git a/src/plugins/texteditor/codeassist/functionhintproposalwidget.cpp b/src/plugins/texteditor/codeassist/functionhintproposalwidget.cpp index 0c9cf5911d2..7074ecd9f64 100644 --- a/src/plugins/texteditor/codeassist/functionhintproposalwidget.cpp +++ b/src/plugins/texteditor/codeassist/functionhintproposalwidget.cpp @@ -221,8 +221,7 @@ bool FunctionHintProposalWidget::eventFilter(QObject *obj, QEvent *e) if (d->m_model && d->m_model->size() > 1) return false; } - QTC_CHECK(d->m_assistant); - if (d->m_assistant) + if (QTC_GUARD(d->m_assistant)) d->m_assistant->notifyChange(); } break;