Commit 4b6ee588 authored by Nikita Baryshnikov's avatar Nikita Baryshnikov Committed by Eike Ziller

PluginManager: share ExecuteOnDestruction with utils

Change-Id: I895d0ae48c36030e58aea1676873bd285680a661
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 954feb48
......@@ -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);
......
/****************************************************************************
**
** 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
......@@ -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 \
......
......@@ -72,6 +72,7 @@ QtcLibrary {
"environmentmodel.h",
"execmenu.cpp",
"execmenu.h",
"executeondestruction.h",
"fadingindicator.cpp",
"fadingindicator.h",
"faketooltip.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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment