forked from qt-creator/qt-creator
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 <orgads@gmail.com>
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -319,8 +319,7 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio
|
||||
if (!action->packageStereotype.isEmpty())
|
||||
package->setStereotypes(QStringList() << action->packageStereotype);
|
||||
auto folderNode = dynamic_cast<const ProjectExplorer::FolderNode *>(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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user