Commit 2df2c065 authored by Daniel Teske's avatar Daniel Teske Committed by hjk

Initialize ITextMark with a lineNumber

Ensure that it is updated as the lines are moved. That can be later used
to quickly find and remove the marks again.

Change-Id: I2285111996d5c8ef12f792fd73ff00ce186addc1
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent b112c277
......@@ -122,13 +122,12 @@ public:
DisassemblerAgentPrivate::DisassemblerAgentPrivate()
: editor(0),
locationMark(0),
mimeType(_("text/x-qtcreator-generic-asm")),
tryMixed(true),
resetLocationScheduled(false)
{
locationMark = new ITextMark;
locationMark->setIcon(debuggerCore()->locationMarkIcon());
locationMark->setPriority(TextEditor::ITextMark::HighPriority);
}
DisassemblerAgentPrivate::~DisassemblerAgentPrivate()
......@@ -349,9 +348,16 @@ void DisassemblerAgent::updateLocationMarker()
const DisassemblerLines contents = d->contentsAtCurrentLocation();
int lineNumber = contents.lineForAddress(d->location.address());
if (d->location.needsMarker()) {
d->editor->markableInterface()->removeMark(d->locationMark);
if (lineNumber)
d->editor->markableInterface()->addMark(d->locationMark, lineNumber);
if (d->locationMark)
d->editor->markableInterface()->removeMark(d->locationMark);
delete d->locationMark;
d->locationMark = 0;
if (lineNumber) {
d->locationMark = new ITextMark(lineNumber);
d->locationMark->setIcon(debuggerCore()->locationMarkIcon());
d->locationMark->setPriority(TextEditor::ITextMark::HighPriority);
d->editor->markableInterface()->addMark(d->locationMark);
}
}
QPlainTextEdit *plainTextEdit =
......@@ -385,11 +391,11 @@ void DisassemblerAgent::updateBreakpointMarkers()
const int lineNumber = contents.lineForAddress(address);
if (!lineNumber)
continue;
ITextMark *marker = new ITextMark;
ITextMark *marker = new ITextMark(lineNumber);
marker->setIcon(handler->icon(id));
marker->setPriority(ITextMark::NormalPriority);
d->breakpointMarks.append(marker);
d->editor->markableInterface()->addMark(marker, lineNumber);
d->editor->markableInterface()->addMark(marker);
}
}
......
......@@ -90,11 +90,10 @@ public:
SourceAgentPrivate::SourceAgentPrivate()
: editor(0)
, locationMark(0)
, producer(QLatin1String("remote"))
{
locationMark = new TextEditor::ITextMark;
locationMark->setIcon(debuggerCore()->locationMarkIcon());
locationMark->setPriority(TextEditor::ITextMark::HighPriority);
}
SourceAgentPrivate::~SourceAgentPrivate()
......@@ -163,10 +162,16 @@ void SourceAgent::updateLocationMarker()
{
QTC_ASSERT(d->editor, return);
d->editor->markableInterface()->removeMark(d->locationMark);
if (d->locationMark)
d->editor->markableInterface()->removeMark(d->locationMark);
delete d->locationMark;
d->locationMark = 0;
if (d->engine->stackHandler()->currentFrame().file == d->path) {
int lineNumber = d->engine->stackHandler()->currentFrame().line;
d->editor->markableInterface()->addMark(d->locationMark, lineNumber);
d->locationMark = new TextEditor::ITextMark(lineNumber);
d->locationMark->setIcon(debuggerCore()->locationMarkIcon());
d->locationMark->setPriority(TextEditor::ITextMark::HighPriority);
d->editor->markableInterface()->addMark(d->locationMark);
QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(d->editor->widget());
QTC_ASSERT(plainTextEdit, return);
QTextCursor tc = plainTextEdit->textCursor();
......
......@@ -47,7 +47,7 @@ public:
TextMarks marks() const { return m_marksCache; }
// ITextMarkable
bool addMark(ITextMark *mark, int line);
bool addMark(ITextMark *mark);
TextMarks marksAt(int line) const;
void removeMark(ITextMark *mark);
void updateMark(ITextMark *mark);
......@@ -69,10 +69,10 @@ DocumentMarker::~DocumentMarker()
}
bool DocumentMarker::addMark(TextEditor::ITextMark *mark, int line)
bool DocumentMarker::addMark(TextEditor::ITextMark *mark)
{
QTC_ASSERT(line >= 1, return false);
int blockNumber = line - 1;
QTC_ASSERT(mark->lineNumber() >= 1, return false);
int blockNumber = mark->lineNumber() - 1;
BaseTextDocumentLayout *documentLayout =
qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
QTC_ASSERT(documentLayout, return false);
......@@ -83,6 +83,7 @@ bool DocumentMarker::addMark(TextEditor::ITextMark *mark, int line)
userData->addMark(mark);
m_marksCache.append(mark);
mark->updateLineNumber(blockNumber + 1);
QTC_CHECK(mark->lineNumber() == blockNumber + 1);
mark->updateBlock(block);
documentLayout->hasMarks = true;
documentLayout->maxMarkWidthFactor = qMax(mark->widthFactor(),
......@@ -719,6 +720,7 @@ void BaseTextDocumentLayout::updateMarksLineNumber()
if (const TextBlockUserData *userData = testUserData(block))
foreach (ITextMark *mrk, userData->marks()) {
mrk->updateLineNumber(blockNumber + 1);
QTC_CHECK(mrk->lineNumber() == blockNumber +1);
}
block = block.next();
++blockNumber;
......
......@@ -57,7 +57,7 @@ void BaseTextMarkRegistry::add(BaseTextMark *mark)
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)) {
if (markableInterface->addMark(mark)) {
mark->m_markableInterface = markableInterface;
// Handle reload of text documents, readding the mark as necessary
connect(textEditor->document(), SIGNAL(reloaded()),
......@@ -89,7 +89,7 @@ void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
foreach (BaseTextMark *mark, m_marks.value(Utils::FileName::fromString(editor->document()->fileName()))) {
if (mark->m_markableInterface == 0) { // We aren't added to something
ITextMarkable *markableInterface = textEditor->markableInterface();
if (markableInterface->addMark(mark, mark->m_line))
if (markableInterface->addMark(mark))
mark->m_markableInterface = markableInterface;
}
}
......@@ -108,13 +108,13 @@ void BaseTextMarkRegistry::documentReloaded()
if (mark->m_markableInterface)
return;
ITextMarkable *markableInterface = doc->documentMarker();
if (markableInterface->addMark(mark, mark->m_line))
if (markableInterface->addMark(mark))
mark->m_markableInterface = markableInterface;
}
}
BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber)
: m_fileName(fileName), m_line(lineNumber)
: ITextMark(lineNumber), m_fileName(fileName)
{
Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->add(this);
}
......@@ -128,11 +128,6 @@ BaseTextMark::~BaseTextMark()
Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->remove(this);
}
void BaseTextMark::updateLineNumber(int lineNumber)
{
m_line = lineNumber;
}
void BaseTextMark::updateMarker()
{
if (m_markableInterface)
......
......@@ -61,19 +61,15 @@ public:
BaseTextMark(const QString &fileName, int lineNumber);
virtual ~BaseTextMark();
void updateLineNumber(int lineNumber);
// call this if the icon has changed.
void updateMarker();
// access to internal data
QString fileName() const { return m_fileName; }
int lineNumber() const { return m_line; }
private:
QWeakPointer<ITextMarkable> m_markableInterface;
QString m_fileName;
int m_line;
};
namespace Internal {
......
......@@ -43,6 +43,11 @@ ITextMark::~ITextMark()
}
int ITextMark::lineNumber() const
{
return m_lineNumber;
}
void ITextMark::paint(QPainter *painter, const QRect &rect) const
{
m_icon.paint(painter, rect, Qt::AlignCenter);
......@@ -50,7 +55,7 @@ void ITextMark::paint(QPainter *painter, const QRect &rect) const
void ITextMark::updateLineNumber(int lineNumber)
{
Q_UNUSED(lineNumber)
m_lineNumber = lineNumber;
}
void ITextMark::updateBlock(const QTextBlock &)
......
......@@ -58,7 +58,7 @@ class ITextEditor;
class TEXTEDITOR_EXPORT ITextMark
{
public:
ITextMark() : m_priority(NormalPriority) {}
ITextMark(int line) : m_lineNumber(line), m_priority(NormalPriority) {}
virtual ~ITextMark();
// determine order on markers on the same line.
......@@ -69,6 +69,7 @@ public:
HighPriority // shown on top.
};
int lineNumber() const;
virtual void paint(QPainter *painter, const QRect &rect) const;
virtual void updateLineNumber(int lineNumber);
virtual void updateBlock(const QTextBlock &block);
......@@ -80,6 +81,7 @@ public:
virtual double widthFactor() const;
private:
int m_lineNumber;
QIcon m_icon;
Priority m_priority;
};
......@@ -93,7 +95,7 @@ class TEXTEDITOR_EXPORT ITextMarkable : public QObject
public:
ITextMarkable(QObject *parent = 0) : QObject(parent) {}
virtual bool addMark(ITextMark *mark, int line) = 0;
virtual bool addMark(ITextMark *mark) = 0;
virtual TextMarks marksAt(int line) const = 0;
virtual void removeMark(ITextMark *mark) = 0;
virtual void updateMark(ITextMark *mark) = 0;
......
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