Merge ITextMark and BaseTextMark

Turns out we don't even need two-phase initialization,
by transparently postponing registration until we get
a non-empty file name, either at constuction, or at
file name change times.

Change-Id: I3e87e47c820066e6707e946fc474ab9c1993e61f
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
hjk
2014-07-19 11:27:28 +02:00
parent 53bfd5285d
commit cf8a614419
32 changed files with 265 additions and 372 deletions

View File

@@ -37,10 +37,10 @@
using namespace Bookmarks::Internal;
Bookmark::Bookmark(const QString& fileName, int lineNumber, BookmarkManager *manager) :
BaseTextMark(fileName, lineNumber),
TextMark(fileName, lineNumber),
m_manager(manager)
{
setPriority(TextEditor::ITextMark::NormalPriority);
setPriority(TextEditor::TextMark::NormalPriority);
setIcon(m_manager->bookmarkIcon());
}
@@ -52,7 +52,7 @@ void Bookmark::removedFromEditor()
void Bookmark::updateLineNumber(int line)
{
if (line != lineNumber()) {
BaseTextMark::updateLineNumber(line);
TextMark::updateLineNumber(line);
m_manager->updateBookmark(this);
}
}
@@ -60,7 +60,7 @@ void Bookmark::updateLineNumber(int line)
void Bookmark::move(int line)
{
if (line != lineNumber()) {
BaseTextMark::move(line);
TextMark::move(line);
m_manager->updateBookmark(this);
}
}
@@ -75,7 +75,7 @@ void Bookmark::updateBlock(const QTextBlock &block)
void Bookmark::updateFileName(const QString &fileName)
{
BaseTextMark::updateFileName(fileName);
TextMark::updateFileName(fileName);
m_manager->updateBookmark(this);
}

View File

