1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
SPDX-FileCopyrightText: 2008 Vladimir Prus <ghost@cs.msu.su>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "breakpointdetails.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QGridLayout>
#include <QWhatsThis>
#include <QSpinBox>
#include <KLocalizedString>
#include "../breakpoint/breakpoint.h"
using namespace KDevelop;
class KDevelop::BreakpointDetailsPrivate
{
public:
QLabel* status;
QLabel* hits;
QSpinBox* ignore;
Breakpoint* currentBreakpoint = nullptr;
};
BreakpointDetails::BreakpointDetails(QWidget *parent)
: QWidget(parent)
, d_ptr(new BreakpointDetailsPrivate)
{
Q_D(BreakpointDetails);
auto* layout = new QVBoxLayout(this);
d->status = new QLabel(this);
connect(d->status, &QLabel::linkActivated,
this, &BreakpointDetails::showExplanation);
layout->addWidget(d->status);
auto* hitsLayout = new QGridLayout();
layout->addLayout(hitsLayout);
hitsLayout->setContentsMargins(0, 0, 0, 0);
d->hits = new QLabel(i18n("Not hit yet"), this);
d->hits->setWordWrap(true);
hitsLayout->addWidget(d->hits, 0, 0, 1, 3);
auto* l2 = new QLabel(i18n("Ignore"), this);
hitsLayout->addWidget(l2, 2, 0);
d->ignore = new QSpinBox(this);
hitsLayout->addWidget(d->ignore, 2, 1);
d->ignore->setRange(0, 99999);
connect(d->ignore, QOverload<int>::of(&QSpinBox::valueChanged), this, &BreakpointDetails::setIgnoreHits);
auto* l3 = new QLabel(i18n("next hits"), this);
hitsLayout->addWidget(l3, 2, 2);
layout->addStretch();
setItem(nullptr); //initialize with no breakpoint active
}
BreakpointDetails::~BreakpointDetails() = default;
void KDevelop::BreakpointDetails::setIgnoreHits(int ignoreHits)
{
Q_D(BreakpointDetails);
if (!d->currentBreakpoint)
return;
d->currentBreakpoint->setIgnoreHits(ignoreHits);
}
void BreakpointDetails::setItem(Breakpoint *breakpoint)
{
Q_D(BreakpointDetails);
d->currentBreakpoint = breakpoint;
if (!breakpoint) {
d->status->hide();
d->hits->hide();
d->ignore->setEnabled(false);
return;
}
d->ignore->setValue(breakpoint->ignoreHits());
if (breakpoint->state() == Breakpoint::NotStartedState) {
d->status->hide();
d->hits->hide();
d->ignore->setEnabled(true);
return;
}
d->status->show();
d->hits->show();
d->ignore->setEnabled(true);
if (breakpoint->errorText().isEmpty()) {
switch (breakpoint->state()) {
case Breakpoint::NotStartedState:
Q_ASSERT(0);
break;
case Breakpoint::PendingState:
d->status->setText(i18n("Breakpoint is <a href=\"pending\">pending</a>"));
break;
case Breakpoint::DirtyState:
d->status->setText(i18n("Breakpoint is <a href=\"dirty\">dirty</a>"));
break;
case Breakpoint::CleanState:
d->status->setText(i18n("Breakpoint is active"));
break;
}
if (breakpoint->hitCount() == -1)
d->hits->clear();
else if (breakpoint->hitCount())
d->hits->setText(i18np("Hit %1 time", "Hit %1 times", breakpoint->hitCount()));
else
d->hits->setText(i18n("Not hit yet"));
} else {
d->status->setText(i18n("Breakpoint has errors"));
d->hits->setText(breakpoint->errorText());
}
}
void BreakpointDetails::showExplanation(const QString& link)
{
Q_D(BreakpointDetails);
QPoint pos = d->status->mapToGlobal(d->status->geometry().topLeft());
if (link == QLatin1String("pending"))
{
QWhatsThis::showText(pos,
i18n("<b>Breakpoint is pending</b>"
"<p>Pending breakpoints are those that have "
"been passed to GDB, but which are not yet "
"installed in the target, because GDB cannot "
"find the function or file to which the breakpoint "
"refers. The most common case is a breakpoint "
"in a shared library: GDB will insert this "
"breakpoint only when the library is loaded.</p>"),
d->status);
}
else if (link == QLatin1String("dirty"))
{
QWhatsThis::showText(pos,
i18n("<b>Breakpoint is dirty</b>"
"<p>The breakpoint has not yet been passed "
"to the debugger.</p>"),
d->status);
}
}
#include "moc_breakpointdetails.cpp"
|