Commit 73ee141c authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kdevplatform/debugger: use Q_DECLARE_PRIVATE/Q_D to forward constness to d

parent dde92909
......@@ -44,8 +44,10 @@ public:
BreakpointDetails::BreakpointDetails(QWidget *parent)
: QWidget(parent)
, d(new BreakpointDetailsPrivate)
, d_ptr(new BreakpointDetailsPrivate)
{
Q_D(BreakpointDetails);
auto* layout = new QVBoxLayout(this);
d->status = new QLabel(this);
......@@ -82,6 +84,8 @@ BreakpointDetails::~BreakpointDetails() = default;
void KDevelop::BreakpointDetails::setIgnoreHits(int ignoreHits)
{
Q_D(BreakpointDetails);
if (!d->currentBreakpoint)
return;
d->currentBreakpoint->setIgnoreHits(ignoreHits);
......@@ -90,6 +94,8 @@ void KDevelop::BreakpointDetails::setIgnoreHits(int ignoreHits)
void BreakpointDetails::setItem(Breakpoint *breakpoint)
{
Q_D(BreakpointDetails);
d->currentBreakpoint = breakpoint;
if (!breakpoint) {
......@@ -142,6 +148,8 @@ void BreakpointDetails::setItem(Breakpoint *breakpoint)
void BreakpointDetails::showExplanation(const QString& link)
{
Q_D(BreakpointDetails);
QPoint pos = d->status->mapToGlobal(d->status->geometry().topLeft());
if (link == QLatin1String("pending"))
{
......
......@@ -27,6 +27,7 @@
namespace KDevelop {
class Breakpoint;
class BreakpointDetailsPrivate;
class KDEVPLATFORMDEBUGGER_EXPORT BreakpointDetails : public QWidget
{
......@@ -43,7 +44,8 @@ private Q_SLOTS:
void setIgnoreHits(int ignoreHits);
private:
const QScopedPointer<class BreakpointDetailsPrivate> d;
const QScopedPointer<class BreakpointDetailsPrivate> d_ptr;
Q_DECLARE_PRIVATE(BreakpointDetails)
};
......
......@@ -78,7 +78,7 @@ public:
BreakpointModel::BreakpointModel(QObject* parent)
: QAbstractTableModel(parent),
d(new BreakpointModelPrivate)
d_ptr(new BreakpointModelPrivate)
{
connect(this, &BreakpointModel::dataChanged, this, &BreakpointModel::updateMarks);
......@@ -105,6 +105,8 @@ BreakpointModel::BreakpointModel(QObject* parent)
BreakpointModel::~BreakpointModel()
{
Q_D(BreakpointModel);
qDeleteAll(d->breakpoints);
}
......@@ -250,6 +252,8 @@ Qt::ItemFlags BreakpointModel::flags(const QModelIndex &index) const
QModelIndex BreakpointModel::breakpointIndex(KDevelop::Breakpoint* b, int column)
{
Q_D(BreakpointModel);
int row = d->breakpoints.indexOf(b);
if (row == -1) return QModelIndex();
return index(row, column);
......@@ -257,6 +261,8 @@ QModelIndex BreakpointModel::breakpointIndex(KDevelop::Breakpoint* b, int column
bool KDevelop::BreakpointModel::removeRows(int row, int count, const QModelIndex& parent)
{
Q_D(BreakpointModel);
if (count < 1 || (row < 0) || (row + count) > rowCount(parent))
return false;
......@@ -281,6 +287,8 @@ bool KDevelop::BreakpointModel::removeRows(int row, int count, const QModelIndex
int KDevelop::BreakpointModel::rowCount(const QModelIndex& parent) const
{
Q_D(const BreakpointModel);
if (!parent.isValid()) {
return d->breakpoints.count();
}
......@@ -295,6 +303,8 @@ int KDevelop::BreakpointModel::columnCount(const QModelIndex& parent) const
QVariant BreakpointModel::data(const QModelIndex& index, int role) const
{
Q_D(const BreakpointModel);
if (!index.parent().isValid() && index.row() < d->breakpoints.count()) {
return d->breakpoints.at(index.row())->data(index.column(), role);
}
......@@ -303,6 +313,8 @@ QVariant BreakpointModel::data(const QModelIndex& index, int role) const
bool KDevelop::BreakpointModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
Q_D(const BreakpointModel);
if (!index.parent().isValid() && index.row() < d->breakpoints.count() && (role == Qt::EditRole || role == Qt::CheckStateRole)) {
return d->breakpoints.at(index.row())->setData(index.column(), value);
}
......@@ -311,6 +323,8 @@ bool KDevelop::BreakpointModel::setData(const QModelIndex& index, const QVariant
void BreakpointModel::updateState(int row, Breakpoint::BreakpointState state)
{
Q_D(BreakpointModel);
Breakpoint* breakpoint = d->breakpoints.at(row);
if (state != breakpoint->m_state) {
breakpoint->m_state = state;
......@@ -320,6 +334,8 @@ void BreakpointModel::updateState(int row, Breakpoint::BreakpointState state)
void BreakpointModel::updateHitCount(int row, int hitCount)
{
Q_D(BreakpointModel);
Breakpoint* breakpoint = d->breakpoints.at(row);
if (hitCount != breakpoint->m_hitCount) {
breakpoint->m_hitCount = hitCount;
......@@ -329,6 +345,8 @@ void BreakpointModel::updateHitCount(int row, int hitCount)
void BreakpointModel::updateErrorText(int row, const QString& errorText)
{
Q_D(BreakpointModel);
Breakpoint* breakpoint = d->breakpoints.at(row);
if (breakpoint->m_errorText != errorText) {
breakpoint->m_errorText = errorText;
......@@ -424,6 +442,8 @@ void BreakpointModel::toggleBreakpoint(const QUrl& url, const KTextEditor::Curso
void BreakpointModel::reportChange(Breakpoint* breakpoint, Breakpoint::Column column)
{
Q_D(BreakpointModel);
// note: just a portion of Breakpoint::Column is displayed in this model!
if (column >= 0 && column < columnCount()) {
QModelIndex idx = breakpointIndex(breakpoint, column);
......@@ -455,6 +475,8 @@ uint BreakpointModel::breakpointType(Breakpoint *breakpoint) const
void KDevelop::BreakpointModel::updateMarks()
{
Q_D(BreakpointModel);
if (d->dontUpdateMarks)
return;
......@@ -508,6 +530,8 @@ void KDevelop::BreakpointModel::updateMarks()
void BreakpointModel::documentSaved(KDevelop::IDocument* doc)
{
Q_D(BreakpointModel);
IF_DEBUG( qCDebug(DEBUGGER); )
for (Breakpoint* breakpoint : qAsConst(d->breakpoints)) {
if (breakpoint->movingCursor()) {
......@@ -521,6 +545,8 @@ void BreakpointModel::documentSaved(KDevelop::IDocument* doc)
}
void BreakpointModel::aboutToDeleteMovingInterfaceContent(KTextEditor::Document* document)
{
Q_D(BreakpointModel);
for (Breakpoint* breakpoint : qAsConst(d->breakpoints)) {
if (breakpoint->movingCursor() && breakpoint->movingCursor()->document() == document) {
breakpoint->setMovingCursor(nullptr);
......@@ -546,6 +572,8 @@ void BreakpointModel::load()
void BreakpointModel::save()
{
Q_D(BreakpointModel);
d->dirty = false;
KConfigGroup breakpoints = ICore::self()->activeSession()->config()->group("Breakpoints");
......@@ -561,6 +589,8 @@ void BreakpointModel::save()
void BreakpointModel::scheduleSave()
{
Q_D(BreakpointModel);
if (d->dirty)
return;
......@@ -570,17 +600,23 @@ void BreakpointModel::scheduleSave()
QList<Breakpoint*> KDevelop::BreakpointModel::breakpoints() const
{
Q_D(const BreakpointModel);
return d->breakpoints;
}
Breakpoint* BreakpointModel::breakpoint(int row) const
{
Q_D(const BreakpointModel);
if (row >= d->breakpoints.count()) return nullptr;
return d->breakpoints.at(row);
}
Breakpoint* BreakpointModel::addCodeBreakpoint()
{
Q_D(BreakpointModel);
beginInsertRows(QModelIndex(), d->breakpoints.count(), d->breakpoints.count());
auto* n = new Breakpoint(this, Breakpoint::CodeBreakpoint);
endInsertRows();
......@@ -603,6 +639,8 @@ Breakpoint* BreakpointModel::addCodeBreakpoint(const QString& expression)
Breakpoint* BreakpointModel::addWatchpoint()
{
Q_D(BreakpointModel);
beginInsertRows(QModelIndex(), d->breakpoints.count(), d->breakpoints.count());
auto* n = new Breakpoint(this, Breakpoint::WriteBreakpoint);
endInsertRows();
......@@ -618,6 +656,8 @@ Breakpoint* BreakpointModel::addWatchpoint(const QString& expression)
Breakpoint* BreakpointModel::addReadWatchpoint()
{
Q_D(BreakpointModel);
beginInsertRows(QModelIndex(), d->breakpoints.count(), d->breakpoints.count());
auto* n = new Breakpoint(this, Breakpoint::ReadBreakpoint);
endInsertRows();
......@@ -633,6 +673,8 @@ Breakpoint* BreakpointModel::addReadWatchpoint(const QString& expression)
Breakpoint* BreakpointModel::addAccessWatchpoint()
{
Q_D(BreakpointModel);
beginInsertRows(QModelIndex(), d->breakpoints.count(), d->breakpoints.count());
auto* n = new Breakpoint(this, Breakpoint::AccessBreakpoint);
endInsertRows();
......@@ -649,6 +691,8 @@ Breakpoint* BreakpointModel::addAccessWatchpoint(const QString& expression)
void BreakpointModel::registerBreakpoint(Breakpoint* breakpoint)
{
Q_D(BreakpointModel);
Q_ASSERT(!d->breakpoints.contains(breakpoint));
int row = d->breakpoints.size();
d->breakpoints << breakpoint;
......@@ -660,6 +704,8 @@ void BreakpointModel::registerBreakpoint(Breakpoint* breakpoint)
Breakpoint* BreakpointModel::breakpoint(const QUrl& url, int line) const
{
Q_D(const BreakpointModel);
auto it = std::find_if(d->breakpoints.constBegin(), d->breakpoints.constEnd(), [&](Breakpoint* b) {
return (b->url() == url && b->line() == line);
});
......
......@@ -38,6 +38,7 @@ namespace KDevelop
{
class IDocument;
class Breakpoint;
class BreakpointModelPrivate;
class KDEVPLATFORMDEBUGGER_EXPORT BreakpointModel : public QAbstractTableModel
{
......@@ -191,7 +192,8 @@ private:
Breakpoint *breakpoint(const QUrl& url, int line) const;
private:
const QScopedPointer<class BreakpointModelPrivate> d;
const QScopedPointer<class BreakpointModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(BreakpointModel)
};
}
......
......@@ -68,8 +68,10 @@ public:
BreakpointWidget::BreakpointWidget(IDebugController *controller, QWidget *parent)
: AutoOrientedSplitter(parent)
, d(new BreakpointWidgetPrivate(controller))
, d_ptr(new BreakpointWidgetPrivate(controller))
{
Q_D(BreakpointWidget);
setWindowTitle(i18nc("@title:window", "Debugger Breakpoints"));
setWhatsThis(i18nc("@info:whatsthis", "Displays a list of breakpoints with "
"their current status. Clicking on a "
......@@ -121,6 +123,8 @@ BreakpointWidget::~BreakpointWidget() = default;
void BreakpointWidget::setupPopupMenu()
{
Q_D(BreakpointWidget);
d->popup = new QMenu(this);
QMenu* newBreakpoint = d->popup->addMenu(i18nc("New breakpoint", "&New"));
......@@ -166,11 +170,15 @@ void BreakpointWidget::setupPopupMenu()
void BreakpointWidget::contextMenuEvent(QContextMenuEvent* event)
{
Q_D(BreakpointWidget);
d->popup->popup(event->globalPos());
}
void BreakpointWidget::slotPopupMenuAboutToShow()
{
Q_D(BreakpointWidget);
if (d->debugController->breakpointModel()->rowCount() < 1) {
d->breakpointDisableAllAction->setDisabled(true);
d->breakpointEnableAllAction->setDisabled(true);
......@@ -194,6 +202,8 @@ void BreakpointWidget::slotPopupMenuAboutToShow()
void BreakpointWidget::showEvent(QShowEvent *)
{
Q_D(BreakpointWidget);
if (d->firstShow && d->debugController->breakpointModel()->rowCount() > 0) {
for (int i = 0; i < d->breakpointsView->model()->columnCount(); ++i) {
if(i == Breakpoint::LocationColumn){
......@@ -212,6 +222,8 @@ void BreakpointWidget::showEvent(QShowEvent *)
void BreakpointWidget::edit(KDevelop::Breakpoint *n)
{
Q_D(BreakpointWidget);
QModelIndex index = d->proxyModel->mapFromSource(d->debugController->breakpointModel()->breakpointIndex(n, Breakpoint::LocationColumn));
d->breakpointsView->setCurrentIndex(index);
d->breakpointsView->edit(index);
......@@ -219,34 +231,46 @@ void BreakpointWidget::edit(KDevelop::Breakpoint *n)
void BreakpointWidget::slotDataInserted(int column, const QVariant& value)
{
Q_D(BreakpointWidget);
Breakpoint* breakpoint = d->debugController->breakpointModel()->addCodeBreakpoint();
breakpoint->setData(column, value);
}
void BreakpointWidget::slotAddBlankBreakpoint()
{
Q_D(BreakpointWidget);
edit(d->debugController->breakpointModel()->addCodeBreakpoint());
}
void BreakpointWidget::slotAddBlankWatchpoint()
{
Q_D(BreakpointWidget);
edit(d->debugController->breakpointModel()->addWatchpoint());
}
void BreakpointWidget::slotAddBlankReadWatchpoint()
{
Q_D(BreakpointWidget);
edit(d->debugController->breakpointModel()->addReadWatchpoint());
}
void KDevelop::BreakpointWidget::slotAddBlankAccessWatchpoint()
{
Q_D(BreakpointWidget);
edit(d->debugController->breakpointModel()->addAccessWatchpoint());
}
void BreakpointWidget::slotRemoveBreakpoint()
{
Q_D(BreakpointWidget);
QItemSelectionModel* sel = d->breakpointsView->selectionModel();
QModelIndexList selected = sel->selectedIndexes();
IF_DEBUG( qCDebug(DEBUGGER) << selected; )
......@@ -257,12 +281,16 @@ void BreakpointWidget::slotRemoveBreakpoint()
void BreakpointWidget::slotRemoveAllBreakpoints()
{
Q_D(BreakpointWidget);
d->debugController->breakpointModel()->removeRows(0, d->debugController->breakpointModel()->rowCount());
}
void BreakpointWidget::slotUpdateBreakpointDetail()
{
Q_D(BreakpointWidget);
showEvent(nullptr);
QModelIndexList selected = d->breakpointsView->selectionModel()->selectedIndexes();
IF_DEBUG( qCDebug(DEBUGGER) << selected; )
......@@ -275,6 +303,8 @@ void BreakpointWidget::slotUpdateBreakpointDetail()
void BreakpointWidget::breakpointHit(int row)
{
Q_D(BreakpointWidget);
const QModelIndex index = d->proxyModel->mapFromSource(d->debugController->breakpointModel()->index(row, 0));
d->breakpointsView->selectionModel()->select(
index,
......@@ -284,6 +314,8 @@ void BreakpointWidget::breakpointHit(int row)
void BreakpointWidget::breakpointError(int row, const QString& msg)
{
Q_D(BreakpointWidget);
// FIXME: we probably should prevent this error notification during
// initial setting of breakpoint, to avoid a cloud of popups.
if (!d->breakpointsView->isVisible())
......@@ -305,6 +337,8 @@ void BreakpointWidget::breakpointError(int row, const QString& msg)
void BreakpointWidget::slotOpenFile(const QModelIndex& breakpointIdx)
{
Q_D(BreakpointWidget);
if (breakpointIdx.column() != Breakpoint::LocationColumn){
return;
}
......@@ -318,6 +352,8 @@ void BreakpointWidget::slotOpenFile(const QModelIndex& breakpointIdx)
void BreakpointWidget::slotDisableAllBreakpoints()
{
Q_D(BreakpointWidget);
for (int i = 0; i < d->debugController->breakpointModel()->rowCount(); ++i) {
Breakpoint* bp = d->debugController->breakpointModel()->breakpoint(i);
bp->setData(Breakpoint::EnableColumn, Qt::Unchecked);
......@@ -326,6 +362,8 @@ void BreakpointWidget::slotDisableAllBreakpoints()
void BreakpointWidget::slotEnableAllBreakpoints()
{
Q_D(BreakpointWidget);
for (int i = 0; i < d->debugController->breakpointModel()->rowCount(); ++i) {
Breakpoint* bp = d->debugController->breakpointModel()->breakpoint(i);
bp->setData(Breakpoint::EnableColumn, Qt::Checked);
......
......@@ -32,6 +32,7 @@ class QModelIndex;
namespace KDevelop {
class IDebugController;
class Breakpoint;
class BreakpointWidgetPrivate;
class KDEVPLATFORMDEBUGGER_EXPORT BreakpointWidget : public AutoOrientedSplitter
{
......@@ -66,7 +67,8 @@ private Q_SLOTS:
void slotPopupMenuAboutToShow();
private:
const QScopedPointer<class BreakpointWidgetPrivate> d;
const QScopedPointer<class BreakpointWidgetPrivate> d_ptr;
Q_DECLARE_PRIVATE(BreakpointWidget)
};
}
......
......@@ -62,12 +62,12 @@ public:
QHash<int, bool> m_hasMoreFrames;
// Caches
QHash<QString, bool> m_fileExistsCache;
mutable QHash<QString, bool> m_fileExistsCache;
};
FrameStackModel::FrameStackModel(IDebugSession *session)
: IFrameStackModel(session)
, d(new FrameStackModelPrivate(this))
, d_ptr(new FrameStackModelPrivate(this))
{
connect(session, &IDebugSession::stateChanged, this, &FrameStackModel::stateChanged);
}
......@@ -78,6 +78,8 @@ FrameStackModel::~FrameStackModel()
void FrameStackModel::setThreads(const QVector<ThreadItem>& threads)
{
Q_D(FrameStackModel);
qCDebug(DEBUGGER) << threads.count();
if (!d->m_threads.isEmpty()) {
......@@ -107,6 +109,8 @@ QModelIndex FrameStackModelPrivate::indexForThreadNumber(int threadNumber)
void FrameStackModel::setFrames(int threadNumber, const QVector<FrameItem>& frames)
{
Q_D(FrameStackModel);
QModelIndex threadIndex = d->indexForThreadNumber(threadNumber);
Q_ASSERT(threadIndex.isValid());
......@@ -139,6 +143,8 @@ void FrameStackModel::setFrames(int threadNumber, const QVector<FrameItem>& fram
void FrameStackModel::insertFrames(int threadNumber, const QVector<FrameItem>& frames)
{
Q_D(FrameStackModel);
QModelIndex threadIndex = d->indexForThreadNumber(threadNumber);
Q_ASSERT(threadIndex.isValid());
......@@ -150,11 +156,15 @@ void FrameStackModel::insertFrames(int threadNumber, const QVector<FrameItem>& f
void FrameStackModel::setHasMoreFrames(int threadNumber, bool hasMoreFrames)
{
Q_D(FrameStackModel);
d->m_hasMoreFrames[threadNumber] = hasMoreFrames;
}
FrameStackModel::FrameItem FrameStackModel::frame(const QModelIndex& index)
{
Q_D(FrameStackModel);
Q_ASSERT(index.internalId());
Q_ASSERT(static_cast<quintptr>(d->m_threads.count()) >= index.internalId());
const ThreadItem &thread = d->m_threads.at(index.internalId()-1);
......@@ -163,11 +173,15 @@ FrameStackModel::FrameItem FrameStackModel::frame(const QModelIndex& index)
QVector<FrameStackModel::FrameItem> FrameStackModel::frames(int threadNumber) const
{
Q_D(const FrameStackModel);
return d->m_frames.value(threadNumber);
}
QVariant FrameStackModel::data(const QModelIndex& index, int role) const
{
Q_D(const FrameStackModel);
if (!index.internalId()) {
//thread
if (d->m_threads.count() <= index.row()) return QVariant();
......@@ -236,6 +250,8 @@ int FrameStackModel::columnCount(const QModelIndex& parent) const
int FrameStackModel::rowCount(const QModelIndex& parent) const
{
Q_D(const FrameStackModel);
if (!parent.isValid()) {
return d->m_threads.count();
} else if (!parent.internalId() && parent.column() == 0) {
......@@ -257,6 +273,8 @@ QModelIndex FrameStackModel::parent(const QModelIndex& child) const
QModelIndex FrameStackModel::index(int row, int column, const QModelIndex& parent) const
{
Q_D(const FrameStackModel);
if (parent.isValid()) {
Q_ASSERT(!parent.internalId());
Q_ASSERT(parent.column() == 0);
......@@ -284,6 +302,8 @@ QVariant FrameStackModel::headerData(int section, Qt::Orientation orientation, i
void FrameStackModel::setCurrentThread(int threadNumber)
{
Q_D(FrameStackModel);
qCDebug(DEBUGGER) << threadNumber;
if (d->m_currentThread != threadNumber && threadNumber != -1) {
// FIXME: this logic means that if we switch to thread 3 and
......@@ -306,6 +326,8 @@ void FrameStackModel::setCurrentThread(int threadNumber)
void FrameStackModel::setCurrentThread(const QModelIndex& index)
{
Q_D(const FrameStackModel);
Q_ASSERT(index.isValid());
Q_ASSERT(!index.internalId());
Q_ASSERT(index.column() == 0);
......@@ -314,21 +336,29 @@ void FrameStackModel::setCurrentThread(const QModelIndex& index)
void FrameStackModel::setCrashedThreadIndex(int index)
{
Q_D(FrameStackModel);
d->m_crashedThreadIndex = index;
}
int FrameStackModel::crashedThreadIndex() const
{
Q_D(const FrameStackModel);
return d->m_crashedThreadIndex;
}
int FrameStackModel::currentThread() const
{
Q_D(const FrameStackModel);
return d->m_currentThread;
}
QModelIndex FrameStackModel::currentThreadIndex() const
{
Q_D(const FrameStackModel);
int i = 0;
for (const ThreadItem& t : qAsConst(d->m_threads)) {
if (t.nr == currentThread()) {
......@@ -341,16 +371,22 @@ QModelIndex FrameStackModel::currentThreadIndex() const
int FrameStackModel::currentFrame() const
{
Q_D(const FrameStackModel);
return d->m_currentFrame;
}
QModelIndex FrameStackModel::currentFrameIndex() const
{
Q_D(const FrameStackModel);
return index(d->m_currentFrame, 0, currentThreadIndex());
}
void FrameStackModel::setCurrentFrame(int frame)
{
Q_D(FrameStackModel);
qCDebug(DEBUGGER) << frame;
if (frame != d->m_currentFrame)