@@ -30,15 +30,14 @@
#ifndef BOOKMARK_H
#define BOOKMARK_H
#include <texteditor/itexteditor.h>
#include <texteditor/basetextmark.h>
#include <texteditor/textmark.h>
namespace Bookmarks {
namespace Internal {
class BookmarkManager;
class Bookmark : public TextEditor::BaseTextMark
class Bookmark : public TextEditor::TextMark
{
public:
Bookmark(const QString &fileName, int lineNumber, BookmarkManager *manager);

View File

@@ -429,9 +429,7 @@ void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber)
}
// Add a new bookmark if no bookmark existed on this line
Bookmark *bookmark = new Bookmark(fileName, editorLine, this);
bookmark->init();
addBookmark(bookmark);
addBookmark(new Bookmark(fileName, editorLine, this));
}
void BookmarkManager::updateBookmark(Bookmark *bookmark)
@@ -769,7 +767,6 @@ void BookmarkManager::addBookmark(const QString &s)
if (!filePath.isEmpty() && !findBookmark(filePath, lineNumber)) {
Bookmark *b = new Bookmark(filePath, lineNumber, this);
b->setNote(note);
b->init();
addBookmark(b, false);
}
} else {

View File

@@ -51,7 +51,7 @@ class DeclarationAST;
namespace TextEditor {
class BaseTextEditor;
class ITextMark;
class TextMark;
} // namespace TextEditor
namespace CppTools {

View File

@@ -1468,10 +1468,8 @@ 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

View File

@@ -43,10 +43,10 @@ namespace Internal {
BreakpointMarker::BreakpointMarker(BreakpointModelId id,
const QString &fileName, int lineNumber)
: BaseTextMark(fileName, lineNumber), m_id(id)
: TextMark(fileName, lineNumber), m_id(id)
{
setIcon(breakHandler()->icon(m_id));
setPriority(TextEditor::ITextMark::NormalPriority);
setPriority(TextEditor::TextMark::NormalPriority);
//qDebug() << "CREATE MARKER " << fileName << lineNumber;
}
@@ -62,7 +62,7 @@ void BreakpointMarker::removedFromEditor()
void BreakpointMarker::updateLineNumber(int lineNumber)
{
BaseTextMark::updateLineNumber(lineNumber);
TextMark::updateLineNumber(lineNumber);
breakHandler()->updateLineNumberFromMarker(m_id, lineNumber);
}
@@ -78,7 +78,7 @@ void BreakpointMarker::clicked()
void BreakpointMarker::updateFileName(const QString &fileName)
{
BaseTextMark::updateFileName(fileName);
TextMark::updateFileName(fileName);
breakHandler()->updateFileNameFromMarker(m_id, fileName);
}

View File

@@ -32,13 +32,13 @@
#include "breakpoint.h"
#include <texteditor/basetextmark.h>
#include <texteditor/textmark.h>
namespace Debugger {
namespace Internal {
// The red blob on the left side in the cpp editor.
class BreakpointMarker : public TextEditor::BaseTextMark
class BreakpointMarker : public TextEditor::TextMark
{
public:
BreakpointMarker(BreakpointModelId id, const QString &fileName, int lineNumber);

View File

@@ -307,7 +307,7 @@ public:
DisassemblerAgent m_disassemblerAgent;
MemoryAgent m_memoryAgent;
QScopedPointer<TextEditor::BaseTextMark> m_locationMark;
QScopedPointer<TextEditor::TextMark> m_locationMark;
QTimer m_locationTimer;
bool m_isStateDebugging;
@@ -565,10 +565,9 @@ void DebuggerEngine::gotoLocation(const Location &loc)
editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, true);
if (loc.needsMarker()) {
d->m_locationMark.reset(new TextEditor::BaseTextMark(file, line));
d->m_locationMark.reset(new TextEditor::TextMark(file, line));
d->m_locationMark->setIcon(debuggerCore()->locationMarkIcon());
d->m_locationMark->setPriority(TextEditor::ITextMark::HighPriority);
d->m_locationMark->init();
d->m_locationMark->setPriority(TextEditor::TextMark::HighPriority);
}
//qDebug() << "MEMORY: " << d->m_memoryAgent.hasVisibleEditor();

View File

@@ -103,8 +103,8 @@ public:
QPointer<BaseTextDocument> document;
Location location;
QPointer<DebuggerEngine> engine;
ITextMark locationMark;
QList<ITextMark *> breakpointMarks;
TextMark locationMark;
QList<TextMark *> breakpointMarks;
QList<CacheEntry> cache;
QString mimeType;
bool tryMixedInitialized;
@@ -114,14 +114,14 @@ public:
DisassemblerAgentPrivate::DisassemblerAgentPrivate()
: document(0),
locationMark(0),
locationMark(QString(), 0),
mimeType(_("text/x-qtcreator-generic-asm")),
tryMixedInitialized(false),
tryMixed(true),
resetLocationScheduled(false)
{
locationMark.setIcon(debuggerCore()->locationMarkIcon());
locationMark.setPriority(TextEditor::ITextMark::HighPriority);
locationMark.setPriority(TextEditor::TextMark::HighPriority);
}
DisassemblerAgentPrivate::~DisassemblerAgentPrivate()
@@ -353,7 +353,7 @@ void DisassemblerAgent::updateBreakpointMarkers()
return;
const DisassemblerLines contents = d->contentsAtCurrentLocation();
foreach (TextEditor::ITextMark *marker, d->breakpointMarks)
foreach (TextEditor::TextMark *marker, d->breakpointMarks)
d->document->removeMark(marker);
qDeleteAll(d->breakpointMarks);
d->breakpointMarks.clear();
@@ -364,9 +364,9 @@ void DisassemblerAgent::updateBreakpointMarkers()
const int lineNumber = contents.lineForAddress(address);
if (!lineNumber)
continue;
ITextMark *marker = new ITextMark(lineNumber);
TextMark *marker = new TextMark(QString(), lineNumber);
marker->setIcon(handler->icon(id));
marker->setPriority(ITextMark::NormalPriority);
marker->setPriority(TextMark::NormalPriority);
d->breakpointMarks.append(marker);
d->document->addMark(marker);
}

View File

@@ -35,6 +35,7 @@
#include "stackhandler.h"
#include <texteditor/basetexteditor.h>
#include <texteditor/textmark.h>
#include <cppeditor/cppeditorconstants.h>
@@ -61,7 +62,7 @@ public:
public:
QPointer<TextEditor::BaseTextEditor> editor;
QPointer<DebuggerEngine> engine;
TextEditor::ITextMark *locationMark;
TextEditor::TextMark *locationMark;
QString path;
QString producer;
};
@@ -140,9 +141,9 @@ void SourceAgent::updateLocationMarker()
d->locationMark = 0;
if (d->engine->stackHandler()->currentFrame().file == d->path) {
int lineNumber = d->engine->stackHandler()->currentFrame().line;
d->locationMark = new TextEditor::ITextMark(lineNumber);
d->locationMark = new TextEditor::TextMark(QString(), lineNumber);
d->locationMark->setIcon(debuggerCore()->locationMarkIcon());
d->locationMark->setPriority(TextEditor::ITextMark::HighPriority);
d->locationMark->setPriority(TextEditor::TextMark::HighPriority);
d->editor->baseTextDocument()->addMark(d->locationMark);
QPlainTextEdit *plainTextEdit = d->editor->editorWidget();
QTC_ASSERT(plainTextEdit, return);

View File

@@ -57,7 +57,7 @@
#include <texteditor/basetextdocumentlayout.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/basetextmark.h>
#include <texteditor/textmark.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/typingsettings.h>
#include <texteditor/tabsettings.h>

View File

@@ -91,11 +91,11 @@ Task Task::buildConfigurationMissingTask()
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
}
void Task::addMark(TextEditor::BaseTextMark *mark)
void Task::addMark(TextEditor::TextMark *mark)
{
QTC_ASSERT(m_mark.isNull(), return);
m_mark = QSharedPointer<TextEditor::BaseTextMark>(mark);
m_mark = QSharedPointer<TextEditor::TextMark>(mark);
}
bool Task::isNull() const

View File

@@ -33,11 +33,11 @@
#include "projectexplorer_export.h"
#include <coreplugin/id.h>
#include <texteditor/basetextmark.h>
#include <texteditor/textmark.h>
#include <utils/fileutils.h>
#include <QIcon>
#include <QMetaType>
#include <QTextLayout>
namespace ProjectExplorer {
@@ -71,7 +71,7 @@ public:
int movedLine; // contains a line number if the line was moved in the editor
Core::Id category;
QIcon icon;
void addMark(TextEditor::BaseTextMark *mark);
void addMark(TextEditor::TextMark *mark);
// Having a QList<QTextLayout::FormatRange> in Task isn't that great
// It would be cleaner to split up the text into
@@ -84,7 +84,7 @@ public:
QList<QTextLayout::FormatRange> formats;
private:
QSharedPointer<TextEditor::BaseTextMark> m_mark;
QSharedPointer<TextEditor::TextMark> m_mark;
static unsigned int s_nextId;
};

View File

@@ -38,11 +38,11 @@ using namespace ProjectExplorer;
TaskHub *m_instance = 0;
QSet<Core::Id> TaskHub::m_registeredCategories;
class TaskMark : public TextEditor::BaseTextMark
class TaskMark : public TextEditor::TextMark
{
public:
TaskMark(unsigned int id, const QString &fileName, int lineNumber, bool visible)
: BaseTextMark(fileName, lineNumber), m_id(id)
: TextMark(fileName, lineNumber), m_id(id)
{
setVisible(visible);
}
@@ -60,13 +60,13 @@ private:
void TaskMark::updateLineNumber(int lineNumber)
{
TaskHub::updateTaskLineNumber(m_id, lineNumber);
BaseTextMark::updateLineNumber(lineNumber);
TextMark::updateLineNumber(lineNumber);
}
void TaskMark::updateFileName(const QString &fileName)
{
TaskHub::updateTaskFileName(m_id, fileName);
BaseTextMark::updateFileName(fileName);
TextMark::updateFileName(fileName);
}
void TaskMark::removedFromEditor()
@@ -131,13 +131,10 @@ void TaskHub::addTask(Task task)
if (task.line != -1 && !task.file.isEmpty()) {
TaskMark *mark = new TaskMark(task.taskId, task.file.toString(), task.line, !task.icon.isNull());
mark->setIcon(task.icon);
mark->setPriority(TextEditor::ITextMark::LowPriority);
mark->setPriority(TextEditor::TextMark::LowPriority);
task.addMark(mark);
emit m_instance->taskAdded(task);
mark->init();
} else {
emit m_instance->taskAdded(task);
}
emit m_instance->taskAdded(task);
}
void TaskHub::clearTasks(Core::Id categoryId)

View File

@@ -683,7 +683,7 @@ TextMarks BaseTextDocument::marks() const
return d->m_marksCache;
}
bool BaseTextDocument::addMark(ITextMark *mark)
bool BaseTextDocument::addMark(TextMark *mark)
{
if (mark->baseTextDocument())
return false;
@@ -730,7 +730,7 @@ TextMarks BaseTextDocument::marksAt(int line) const
return TextMarks();
}
void BaseTextDocument::removeMarkFromMarksCache(ITextMark *mark)
void BaseTextDocument::removeMarkFromMarksCache(TextMark *mark)
{
auto documentLayout = qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
QTC_ASSERT(documentLayout, return);
@@ -753,7 +753,7 @@ void BaseTextDocument::removeMarkFromMarksCache(ITextMark *mark)
documentLayout->requestExtraAreaUpdate();
} else {
double maxWidthFactor = 1.0;
foreach (const ITextMark *mark, marks()) {
foreach (const TextMark *mark, marks()) {
if (!mark->isVisible())
continue;
maxWidthFactor = qMax(mark->widthFactor(), maxWidthFactor);
@@ -770,7 +770,7 @@ void BaseTextDocument::removeMarkFromMarksCache(ITextMark *mark)
}
}
void BaseTextDocument::removeMark(ITextMark *mark)
void BaseTextDocument::removeMark(TextMark *mark)
{
QTextBlock block = d->m_document->findBlockByNumber(mark->lineNumber() - 1);
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
@@ -782,7 +782,7 @@ void BaseTextDocument::removeMark(ITextMark *mark)
mark->setBaseTextDocument(0);
}
void BaseTextDocument::updateMark(ITextMark *mark)
void BaseTextDocument::updateMark(TextMark *mark)
{
Q_UNUSED(mark)
auto documentLayout = qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
@@ -790,7 +790,7 @@ void BaseTextDocument::updateMark(ITextMark *mark)
documentLayout->requestUpdate();
}
void BaseTextDocument::moveMark(ITextMark *mark, int previousLine)
void BaseTextDocument::moveMark(TextMark *mark, int previousLine)
{
QTextBlock block = d->m_document->findBlockByNumber(previousLine - 1);
if (TextBlockUserData *data = BaseTextDocumentLayout::testUserData(block)) {

View File

@@ -32,6 +32,7 @@
#include "texteditor_global.h"
#include "itexteditor.h"
#include "itexteditor.h"
#include <QList>
@@ -50,9 +51,10 @@ class Indenter;
class StorageSettings;
class SyntaxHighlighter;
class TabSettings;
class TextMark;
class TypingSettings;
typedef QList<ITextMark *> TextMarks;
typedef QList<TextMark *> TextMarks;
class TEXTEDITOR_EXPORT BaseTextDocument : public ITextEditorDocument
{
@@ -85,12 +87,12 @@ public:
QTextCursor unindent(const QTextCursor &cursor);
TextMarks marks() const;
bool addMark(ITextMark *mark);
bool addMark(TextMark *mark);
TextMarks marksAt(int line) const;
void removeMark(ITextMark *mark);
void updateMark(ITextMark *mark);
void moveMark(ITextMark *mark, int previousLine);
void removeMarkFromMarksCache(TextEditor::ITextMark *mark);
void removeMark(TextMark *mark);
void updateMark(TextMark *mark);
void moveMark(TextMark *mark, int previousLine);
void removeMarkFromMarksCache(TextEditor::TextMark *mark);
// IDocument implementation.
bool save(QString *errorString, const QString &fileName, bool autoSave);

View File

@@ -40,7 +40,7 @@ CodeFormatterData::~CodeFormatterData()
TextBlockUserData::~TextBlockUserData()
{
foreach (ITextMark *mrk, m_marks) {
foreach (TextMark *mrk, m_marks) {
mrk->baseTextDocument()->removeMarkFromMarksCache(mrk);
mrk->setBaseTextDocument(0);
mrk->removedFromEditor();
@@ -376,7 +376,7 @@ void TextBlockUserData::setCodeFormatterData(CodeFormatterData *data)
m_codeFormatterData = data;
}
void TextBlockUserData::addMark(ITextMark *mark)
void TextBlockUserData::addMark(TextMark *mark)
{
int i = 0;
for ( ; i < m_marks.size(); ++i) {
@@ -593,7 +593,7 @@ TextMarks BaseTextDocumentLayout::documentClosing()
void BaseTextDocumentLayout::documentReloaded(TextMarks marks, BaseTextDocument *baseTextDocument)
{
foreach (ITextMark *mark, marks) {
foreach (TextMark *mark, marks) {
int blockNumber = mark->lineNumber() - 1;
QTextBlock block = document()->findBlockByNumber(blockNumber);
if (block.isValid()) {
@@ -618,7 +618,7 @@ void BaseTextDocumentLayout::updateMarksLineNumber()
int blockNumber = 0;
while (block.isValid()) {
if (const TextBlockUserData *userData = testUserData(block))
foreach (ITextMark *mrk, userData->marks())
foreach (TextMark *mrk, userData->marks())
mrk->updateLineNumber(blockNumber + 1);
block = block.next();
++blockNumber;
@@ -628,7 +628,7 @@ void BaseTextDocumentLayout::updateMarksLineNumber()
void BaseTextDocumentLayout::updateMarksBlock(const QTextBlock &block)
{
if (const TextBlockUserData *userData = testUserData(block))
foreach (ITextMark *mrk, userData->marks())
foreach (TextMark *mrk, userData->marks())
mrk->updateBlock(block);
}

View File

@@ -33,6 +33,7 @@
#include "texteditor_global.h"
#include "basetexteditor.h"
#include "textmark.h"
#include <QTextBlockUserData>
#include <QPlainTextDocumentLayout>
@@ -75,12 +76,12 @@ public:
~TextBlockUserData();
inline TextMarks marks() const { return m_marks; }
void addMark(ITextMark *mark);
inline bool removeMark(ITextMark *mark) { return m_marks.removeAll(mark); }
void addMark(TextMark *mark);
inline bool removeMark(TextMark *mark) { return m_marks.removeAll(mark); }
inline TextMarks documentClosing() {
TextMarks marks = m_marks;
foreach (ITextMark *mrk, m_marks)
foreach (TextMark *mrk, m_marks)
mrk->setBaseTextDocument(0);
m_marks.clear();
return marks;

View File

@@ -3933,7 +3933,7 @@ void BaseTextEditorWidget::extraAreaPaintEvent(QPaintEvent *e)
}
TextMarks::const_iterator end = marks.constEnd();
for ( ; it != end; ++it) {
ITextMark *mark = *it;
TextMark *mark = *it;
if (!mark->isVisible())
continue;
const int height = fmLineSpacing - 1;
@@ -4605,7 +4605,7 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
TextMarks marks = data->marks();
for (int i = marks.size(); --i >= 0; ) {
ITextMark *mark = marks.at(i);
TextMark *mark = marks.at(i);
if (mark->isDraggable()) {
d->m_markDragStart = e->pos();
break;
@@ -4653,7 +4653,7 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
TextMarks marks = data->marks();
for (int i = marks.size(); --i >= 0; ) {
ITextMark *mark = marks.at(i);
TextMark *mark = marks.at(i);
if (sameLine) {
if (mark->isClickable()) {
mark->clicked();

View File

@@ -1,60 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef BASETEXTMARK_H
#define BASETEXTMARK_H
#include "texteditor_global.h"
#include "itextmark.h"
namespace TextEditor {
namespace Internal { class BaseTextMarkRegistry; }
class TEXTEDITOR_EXPORT BaseTextMark : public TextEditor::ITextMark
{
friend class Internal::BaseTextMarkRegistry;
public:
BaseTextMark(const QString &fileName, int lineNumber);
void init();
virtual ~BaseTextMark();
/// called if the filename of the document changed
virtual void updateFileName(const QString &fileName);
// access to internal data
QString fileName() const { return m_fileName; }
private:
QString m_fileName;
};
} // namespace TextEditor
#endif // BASETEXTMARK_H

View File

@@ -32,17 +32,13 @@
#include "texteditor_global.h"
#include "itextmark.h"
#include <coreplugin/textdocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <QMap>
#include <QIcon>
QT_BEGIN_NAMESPACE
class QIcon;
class QMenu;
class QPainter;
class QPoint;

View File

@@ -1,143 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "itextmark.h"
#include "basetextdocument.h"
using namespace TextEditor;
ITextMark::~ITextMark()
{
if (m_baseTextDocument)
m_baseTextDocument->removeMark(this);
m_baseTextDocument = 0;
}
int ITextMark::lineNumber() const
{
return m_lineNumber;
}
void ITextMark::paint(QPainter *painter, const QRect &rect) const
{
m_icon.paint(painter, rect, Qt::AlignCenter);
}
void ITextMark::updateLineNumber(int lineNumber)
{
m_lineNumber = lineNumber;
}
void ITextMark::move(int line)
{
if (line == m_lineNumber)
return;
const int previousLine = m_lineNumber;
m_lineNumber = line;
if (m_baseTextDocument)
m_baseTextDocument->moveMark(this, previousLine);
}
void ITextMark::updateBlock(const QTextBlock &)
{}
void ITextMark::removedFromEditor()
{}
void ITextMark::setIcon(const QIcon &icon)
{
m_icon = icon;
}
void ITextMark::updateMarker()
{
if (m_baseTextDocument)
m_baseTextDocument->updateMark(this);
}
void ITextMark::setPriority(Priority priority)
{
m_priority = priority;
}
ITextMark::Priority ITextMark::priority() const
{
return m_priority;
}
bool ITextMark::isVisible() const
{
return m_visible;
}
void ITextMark::setVisible(bool visible)
{
m_visible = visible;
if (m_baseTextDocument)
m_baseTextDocument->updateMark(this);
}
double ITextMark::widthFactor() const
{
return m_widthFactor;
}
void ITextMark::setWidthFactor(double factor)
{
m_widthFactor = factor;
}
bool ITextMark::isClickable() const
{
return false;
}
void ITextMark::clicked()
{}
bool ITextMark::isDraggable() const
{
return false;
}
void ITextMark::dragToLine(int lineNumber)
{
Q_UNUSED(lineNumber);
}
BaseTextDocument *ITextMark::baseTextDocument() const
{
return m_baseTextDocument;
}
void ITextMark::setBaseTextDocument(BaseTextDocument *baseTextDocument)
{
m_baseTextDocument = baseTextDocument;
}

View File

@@ -21,7 +21,6 @@ SOURCES += texteditorplugin.cpp \
displaysettingspage.cpp \
fontsettings.cpp \
linenumberfilter.cpp \
basetextmark.cpp \
findinfiles.cpp \
basefilefind.cpp \
texteditorsettings.cpp \
@@ -106,7 +105,7 @@ SOURCES += texteditorplugin.cpp \
codestyleeditor.cpp \
circularclipboard.cpp \
circularclipboardassist.cpp \
itextmark.cpp \
textmark.cpp \
codeassist/keywordscompletionassist.cpp \
marginsettings.cpp
@@ -130,7 +129,6 @@ HEADERS += texteditorplugin.h \
itexteditor.h \
linenumberfilter.h \
texteditor_global.h \
basetextmark.h \
findinfiles.h \
basefilefind.h \
texteditorsettings.h \
@@ -223,9 +221,9 @@ HEADERS += texteditorplugin.h \
basefilefind_p.h \
circularclipboard.h \
circularclipboardassist.h \
itextmark.h \
textmark.h \
codeassist/keywordscompletionassist.h \
basetextmarkregistry.h \
textmarkregistry.h \
marginsettings.h
FORMS += \

View File

@@ -28,9 +28,6 @@ QtcPlugin {
"basetexteditor.cpp",
"basetexteditor.h",
"basetexteditor_p.h",
"basetextmark.cpp",
"basetextmark.h",
"basetextmarkregistry.h",
"behaviorsettings.cpp",
"behaviorsettings.h",
"behaviorsettingspage.cpp",
@@ -93,8 +90,6 @@ QtcPlugin {
"ioutlinewidget.h",
"itexteditor.cpp",
"itexteditor.h",
"itextmark.cpp",
"itextmark.h",
"linenumberfilter.cpp",
"linenumberfilter.h",
"marginsettings.cpp",
@@ -144,6 +139,9 @@ QtcPlugin {
"texteditorsettings.h",
"textfilewizard.cpp",
"textfilewizard.h",
"textmark.cpp",
"textmark.h",
"textmarkregistry.h",
"typingsettings.cpp",
"typingsettings.h",
]

View File

@@ -40,7 +40,7 @@
#include "plaintexteditor.h"
#include "outlinefactory.h"
#include "snippets/plaintextsnippetprovider.h"
#include "basetextmarkregistry.h"
#include "textmarkregistry.h"
#include <texteditor/generichighlighter/manager.h>
#include <coreplugin/icore.h>
@@ -190,7 +190,7 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
m_outlineFactory = new OutlineFactory;
addAutoReleasedObject(m_outlineFactory);
m_baseTextMarkRegistry = new BaseTextMarkRegistry(this);
m_baseTextMarkRegistry = new TextMarkRegistry(this);
return true;
}
@@ -271,7 +271,7 @@ LineNumberFilter *TextEditorPlugin::lineNumberFilter()
return m_instance->m_lineNumberFilter;
}
BaseTextMarkRegistry *TextEditorPlugin::baseTextMarkRegistry()
TextMarkRegistry *TextEditorPlugin::baseTextMarkRegistry()
{
return m_instance->m_baseTextMarkRegistry;
}

View File

@@ -45,7 +45,7 @@ namespace Internal {
class LineNumberFilter;
class PlainTextEditorFactory;
class OutlineFactory;
class BaseTextMarkRegistry;
class TextMarkRegistry;
class TextEditorPlugin : public ExtensionSystem::IPlugin
{
@@ -62,7 +62,7 @@ public:
static PlainTextEditorFactory *editorFactory();
static LineNumberFilter *lineNumberFilter();
static BaseTextMarkRegistry *baseTextMarkRegistry();
static TextMarkRegistry *baseTextMarkRegistry();
private slots:
void invokeCompletion();
@@ -76,7 +76,7 @@ private:
LineNumberFilter *m_lineNumberFilter;
Core::SearchResultWindow *m_searchResultWindow;
OutlineFactory *m_outlineFactory;
BaseTextMarkRegistry *m_baseTextMarkRegistry;
TextMarkRegistry *m_baseTextMarkRegistry;
#ifdef WITH_TESTS

View File

@@ -27,24 +27,163 @@
**
****************************************************************************/
#include "basetextmarkregistry.h"
#include "basetextmark.h"
#include "textmark.h"
#include "basetextdocument.h"
#include "textmarkregistry.h"
#include "itexteditor.h"
#include "basetextdocument.h"
#include "texteditorplugin.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/documentmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
using namespace Core;
using namespace Utils;
using namespace TextEditor::Internal;
namespace TextEditor {
namespace Internal {
BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent)
TextMark::TextMark(const QString &fileName, int lineNumber)
: m_baseTextDocument(0),
m_fileName(fileName),
m_lineNumber(lineNumber),
m_priority(NormalPriority),
m_visible(true),
m_widthFactor(1.0)
{
if (!m_fileName.isEmpty())
TextEditorPlugin::baseTextMarkRegistry()->add(this);
}
TextMark::~TextMark()
{
TextEditorPlugin::baseTextMarkRegistry()->remove(this);
if (m_baseTextDocument)
m_baseTextDocument->removeMark(this);
m_baseTextDocument = 0;
}
QString TextMark::fileName() const
{
return m_fileName;
}
void TextMark::updateFileName(const QString &fileName)
{
if (fileName == m_fileName)
return;
if (!m_fileName.isEmpty())
TextEditorPlugin::baseTextMarkRegistry()->remove(this);
m_fileName = fileName;
if (!m_fileName.isEmpty())
TextEditorPlugin::baseTextMarkRegistry()->add(this);
}
int TextMark::lineNumber() const
{
return m_lineNumber;
}
void TextMark::paint(QPainter *painter, const QRect &rect) const
{
m_icon.paint(painter, rect, Qt::AlignCenter);
}
void TextMark::updateLineNumber(int lineNumber)
{
m_lineNumber = lineNumber;
}
void TextMark::move(int line)
{
if (line == m_lineNumber)
return;
const int previousLine = m_lineNumber;
m_lineNumber = line;
if (m_baseTextDocument)
m_baseTextDocument->moveMark(this, previousLine);
}
void TextMark::updateBlock(const QTextBlock &)
{}
void TextMark::removedFromEditor()
{}
void TextMark::setIcon(const QIcon &icon)
{
m_icon = icon;
}
void TextMark::updateMarker()
{
if (m_baseTextDocument)
m_baseTextDocument->updateMark(this);
}
void TextMark::setPriority(Priority priority)
{
m_priority = priority;
}
TextMark::Priority TextMark::priority() const
{
return m_priority;
}
bool TextMark::isVisible() const
{
return m_visible;
}
void TextMark::setVisible(bool visible)
{
m_visible = visible;
if (m_baseTextDocument)
m_baseTextDocument->updateMark(this);
}
double TextMark::widthFactor() const
{
return m_widthFactor;
}
void TextMark::setWidthFactor(double factor)
{
m_widthFactor = factor;
}
bool TextMark::isClickable() const
{
return false;
}
void TextMark::clicked()
{}
bool TextMark::isDraggable() const
{
return false;
}
void TextMark::dragToLine(int lineNumber)
{
Q_UNUSED(lineNumber);
}
BaseTextDocument *TextMark::baseTextDocument() const
{
return m_baseTextDocument;
}
void TextMark::setBaseTextDocument(BaseTextDocument *baseTextDocument)
{
m_baseTextDocument = baseTextDocument;
}
TextMarkRegistry::TextMarkRegistry(QObject *parent)
: QObject(parent)
{
connect(EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)),
@@ -56,7 +195,7 @@ BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent)
this, SLOT(documentRenamed(Core::IDocument*,QString,QString)));
}
void BaseTextMarkRegistry::add(BaseTextMark *mark)
void TextMarkRegistry::add(TextMark *mark)
{
m_marks[FileName::fromString(mark->fileName())].insert(mark);
auto document = qobject_cast<BaseTextDocument*>(DocumentModel::documentForFilePath(mark->fileName()));
@@ -65,12 +204,12 @@ void BaseTextMarkRegistry::add(BaseTextMark *mark)
document->addMark(mark);
}
bool BaseTextMarkRegistry::remove(BaseTextMark *mark)
bool TextMarkRegistry::remove(TextMark *mark)
{
return m_marks[FileName::fromString(mark->fileName())].remove(mark);
}
void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
void TextMarkRegistry::editorOpened(Core::IEditor *editor)
{
auto document = qobject_cast<BaseTextDocument *>(editor ? editor->document() : 0);
if (!document)
@@ -78,15 +217,14 @@ void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
if (!m_marks.contains(FileName::fromString(document->filePath())))
return;
foreach (BaseTextMark *mark, m_marks.value(FileName::fromString(document->filePath())))
foreach (TextMark *mark, m_marks.value(FileName::fromString(document->filePath())))
document->addMark(mark);
}
void BaseTextMarkRegistry::documentRenamed(IDocument *document, const
void TextMarkRegistry::documentRenamed(IDocument *document, const
QString &oldName, const QString &newName)
{
TextEditor::BaseTextDocument *baseTextDocument
= qobject_cast<TextEditor::BaseTextDocument *>(document);
BaseTextDocument *baseTextDocument = qobject_cast<BaseTextDocument *>(document);
if (!document)
return;
FileName oldFileName = FileName::fromString(oldName);
@@ -94,60 +232,31 @@ void BaseTextMarkRegistry::documentRenamed(IDocument *document, const
if (!m_marks.contains(oldFileName))
return;
QSet<BaseTextMark *> toBeMoved;
foreach (ITextMark *mark, baseTextDocument->marks())
if (BaseTextMark *baseTextMark = dynamic_cast<BaseTextMark *>(mark))
toBeMoved.insert(baseTextMark);
QSet<TextMark *> toBeMoved;
foreach (TextMark *mark, baseTextDocument->marks())
toBeMoved.insert(mark);
m_marks[oldFileName].subtract(toBeMoved);
m_marks[newFileName].unite(toBeMoved);
foreach (BaseTextMark *mark, toBeMoved)
foreach (TextMark *mark, toBeMoved)
mark->updateFileName(newName);
}
void BaseTextMarkRegistry::allDocumentsRenamed(const QString &oldName, const QString &newName)
void TextMarkRegistry::allDocumentsRenamed(const QString &oldName, const QString &newName)
{
FileName oldFileName = FileName::fromString(oldName);
FileName newFileName = FileName::fromString(newName);
if (!m_marks.contains(oldFileName))
return;
QSet<BaseTextMark *> oldFileNameMarks = m_marks.value(oldFileName);
QSet<TextMark *> oldFileNameMarks = m_marks.value(oldFileName);
m_marks[newFileName].unite(oldFileNameMarks);
m_marks[oldFileName].clear();
foreach (BaseTextMark *mark, oldFileNameMarks)
foreach (TextMark *mark, oldFileNameMarks)
mark->updateFileName(newName);
}
} // namespace Internal
BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber)
: ITextMark(lineNumber), m_fileName(fileName)
{
}
// we need two phase initialization, since we are calling virtual functions
// of BaseTextMark in add() and also accessing widthFactor
// which might be set in the derived constructor
void BaseTextMark::init()
{
Internal::TextEditorPlugin::baseTextMarkRegistry()->add(this);
}
BaseTextMark::~BaseTextMark()
{
// oha we are deleted
bool b = Internal::TextEditorPlugin::baseTextMarkRegistry()->remove(this);
// If you get a assertion in this line, init() was never called
QTC_CHECK(b);
}
void BaseTextMark::updateFileName(const QString &fileName)
{
m_fileName = fileName;
}
} // namespace TextEditor

View File

@@ -27,8 +27,8 @@
**
****************************************************************************/
#ifndef ITEXTMARK_H
#define ITEXTMARK_H
#ifndef TextMark_H
#define TextMark_H
#include "texteditor_global.h"
@@ -46,17 +46,13 @@ namespace TextEditor {
class ITextEditor;
class BaseTextDocument;
class TEXTEDITOR_EXPORT ITextMark
namespace Internal { class TextMarkRegistry; }
class TEXTEDITOR_EXPORT TextMark
{
public:
ITextMark(int line)
: m_baseTextDocument(0),
m_lineNumber(line),
m_priority(NormalPriority),
m_visible(true),
m_widthFactor(1.0)
{}
virtual ~ITextMark();
TextMark(const QString &fileName, int lineNumber);
virtual ~TextMark();
// determine order on markers on the same line.
enum Priority
@@ -66,8 +62,12 @@ public:
HighPriority // shown on top.
};
QString fileName() const;
int lineNumber() const;
virtual void paint(QPainter *painter, const QRect &rect) const;
/// called if the filename of the document changed
virtual void updateFileName(const QString &fileName);
virtual void updateLineNumber(int lineNumber);
virtual void updateBlock(const QTextBlock &block);
virtual void move(int line);
@@ -91,8 +91,11 @@ public:
void setBaseTextDocument(BaseTextDocument *baseTextDocument);
private:
Q_DISABLE_COPY(ITextMark)
Q_DISABLE_COPY(TextMark)
friend class Internal::TextMarkRegistry;
BaseTextDocument *m_baseTextDocument;
QString m_fileName;
int m_lineNumber;
Priority m_priority;
bool m_visible;
@@ -102,4 +105,4 @@ private:
} // namespace TextEditor
#endif // ITEXTMARK_H
#endif // TextMark_H

View File

@@ -42,23 +42,23 @@ class IDocument;
}
namespace TextEditor {
class BaseTextMark;
class TextMark;
namespace Internal {
class BaseTextMarkRegistry : public QObject
class TextMarkRegistry : public QObject
{
Q_OBJECT
public:
BaseTextMarkRegistry(QObject *parent);
TextMarkRegistry(QObject *parent);
void add(BaseTextMark *mark);
bool remove(BaseTextMark *mark);
void add(TextMark *mark);
bool remove(TextMark *mark);
private slots:
void editorOpened(Core::IEditor *editor);
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
void allDocumentsRenamed(const QString &oldName, const QString &newName);
private:
QHash<Utils::FileName, QSet<BaseTextMark *> > m_marks;
QHash<Utils::FileName, QSet<TextMark *> > m_marks;
};
} // namespace Internal

View File

@@ -44,9 +44,9 @@ using namespace Valgrind::Callgrind;
CallgrindTextMark::CallgrindTextMark(const QPersistentModelIndex &index,
const QString &fileName, int lineNumber)
: TextEditor::BaseTextMark(fileName, lineNumber), m_modelIndex(index)
: TextEditor::TextMark(fileName, lineNumber), m_modelIndex(index)
{
setPriority(TextEditor::ITextMark::HighPriority);
setPriority(TextEditor::TextMark::HighPriority);
setWidthFactor(4.0);
}

View File

@@ -30,7 +30,7 @@
#ifndef CALLGRINDTEXTMARK_H
#define CALLGRINDTEXTMARK_H
#include <texteditor/basetextmark.h>
#include <texteditor/textmark.h>
#include <QPersistentModelIndex>
@@ -40,7 +40,7 @@ namespace Callgrind { class Function; }
namespace Internal {
class CallgrindTextMark : public TextEditor::BaseTextMark
class CallgrindTextMark : public TextEditor::TextMark
{
public:
/**

View File

@@ -1014,9 +1014,7 @@ void CallgrindToolPrivate::createTextMarks()
continue;
locations << location;
CallgrindTextMark *mark = new CallgrindTextMark(index, fileName, lineNumber);
mark->init();
m_textMarks.append(mark);
m_textMarks.append(new CallgrindTextMark(index, fileName, lineNumber));
}
}