Commit d9a5385a authored by Daniel Teske's avatar Daniel Teske
Browse files

BaseTextMark: Use (explicit) two phase initilization



Fixes a bug where the text in the bookmarks view is missing on initial
adding a bookmark.

Change-Id: Iefbf05e6124c0b4e911aa8d67beaa82ceeac8e21
Reviewed-by: default avatarhjk <qthjk@ovi.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 8b37921b
......@@ -410,6 +410,7 @@ void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber)
// Add a new bookmark if no bookmark existed on this line
Bookmark *bookmark = new Bookmark(fi.filePath(), editorLine, this);
bookmark->init();
addBookmark(bookmark);
}
......@@ -716,6 +717,7 @@ void BookmarkManager::addBookmark(const QString &s)
if (!filePath.isEmpty() && !findBookmark(fi.path(), fi.fileName(), lineNumber)) {
Bookmark *b = new Bookmark(filePath, lineNumber, this);
b->init();
addBookmark(b, false);
}
} else {
......
......@@ -1439,8 +1439,10 @@ void BreakHandler::BreakpointItem::updateMarker(BreakpointModelId id)
if (marker && (file != marker->fileName() || line != marker->lineNumber()))
destroyMarker();
if (!marker && !file.isEmpty() && line > 0)
if (!marker && !file.isEmpty() && line > 0) {
marker = new BreakpointMarker(id, file, line);
marker->init();
}
}
QIcon BreakHandler::BreakpointItem::icon() const
......
......@@ -114,6 +114,7 @@ void TaskHub::addTask(Task task)
TaskMark *mark = new TaskMark(task.taskId, task.file.toString(), task.line, visible);
mark->setIcon(taskTypeIcon(task.type));
mark->setPriority(TextEditor::ITextMark::LowPriority);
mark->init();
task.addMark(mark);
}
emit taskAdded(task);
......
......@@ -38,6 +38,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/documentmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
using namespace TextEditor;
using namespace TextEditor::Internal;
......@@ -70,7 +71,7 @@ void BaseTextMarkRegistry::add(BaseTextMark *mark)
}
}
void BaseTextMarkRegistry::remove(BaseTextMark *mark)
bool BaseTextMarkRegistry::remove(BaseTextMark *mark)
{
m_marks[Utils::FileName::fromString(mark->fileName())].remove(mark);
}
......@@ -131,6 +132,13 @@ void BaseTextMarkRegistry::allDocumentsRenamed(const QString &oldName, const QSt
BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber)
: ITextMark(lineNumber), m_fileName(fileName)
{
}
// we need two phase initilization, since we are calling virtual methods
// of BaseTextMark in add() and also accessing widthFactor
// which might be set in the derived constructor
void BaseTextMark::init()
{
Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->add(this);
}
......@@ -138,7 +146,9 @@ BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber)
BaseTextMark::~BaseTextMark()
{
// oha we are deleted
Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->remove(this);
bool b = Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->remove(this);
// If you get a assertion in this line, init() was never called
QTC_CHECK(b)
}
void BaseTextMark::updateFileName(const QString &fileName)
......
......@@ -60,6 +60,7 @@ class TEXTEDITOR_EXPORT BaseTextMark : public TextEditor::ITextMark
public:
BaseTextMark(const QString &fileName, int lineNumber);
void init();
virtual ~BaseTextMark();
/// called if the filename of the document changed
......@@ -80,7 +81,7 @@ public:
BaseTextMarkRegistry(QObject *parent);
void add(BaseTextMark *mark);
void remove(BaseTextMark *mark);
bool remove(BaseTextMark *mark);
private slots:
void editorOpened(Core::IEditor *editor);
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
......
......@@ -999,7 +999,9 @@ void CallgrindToolPrivate::createTextMarks()
continue;
locations << location;
m_textMarks.append(new CallgrindTextMark(index, fileName, lineNumber));
CallgrindTextMark *mark = new CallgrindTextMark(index, fileName, lineNumber);
mark->init();
m_textMarks.append(mark);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment