forked from qt-creator/qt-creator
Core: Add a static IContext::attach() function
... to simplify the user code. Some, but not all, potential beneficiaries are adapted. Change-Id: Ia7d514a0114a4f99f8ee745523435f5b990bd095 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -7,19 +7,15 @@
|
||||
#include "testtreemodel.h"
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
|
||||
TestTreeView::TestTreeView(QWidget *parent)
|
||||
: NavigationTreeView(parent),
|
||||
m_context(new Core::IContext(this))
|
||||
: NavigationTreeView(parent)
|
||||
{
|
||||
setExpandsOnDoubleClick(false);
|
||||
m_context->setWidget(this);
|
||||
m_context->setContext(Core::Context(Constants::AUTOTEST_CONTEXT));
|
||||
Core::ICore::addContextObject(m_context);
|
||||
Core::IContext::attach(this, Core::Context(Constants::AUTOTEST_CONTEXT));
|
||||
}
|
||||
|
||||
static void changeCheckStateAll(const Qt::CheckState checkState)
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
|
||||
#include <utils/navigationtreeview.h>
|
||||
|
||||
namespace Core {
|
||||
class IContext;
|
||||
}
|
||||
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
|
||||
@@ -21,9 +17,6 @@ public:
|
||||
|
||||
void selectAll() override;
|
||||
void deselectAll();
|
||||
|
||||
private:
|
||||
Core::IContext *m_context;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -66,14 +66,10 @@ EditMode::EditMode() :
|
||||
this, &EditMode::grabEditorManager);
|
||||
m_splitter->setFocusProxy(editorPlaceHolder);
|
||||
|
||||
auto modeContextObject = new IContext(this);
|
||||
modeContextObject->setContext(Context(Constants::C_EDITORMANAGER));
|
||||
modeContextObject->setWidget(m_splitter);
|
||||
ICore::addContextObject(modeContextObject);
|
||||
IContext::attach(m_splitter, Context(Constants::C_EDITORMANAGER));
|
||||
|
||||
setWidget(m_splitter);
|
||||
setContext(Context(Constants::C_EDIT_MODE,
|
||||
Constants::C_NAVIGATION_PANE));
|
||||
setContext(Context(Constants::C_EDIT_MODE, Constants::C_NAVIGATION_PANE));
|
||||
}
|
||||
|
||||
EditMode::~EditMode()
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "../coreconstants.h"
|
||||
#include "../icontext.h"
|
||||
#include "../icore.h"
|
||||
#include "../idocument.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -20,10 +19,7 @@ namespace Internal {
|
||||
|
||||
EditorArea::EditorArea()
|
||||
{
|
||||
m_context = new IContext;
|
||||
m_context->setContext(Context(Constants::C_EDITORMANAGER));
|
||||
m_context->setWidget(this);
|
||||
ICore::addContextObject(m_context);
|
||||
IContext::attach(this, Context(Constants::C_EDITORMANAGER));
|
||||
|
||||
setCurrentView(view());
|
||||
updateCloseSplitButton();
|
||||
@@ -39,8 +35,6 @@ EditorArea::~EditorArea()
|
||||
setCurrentView(nullptr);
|
||||
disconnect(qApp, &QApplication::focusChanged,
|
||||
this, &EditorArea::focusChanged);
|
||||
|
||||
delete m_context;
|
||||
}
|
||||
|
||||
IDocument *EditorArea::currentDocument() const
|
||||
|
||||
@@ -7,11 +7,7 @@
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class IContext;
|
||||
|
||||
namespace Internal {
|
||||
namespace Core::Internal {
|
||||
|
||||
class EditorArea : public SplitterOrView
|
||||
{
|
||||
@@ -35,10 +31,8 @@ private:
|
||||
void updateCloseSplitButton();
|
||||
void hideEvent(QHideEvent *) override;
|
||||
|
||||
IContext *m_context;
|
||||
QPointer<EditorView> m_currentView;
|
||||
QPointer<IDocument> m_currentDocument;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // Core
|
||||
} // Core::Internal
|
||||
|
||||
@@ -247,10 +247,7 @@ void Find::initialize()
|
||||
d->m_currentDocumentFind = new Internal::CurrentDocumentFind;
|
||||
|
||||
d->m_findToolBar = new Internal::FindToolBar(d->m_currentDocumentFind);
|
||||
auto *findToolBarContext = new IContext(m_instance);
|
||||
findToolBarContext->setWidget(d->m_findToolBar);
|
||||
findToolBarContext->setContext(Context(Constants::C_FINDTOOLBAR));
|
||||
ICore::addContextObject(findToolBarContext);
|
||||
IContext::attach(d->m_findToolBar, Context(Constants::C_FINDTOOLBAR));
|
||||
|
||||
d->m_findDialog = new Internal::FindToolWindow;
|
||||
d->m_searchResultWindow = new SearchResultWindow(d->m_findDialog);
|
||||
|
||||
@@ -256,10 +256,7 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) : QWidget(parent
|
||||
m_crumbContainer(new QWidget(this)),
|
||||
m_crumbLabel(new DelayedFileCrumbLabel(this))
|
||||
{
|
||||
auto context = new IContext(this);
|
||||
context->setContext(Context(C_FOLDERNAVIGATIONWIDGET));
|
||||
context->setWidget(this);
|
||||
ICore::addContextObject(context);
|
||||
IContext::attach(this, Context(C_FOLDERNAVIGATIONWIDGET));
|
||||
|
||||
setBackgroundRole(QPalette::Base);
|
||||
setAutoFillBackground(true);
|
||||
|
||||
@@ -3,9 +3,21 @@
|
||||
|
||||
#include "icontext.h"
|
||||
|
||||
#include "icore.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace Core {
|
||||
|
||||
void IContext::attach(QWidget *widget, const Context &context, const HelpItem &help)
|
||||
{
|
||||
auto icontext = new IContext(widget); // As QObject parent.
|
||||
icontext->setContext(context);
|
||||
icontext->setWidget(widget);
|
||||
icontext->setContextHelp(help);
|
||||
ICore::addContextObject(icontext);
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const Core::Context &context)
|
||||
{
|
||||
debug.nospace() << "Context(";
|
||||
@@ -23,6 +35,7 @@ QDebug operator<<(QDebug debug, const Core::Context &context)
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
/*!
|
||||
|
||||
@@ -60,6 +60,10 @@ public:
|
||||
virtual void setWidget(QWidget *widget) { m_widget = widget; }
|
||||
virtual void setContextHelp(const HelpItem &id) { m_contextHelp = id; }
|
||||
|
||||
static void attach(QWidget *widget,
|
||||
const Context &context,
|
||||
const HelpItem &contextHelp = {});
|
||||
|
||||
friend CORE_EXPORT QDebug operator<<(QDebug debug, const Core::Context &context);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -87,8 +87,6 @@ protected:
|
||||
void setupContext(const Context &context, QWidget *widget);
|
||||
void setZoomButtonsEnabled(bool enabled);
|
||||
|
||||
IContext *m_context = nullptr;
|
||||
|
||||
private:
|
||||
virtual void updateFilter();
|
||||
|
||||
|
||||
@@ -224,11 +224,7 @@ void IOutputPane::setupContext(const char *context, QWidget *widget)
|
||||
|
||||
void IOutputPane::setupContext(const Context &context, QWidget *widget)
|
||||
{
|
||||
QTC_ASSERT(!m_context, return);
|
||||
m_context = new IContext(this);
|
||||
m_context->setContext(context);
|
||||
m_context->setWidget(widget);
|
||||
ICore::addContextObject(m_context);
|
||||
IContext::attach(widget, context);
|
||||
|
||||
ActionBuilder(this, Constants::ZOOM_IN)
|
||||
.setContext(context)
|
||||
|
||||
@@ -98,10 +98,7 @@ OutputWindow::OutputWindow(Context context, const Key &settingsKey, QWidget *par
|
||||
|
||||
d->settingsKey = settingsKey;
|
||||
|
||||
auto outputWindowContext = new IContext(this);
|
||||
outputWindowContext->setContext(context);
|
||||
outputWindowContext->setWidget(this);
|
||||
ICore::addContextObject(outputWindowContext);
|
||||
IContext::attach(this, context);
|
||||
|
||||
auto undoAction = new QAction(this);
|
||||
auto redoAction = new QAction(this);
|
||||
|
||||
@@ -34,10 +34,7 @@ WindowSupport::WindowSupport(QWidget *window, const Context &context, const Cont
|
||||
{
|
||||
m_window->installEventFilter(this);
|
||||
|
||||
m_contextObject = new IContext(this);
|
||||
m_contextObject->setWidget(window);
|
||||
m_contextObject->setContext(context);
|
||||
ICore::addContextObject(m_contextObject);
|
||||
IContext::attach(window, context);
|
||||
const Context ac = actionContext.isEmpty() ? context : actionContext;
|
||||
|
||||
if (useMacShortcuts) {
|
||||
|
||||
@@ -54,7 +54,6 @@ private:
|
||||
void updateFullScreenAction();
|
||||
|
||||
QWidget *m_window;
|
||||
IContext *m_contextObject;
|
||||
QAction *m_minimizeAction;
|
||||
QAction *m_zoomAction;
|
||||
QAction *m_closeAction;
|
||||
|
||||
@@ -683,7 +683,6 @@ public:
|
||||
QStringList m_arguments;
|
||||
|
||||
QList<IOptionsPage *> m_optionPages;
|
||||
IContext m_debugModeContext;
|
||||
|
||||
Perspective m_perspective{Constants::PRESET_PERSPECTIVE_ID, Tr::tr("Debugger")};
|
||||
Perspective m_perspectiveDap{Constants::DAP_PERSPECTIVE_ID, Tr::tr("DAP")};
|
||||
@@ -1165,9 +1164,7 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(const QStringList &arguments)
|
||||
// Debug mode setup
|
||||
m_mode = new DebugMode;
|
||||
|
||||
m_debugModeContext.setContext(Context(CC::C_EDITORMANAGER));
|
||||
m_debugModeContext.setWidget(m_mode->widget());
|
||||
ICore::addContextObject(&m_debugModeContext);
|
||||
IContext::attach(m_mode->widget(), Context(CC::C_EDITORMANAGER));
|
||||
|
||||
//
|
||||
// Connections
|
||||
|
||||
@@ -88,10 +88,7 @@ DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
auto context = new IContext(this);
|
||||
context->setWidget(this);
|
||||
context->setContext(Context(Constants::C_DIFF_EDITOR_DESCRIPTION));
|
||||
ICore::addContextObject(context);
|
||||
IContext::attach(this, Context(Constants::C_DIFF_EDITOR_DESCRIPTION));
|
||||
|
||||
textDocument()->resetSyntaxHighlighter([] { return new SyntaxHighlighter(); });
|
||||
}
|
||||
|
||||
@@ -716,10 +716,8 @@ SideBySideDiffEditorWidget::SideBySideDiffEditorWidget(QWidget *parent)
|
||||
connect(m_editor[side]->horizontalScrollBar(), &QAbstractSlider::rangeChanged,
|
||||
this, &SideBySideDiffEditorWidget::syncHorizontalScrollBarPolicy);
|
||||
|
||||
auto context = new IContext(this);
|
||||
context->setWidget(m_editor[side]);
|
||||
context->setContext(Context(Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(side + 1)));
|
||||
ICore::addContextObject(context);
|
||||
IContext::attach(m_editor[side],
|
||||
Context(Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(side + 1)));
|
||||
};
|
||||
setupEditor(LeftSide);
|
||||
setupEditor(RightSide);
|
||||
|
||||
@@ -43,10 +43,7 @@ UnifiedDiffEditorWidget::UnifiedDiffEditorWidget(QWidget *parent)
|
||||
connect(this, &QPlainTextEdit::cursorPositionChanged,
|
||||
this, &UnifiedDiffEditorWidget::slotCursorPositionChangedInEditor);
|
||||
|
||||
auto context = new IContext(this);
|
||||
context->setWidget(this);
|
||||
context->setContext(Context(Constants::UNIFIED_VIEW_ID));
|
||||
ICore::addContextObject(context);
|
||||
IContext::attach(this, Context(Constants::UNIFIED_VIEW_ID));
|
||||
}
|
||||
|
||||
UnifiedDiffEditorWidget::~UnifiedDiffEditorWidget() = default;
|
||||
|
||||
@@ -142,11 +142,8 @@ public:
|
||||
setDragDropMode(QAbstractItemView::DragDrop);
|
||||
viewport()->setAcceptDrops(true);
|
||||
setDropIndicatorShown(true);
|
||||
auto context = new IContext(this);
|
||||
context->setContext(Context(ProjectExplorer::Constants::C_PROJECT_TREE));
|
||||
context->setWidget(this);
|
||||
|
||||
ICore::addContextObject(context);
|
||||
IContext::attach(this, Context(ProjectExplorer::Constants::C_PROJECT_TREE));
|
||||
|
||||
connect(this, &ProjectTreeView::expanded,
|
||||
this, &ProjectTreeView::invalidateSize);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/coreplugintr.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
||||
@@ -30,14 +29,11 @@
|
||||
namespace QmlDesigner {
|
||||
|
||||
BindingEditorWidget::BindingEditorWidget()
|
||||
: m_context(new Core::IContext(this))
|
||||
{
|
||||
Core::Context context(BINDINGEDITOR_CONTEXT_ID,
|
||||
ProjectExplorer::Constants::QMLJS_LANGUAGE_ID);
|
||||
|
||||
m_context->setWidget(this);
|
||||
m_context->setContext(context);
|
||||
Core::ICore::addContextObject(m_context);
|
||||
Core::IContext::attach(this, context);
|
||||
|
||||
Utils::TransientScrollAreaSupport::support(this);
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ signals:
|
||||
|
||||
public:
|
||||
QmlJSEditor::QmlJSEditorDocument *qmljsdocument = nullptr;
|
||||
Core::IContext *m_context = nullptr;
|
||||
QAction *m_completionAction = nullptr;
|
||||
bool m_isMultiline = false;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
#include <coreplugin/editortoolbar.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/minisplitter.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
@@ -218,10 +217,7 @@ void ScxmlEditorData::fullInit()
|
||||
|
||||
Context scxmlContexts = m_contexts;
|
||||
scxmlContexts.add(Core::Constants::C_EDITORMANAGER);
|
||||
auto context = new IContext(this);
|
||||
context->setContext(scxmlContexts);
|
||||
context->setWidget(m_modeWidget);
|
||||
ICore::addContextObject(context);
|
||||
IContext::attach(m_modeWidget, scxmlContexts);
|
||||
|
||||
DesignMode::registerDesignWidget(m_modeWidget, QStringList(Utils::Constants::SCXML_MIMETYPE), m_contexts);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fancylineedit.h>
|
||||
@@ -23,12 +22,9 @@ namespace Squish::Internal {
|
||||
|
||||
SquishTestTreeView::SquishTestTreeView(QWidget *parent)
|
||||
: Utils::NavigationTreeView(parent)
|
||||
, m_context(new Core::IContext(this))
|
||||
{
|
||||
setExpandsOnDoubleClick(false);
|
||||
m_context->setWidget(this);
|
||||
m_context->setContext(Core::Context(Constants::SQUISH_CONTEXT));
|
||||
Core::ICore::addContextObject(m_context);
|
||||
Core::IContext::attach(this, Core::Context(Constants::SQUISH_CONTEXT));
|
||||
}
|
||||
|
||||
void SquishTestTreeView::resizeEvent(QResizeEvent *event)
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include <QModelIndex>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace Core { class IContext; }
|
||||
|
||||
namespace Squish {
|
||||
namespace Internal {
|
||||
|
||||
@@ -29,7 +27,6 @@ signals:
|
||||
void recordTestCase(const QString &suiteName, const QString &testCaseName);
|
||||
|
||||
private:
|
||||
Core::IContext *m_context;
|
||||
QModelIndex m_lastMousePressedIndex;
|
||||
};
|
||||
|
||||
|
||||
@@ -809,10 +809,7 @@ WelcomeMode::WelcomeMode()
|
||||
m_modeWidget = new QWidget;
|
||||
m_modeWidget->setLayout(boxLayout);
|
||||
boxLayout->addWidget(m_quickWidget);
|
||||
auto context = new IContext(m_modeWidget);
|
||||
context->setWidget(m_modeWidget);
|
||||
context->setContextHelp("Qt Design Studio Manual");
|
||||
ICore::addContextObject(context);
|
||||
IContext::attach(m_modeWidget, {}, "Qt Design Studio Manual");
|
||||
setWidget(m_modeWidget);
|
||||
|
||||
QStringList designStudioQchPathes
|
||||
|
||||
@@ -52,15 +52,13 @@ using namespace Utils::Terminal;
|
||||
using namespace Core;
|
||||
|
||||
namespace Terminal {
|
||||
|
||||
TerminalWidget::TerminalWidget(QWidget *parent, const OpenTerminalParameters &openParameters)
|
||||
: Core::SearchableTerminal(parent)
|
||||
, m_context(Utils::Id("TerminalWidget_").withSuffix(QString::number((uintptr_t) this)))
|
||||
, m_openParameters(openParameters)
|
||||
{
|
||||
auto contextObj = new IContext(this);
|
||||
contextObj->setWidget(this);
|
||||
contextObj->setContext(m_context);
|
||||
ICore::addContextObject(contextObj);
|
||||
IContext::attach(this, m_context);
|
||||
|
||||
setupFont();
|
||||
setupColors();
|
||||
|
||||
@@ -192,19 +192,14 @@ protected:
|
||||
void keyPressEvent(QKeyEvent *event) final;
|
||||
|
||||
private:
|
||||
Core::IContext *m_bookmarkContext;
|
||||
QModelIndex m_contextMenuIndex;
|
||||
};
|
||||
|
||||
BookmarkView::BookmarkView()
|
||||
: m_bookmarkContext(new IContext(this))
|
||||
{
|
||||
setWindowTitle(Tr::tr("Bookmarks"));
|
||||
|
||||
m_bookmarkContext->setWidget(this);
|
||||
m_bookmarkContext->setContext(Context(BOOKMARKS_CONTEXT));
|
||||
|
||||
ICore::addContextObject(m_bookmarkContext);
|
||||
IContext::attach(this, Context(BOOKMARKS_CONTEXT));
|
||||
|
||||
ListView::setModel(&bookmarkManager());
|
||||
|
||||
|
||||
@@ -125,10 +125,8 @@ public:
|
||||
&TextEditorWidget::addCurrentStateToNavigationHistory,
|
||||
this,
|
||||
&MarkdownEditor::addCurrentStateToNavigationHistory);
|
||||
auto context = new IContext(this);
|
||||
context->setWidget(m_textEditorWidget);
|
||||
context->setContext(Context(MARKDOWNVIEWER_TEXT_CONTEXT));
|
||||
ICore::addContextObject(context);
|
||||
|
||||
IContext::attach(m_textEditorWidget, Context(MARKDOWNVIEWER_TEXT_CONTEXT));
|
||||
|
||||
m_splitter->addWidget(m_textEditorWidget); // sets splitter->focusWidget() on non-Windows
|
||||
m_splitter->addWidget(m_previewWidget);
|
||||
|
||||
Reference in New Issue
Block a user