Changeset View
Changeset View
Standalone View
Standalone View
plugins/problemreporter/problemreporterplugin.cpp
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 87 | { | |||
---|---|---|---|---|---|
89 | pms->addModel(QStringLiteral("Parser"), m_model); | 89 | pms->addModel(QStringLiteral("Parser"), m_model); | ||
90 | core()->uiController()->addToolView(i18n("Problems"), m_factory); | 90 | core()->uiController()->addToolView(i18n("Problems"), m_factory); | ||
91 | setXMLFile(QStringLiteral("kdevproblemreporter.rc")); | 91 | setXMLFile(QStringLiteral("kdevproblemreporter.rc")); | ||
92 | 92 | | |||
93 | connect(ICore::self()->documentController(), &IDocumentController::documentClosed, this, | 93 | connect(ICore::self()->documentController(), &IDocumentController::documentClosed, this, | ||
94 | &ProblemReporterPlugin::documentClosed); | 94 | &ProblemReporterPlugin::documentClosed); | ||
95 | connect(ICore::self()->documentController(), &IDocumentController::textDocumentCreated, this, | 95 | connect(ICore::self()->documentController(), &IDocumentController::textDocumentCreated, this, | ||
96 | &ProblemReporterPlugin::textDocumentCreated); | 96 | &ProblemReporterPlugin::textDocumentCreated); | ||
97 | connect(ICore::self()->documentController(), &IDocumentController::documentActivated, this, | ||||
98 | &ProblemReporterPlugin::documentActivated); | ||||
97 | connect(DUChain::self(), &DUChain::updateReady, | 99 | connect(DUChain::self(), &DUChain::updateReady, | ||
98 | this, &ProblemReporterPlugin::updateReady); | 100 | this, &ProblemReporterPlugin::updateReady); | ||
99 | connect(ICore::self()->languageController()->staticAssistantsManager(), &StaticAssistantsManager::problemsChanged, | 101 | connect(ICore::self()->languageController()->staticAssistantsManager(), &StaticAssistantsManager::problemsChanged, | ||
100 | this, &ProblemReporterPlugin::updateHighlight); | 102 | this, &ProblemReporterPlugin::updateHighlight); | ||
101 | connect(pms, &ProblemModelSet::showRequested, this, &ProblemReporterPlugin::showModel); | 103 | connect(pms, &ProblemModelSet::showRequested, this, &ProblemReporterPlugin::showModel); | ||
104 | connect(pms, &ProblemModelSet::problemsChanged, this, &ProblemReporterPlugin::updateOpenedDocumentsHighlight); | ||||
102 | } | 105 | } | ||
103 | 106 | | |||
104 | ProblemReporterPlugin::~ProblemReporterPlugin() | 107 | ProblemReporterPlugin::~ProblemReporterPlugin() | ||
105 | { | 108 | { | ||
106 | qDeleteAll(m_highlighters); | 109 | qDeleteAll(m_highlighters); | ||
107 | } | 110 | } | ||
108 | 111 | | |||
109 | ProblemReporterModel* ProblemReporterPlugin::model() const | 112 | ProblemReporterModel* ProblemReporterPlugin::model() const | ||
Show All 11 Lines | |||||
121 | 124 | | |||
122 | void ProblemReporterPlugin::documentClosed(IDocument* doc) | 125 | void ProblemReporterPlugin::documentClosed(IDocument* doc) | ||
123 | { | 126 | { | ||
124 | if (!doc->textDocument()) | 127 | if (!doc->textDocument()) | ||
125 | return; | 128 | return; | ||
126 | 129 | | |||
127 | IndexedString url(doc->url()); | 130 | IndexedString url(doc->url()); | ||
128 | delete m_highlighters.take(url); | 131 | delete m_highlighters.take(url); | ||
132 | m_reHighlightNeeded.remove(url); | ||||
129 | } | 133 | } | ||
130 | 134 | | |||
131 | void ProblemReporterPlugin::textDocumentCreated(KDevelop::IDocument* document) | 135 | void ProblemReporterPlugin::textDocumentCreated(KDevelop::IDocument* document) | ||
132 | { | 136 | { | ||
133 | Q_ASSERT(document->textDocument()); | 137 | Q_ASSERT(document->textDocument()); | ||
134 | m_highlighters.insert(IndexedString(document->url()), new ProblemHighlighter(document->textDocument())); | 138 | m_highlighters.insert(IndexedString(document->url()), new ProblemHighlighter(document->textDocument())); | ||
135 | DUChain::self()->updateContextForUrl(IndexedString(document->url()), | 139 | DUChain::self()->updateContextForUrl(IndexedString(document->url()), | ||
136 | KDevelop::TopDUContext::AllDeclarationsContextsAndUses, this); | 140 | KDevelop::TopDUContext::AllDeclarationsContextsAndUses, this); | ||
137 | } | 141 | } | ||
138 | 142 | | |||
143 | void ProblemReporterPlugin::documentActivated(KDevelop::IDocument* document) | ||||
144 | { | ||||
145 | IndexedString documentUrl(document->url()); | ||||
146 | | ||||
147 | if (m_reHighlightNeeded.contains(documentUrl)) { | ||||
148 | m_reHighlightNeeded.remove(documentUrl); | ||||
149 | updateHighlight(documentUrl); | ||||
150 | } | ||||
151 | } | ||||
152 | | ||||
139 | void ProblemReporterPlugin::updateReady(const IndexedString& url, const KDevelop::ReferencedTopDUContext&) | 153 | void ProblemReporterPlugin::updateReady(const IndexedString& url, const KDevelop::ReferencedTopDUContext&) | ||
140 | { | 154 | { | ||
141 | m_model->problemsUpdated(url); | 155 | m_model->problemsUpdated(url); | ||
142 | updateHighlight(url); | 156 | updateHighlight(url); | ||
143 | } | 157 | } | ||
144 | 158 | | |||
145 | void ProblemReporterPlugin::updateHighlight(const KDevelop::IndexedString& url) | 159 | void ProblemReporterPlugin::updateHighlight(const KDevelop::IndexedString& url) | ||
146 | { | 160 | { | ||
147 | ProblemHighlighter* ph = m_highlighters.value(url); | 161 | ProblemHighlighter* ph = m_highlighters.value(url); | ||
148 | if (ph) { | 162 | if (!ph) | ||
149 | auto allProblems = m_model->problems(url, false); | 163 | return; | ||
150 | ph->setProblems(allProblems); | 164 | | ||
165 | KDevelop::ProblemModelSet* pms(core()->languageController()->problemModelSet()); | ||||
166 | QVector<IProblem::Ptr> documentProblems; | ||||
167 | | ||||
168 | foreach (const ModelData& modelData, pms->models()) { | ||||
169 | documentProblems += modelData.model->problems(url); | ||||
151 | } | 170 | } | ||
171 | | ||||
172 | ph->setProblems(documentProblems); | ||||
152 | } | 173 | } | ||
153 | 174 | | |||
154 | void ProblemReporterPlugin::showModel(const QString& name) | 175 | void ProblemReporterPlugin::showModel(const QString& name) | ||
155 | { | 176 | { | ||
156 | auto w = dynamic_cast<ProblemsView*>(core()->uiController()->findToolView(i18n("Problems"), m_factory)); | 177 | auto w = dynamic_cast<ProblemsView*>(core()->uiController()->findToolView(i18n("Problems"), m_factory)); | ||
157 | if (w) | 178 | if (w) | ||
158 | w->showModel(name); | 179 | w->showModel(name); | ||
159 | } | 180 | } | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 223 | foreach (QAction* action, actions) | |||
203 | menu->addAction(action); | 224 | menu->addAction(action); | ||
204 | 225 | | |||
205 | extension.addAction(ContextMenuExtension::ExtensionGroup, menuAction); | 226 | extension.addAction(ContextMenuExtension::ExtensionGroup, menuAction); | ||
206 | } | 227 | } | ||
207 | } | 228 | } | ||
208 | return extension; | 229 | return extension; | ||
209 | } | 230 | } | ||
210 | 231 | | |||
232 | void ProblemReporterPlugin::updateOpenedDocumentsHighlight() | ||||
kfunk: Hm, why do update the problems for all open documents now? This could get slow with lots of… | |||||
This is necessary due re-highlighting is not performed automatically for opened documents. If we switch to other opened document it will have "old highlights" which is wrong. Currently re-highlighting runs only for new opened documents. My previous version do it (with using other signals connected) for such case but it's wrong to run re-highlighting every time for non-changed problems. We can add some mechanism to save re-highlighting "queries" to some structure (like vector) and run needed on document switch. I can do it in next revision if necessary. antonanikin: This is necessary due re-highlighting is not performed automatically for opened documents. If… | |||||
233 | { | ||||
234 | foreach(auto document, core()->documentController()->openDocuments()) { | ||||
235 | IndexedString documentUrl(document->url()); | ||||
236 | | ||||
237 | if (document->isActive()) | ||||
238 | updateHighlight(documentUrl); | ||||
239 | else | ||||
240 | m_reHighlightNeeded.insert(documentUrl); | ||||
241 | } | ||||
242 | } | ||||
243 | | ||||
211 | #include "problemreporterplugin.moc" | 244 | #include "problemreporterplugin.moc" | ||
212 | 245 | | |||
213 | // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on | 246 | // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on |
Hm, why do update the problems for all open documents now? This could get slow with lots of documents open at a time, no?