work save

This commit is contained in:
Roy Qu 2021-11-25 11:24:38 +08:00
parent 3abbf66251
commit 39ab388458
3 changed files with 55 additions and 31 deletions

View File

@ -288,9 +288,10 @@ void Debugger::addWatchVar(const QString &namein)
PWatchVar var = std::make_shared<WatchVar>(); PWatchVar var = std::make_shared<WatchVar>();
var->parent= nullptr; var->parent= nullptr;
var->name = namein; var->expression = namein;
var->value = tr("Execute to evaluate"); var->value = tr("Execute to evaluate");
var->gdbIndex = -1; var->numChild = 0;
var->hasMore = false;
mWatchModel->addWatchVar(var); mWatchModel->addWatchVar(var);
sendWatchCommand(var); sendWatchCommand(var);
@ -412,12 +413,12 @@ BreakpointModel *Debugger::breakpointModel()
void Debugger::sendWatchCommand(PWatchVar var) void Debugger::sendWatchCommand(PWatchVar var)
{ {
sendCommand("display", var->name); sendCommand("-var-carete", QString(" - %1").arg(var->expression));
} }
void Debugger::sendRemoveWatchCommand(PWatchVar var) void Debugger::sendRemoveWatchCommand(PWatchVar var)
{ {
sendCommand("undisplay",QString("%1").arg(var->gdbIndex)); sendCommand("-var-delete",QString("%1").arg(var->name));
} }
void Debugger::sendBreakpointCommand(PBreakpoint breakpoint) void Debugger::sendBreakpointCommand(PBreakpoint breakpoint)
@ -1812,8 +1813,10 @@ QVariant WatchModel::data(const QModelIndex &index, int role) const
//qDebug()<<"item->text:"<<item->text; //qDebug()<<"item->text:"<<item->text;
switch(index.column()) { switch(index.column()) {
case 0: case 0:
return item->name; return item->expression;
case 1: case 1:
return item->type;
case 2:
return item->value; return item->value;
} }
} }
@ -1884,13 +1887,13 @@ int WatchModel::rowCount(const QModelIndex &parent) const
int WatchModel::columnCount(const QModelIndex&) const int WatchModel::columnCount(const QModelIndex&) const
{ {
return 2; return 3;
} }
void WatchModel::addWatchVar(PWatchVar watchVar) void WatchModel::addWatchVar(PWatchVar watchVar)
{ {
for (PWatchVar var:mWatchVars) { for (PWatchVar var:mWatchVars) {
if (watchVar->name == var->name) { if (watchVar->expression == var->expression) {
return; return;
} }
} }
@ -1899,25 +1902,11 @@ void WatchModel::addWatchVar(PWatchVar watchVar)
this->endInsertRows(); this->endInsertRows();
} }
void WatchModel::removeWatchVar(const QString &name) void WatchModel::removeWatchVar(const QString &express)
{ {
for (int i=mWatchVars.size()-1;i>=0;i--) { for (int i=mWatchVars.size()-1;i>=0;i--) {
PWatchVar var = mWatchVars[i]; PWatchVar var = mWatchVars[i];
if (name == var->name) { if (express == var->expression) {
this->beginResetModel();
//this->beginRemoveRows(QModelIndex(),i,i);
mWatchVars.removeAt(i);
//this->endRemoveRows();
this->endResetModel();
}
}
}
void WatchModel::removeWatchVar(int gdbIndex)
{
for (int i=mWatchVars.size()-1;i>=0;i--) {
PWatchVar var = mWatchVars[i];
if (gdbIndex == var->gdbIndex) {
this->beginResetModel(); this->beginResetModel();
//this->beginRemoveRows(QModelIndex(),i,i); //this->beginRemoveRows(QModelIndex(),i,i);
mWatchVars.removeAt(i); mWatchVars.removeAt(i);
@ -2006,7 +1995,7 @@ void WatchModel::save(const QString &filename)
QJsonArray array; QJsonArray array;
foreach (const PWatchVar& watchVar, mWatchVars) { foreach (const PWatchVar& watchVar, mWatchVars) {
QJsonObject obj; QJsonObject obj;
obj["name"]=watchVar->name; obj["expression"]=watchVar->expression;
array.append(obj); array.append(obj);
} }
QJsonDocument doc; QJsonDocument doc;
@ -2043,9 +2032,10 @@ void WatchModel::load(const QString &filename)
QJsonObject obj=value.toObject(); QJsonObject obj=value.toObject();
PWatchVar var = std::make_shared<WatchVar>(); PWatchVar var = std::make_shared<WatchVar>();
var->parent= nullptr; var->parent= nullptr;
var->name = obj["name"].toString(); var->expression = obj["expression"].toString();
var->value = tr("Execute to evaluate"); var->value = tr("Execute to evaluate");
var->gdbIndex = -1; var->numChild = 0;
var->hasMore=false;
addWatchVar(var); addWatchVar(var);
} }
@ -2063,12 +2053,37 @@ QVariant WatchModel::headerData(int section, Qt::Orientation orientation, int ro
case 0: case 0:
return tr("Expression"); return tr("Expression");
case 1: case 1:
return tr("Type");
case 2:
return tr("Value"); return tr("Value");
} }
} }
return QVariant(); return QVariant();
} }
void WatchModel::fetchMore(const QModelIndex &parent)
{
//todo
}
bool WatchModel::canFetchMore(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return false;
}
WatchVar* item = static_cast<WatchVar*>(parent.internalPointer());
return item->numChild>item->children.count();
}
bool WatchModel::hasChildren(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return false;
}
WatchVar* item = static_cast<WatchVar*>(parent.internalPointer());
return item->numChild>0;
}
RegisterModel::RegisterModel(QObject *parent):QAbstractTableModel(parent) RegisterModel::RegisterModel(QObject *parent):QAbstractTableModel(parent)
{ {

View File

@ -31,9 +31,11 @@ struct WatchVar;
using PWatchVar = std::shared_ptr<WatchVar>; using PWatchVar = std::shared_ptr<WatchVar>;
struct WatchVar { struct WatchVar {
QString name; QString name;
QString expression;
bool hasMore;
QString value; QString value;
QString fullName; QString type;
int gdbIndex; int numChild;
QList<PWatchVar> children; QList<PWatchVar> children;
WatchVar * parent; //use raw point to prevent circular-reference WatchVar * parent; //use raw point to prevent circular-reference
}; };
@ -133,8 +135,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
void addWatchVar(PWatchVar watchVar); void addWatchVar(PWatchVar watchVar);
void removeWatchVar(const QString& name); void removeWatchVar(const QString& expression);
void removeWatchVar(int gdbIndex);
void removeWatchVar(const QModelIndex& index); void removeWatchVar(const QModelIndex& index);
void clear(); void clear();
const QList<PWatchVar>& watchVars(); const QList<PWatchVar>& watchVars();
@ -152,6 +153,12 @@ private:
// QAbstractItemModel interface // QAbstractItemModel interface
public: public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void fetchMore(const QModelIndex &parent);
bool canFetchMore(const QModelIndex &parent) const;
// QAbstractItemModel interface
public:
bool hasChildren(const QModelIndex &parent) const;
}; };

View File

@ -18,7 +18,9 @@ enum class GDBMIResultType {
Evaluation, Evaluation,
RegisterNames, RegisterNames,
RegisterValues, RegisterValues,
Memory Memory,
VariableInfo,
}; };