Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 5280 Lines • ▼ Show 20 Line(s) | |||||
5281 | } | 5281 | } | ||
5282 | 5282 | | |||
5283 | KTextEditor::AnnotationModel *KTextEditor::DocumentPrivate::annotationModel() const | 5283 | KTextEditor::AnnotationModel *KTextEditor::DocumentPrivate::annotationModel() const | ||
5284 | { | 5284 | { | ||
5285 | return m_annotationModel; | 5285 | return m_annotationModel; | ||
5286 | } | 5286 | } | ||
5287 | //END KTextEditor::AnnotationInterface | 5287 | //END KTextEditor::AnnotationInterface | ||
5288 | 5288 | | |||
5289 | //BEGIN KTextEditor::InlineNoteInterface | ||||
5290 | void KTextEditor::DocumentPrivate::registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) | ||||
5291 | { | ||||
5292 | if (! m_inlineNoteProviders.contains(provider)) { | ||||
5293 | m_inlineNoteProviders.append(provider); | ||||
5294 | | ||||
5295 | connect(provider, SIGNAL(reset()), this, SLOT(inlineNotesReset())); | ||||
brauch: Can you use new-style connect here, i.e. the function-pointer syntax
connect(provider… | |||||
5296 | connect(provider, SIGNAL(lineChanged(int)), this, SLOT(inlineNotesLineChanged(int))); | ||||
5297 | | ||||
5298 | inlineNotesReset(); | ||||
5299 | } | ||||
5300 | } | ||||
5301 | | ||||
5302 | void KTextEditor::DocumentPrivate::unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) | ||||
5303 | { | ||||
5304 | const int index = m_inlineNoteProviders.indexOf(provider); | ||||
5305 | if (index >= 0) { | ||||
5306 | m_inlineNoteProviders.removeAt(index); | ||||
5307 | | ||||
5308 | disconnect(provider, 0, this, 0); | ||||
5309 | | ||||
5310 | inlineNotesReset(); | ||||
5311 | } | ||||
5312 | } | ||||
5313 | | ||||
5314 | QVector<const KTextEditor::InlineNote *> KTextEditor::DocumentPrivate::inlineNotes(int line) const | ||||
5315 | { | ||||
5316 | // Common cases first | ||||
5317 | switch (m_inlineNoteProviders.size()) { | ||||
5318 | case 0: return {}; | ||||
5319 | case 1: return m_inlineNoteProviders.first()->inlineNotes(line); | ||||
5320 | } | ||||
This look like premature optimization. I would prefer to delete this "common cases first" block. Except if this turned out to be a bottleneck already? dhaumann: This look like premature optimization. I would prefer to delete this "common cases first" block. | |||||
Btw, may I am wrong here, since this is really called often when painting lines... So this may be good to have. dhaumann: Btw, may I am wrong here, since this is really called often when painting lines... So this may… | |||||
I also stumbled upon it but it avoids an alloc in a very deep loop, so it might be worth it here. brauch: I also stumbled upon it but it avoids an alloc in a very deep loop, so it might be worth it… | |||||
5321 | | ||||
5322 | QVector<const KTextEditor::InlineNote *> allInlineNotes; | ||||
5323 | foreach (KTextEditor::InlineNoteProvider *provider, m_inlineNoteProviders) { | ||||
5324 | allInlineNotes.append(provider->inlineNotes(line)); | ||||
5325 | } | ||||
5326 | return allInlineNotes; | ||||
5327 | } | ||||
5328 | | ||||
5329 | void KTextEditor::DocumentPrivate::inlineNotesReset() | ||||
5330 | { | ||||
5331 | repaintViews(false); | ||||
5332 | } | ||||
5333 | | ||||
5334 | void KTextEditor::DocumentPrivate::inlineNotesLineChanged(int line) | ||||
5335 | { | ||||
5336 | tagLines(line, line); | ||||
5337 | repaintViews(false); | ||||
5338 | } | ||||
5339 | | ||||
5340 | //END KTextEditor::InlineNoteInterface | ||||
5341 | | ||||
5289 | //TAKEN FROM kparts.h | 5342 | //TAKEN FROM kparts.h | ||
5290 | bool KTextEditor::DocumentPrivate::queryClose() | 5343 | bool KTextEditor::DocumentPrivate::queryClose() | ||
5291 | { | 5344 | { | ||
5292 | if (!isReadWrite() || !isModified()) { | 5345 | if (!isReadWrite() || !isModified()) { | ||
5293 | return true; | 5346 | return true; | ||
5294 | } | 5347 | } | ||
5295 | 5348 | | |||
5296 | QString docName = documentName(); | 5349 | QString docName = documentName(); | ||
▲ Show 20 Lines • Show All 739 Lines • Show Last 20 Lines |
Can you use new-style connect here, i.e. the function-pointer syntax
connect(provider, &NoteProvider::reset, this, &DocumentPrivate::inlineNotesReset)?
This gives compile-time argument type checking.