Remove unnecessary removeContextObject calls

They are removed on deletion now.

Change-Id: I08461ea4938e24ab450df013a0f8f820032381da
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-05-26 14:48:38 +02:00
parent 7b5481f75c
commit e5bb7d1ffe
24 changed files with 46 additions and 126 deletions

View File

@@ -1560,9 +1560,3 @@ AndroidManifestTextEditorWidget::AndroidManifestTextEditorWidget(AndroidManifest
m_context->setContext(Core::Context(Constants::ANDROID_MANIFEST_EDITOR_CONTEXT));
Core::ICore::addContextObject(m_context);
}
AndroidManifestTextEditorWidget::~AndroidManifestTextEditorWidget()
{
Core::ICore::removeContextObject(m_context);
}

View File

@@ -79,7 +79,6 @@ class AndroidManifestTextEditorWidget : public TextEditor::TextEditorWidget
{
public:
explicit AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent);
~AndroidManifestTextEditorWidget() override;
private:
Core::IContext *m_context;

View File

@@ -211,11 +211,6 @@ BookmarkView::BookmarkView(BookmarkManager *manager) :
connect(this, &QAbstractItemView::activated, this, &BookmarkView::gotoBookmark);
}
BookmarkView::~BookmarkView()
{
ICore::removeContextObject(m_bookmarkContext);
}
QList<QToolButton *> BookmarkView::createToolBarWidgets()
{
Command *prevCmd = ActionManager::command(Constants::BOOKMARKS_PREV_ACTION);

View File

@@ -128,7 +128,6 @@ class BookmarkView final : public Utils::ListView
public:
explicit BookmarkView(BookmarkManager *manager);
~BookmarkView() final;
QList<QToolButton *> createToolBarWidgets();

View File

@@ -61,7 +61,6 @@ EditorArea::~EditorArea()
disconnect(qApp, &QApplication::focusChanged,
this, &EditorArea::focusChanged);
ICore::removeContextObject(m_context);
delete m_context;
}

View File

