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)
|
bool askAgain(QSettings *settings, const QString &settingsSubKey)
|
||||||
{
|
{
|
||||||
QTC_CHECK(settings);
|
if (QTC_GUARD(settings)) {
|
||||||
if (settings) {
|
|
||||||
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||||
bool shouldNotAsk = settings->value(settingsSubKey, false).toBool();
|
bool shouldNotAsk = settings->value(settingsSubKey, false).toBool();
|
||||||
settings->endGroup();
|
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_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_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();
|
saveState();
|
||||||
if (m_ui->templatesView->currentIndex().isValid()) {
|
if (m_ui->templatesView->currentIndex().isValid()) {
|
||||||
IWizardFactory *wizard = currentWizardFactory();
|
IWizardFactory *wizard = currentWizardFactory();
|
||||||
QTC_CHECK(wizard);
|
if (QTC_GUARD(wizard)) {
|
||||||
if (wizard) {
|
|
||||||
QTimer::singleShot(0, std::bind(&runWizard, wizard, m_defaultLocation,
|
QTimer::singleShot(0, std::bind(&runWizard, wizard, m_defaultLocation,
|
||||||
selectedPlatform(), m_extraVariables));
|
selectedPlatform(), m_extraVariables));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1674,10 +1674,9 @@ void EditorManagerPrivate::gotoNextSplit()
|
|||||||
if (nextIndex >= d->m_editorAreas.size())
|
if (nextIndex >= d->m_editorAreas.size())
|
||||||
nextIndex = 0;
|
nextIndex = 0;
|
||||||
nextView = d->m_editorAreas.at(nextIndex)->findFirstView();
|
nextView = d->m_editorAreas.at(nextIndex)->findFirstView();
|
||||||
QTC_CHECK(nextView);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextView)
|
if (QTC_GUARD(nextView))
|
||||||
activateView(nextView);
|
activateView(nextView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1698,10 +1697,9 @@ void EditorManagerPrivate::gotoPreviousSplit()
|
|||||||
if (nextIndex < 0)
|
if (nextIndex < 0)
|
||||||
nextIndex = d->m_editorAreas.count() - 1;
|
nextIndex = d->m_editorAreas.count() - 1;
|
||||||
prevView = d->m_editorAreas.at(nextIndex)->findLastView();
|
prevView = d->m_editorAreas.at(nextIndex)->findLastView();
|
||||||
QTC_CHECK(prevView);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevView)
|
if (QTC_GUARD(prevView))
|
||||||
activateView(prevView);
|
activateView(prevView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,8 +103,7 @@ void SemanticHighlighter::onHighlighterFinished()
|
|||||||
QTC_ASSERT(m_watcher, return);
|
QTC_ASSERT(m_watcher, return);
|
||||||
if (!m_watcher->isCanceled() && documentRevision() == m_revision) {
|
if (!m_watcher->isCanceled() && documentRevision() == m_revision) {
|
||||||
SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter();
|
SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter();
|
||||||
QTC_CHECK(highlighter);
|
if (QTC_GUARD(highlighter)) {
|
||||||
if (highlighter) {
|
|
||||||
qCDebug(log) << "onHighlighterFinished() - clearing formats";
|
qCDebug(log) << "onHighlighterFinished() - clearing formats";
|
||||||
clearExtraAdditionalFormatsUntilEnd(highlighter, m_watcher->future());
|
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);
|
connect(m_copy, &QAction::triggered, this, &HelpWidget::copy);
|
||||||
|
|
||||||
Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
|
Core::ActionContainer *advancedMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
|
||||||
QTC_CHECK(advancedMenu);
|
if (QTC_GUARD(advancedMenu)) {
|
||||||
if (advancedMenu) {
|
|
||||||
// reuse TextEditor constants to avoid a second pair of menu actions
|
// reuse TextEditor constants to avoid a second pair of menu actions
|
||||||
m_scaleUp = new QAction(tr("Increase Font Size"), this);
|
m_scaleUp = new QAction(tr("Increase Font Size"), this);
|
||||||
cmd = Core::ActionManager::registerAction(m_scaleUp, TextEditor::Constants::INCREASE_FONT_SIZE,
|
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())
|
if (!action->packageStereotype.isEmpty())
|
||||||
package->setStereotypes(QStringList() << action->packageStereotype);
|
package->setStereotypes(QStringList() << action->packageStereotype);
|
||||||
auto folderNode = dynamic_cast<const ProjectExplorer::FolderNode *>(node);
|
auto folderNode = dynamic_cast<const ProjectExplorer::FolderNode *>(node);
|
||||||
QTC_CHECK(folderNode);
|
if (QTC_GUARD(folderNode)) {
|
||||||
if (folderNode) {
|
|
||||||
d->diagramSceneController->modelController()->undoController()->beginMergeSequence(tr("Create Component Model"));
|
d->diagramSceneController->modelController()->undoController()->beginMergeSequence(tr("Create Component Model"));
|
||||||
QStringList relativeElements = qmt::NameController::buildElementsPath(
|
QStringList relativeElements = qmt::NameController::buildElementsPath(
|
||||||
d->pxnodeUtilities->calcRelativePath(folderNode, d->anchorFolder), true);
|
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)
|
if (d->m_model && d->m_model->size() > 1)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QTC_CHECK(d->m_assistant);
|
if (QTC_GUARD(d->m_assistant))
|
||||||
if (d->m_assistant)
|
|
||||||
d->m_assistant->notifyChange();
|
d->m_assistant->notifyChange();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user