Skip to content

Commit

Permalink
Remove remnants of the deactivated sorting mechanism.
Browse files Browse the repository at this point in the history
This sorting mechanism was deactivated in 65bb529, but the
actual functionality was still in the code base.

Note that sorting was disabled due to its implementation being
destructive: the actual watch nodes were reordered; not just the visual
representation of the items in the Qt tree view. If the functionality
is reinstated in the future, a `QSortFilterProxyModel` should be used.
  • Loading branch information
cristian64 committed May 18, 2024
1 parent d0abec0 commit 530bfc2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
118 changes: 0 additions & 118 deletions Source/GUI/MemWatcher/MemWatchModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,124 +570,6 @@ bool MemWatchModel::dropMimeData(const QMimeData* data, Qt::DropAction action, i
return true;
}

void MemWatchModel::sort(int column, Qt::SortOrder order)
{
sortRecursive(column, order, m_rootNode);
emit layoutChanged();
}

void MemWatchModel::sortRecursive(int column, Qt::SortOrder order, MemWatchTreeNode* parent)
{
if (!parent->hasChildren())
return;

QVector<MemWatchTreeNode*> children = parent->getChildren();

switch (column)
{
case WATCH_COL_LABEL:
{
std::sort(
children.begin(), children.end(), [order](MemWatchTreeNode* left, MemWatchTreeNode* right) {
if (left->isGroup() && right->isGroup())
{
int compareResult =
QString::compare(left->getGroupName(), right->getGroupName(), Qt::CaseInsensitive);
return order == Qt::AscendingOrder ? compareResult < 0 : compareResult > 0;
}
if (left->isGroup())
return true;
if (right->isGroup())
return false;

int compareResult = QString::compare(left->getEntry()->getLabel(),
right->getEntry()->getLabel(), Qt::CaseInsensitive);
return order == Qt::AscendingOrder ? compareResult < 0 : compareResult > 0;
});
break;
}
case WATCH_COL_TYPE:
{
std::sort(children.begin(), children.end(),
[order](MemWatchTreeNode* left, MemWatchTreeNode* right) {
if (left->isGroup())
return true;
if (right->isGroup())
return false;

int compareResult = static_cast<int>(left->getEntry()->getType()) -
static_cast<int>(right->getEntry()->getType());
return order == Qt::AscendingOrder ? compareResult < 0 : compareResult > 0;
});
break;
}
case WATCH_COL_ADDRESS:
{
std::sort(children.begin(), children.end(),
[order](MemWatchTreeNode* left, MemWatchTreeNode* right) {
if (left->isGroup())
return true;
if (right->isGroup())
return false;

u32 leftAddress = left->getEntry()->getConsoleAddress();
u32 rightAddress = right->getEntry()->getConsoleAddress();

return order == Qt::AscendingOrder ? leftAddress < rightAddress :
leftAddress > rightAddress;
});
break;
}
case WATCH_COL_LOCK:
{
std::sort(children.begin(), children.end(),
[order](MemWatchTreeNode* left, MemWatchTreeNode* right) {
if (left->isGroup())
return true;
if (right->isGroup())
return false;

bool lessThan = !left->getEntry()->isLocked() && right->getEntry()->isLocked();
bool equal = left->getEntry()->isLocked() == right->getEntry()->isLocked();
return order == Qt::AscendingOrder ? lessThan : !lessThan && !equal;
});
break;
}
case WATCH_COL_VALUE:
{
std::sort(
children.begin(), children.end(), [order](MemWatchTreeNode* left, MemWatchTreeNode* right) {
if (left->isGroup() && right->isGroup())
return false;
if (left->isGroup())
return true;
if (right->isGroup())
return false;

int compareResult =
QString::compare(QString::fromStdString(left->getEntry()->getStringFromMemory()),
QString::fromStdString(right->getEntry()->getStringFromMemory()),
Qt::CaseInsensitive);
return order == Qt::AscendingOrder ? compareResult < 0 : compareResult > 0;
});
break;
}
default:
assert(0 && "Unhandled column index");
break;
}

parent->setChildren(children);

for (MemWatchTreeNode* const child : parent->getChildren())
{
if (child->isGroup())
{
sortRecursive(column, order, child);
}
}
}

void MemWatchModel::loadRootFromJsonRecursive(const QJsonObject& json)
{
m_rootNode->readFromJson(json);
Expand Down
2 changes: 0 additions & 2 deletions Source/GUI/MemWatcher/MemWatchModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class MemWatchModel : public QAbstractItemModel
Qt::DropActions supportedDragActions() const override;
QStringList mimeTypes() const override;
QMimeData* mimeData(const QModelIndexList& indexes) const override;
void sort(int column, Qt::SortOrder order) override;
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) override;

Expand All @@ -60,7 +59,6 @@ class MemWatchModel : public QAbstractItemModel
void addGroup(const QString& name, const QModelIndex& referenceIndex = QModelIndex{});
void addEntry(MemWatchEntry* entry, const QModelIndex& referenceIndex = QModelIndex{});
void editEntry(MemWatchEntry* entry, const QModelIndex& index);
void sortRecursive(int column, Qt::SortOrder order, MemWatchTreeNode* parent);
void clearRoot();
void removeNode(const QModelIndex& index);
void onUpdateTimer();
Expand Down

0 comments on commit 530bfc2

Please sign in to comment.