kdevplatform/language/duchain
Go to the documentation of this file.
25 #include <QApplication>
27 #include <KLocalizedString>
35 #include <language/editor/documentrange.h>
40 QString KEY_INVOKE_ACTION(
int num) {
return QStringLiteral(
"invoke_action_%1").
arg(num); }
42 QString htmlImg(
const QIcon& icon, QStyle::PixelMetric metric)
44 const int size = qApp->style()->pixelMetric(metric,
nullptr,
nullptr);
48 buffer.open(QIODevice::WriteOnly);
49 pixmap.
save(&buffer,
"PNG", 100);
51 const QString imgTag = QStringLiteral(
"<img width='%1' height='%1' src='data:image/png;base64, %2'/>")
66 std::sort(m_problems.
begin(), m_problems.
end(), [](
const IProblem::Ptr& a,
const IProblem::Ptr& b) {
67 if (a->severity() < b->severity())
70 if (a->severity() > b->severity())
73 if (a->sourceString() < b->sourceString())
97 return i18n(
"Problem");
100 QString ProblemNavigationContext::escapedHtml(
const QString& text)
const
102 const QString htmlStart = QStringLiteral(
"<html>");
103 const QString htmlEnd = QStringLiteral(
"</html>");
108 return result.toHtmlEscaped();
118 modifyHtml() += QStringLiteral(
"<table><tr>");
120 modifyHtml() += QStringLiteral(
"<td valign=\"middle\">%1</td>")
121 .arg(htmlImg(IProblem::iconForSeverity(problem->severity()), QStyle::PM_LargeIconSize));
126 modifyHtml() += i18n(
"Problem in <i>%1</i>", problem->sourceString());
132 .arg(problem->finalLocation().document.toUrl().fileName())
133 .arg(problem->finalLocation().start().line() + 1),
135 NavigationAction(problem->finalLocation().document.toUrl(), problem->finalLocation().start())
141 QString description = escapedHtml(problem->description());
142 QString explanation = escapedHtml(problem->explanation());
148 if (m_problems.
size() == 1 && !explanation.isEmpty() && explanation != description)
155 modifyHtml() += QStringLiteral(
"</tr></table>");
157 const auto diagnostics = problem->diagnostics();
158 if (!diagnostics.isEmpty()) {
160 for (
auto diagnostic : diagnostics) {
163 modifyHtml() += escapedHtml(diagnostic->description());
165 const DocumentRange range = diagnostic->finalLocation();
172 const auto url = declaration->
url().toUrl();
177 }
else if (range.start().isValid()) {
179 const auto url = range.document.toUrl();
182 .arg(range.start().line() + 1),
183 url.toDisplayString(QUrl::PreferLocalFile),
NavigationAction(url, range.start()));
190 auto assistant = problem->solutionAssistant();
191 if (assistant && !assistant->actions().isEmpty()) {
193 QStringLiteral(
"<table width='100%' style='border: 1px solid black; background-color: %1;'>").arg(QStringLiteral(
196 QStringLiteral(
"<tr><td valign='middle'>%1</td><td width='100%'>")
197 .arg(htmlImg(
QIcon::fromTheme(QStringLiteral(
"dialog-ok-apply")), QStyle::PM_LargeIconSize));
199 const int startIndex = m_assistantsActions.
size();
200 int currentIndex = startIndex;
201 const auto assistantActions = assistant->actions();
202 for (
auto& assistantAction : assistantActions) {
203 m_assistantsActions.
append(assistantAction);
205 if (currentIndex != startIndex)
208 makeLink(i18n(
"Solution (%1)", currentIndex + 1), KEY_INVOKE_ACTION(currentIndex),
225 m_assistantsActions.
clear();
227 int problemIndex = 0;
228 for (
auto& problem : qAsConst(m_problems)) {
231 if (++problemIndex != m_problems.
size())
242 const int index = key.
midRef(invokeActionPrefix.size()).toInt();
251 if (index < 0 || index >= m_assistantsActions.
size())
254 auto action = m_assistantsActions.
at(index);
262 qCWarning(LANGUAGE()) <<
"No such action";
KDEVPLATFORMLANGUAGE_EXPORT ItemUnderCursor itemUnderCursor(const QUrl &url, const KTextEditor::Cursor &cursor)
Returns 1.
bool isWidgetMaximized() const override
Whether the widget returned by widget() should take the maximum possible spsace.
Customized read locker for the definition-use chain.
QString currentHtml() const
Returns the html text being built in its current state.
static const Colorizer labelHighlight
QStringRef midRef(int position, int n) const
void updateContextForUrl(const IndexedString &document, TopDUContext::Features minFeatures, QObject *notifyReady=nullptr, int priority=1) const
Makes sure the standard-context for the given url is up-to-date.
void append(const T &value)
QIcon fromTheme(const QString &name, const QIcon &fallback)
KDEVPLATFORMLANGUAGE_EXPORT m_problems
DUContext::SearchFlags m_flags
virtual QString toString() const
Determine this declaration as a string.
QWidget * widget() const override
Here the context can return a widget to be displayed.
Represents a single declaration in a definition-use chain.
QString html(bool shorten=false) override
Here the context can return html to be displayed.
ProblemNavigationContext(const QVector< IProblem::Ptr > &problems, const Flags flags={})
virtual void makeLink(const QString &name, const DeclarationPointer &declaration, NavigationAction::Type actionType)
Creates and registers a link to the given declaration, labeled by the given name.
virtual IndexedString url() const
const T & at(int i) const
bool save(const QString &fileName, const char *format, int quality) const
TextHandler modifyHtml()
Returns a convenience object that allows writing "modifyHtml() += "Hallo";".
NavigationContextPointer executeKeyAction(const QString &key) override
Override this to execute own key-actions using NavigationAction.
KTextEditor::Range rangeInCurrentRevision() const
Returns the range assigned to this object, transformed into the current revision of the document.
QString & remove(int position, int n)
virtual QString html(bool shorten=false)
Here the context can return html to be displayed.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
TopDUContextPointer topContext() const
~ProblemNavigationContext() override
QPixmap pixmap(const QSize &size, Mode mode, State state) const
QString fromLatin1(const char *str, int size)
QByteArray toBase64() const
void executeAction(int index)
QString name() const override
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
DUChainPointer< Declaration > DeclarationPointer
static DUChain * self()
Returns the global static instance.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Mar 8 2021 23:29:50 by
doxygen 1.8.16 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.