- enhancement: modify values in the watch view by double click

This commit is contained in:
Roy Qu 2022-01-12 17:14:39 +08:00
parent 3ca1a9fc4c
commit d8413ab76c
4 changed files with 48 additions and 2 deletions

View File

@ -8,6 +8,7 @@ Red Panda C++ Version 0.13.2
- enhancement: modify values in the memory view while debugging
- enhancement: auto update watch, local and memory view after expression evaluated
- enhancement: auto update watch, local and memory view after memory modified
- enhancement: modify values in the watch view by double click

View File

@ -42,6 +42,8 @@ Debugger::Debugger(QObject *parent) : QObject(parent)
mMemoryModel = new MemoryModel(8,this);
connect(mMemoryModel,&MemoryModel::setMemoryData,
this, &Debugger::setMemoryData);
connect(mWatchModel, &WatchModel::setWatchVarValue,
this, &Debugger::setWatchVarValue);
mExecuting = false;
mReader = nullptr;
mTarget = nullptr;
@ -590,6 +592,12 @@ void Debugger::setMemoryData(qulonglong address, unsigned char data)
refreshAll();
}
void Debugger::setWatchVarValue(const QString &name, const QString &value)
{
sendCommand("-var-assign",QString("%1 %2").arg(name,value));
refreshAll();
}
void Debugger::updateMemory(const QStringList &value)
{
mMemoryModel->updateMemory(value);
@ -2138,6 +2146,35 @@ QModelIndex WatchModel::index(WatchVar* pVar) const {
}
}
bool WatchModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid()) {
return false;
}
if (index.column()==2 && role == Qt::EditRole) {
WatchVar* item = static_cast<WatchVar*>(index.internalPointer());
emit setWatchVarValue(item->name,value.toString());
}
return false;
}
Qt::ItemFlags WatchModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (!index.isValid()) {
return Qt::ItemIsEnabled;
}
if (index.column() == 2) {
WatchVar* item = static_cast<WatchVar*>(index.internalPointer());
qDebug()<<item->name<<item->numChild<<item->type<<item->hasMore<<(item->numChild==0 && !item->hasMore && !item->type.isEmpty());
if (item->numChild==0 && !item->type.isEmpty())
flags |= Qt::ItemIsEditable;
qDebug()<<flags;
}
return flags;
}
QVariant WatchModel::headerData(int section, Qt::Orientation orientation, int role) const
{

View File

@ -178,6 +178,8 @@ public:
void notifyUpdated(PWatchVar var);
void save(const QString& filename);
void load(const QString& filename);
signals:
void setWatchVarValue(const QString& name, const QString& value);
public slots:
void updateVarInfo(const QString& expression,
const QString& name,
@ -203,6 +205,11 @@ private:
QList<PWatchVar> mWatchVars;
QHash<QString,PWatchVar> mVarIndex;
int mUpdateCount;
// QAbstractItemModel interface
public:
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
};
struct MemoryLine {
@ -313,6 +320,7 @@ private:
private slots:
void syncFinishedParsing();
void setMemoryData(qulonglong address, unsigned char data);
void setWatchVarValue(const QString& name, const QString& value);
void updateMemory(const QStringList& value);
void updateEval(const QString& value);
void updateDisassembly(const QString& file, const QString& func,const QStringList& value);

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -165,7 +165,7 @@
<item>
<widget class="QTreeView" name="watchView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::DoubleClicked</set>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>