forked from qt-creator/qt-creator
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: hjk <qthjk@ovi.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
@@ -410,6 +410,7 @@ void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber)
|
|||||||
|
|
||||||
// Add a new bookmark if no bookmark existed on this line
|
// Add a new bookmark if no bookmark existed on this line
|
||||||
Bookmark *bookmark = new Bookmark(fi.filePath(), editorLine, this);
|
Bookmark *bookmark = new Bookmark(fi.filePath(), editorLine, this);
|
||||||
|
bookmark->init();
|
||||||
addBookmark(bookmark);
|
addBookmark(bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,6 +717,7 @@ void BookmarkManager::addBookmark(const QString &s)
|
|||||||
|
|
||||||
if (!filePath.isEmpty() && !findBookmark(fi.path(), fi.fileName(), lineNumber)) {
|
if (!filePath.isEmpty() && !findBookmark(fi.path(), fi.fileName(), lineNumber)) {
|
||||||
Bookmark *b = new Bookmark(filePath, lineNumber, this);
|
Bookmark *b = new Bookmark(filePath, lineNumber, this);
|
||||||
|
b->init();
|
||||||
addBookmark(b, false);
|
addBookmark(b, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1439,8 +1439,10 @@ void BreakHandler::BreakpointItem::updateMarker(BreakpointModelId id)
|
|||||||
if (marker && (file != marker->fileName() || line != marker->lineNumber()))
|
if (marker && (file != marker->fileName() || line != marker->lineNumber()))
|
||||||
destroyMarker();
|
destroyMarker();
|
||||||
|
|
||||||
if (!marker && !file.isEmpty() && line > 0)
|
if (!marker && !file.isEmpty() && line > 0) {
|
||||||
marker = new BreakpointMarker(id, file, line);
|
marker = new BreakpointMarker(id, file, line);
|
||||||
|
marker->init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon BreakHandler::BreakpointItem::icon() const
|
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);
|
TaskMark *mark = new TaskMark(task.taskId, task.file.toString(), task.line, visible);
|
||||||
mark->setIcon(taskTypeIcon(task.type));
|
mark->setIcon(taskTypeIcon(task.type));
|
||||||
mark->setPriority(TextEditor::ITextMark::LowPriority);
|
mark->setPriority(TextEditor::ITextMark::LowPriority);
|
||||||
|
mark->init();
|
||||||
task.addMark(mark);
|
task.addMark(mark);
|
||||||
}
|
}
|
||||||
emit taskAdded(task);
|
emit taskAdded(task);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace TextEditor::Internal;
|
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);
|
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)
|
BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber)
|
||||||
: ITextMark(lineNumber), m_fileName(fileName)
|
: 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);
|
Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->add(this);
|
||||||
}
|
}
|
||||||
@@ -138,7 +146,9 @@ BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber)
|
|||||||
BaseTextMark::~BaseTextMark()
|
BaseTextMark::~BaseTextMark()
|
||||||
{
|
{
|
||||||
// oha we are deleted
|
// 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)
|
void BaseTextMark::updateFileName(const QString &fileName)
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class TEXTEDITOR_EXPORT BaseTextMark : public TextEditor::ITextMark
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
BaseTextMark(const QString &fileName, int lineNumber);
|
BaseTextMark(const QString &fileName, int lineNumber);
|
||||||
|
void init();
|
||||||
virtual ~BaseTextMark();
|
virtual ~BaseTextMark();
|
||||||
|
|
||||||
/// called if the filename of the document changed
|
/// called if the filename of the document changed
|
||||||
@@ -80,7 +81,7 @@ public:
|
|||||||
BaseTextMarkRegistry(QObject *parent);
|
BaseTextMarkRegistry(QObject *parent);
|
||||||
|
|
||||||
void add(BaseTextMark *mark);
|
void add(BaseTextMark *mark);
|
||||||
void remove(BaseTextMark *mark);
|
bool remove(BaseTextMark *mark);
|
||||||
private slots:
|
private slots:
|
||||||
void editorOpened(Core::IEditor *editor);
|
void editorOpened(Core::IEditor *editor);
|
||||||
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
|
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
|
||||||
|
|||||||
@@ -999,7 +999,9 @@ void CallgrindToolPrivate::createTextMarks()
|
|||||||
continue;
|
continue;
|
||||||
locations << location;
|
locations << location;
|
||||||
|
|
||||||
m_textMarks.append(new CallgrindTextMark(index, fileName, lineNumber));
|
CallgrindTextMark *mark = new CallgrindTextMark(index, fileName, lineNumber);
|
||||||
|
mark->init();
|
||||||
|
m_textMarks.append(mark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user