@@ -109,9 +109,6 @@ IOutputPane::IOutputPane(QObject *parent)
IOutputPane::~IOutputPane()
{
if (m_context)
ICore::removeContextObject(m_context);
const int i = Utils::indexOf(g_outputPanes, Utils::equal(&OutputPaneData::pane, this));
QTC_ASSERT(i >= 0, return);
delete g_outputPanes.at(i).button;

View File

@@ -66,13 +66,6 @@ public:
{
}
~OutputWindowPrivate()
{
ICore::removeContextObject(outputWindowContext);
delete outputWindowContext;
}
IContext *outputWindowContext = nullptr;
QString settingsKey;
OutputFormatter formatter;
QList<QPair<QString, OutputFormat>> queuedOutput;
@@ -116,10 +109,10 @@ OutputWindow::OutputWindow(Context context, const QString &settingsKey, QWidget
d->settingsKey = settingsKey;
d->outputWindowContext = new IContext;
d->outputWindowContext->setContext(context);
d->outputWindowContext->setWidget(this);
ICore::addContextObject(d->outputWindowContext);
auto outputWindowContext = new IContext(this);
outputWindowContext->setContext(context);
outputWindowContext->setWidget(this);
ICore::addContextObject(outputWindowContext);
auto undoAction = new QAction(this);
auto redoAction = new QAction(this);

View File

@@ -98,9 +98,9 @@ static void createStatusBarManager()
bar->insertPermanentWidget(1, rightCornerWidget);
m_statusBarWidgets.append(rightCornerWidget);
auto context = new StatusBarContext(bar);
context->setWidget(bar);
ICore::addContextObject(context);
auto statusContext = new StatusBarContext(bar);
statusContext->setWidget(bar);
ICore::addContextObject(statusContext);
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, [] {
QSettings *s = ICore::settings();
@@ -109,7 +109,8 @@ static void createStatusBarManager()
s->endGroup();
});
QObject::connect(ICore::instance(), &ICore::coreAboutToClose, [] {
QObject::connect(ICore::instance(), &ICore::coreAboutToClose, [statusContext] {
delete statusContext;
// This is the catch-all on rampdown. Individual items may
// have been removed earlier by destroyStatusBarWidget().
for (const QPointer<IContext> &context : m_contexts) {
@@ -144,8 +145,8 @@ void StatusBarManager::destroyStatusBarWidget(QWidget *widget)
QTC_ASSERT(widget, return);
for (const QPointer<IContext> &context : m_contexts) {
if (context->widget() == widget) {
ICore::removeContextObject(context);
m_contexts.removeAll(context);
delete context;
break;
}
}

View File

@@ -91,7 +91,6 @@ WindowSupport::~WindowSupport()
ActionManager::unregisterAction(m_closeAction, Constants::CLOSE_WINDOW);
}
ActionManager::unregisterAction(m_toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN);
ICore::removeContextObject(m_contextObject);
m_windowList->removeWindow(m_window);
}
}

View File

@@ -211,7 +211,6 @@ public:
QMenu *m_previewInStyleMenu = nullptr;
QAction *m_actionAboutPlugins = nullptr;
DesignerContext *m_context = nullptr;
Context m_contexts;
QList<Id> m_toolActionIds;
@@ -275,8 +274,6 @@ FormEditorData::FormEditorData() :
FormEditorData::~FormEditorData()
{
if (m_context)
ICore::removeContextObject(m_context);
if (m_initStage == FormEditorW::FullyInitialized) {
QSettings *s = ICore::settings();
s->beginGroup(settingsGroupC);
@@ -423,8 +420,7 @@ void FormEditorData::fullInit()
Context designerContexts = m_contexts;
designerContexts.add(Core::Constants::C_EDITORMANAGER);
m_context = new DesignerContext(designerContexts, m_modeWidget, m_instance);
ICore::addContextObject(m_context);
ICore::addContextObject(new DesignerContext(designerContexts, m_modeWidget, m_instance));
DesignMode::registerDesignWidget(m_modeWidget, QStringList(FORM_MIMETYPE), m_contexts);

View File

@@ -77,16 +77,12 @@ class DescriptionEditorWidget : public TextEditorWidget
Q_OBJECT
public:
DescriptionEditorWidget(QWidget *parent = nullptr);
~DescriptionEditorWidget() override;
QSize sizeHint() const override;
protected:
void setDisplaySettings(const DisplaySettings &ds) override;
void setMarginSettings(const MarginSettings &ms) override;
private:
Core::IContext *m_context;
};
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
@@ -107,19 +103,14 @@ DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_context = new Core::IContext(this);
m_context->setWidget(this);
m_context->setContext(Core::Context(Constants::C_DIFF_EDITOR_DESCRIPTION));
Core::ICore::addContextObject(m_context);
auto context = new Core::IContext(this);
context->setWidget(this);
context->setContext(Core::Context(Constants::C_DIFF_EDITOR_DESCRIPTION));
Core::ICore::addContextObject(context);
textDocument()->setSyntaxHighlighter(new SyntaxHighlighter);
}
DescriptionEditorWidget::~DescriptionEditorWidget()
{
Core::ICore::removeContextObject(m_context);
}
QSize DescriptionEditorWidget::sizeHint() const
{
QSize size = TextEditorWidget::sizeHint();

View File

@@ -802,20 +802,14 @@ SideBySideDiffEditorWidget::SideBySideDiffEditorWidget(QWidget *parent)
l->addWidget(m_splitter);
setFocusProxy(m_leftEditor);
m_leftContext = new IContext(this);
m_leftContext->setWidget(m_leftEditor);
m_leftContext->setContext(Core::Context(Core::Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(1)));
Core::ICore::addContextObject(m_leftContext);
m_rightContext = new IContext(this);
m_rightContext->setWidget(m_rightEditor);
m_rightContext->setContext(Core::Context(Core::Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(2)));
Core::ICore::addContextObject(m_rightContext);
}
SideBySideDiffEditorWidget::~SideBySideDiffEditorWidget()
{
Core::ICore::removeContextObject(m_leftContext);
Core::ICore::removeContextObject(m_rightContext);
auto leftContext = new IContext(this);
leftContext->setWidget(m_leftEditor);
leftContext->setContext(Core::Context(Core::Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(1)));
Core::ICore::addContextObject(leftContext);
auto rightContext = new IContext(this);
rightContext->setWidget(m_rightEditor);
rightContext->setContext(Core::Context(Core::Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(2)));
Core::ICore::addContextObject(rightContext);
}
TextEditorWidget *SideBySideDiffEditorWidget::leftEditorWidget() const

View File

@@ -56,7 +56,6 @@ class SideBySideDiffEditorWidget : public QWidget
Q_OBJECT
public:
explicit SideBySideDiffEditorWidget(QWidget *parent = nullptr);
~SideBySideDiffEditorWidget() override;
TextEditor::TextEditorWidget *leftEditorWidget() const;
TextEditor::TextEditorWidget *rightEditorWidget() const;
@@ -109,8 +108,6 @@ private:
bool m_horizontalSync = false;
QTextCharFormat m_spanLineFormat;
Core::IContext *m_leftContext = nullptr;
Core::IContext *m_rightContext = nullptr;
};
} // namespace Internal

View File

@@ -77,18 +77,13 @@ UnifiedDiffEditorWidget::UnifiedDiffEditorWidget(QWidget *parent)
connect(this, &QPlainTextEdit::cursorPositionChanged,
this, &UnifiedDiffEditorWidget::slotCursorPositionChangedInEditor);
m_context = new Core::IContext(this);
m_context->setWidget(this);
m_context->setContext(Core::Context(Constants::UNIFIED_VIEW_ID));
Core::ICore::addContextObject(m_context);
auto context = new Core::IContext(this);
context->setWidget(this);
context->setContext(Core::Context(Constants::UNIFIED_VIEW_ID));
Core::ICore::addContextObject(context);
setCodeFoldingSupported(true);
}
UnifiedDiffEditorWidget::~UnifiedDiffEditorWidget()
{
Core::ICore::removeContextObject(m_context);
}
void UnifiedDiffEditorWidget::setDocument(DiffEditorDocument *document)
{
m_controller.setDocument(document);

View File

@@ -50,7 +50,6 @@ class UnifiedDiffEditorWidget : public SelectableTextEditorWidget
Q_OBJECT
public:
UnifiedDiffEditorWidget(QWidget *parent = nullptr);
~UnifiedDiffEditorWidget() override;
void setDocument(DiffEditorDocument *document);
DiffEditorDocument *diffDocument() const;
@@ -117,7 +116,6 @@ private:
QMap<int, QPair<int, int> > m_chunkInfo;
QByteArray m_state;
Core::IContext *m_context = nullptr;
};
} // namespace Internal

