QmlJSEditor: Move ownership of QmlJSTextMarks to document

Task-number: QTCREATORBUG-19607
Change-Id: I65fa11b43dcbe3c28ab100a1636ad592cfff5a4d
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2018-01-22 10:45:04 +01:00
parent 63e47f903f
commit f9c959cee2
4 changed files with 69 additions and 70 deletions

View File

@@ -34,7 +34,6 @@
#include "qmljshighlighter.h"
#include "qmljshoverhandler.h"
#include "qmljsquickfixassist.h"
#include "qmljstextmark.h"
#include "qmloutlinemodel.h"
#include <qmljs/qmljsbind.h>
@@ -203,14 +202,12 @@ static void appendExtraSelectionsForMessages(
void QmlJSEditorWidget::updateCodeWarnings(Document::Ptr doc)
{
cleanDiagnosticMarks();
if (doc->ast()) {
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
} else if (doc->language().isFullySupportedLanguage()) {
// show parsing errors
QList<QTextEdit::ExtraSelection> selections;
appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document());
createTextMarks(doc->diagnosticMessages());
setExtraSelections(CodeWarningsSelection, selections);
} else {
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
@@ -935,8 +932,6 @@ void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo)
}
}
createTextMarks(semanticInfo);
updateUses();
}
@@ -978,61 +973,6 @@ bool QmlJSEditorWidget::hideContextPane()
return b;
}
void QmlJSEditorWidget::createTextMarks(const QList<DiagnosticMessage> &diagnostics)
{
for (const DiagnosticMessage &diagnostic : diagnostics) {
const auto onMarkRemoved = [this](QmlJSTextMark *mark) {
m_diagnosticMarks.removeAll(mark);
delete mark;
};
auto mark = new QmlJSTextMark(textDocument()->filePath().toString(),
diagnostic, onMarkRemoved);
m_diagnosticMarks.append(mark);
textDocument()->addMark(mark);
}
}
static void cleanMarks(QVector<TextMark *> *marks, TextDocument *doc)
{
for (TextEditor::TextMark *mark : *marks) {
doc->removeMark(mark);
delete mark;
}
marks->clear();
}
void QmlJSEditorWidget::cleanDiagnosticMarks()
{
cleanMarks(&m_diagnosticMarks, textDocument());
}
void QmlJSEditorWidget::createTextMarks(const SemanticInfo &info)
{
cleanSemanticMarks();
const auto onMarkRemoved = [this](QmlJSTextMark *mark) {
m_semanticMarks.removeAll(mark);
delete mark;
};
for (const DiagnosticMessage &diagnostic : info.semanticMessages) {
auto mark = new QmlJSTextMark(textDocument()->filePath().toString(),
diagnostic, onMarkRemoved);
m_semanticMarks.append(mark);
textDocument()->addMark(mark);
}
for (const QmlJS::StaticAnalysis::Message &message : info.staticAnalysisMessages) {
auto mark = new QmlJSTextMark(textDocument()->filePath().toString(),
message, onMarkRemoved);
m_semanticMarks.append(mark);
textDocument()->addMark(mark);
}
}
void QmlJSEditorWidget::cleanSemanticMarks()
{
cleanMarks(&m_semanticMarks, textDocument());
}
AssistInterface *QmlJSEditorWidget::createAssistInterface(
AssistKind assistKind,
AssistReason reason) const