Commit ff7a0ea6 authored by Axel Kellermann's avatar Axel Kellermann Committed by Igor Kushnir

Associate loaded breakpoints with a moving cursor

Loaded breakpoints don't trigger markChanged(), which is normally
responsible for getting a moving cursor for breakpoints. Instead
the moving cursor for loaded breakpoints is now added in
textDocumentCreated().
Logic for adding moving cursors is also moved into seperate function,
as the same code snippet was used multiple times.

BUG: 424431
FIXED-IN: 5.6.0
parent cc3f98b8
Pipeline #30847 failed with stage
in 60 minutes
......@@ -130,16 +130,25 @@ void BreakpointModel::slotPartAdded(KParts::Part* part)
void BreakpointModel::textDocumentCreated(KDevelop::IDocument* doc)
{
KTextEditor::MarkInterface *iface =
qobject_cast<KTextEditor::MarkInterface*>(doc->textDocument());
Q_D(const BreakpointModel);
KTextEditor::Document* const textDocument = doc->textDocument();
if (iface) {
if (qobject_cast<KTextEditor::MarkInterface*>(textDocument)) {
// can't use new signal slot syntax here, MarkInterface is not a QObject
connect(doc->textDocument(), SIGNAL(markChanged(KTextEditor::Document*,KTextEditor::Mark,KTextEditor::MarkInterface::MarkChangeAction)),
connect(textDocument, SIGNAL(markChanged(KTextEditor::Document*,KTextEditor::Mark,KTextEditor::MarkInterface::MarkChangeAction)),
this, SLOT(markChanged(KTextEditor::Document*,KTextEditor::Mark,KTextEditor::MarkInterface::MarkChangeAction)));
connect(doc->textDocument(), SIGNAL(markContextMenuRequested(KTextEditor::Document*,KTextEditor::Mark,QPoint,bool&)),
connect(textDocument, SIGNAL(markContextMenuRequested(KTextEditor::Document*,KTextEditor::Mark,QPoint,bool&)),
SLOT(markContextMenuRequested(KTextEditor::Document*,KTextEditor::Mark,QPoint,bool&)));
}
// markChanged() is not triggered for loaded breakpoints, so get them a moving cursor now
const QUrl docUrl = textDocument->url();
for (Breakpoint* breakpoint : qAsConst(d->breakpoints)) {
if (docUrl == breakpoint->url()) {
setupMovingCursor(textDocument, breakpoint);
}
}
}
void BreakpointModel::markContextMenuRequested(Document* document, Mark mark, const QPoint &pos, bool& handled)
......@@ -183,15 +192,8 @@ void BreakpointModel::markContextMenuRequested(Document* document, Mark mark, co
if (b) {
b->setDeleted();
} else {
Breakpoint *breakpoint = addCodeBreakpoint(document->url(), mark.line);
MovingInterface *moving = qobject_cast<MovingInterface*>(document);
if (moving) {
MovingCursor* cursor = moving->newMovingCursor(Cursor(mark.line, 0));
// can't use new signal/slot syntax here, MovingInterface is not a QObject
connect(document, SIGNAL(aboutToDeleteMovingInterfaceContent(Document*)),
this, SLOT(aboutToDeleteMovingInterfaceContent(Document*)), Qt::UniqueConnection);
breakpoint->setMovingCursor(cursor);
}
Breakpoint* breakpoint = addCodeBreakpoint(document->url(), mark.line);
setupMovingCursor(document, breakpoint);
}
} else if (triggeredAction == enableAction) {
b->setData(Breakpoint::EnableColumn, b->enabled() ? Qt::Unchecked : Qt::Checked);
......@@ -379,15 +381,8 @@ void BreakpointModel::markChanged(
b->setDeleted();
return;
}
Breakpoint *breakpoint = addCodeBreakpoint(document->url(), mark.line);
KTextEditor::MovingInterface *moving = qobject_cast<KTextEditor::MovingInterface*>(document);
if (moving) {
KTextEditor::MovingCursor* cursor = moving->newMovingCursor(KTextEditor::Cursor(mark.line, 0));
// can't use new signal/slot syntax here, MovingInterface is not a QObject
connect(document, SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document*)),
this, SLOT(aboutToDeleteMovingInterfaceContent(KTextEditor::Document*)), Qt::UniqueConnection);
breakpoint->setMovingCursor(cursor);
}
Breakpoint* breakpoint = addCodeBreakpoint(document->url(), mark.line);
setupMovingCursor(document, breakpoint);
} else {
// Find this breakpoint and delete it
Breakpoint *b = breakpoint(document->url(), mark.line);
......@@ -714,3 +709,17 @@ Breakpoint* BreakpointModel::breakpoint(const QUrl& url, int line) const
});
return (it != d->breakpoints.constEnd()) ? *it : nullptr;
}
void BreakpointModel::setupMovingCursor(KTextEditor::Document* document, Breakpoint* breakpoint) const
{
Q_ASSERT(document->url() == breakpoint->url() && breakpoint->movingCursor() == nullptr);
auto* const movingInterface = qobject_cast<KTextEditor::MovingInterface*>(document);
if (movingInterface) {
auto* const cursor = movingInterface->newMovingCursor(KTextEditor::Cursor(breakpoint->line(), 0));
// can't use new signal/slot syntax here, MovingInterface is not a QObject
connect(document, SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document*)),
this, SLOT(aboutToDeleteMovingInterfaceContent(KTextEditor::Document*)), Qt::UniqueConnection);
breakpoint->setMovingCursor(cursor);
}
}
......@@ -114,7 +114,7 @@ public:
///Note: to retrieve the full path use Breakpoint::LocationRole, Qt::DisplayRole returns only a file's name
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
void toggleBreakpoint(const QUrl &url, const KTextEditor::Cursor& cursor);
......@@ -191,6 +191,8 @@ private:
uint breakpointType(Breakpoint *breakpoint) const;
Breakpoint *breakpoint(const QUrl& url, int line) const;
void setupMovingCursor(KTextEditor::Document* document, Breakpoint* breakpoint) const;
private:
const QScopedPointer<class BreakpointModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(BreakpointModel)
......
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