View File

@@ -548,7 +548,6 @@ HelpWidget::~HelpWidget()
if (m_openPagesAction)
Core::ActionManager::unregisterAction(m_openPagesAction, Constants::HELP_OPENPAGES);
}
Core::ICore::removeContextObject(m_context);
Core::ActionManager::unregisterAction(m_copy, Core::Constants::COPY);
Core::ActionManager::unregisterAction(m_printAction, Core::Constants::PRINT);
if (m_toggleSideBarAction)

View File

@@ -299,10 +299,10 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) : QWidget(parent
m_crumbContainer(new QWidget(this)),
m_crumbLabel(new DelayedFileCrumbLabel(this))
{
m_context = new Core::IContext(this);
m_context->setContext(Core::Context(C_FOLDERNAVIGATIONWIDGET));
m_context->setWidget(this);
Core::ICore::addContextObject(m_context);
auto context = new Core::IContext(this);
context->setContext(Core::Context(C_FOLDERNAVIGATIONWIDGET));
context->setWidget(this);
Core::ICore::addContextObject(context);
setBackgroundRole(QPalette::Base);
setAutoFillBackground(true);
@@ -435,11 +435,6 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) : QWidget(parent
setRootAutoSynchronization(true);
}
FolderNavigationWidget::~FolderNavigationWidget()
{
Core::ICore::removeContextObject(m_context);
}
void FolderNavigationWidget::toggleAutoSynchronization()
{
setAutoSynchronization(!m_autoSync);

View File

@@ -94,7 +94,6 @@ class FolderNavigationWidget : public QWidget
Q_PROPERTY(bool autoSynchronization READ autoSynchronization WRITE setAutoSynchronization)
public:
explicit FolderNavigationWidget(QWidget *parent = nullptr);
~FolderNavigationWidget() override;
static QStringList projectFilesInDirectory(const QString &path);
@@ -135,7 +134,6 @@ private:
void openProjectsInDirectory(const QModelIndex &index);
void createNewFolder(const QModelIndex &parent);
Core::IContext *m_context = nullptr;
Utils::NavigationTreeView *m_listView = nullptr;
QFileSystemModel *m_fileSystemModel = nullptr;
QSortFilterProxyModel *m_sortProxyModel = nullptr;

View File

@@ -152,11 +152,11 @@ public:
setDragDropMode(QAbstractItemView::DragDrop);
viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);
m_context = new IContext(this);
m_context->setContext(Context(ProjectExplorer::Constants::C_PROJECT_TREE));
m_context->setWidget(this);
auto context = new IContext(this);
context->setContext(Context(ProjectExplorer::Constants::C_PROJECT_TREE));
context->setWidget(this);
ICore::addContextObject(m_context);
ICore::addContextObject(context);
connect(this, &ProjectTreeView::expanded,
this, &ProjectTreeView::invalidateSize);
@@ -204,12 +204,6 @@ public:
NavigationTreeView::setModel(newModel);
}
~ProjectTreeView() override
{
ICore::removeContextObject(m_context);
delete m_context;
}
int sizeHintForColumn(int column) const override
{
if (m_cachedSize < 0)
@@ -220,7 +214,6 @@ public:
private:
mutable int m_cachedSize = -1;
IContext *m_context;
};
/*!

View File

@@ -397,7 +397,6 @@ TaskWindow::TaskWindow() : d(std::make_unique<TaskWindowPrivate>())
TaskWindow::~TaskWindow()
{
Core::ICore::removeContextObject(d->m_taskWindowContext);
delete d->m_filterWarningsButton;
delete d->m_listview;
delete d->m_filter;

View File

@@ -68,9 +68,6 @@ BindingEditorWidget::BindingEditorWidget()
BindingEditorWidget::~BindingEditorWidget()
{
unregisterAutoCompletion();
Core::ICore::removeContextObject(m_context);
delete m_context;
}
void BindingEditorWidget::unregisterAutoCompletion()

View File

@@ -118,7 +118,6 @@ public:
SettingsPage settingsPage;
DesignModeWidget mainWidget;
DesignerSettings settings;
DesignModeContext *context = nullptr;
QtQuickDesignerFactory m_qtQuickDesignerFactory;
bool blockEditorChange = false;
};
@@ -194,11 +193,8 @@ QmlDesignerPlugin::QmlDesignerPlugin()
QmlDesignerPlugin::~QmlDesignerPlugin()
{
if (d) {
if (d)
Core::DesignMode::unregisterDesignWidget(&d->mainWidget);
Core::ICore::removeContextObject(d->context);
d->context = nullptr;
}
delete d;
d = nullptr;
m_instance = nullptr;
@@ -290,18 +286,18 @@ static QString projectPath(const Utils::FilePath &fileName)
void QmlDesignerPlugin::integrateIntoQtCreator(QWidget *modeWidget)
{
d->context = new Internal::DesignModeContext(modeWidget);
Core::ICore::addContextObject(d->context);
auto context = new Internal::DesignModeContext(modeWidget);
Core::ICore::addContextObject(context);
Core::Context qmlDesignerMainContext(Constants::C_QMLDESIGNER);
Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR);
Core::Context qmlDesignerEditor3dContext(Constants::C_QMLEDITOR3D);
Core::Context qmlDesignerNavigatorContext(Constants::C_QMLNAVIGATOR);
d->context->context().add(qmlDesignerMainContext);
d->context->context().add(qmlDesignerFormEditorContext);
d->context->context().add(qmlDesignerEditor3dContext);
d->context->context().add(qmlDesignerNavigatorContext);
d->context->context().add(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID);
context->context().add(qmlDesignerMainContext);
context->context().add(qmlDesignerFormEditorContext);
context->context().add(qmlDesignerEditor3dContext);
context->context().add(qmlDesignerNavigatorContext);
context->context().add(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID);
d->shortCutManager.registerActions(qmlDesignerMainContext, qmlDesignerFormEditorContext,
qmlDesignerEditor3dContext, qmlDesignerNavigatorContext);
@@ -309,7 +305,7 @@ void QmlDesignerPlugin::integrateIntoQtCreator(QWidget *modeWidget)
const QStringList mimeTypes = { QmlJSTools::Constants::QML_MIMETYPE,
QmlJSTools::Constants::QMLUI_MIMETYPE };
Core::DesignMode::registerDesignWidget(modeWidget, mimeTypes, d->context->context());
Core::DesignMode::registerDesignWidget(modeWidget, mimeTypes, context->context());
connect(Core::DesignMode::instance(), &Core::DesignMode::actionsUpdated,
&d->shortCutManager, &ShortCutManager::updateActions);

View File

@@ -111,9 +111,6 @@ ScxmlEditorData::ScxmlEditorData()
ScxmlEditorData::~ScxmlEditorData()
{
if (m_context)
ICore::removeContextObject(m_context);
if (m_modeWidget) {
DesignMode::unregisterDesignWidget(m_modeWidget);
delete m_modeWidget;
@@ -146,8 +143,8 @@ void ScxmlEditorData::fullInit()
Context scxmlContexts = m_contexts;
scxmlContexts.add(Core::Constants::C_EDITORMANAGER);
m_context = new ScxmlContext(scxmlContexts, m_modeWidget, this);
ICore::addContextObject(m_context);
auto context = new ScxmlContext(scxmlContexts, m_modeWidget, this);
ICore::addContextObject(context);
DesignMode::registerDesignWidget(m_modeWidget, QStringList(QLatin1String(ProjectExplorer::Constants::SCXML_MIMETYPE)), m_contexts);
}

View File

@@ -57,7 +57,6 @@ private:
QWidget *createModeWidget();
EditorToolBar *createMainToolBar();
ScxmlContext *m_context = nullptr;
Context m_contexts;
QWidget *m_modeWidget = nullptr;
ScxmlEditorStack *m_widgetStack = nullptr;