forked from qt-creator/qt-creator
TextEditor: Let TextMark subclasses provide a settings page
Task-number: QTCREATORBUG-25150 Change-Id: Id5bbdcf2db7afacb823140d77ebd5bc141ac7f81 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
#include <cpptools/clangdiagnosticconfigsmodel.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <cpptools/cppcodemodelsettings.h>
|
||||
@@ -218,6 +219,8 @@ ClangTextMark::ClangTextMark(const FilePath &fileName,
|
||||
, m_removedFromEditorHandler(removedHandler)
|
||||
, m_diagMgr(diagMgr)
|
||||
{
|
||||
setSettingsPage(CppTools::Constants::CPP_CODE_MODEL_SETTINGS_ID);
|
||||
|
||||
const bool warning = isWarningOrNote(diagnostic.severity);
|
||||
setDefaultToolTip(warning ? QApplication::translate("Clang Code Model Marks", "Code Model Warning")
|
||||
: QApplication::translate("Clang Code Model Marks", "Code Model Error"));
|
||||
|
@@ -43,6 +43,8 @@ DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic)
|
||||
Utils::Id(Constants::DIAGNOSTIC_MARK_ID))
|
||||
, m_diagnostic(diagnostic)
|
||||
{
|
||||
setSettingsPage(Constants::SETTINGS_PAGE_ID);
|
||||
|
||||
if (diagnostic.type == "error" || diagnostic.type == "fatal")
|
||||
setColor(Utils::Theme::CodeModel_Error_TextMarkColor);
|
||||
else
|
||||
|
@@ -76,6 +76,7 @@ CppcheckTextMark::CppcheckTextMark (const Diagnostic &diagnostic)
|
||||
setIcon(visual.icon);
|
||||
setToolTip(toolTipText(diagnostic.severityText));
|
||||
setLineAnnotation(diagnostic.message);
|
||||
setSettingsPage(Constants::OPTIONS_PAGE_ID);
|
||||
}
|
||||
|
||||
QString CppcheckTextMark::toolTipText(const QString &severityText) const
|
||||
|
@@ -32,8 +32,10 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QGridLayout>
|
||||
@@ -95,6 +97,7 @@ TextMark::~TextMark()
|
||||
{
|
||||
qDeleteAll(m_actions);
|
||||
m_actions.clear();
|
||||
delete m_settingsAction;
|
||||
if (!m_fileName.isEmpty())
|
||||
TextMarkRegistry::remove(this);
|
||||
if (m_baseTextDocument)
|
||||
@@ -295,12 +298,15 @@ void TextMark::addToToolTipLayout(QGridLayout *target) const
|
||||
target->addLayout(contentLayout, row, 1);
|
||||
|
||||
// Right column: action icons/button
|
||||
if (!m_actions.isEmpty()) {
|
||||
QVector<QAction *> actions = m_actions;
|
||||
if (m_settingsAction)
|
||||
actions << m_settingsAction;
|
||||
if (!actions.isEmpty()) {
|
||||
auto actionsLayout = new QHBoxLayout;
|
||||
QMargins margins = actionsLayout->contentsMargins();
|
||||
margins.setLeft(margins.left() + 5);
|
||||
actionsLayout->setContentsMargins(margins);
|
||||
for (QAction *action : m_actions) {
|
||||
for (QAction *action : qAsConst(actions)) {
|
||||
QTC_ASSERT(!action->icon().isNull(), continue);
|
||||
auto button = new QToolButton;
|
||||
button->setIcon(action->icon());
|
||||
@@ -387,6 +393,16 @@ void TextMark::setActions(const QVector<QAction *> &actions)
|
||||
m_actions = actions;
|
||||
}
|
||||
|
||||
void TextMark::setSettingsPage(Id settingsPage)
|
||||
{
|
||||
delete m_settingsAction;
|
||||
m_settingsAction = new QAction;
|
||||
m_settingsAction->setIcon(Utils::Icons::SETTINGS_TOOLBAR.icon());
|
||||
QObject::connect(m_settingsAction, &QAction::triggered, [this, settingsPage] {
|
||||
Core::ICore::showOptionsDialog(settingsPage);
|
||||
});
|
||||
}
|
||||
|
||||
TextMarkRegistry::TextMarkRegistry(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
@@ -129,6 +129,9 @@ public:
|
||||
QVector<QAction *> actions() const;
|
||||
void setActions(const QVector<QAction *> &actions); // Takes ownership
|
||||
|
||||
protected:
|
||||
void setSettingsPage(Utils::Id settingsPage);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TextMark)
|
||||
|
||||
@@ -147,6 +150,7 @@ private:
|
||||
std::function<QString()> m_toolTipProvider;
|
||||
QString m_defaultToolTip;
|
||||
QVector<QAction *> m_actions;
|
||||
QAction *m_settingsAction = nullptr;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
Reference in New Issue
Block a user