Skip to content

Commit

Permalink
Merge pull request #106 from cristian64/multi_value_edits
Browse files Browse the repository at this point in the history
Support for multiple value edits.
  • Loading branch information
dreamsyntax authored Mar 7, 2024
2 parents 5b7f3ba + cb2e119 commit b2b2074
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Source/GUI/MemWatcher/MemWatchModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ QVariant MemWatchModel::data(const QModelIndex& index, int role) const
}

bool MemWatchModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
return editData(index, value, role, true);
}

bool MemWatchModel::editData(const QModelIndex& index, const QVariant& value, const int role,
const bool emitEdit)
{
if (!index.isValid())
return false;
Expand Down Expand Up @@ -257,6 +263,8 @@ bool MemWatchModel::setData(const QModelIndex& index, const QVariant& value, int
return false;
}
emit dataChanged(index, index);
if (emitEdit)
emit dataEdited(index, value, role);
return true;
}
default:
Expand Down
3 changes: 3 additions & 0 deletions Source/GUI/MemWatcher/MemWatchModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class MemWatchModel : public QAbstractItemModel
bool hasAnyNodes() const;
MemWatchTreeNode* getRootNode() const;
MemWatchTreeNode* getTreeNodeFromIndex(const QModelIndex& index) const;
bool editData(const QModelIndex& index, const QVariant& value, int role, bool emitEdit = false);

signals:
void dataEdited(const QModelIndex& index, const QVariant& value, int role);
void writeFailed(const QModelIndex& index, Common::MemOperationReturnCode writeReturn);
void readFailed();
void dropSucceeded();
Expand Down
31 changes: 31 additions & 0 deletions Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MemWatchWidget::~MemWatchWidget()
void MemWatchWidget::initialiseWidgets()
{
m_watchModel = new MemWatchModel(this);
connect(m_watchModel, &MemWatchModel::dataEdited, this, &MemWatchWidget::onDataEdited);
connect(m_watchModel, &MemWatchModel::writeFailed, this, &MemWatchWidget::onValueWriteError);
connect(m_watchModel, &MemWatchModel::dropSucceeded, this, &MemWatchWidget::onDropSucceeded);
connect(m_watchModel, &MemWatchModel::readFailed, this, &MemWatchWidget::mustUnhook);
Expand Down Expand Up @@ -388,6 +389,36 @@ void MemWatchWidget::onWatchDoubleClicked(const QModelIndex& index)
}
}

void MemWatchWidget::onDataEdited(const QModelIndex& index, const QVariant& value, const int role)
{
MemWatchTreeNode* const node{static_cast<MemWatchTreeNode*>(index.internalPointer())};
if (node->isGroup())
return;

if (role == Qt::EditRole && index.column() == MemWatchModel::WATCH_COL_VALUE)
{
MemWatchEntry* const entry{node->getEntry()};
const Common::MemType entryType{entry->getType()};

for (const auto& selectedIndex : m_watchView->selectionModel()->selectedIndexes())
{
if (selectedIndex == index)
continue;
if (selectedIndex.column() != MemWatchModel::WATCH_COL_VALUE)
continue;

MemWatchTreeNode* const selectedNode{static_cast<MemWatchTreeNode*>(selectedIndex.internalPointer())};
if (selectedNode->isGroup())
continue;
MemWatchEntry* const selectedEntry{selectedNode->getEntry()};
if (selectedEntry->getType() != entryType)
continue;

m_watchModel->editData(selectedIndex, value, role);
}
}
}

void MemWatchWidget::onValueWriteError(const QModelIndex& index,
Common::MemOperationReturnCode writeReturn)
{
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/MemWatcher/MemWatchWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class MemWatchWidget : public QWidget
~MemWatchWidget();

void onMemWatchContextMenuRequested(const QPoint& pos);
void onDataEdited(const QModelIndex& index, const QVariant& value, int role);
void onValueWriteError(const QModelIndex& index, Common::MemOperationReturnCode writeReturn);
void onWatchDoubleClicked(const QModelIndex& index);
void onAddGroup();
Expand Down

0 comments on commit b2b2074

Please sign in to comment.