summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/basetextmark.cpp
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@nokia.com>2012-02-08 17:21:12 +0100
committerDaniel Teske <daniel.teske@nokia.com>2012-02-14 14:27:30 +0100
commitb267027c9e99185bf9d92ee7952b1a4b98f82d65 (patch)
treed41540227eb59511462638788016ee764a724473 /src/plugins/texteditor/basetextmark.cpp
parentcf4c131541f5b73caccc8280db963a95de1a0acb (diff)
downloadqt-creator-b267027c9e99185bf9d92ee7952b1a4b98f82d65.tar.gz
Optimize BaseTextMark
Instead of each BaseTextMark being a QObject and being connected to editorOpened, centralize that and distribute the signal to only the BaseTextMarks that need it. Change-Id: I3f2783c34a25d78aa335418236850436028bfdf3 Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
Diffstat (limited to 'src/plugins/texteditor/basetextmark.cpp')
-rw-r--r--src/plugins/texteditor/basetextmark.cpp117
1 files changed, 60 insertions, 57 deletions
diff --git a/src/plugins/texteditor/basetextmark.cpp b/src/plugins/texteditor/basetextmark.cpp
index b67b8aabd4..792b5d411f 100644
--- a/src/plugins/texteditor/basetextmark.cpp
+++ b/src/plugins/texteditor/basetextmark.cpp
@@ -33,94 +33,97 @@
#include "basetextmark.h"
#include "itexteditor.h"
#include "basetextdocument.h"
+#include "texteditorplugin.h"
#include <coreplugin/editormanager/editormanager.h>
#include <extensionsystem/pluginmanager.h>
-#include <QtCore/QTimer>
-#include <QtGui/QIcon>
+using namespace TextEditor;
+using namespace TextEditor::Internal;
-namespace TextEditor {
-
-BaseTextMark::BaseTextMark()
- : m_markableInterface(0)
-{}
-
-BaseTextMark::~BaseTextMark()
-{
- // oha we are deleted
- if (m_markableInterface)
- m_markableInterface->removeMark(this);
- removeInternalMark();
-}
-
-void BaseTextMark::setLocation(const QString &fileName, int line)
-{
- m_fileName = fileName;
- m_line = line;
- //init();
- // This basically mimics 'two phase initialization'
- QTimer::singleShot(0, this, SLOT(init()));
-}
-
-void BaseTextMark::init()
+BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent)
+ : QObject(parent)
{
Core::EditorManager *em = Core::EditorManager::instance();
connect(em, SIGNAL(editorOpened(Core::IEditor *)),
SLOT(editorOpened(Core::IEditor *)));
-
- foreach (Core::IEditor *editor, em->openedEditors())
- editorOpened(editor);
}
-void BaseTextMark::editorOpened(Core::IEditor *editor)
+void BaseTextMarkRegistry::add(BaseTextMark *mark)
{
-#ifdef Q_OS_WIN
- if (m_fileName.compare(editor->file()->fileName(), Qt::CaseInsensitive))
- return;
-#else
- if (editor->file()->fileName() != m_fileName)
- return;
-#endif
- if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) {
- if (m_markableInterface == 0) { // We aren't added to something
- m_markableInterface = textEditor->markableInterface();
- if (m_markableInterface->addMark(this, m_line)) {
- // Handle reload of text documents, readding the mark as necessary
- connect(textEditor->file(), SIGNAL(reloaded()),
- this, SLOT(documentReloaded()), Qt::UniqueConnection);
- } else {
- removeInternalMark();
+ m_marks[Utils::FileName::fromString(mark->fileName())].append(mark);
+ Core::EditorManager *em = Core::EditorManager::instance();
+ foreach (Core::IEditor *editor, em->editorsForFileName(mark->fileName())) {
+ if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) {
+ if (mark->m_markableInterface == 0) { // We aren't added to something
+ ITextMarkable *markableInterface = textEditor->markableInterface();
+ if (markableInterface->addMark(mark, mark->m_line)) {
+ mark->m_markableInterface = markableInterface;
+ // Handle reload of text documents, readding the mark as necessary
+ connect(textEditor->file(), SIGNAL(reloaded()),
+ this, SLOT(documentReloaded()), Qt::UniqueConnection);
+ break;
+ }
}
}
}
}
-void BaseTextMark::documentReloaded()
+void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
{
- if (m_markableInterface)
+ ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor);
+ if (!textEditor)
return;
+ if (!m_marks.contains(Utils::FileName::fromString(editor->file()->fileName())))
+ return;
+
+ // Handle reload of text documents, readding the mark as necessary
+ connect(textEditor->file(), SIGNAL(reloaded()),
+ this, SLOT(documentReloaded()), Qt::UniqueConnection);
+
+ foreach (BaseTextMark *mark, m_marks.value(Utils::FileName::fromString(editor->file()->fileName()))) {
+ if (mark->m_markableInterface == 0) { // We aren't added to something
+ ITextMarkable *markableInterface = textEditor->markableInterface();
+ if (markableInterface->addMark(mark, mark->m_line))
+ mark->m_markableInterface = markableInterface;
+ }
+ }
+}
+void BaseTextMarkRegistry::documentReloaded()
+{
BaseTextDocument *doc = qobject_cast<BaseTextDocument*>(sender());
if (!doc)
return;
- m_markableInterface = doc->documentMarker();
+ if (!m_marks.contains(Utils::FileName::fromString(doc->fileName())))
+ return;
+
+ foreach (BaseTextMark *mark, m_marks.value(Utils::FileName::fromString(doc->fileName()))) {
+ if (mark->m_markableInterface)
+ return;
+ ITextMarkable *markableInterface = doc->documentMarker();
+ if (markableInterface->addMark(mark, mark->m_line))
+ mark->m_markableInterface = markableInterface;
+ }
+}
- if (!m_markableInterface->addMark(this, m_line))
- removeInternalMark();
+BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber)
+ : m_fileName(fileName), m_line(lineNumber)
+{
+ Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->add(this);
}
-void BaseTextMark::removeInternalMark()
+BaseTextMark::~BaseTextMark()
{
- m_markableInterface = 0;
+ // oha we are deleted
+ if (m_markableInterface)
+ m_markableInterface.data()->removeMark(this);
+ m_markableInterface.clear();
}
void BaseTextMark::updateMarker()
{
- //qDebug()<<"BaseTextMark::updateMarker()"<<m_markableInterface<<this;
if (m_markableInterface)
- m_markableInterface->updateMark(this);
+ m_markableInterface.data()->updateMark(this);
}
-
-} // namespace TextEditor