diff options
-rw-r--r-- | src/libs/extensionsystem/pluginmanager.cpp | 14 | ||||
-rw-r--r-- | src/libs/utils/executeondestruction.h | 50 | ||||
-rw-r--r-- | src/libs/utils/utils-lib.pri | 3 | ||||
-rw-r--r-- | src/libs/utils/utils.qbs | 1 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.cpp | 11 |
5 files changed, 61 insertions, 18 deletions
diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp index 5c2fd958d3..5f2785236d 100644 --- a/src/libs/extensionsystem/pluginmanager.cpp +++ b/src/libs/extensionsystem/pluginmanager.cpp @@ -52,6 +52,7 @@ #include <QSysInfo> #include <utils/algorithm.h> +#include <utils/executeondestruction.h> #include <utils/qtcassert.h> #ifdef WITH_TESTS @@ -1059,16 +1060,6 @@ static TestPlan generateCustomTestPlan(IPlugin *plugin, const QList<QObject *> & return testPlan; } -class ExecuteOnDestruction -{ -public: - ExecuteOnDestruction(std::function<void()> code) : destructionCode(code) {} - ~ExecuteOnDestruction() { if (destructionCode) destructionCode(); } - -private: - const std::function<void()> destructionCode; -}; - void PluginManagerPrivate::startTests() { if (PluginManager::hasError()) { @@ -1084,7 +1075,8 @@ void PluginManagerPrivate::startTests() continue; // plugin not loaded const QList<QObject *> testObjects = plugin->createTestObjects(); - ExecuteOnDestruction deleteTestObjects([&]() { qDeleteAll(testObjects); }); + Utils::ExecuteOnDestruction deleteTestObjects([&]() { qDeleteAll(testObjects); }); + Q_UNUSED(deleteTestObjects) const bool hasDuplicateTestObjects = testObjects.size() != testObjects.toSet().size(); QTC_ASSERT(!hasDuplicateTestObjects, continue); diff --git a/src/libs/utils/executeondestruction.h b/src/libs/utils/executeondestruction.h new file mode 100644 index 0000000000..985df09e0b --- /dev/null +++ b/src/libs/utils/executeondestruction.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef EXECUTEONDESTRUCTION_H +#define EXECUTEONDESTRUCTION_H + +#include <functional> + +namespace Utils { + +class ExecuteOnDestruction +{ +public: + ExecuteOnDestruction(std::function<void()> code) : destructionCode(code) {} + ~ExecuteOnDestruction() { if (destructionCode) destructionCode(); } + +private: + const std::function<void()> destructionCode; +}; + +} // Utils + +#endif // EXECUTEONDESTRUCTION_H diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 71151b6971..fd7ced8e25 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -187,7 +187,8 @@ HEADERS += \ $$PWD/theme/theme.h \ $$PWD/theme/theme_p.h \ $$PWD/progressindicator.h \ - $$PWD/fadingindicator.h + $$PWD/fadingindicator.h \ + $$PWD/executeondestruction.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 9453e08902..a31e35d741 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -72,6 +72,7 @@ QtcLibrary { "environmentmodel.h", "execmenu.cpp", "execmenu.h", + "executeondestruction.h", "fadingindicator.cpp", "fadingindicator.h", "faketooltip.cpp", diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 95721873f4..076aac930f 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -65,6 +65,7 @@ #include <extensionsystem/pluginmanager.h> #include <utils/algorithm.h> +#include <utils/executeondestruction.h> #include <utils/fileutils.h> #include <utils/hostosinfo.h> #include <utils/macroexpander.h> @@ -2379,6 +2380,9 @@ IEditor *EditorManager::openEditorWithContents(Id editorId, EditorManager::gotoOtherSplit(); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + Utils::ExecuteOnDestruction appRestoreCursor(&QApplication::restoreOverrideCursor); + Q_UNUSED(appRestoreCursor) + const QString title = makeTitleUnique(titlePattern); @@ -2392,20 +2396,16 @@ IEditor *EditorManager::openEditorWithContents(Id editorId, if (!title.isEmpty()) edt->document()->setPreferredDisplayName(title); - QApplication::restoreOverrideCursor(); activateEditor(edt, flags); return edt; } } edt = EditorManagerPrivate::createEditor(editorId, title); - if (!edt) { - QApplication::restoreOverrideCursor(); + if (!edt) return 0; - } if (!edt->document()->setContents(contents)) { - QApplication::restoreOverrideCursor(); delete edt; edt = 0; return 0; @@ -2418,7 +2418,6 @@ IEditor *EditorManager::openEditorWithContents(Id editorId, edt->document()->setPreferredDisplayName(title); EditorManagerPrivate::addEditor(edt); - QApplication::restoreOverrideCursor(); activateEditor(edt, flags); return edt; } |