forked from qt-creator/qt-creator
CppEditor: Reuse QScopeGuard instead of ExecuteOnDestruction
Change-Id: Ia60c8eab687599dbaa519daeab74e8799c33af95 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QSignalSpy>
|
||||
|
@@ -8,7 +8,6 @@
|
||||
#include "wrappablelineedit.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/infolabel.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -21,6 +20,7 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QPushButton>
|
||||
#include <QScopeGuard>
|
||||
#include <QTabWidget>
|
||||
#include <QTreeView>
|
||||
|
||||
@@ -323,7 +323,7 @@ void ClangDiagnosticConfigsWidget::sync()
|
||||
return;
|
||||
|
||||
disconnectClangOnlyOptionsChanged();
|
||||
ExecuteOnDestruction e([this] { connectClangOnlyOptionsChanged(); });
|
||||
const QScopeGuard cleanup([this] { connectClangOnlyOptionsChanged(); });
|
||||
|
||||
// Update main button row
|
||||
const ClangDiagnosticConfig &config = currentConfig();
|
||||
|
@@ -20,8 +20,8 @@
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
|
||||
#include <QScopeGuard>
|
||||
#include <QtTest>
|
||||
|
||||
#endif // WITH_TESTS
|
||||
@@ -267,9 +267,7 @@ void AutoCompleterTest::testAutoComplete()
|
||||
|
||||
QVERIFY(text.contains(QLatin1Char('|')));
|
||||
|
||||
Utils::ExecuteOnDestruction guard([](){
|
||||
Core::EditorManager::closeAllEditors(false);
|
||||
});
|
||||
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||
QTextCursor tc = openEditor(text);
|
||||
|
||||
QVERIFY(!tc.isNull());
|
||||
@@ -328,9 +326,7 @@ void AutoCompleterTest::testSurroundWithSelection()
|
||||
|
||||
QVERIFY(text.count(QLatin1Char('|')) == 2);
|
||||
|
||||
Utils::ExecuteOnDestruction guard([](){
|
||||
Core::EditorManager::closeAllEditors(false);
|
||||
});
|
||||
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||
QTextCursor tc = openEditor(text);
|
||||
|
||||
QVERIFY(!tc.isNull());
|
||||
@@ -363,9 +359,7 @@ void AutoCompleterTest::testAutoBackspace()
|
||||
|
||||
QVERIFY(text.contains(QLatin1Char('|')));
|
||||
|
||||
Utils::ExecuteOnDestruction guard([](){
|
||||
Core::EditorManager::closeAllEditors(false);
|
||||
});
|
||||
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||
QTextCursor tc = openEditor(text);
|
||||
|
||||
QVERIFY(!tc.isNull());
|
||||
@@ -405,9 +399,7 @@ void AutoCompleterTest::testInsertParagraph()
|
||||
|
||||
QVERIFY(text.contains(QLatin1Char('|')));
|
||||
|
||||
Utils::ExecuteOnDestruction guard([](){
|
||||
Core::EditorManager::closeAllEditors(false);
|
||||
});
|
||||
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||
QTextCursor tc = openEditor(text);
|
||||
|
||||
QVERIFY(!tc.isNull());
|
||||
|
@@ -16,12 +16,12 @@
|
||||
#include <app/app_version.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <texteditor/basehoverhandler.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/textutils.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFile>
|
||||
#include <QScopeGuard>
|
||||
#include <QTextDocument>
|
||||
|
||||
using namespace Core;
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
const QScopeGuard cleanup([this, report] { report(priority()); });
|
||||
|
||||
QTextCursor tc(editorWidget->document());
|
||||
tc.setPosition(pos);
|
||||
|
@@ -23,7 +23,6 @@
|
||||
#include <texteditor/textdocumentlayout.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/mimeutils.h>
|
||||
#include <utils/minimizableinfobars.h>
|
||||
@@ -31,6 +30,7 @@
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QScopeGuard>
|
||||
#include <QTextDocument>
|
||||
|
||||
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
||||
@@ -437,47 +437,45 @@ TextEditor::TabSettings CppEditorDocument::tabSettings() const
|
||||
|
||||
bool CppEditorDocument::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||
{
|
||||
ExecuteOnDestruction resetSettingsOnScopeExit;
|
||||
if (!indenter()->formatOnSave() || autoSave)
|
||||
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
||||
|
||||
if (indenter()->formatOnSave() && !autoSave) {
|
||||
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
|
||||
const int documentRevision = layout->lastSaveRevision;
|
||||
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
|
||||
const int documentRevision = layout->lastSaveRevision;
|
||||
|
||||
TextEditor::RangesInLines editedRanges;
|
||||
TextEditor::RangeInLines lastRange{-1, -1};
|
||||
for (int i = 0; i < document()->blockCount(); ++i) {
|
||||
const QTextBlock block = document()->findBlockByNumber(i);
|
||||
if (block.revision() == documentRevision) {
|
||||
if (lastRange.startLine != -1)
|
||||
editedRanges.push_back(lastRange);
|
||||
TextEditor::RangesInLines editedRanges;
|
||||
TextEditor::RangeInLines lastRange{-1, -1};
|
||||
for (int i = 0; i < document()->blockCount(); ++i) {
|
||||
const QTextBlock block = document()->findBlockByNumber(i);
|
||||
if (block.revision() == documentRevision) {
|
||||
if (lastRange.startLine != -1)
|
||||
editedRanges.push_back(lastRange);
|
||||
|
||||
lastRange.startLine = lastRange.endLine = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// block.revision() != documentRevision
|
||||
if (lastRange.startLine == -1)
|
||||
lastRange.startLine = block.blockNumber() + 1;
|
||||
lastRange.endLine = block.blockNumber() + 1;
|
||||
lastRange.startLine = lastRange.endLine = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lastRange.startLine != -1)
|
||||
editedRanges.push_back(lastRange);
|
||||
|
||||
if (!editedRanges.empty()) {
|
||||
QTextCursor cursor(document());
|
||||
cursor.joinPreviousEditBlock();
|
||||
indenter()->format(editedRanges);
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
TextEditor::StorageSettings settings = storageSettings();
|
||||
resetSettingsOnScopeExit.reset(
|
||||
[this, defaultSettings = settings]() { setStorageSettings(defaultSettings); });
|
||||
settings.m_cleanWhitespace = false;
|
||||
setStorageSettings(settings);
|
||||
// block.revision() != documentRevision
|
||||
if (lastRange.startLine == -1)
|
||||
lastRange.startLine = block.blockNumber() + 1;
|
||||
lastRange.endLine = block.blockNumber() + 1;
|
||||
}
|
||||
|
||||
if (lastRange.startLine != -1)
|
||||
editedRanges.push_back(lastRange);
|
||||
|
||||
if (!editedRanges.empty()) {
|
||||
QTextCursor cursor(document());
|
||||
cursor.joinPreviousEditBlock();
|
||||
indenter()->format(editedRanges);
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
TextEditor::StorageSettings settings = storageSettings();
|
||||
const QScopeGuard cleanup([this, settings] { setStorageSettings(settings); });
|
||||
settings.m_cleanWhitespace = false;
|
||||
setStorageSettings(settings);
|
||||
|
||||
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
||||
}
|
||||
|
||||
|
@@ -20,11 +20,11 @@
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QScopeGuard>
|
||||
#include <QtTest>
|
||||
|
||||
#define VERIFY_DOCUMENT_REVISION(document, expectedRevision) \
|
||||
@@ -1085,9 +1085,7 @@ void ModelManagerTest::testRenameIncludesInEditor()
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(mainFile);
|
||||
QVERIFY(editor);
|
||||
EditorCloser editorCloser(editor);
|
||||
Utils::ExecuteOnDestruction saveAllFiles([](){
|
||||
Core::DocumentManager::saveAllModifiedDocumentsSilently();
|
||||
});
|
||||
const QScopeGuard cleanup([] { Core::DocumentManager::saveAllModifiedDocumentsSilently(); });
|
||||
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
|
||||
QVERIFY(modelManager->isCppEditor(editor));
|
||||
QVERIFY(modelManager->workingCopy().get(mainFile));
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include <texteditor/storagesettings.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -376,11 +375,8 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
||||
return;
|
||||
|
||||
bool hasGcFinished = false;
|
||||
QMetaObject::Connection connection;
|
||||
Utils::ExecuteOnDestruction disconnect([&]() { QObject::disconnect(connection); });
|
||||
connection = QObject::connect(CppModelManager::instance(), &CppModelManager::gcFinished, [&]() {
|
||||
hasGcFinished = true;
|
||||
});
|
||||
auto connection = QObject::connect(CppModelManager::instance(), &CppModelManager::gcFinished,
|
||||
[&hasGcFinished] { hasGcFinished = true; });
|
||||
|
||||
for (Project *project : std::as_const(m_openProjects))
|
||||
ProjectExplorerPlugin::unloadProject(project);
|
||||
@@ -389,6 +385,8 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
||||
t.start();
|
||||
while (!hasGcFinished && t.elapsed() <= 30000)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QObject::disconnect(connection);
|
||||
}
|
||||
|
||||
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile,
|
||||
|
@@ -8,13 +8,13 @@
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/mimeutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
|
||||
#include <QPoint>
|
||||
#include <QScopeGuard>
|
||||
#include <QTextBlock>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
@@ -148,7 +148,7 @@ void ResourcePreviewHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report)
|
||||
{
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
const QScopeGuard cleanup([this, report] { report(priority()); });
|
||||
|
||||
if (editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||
const QTextBlock tb = editorWidget->document()->findBlock(pos);
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include <texteditor/textmark.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
|
Reference in New Issue
Block a user