diff --git a/src/Helpers/DereferenceLessComparator.hpp b/src/Helpers/DereferenceLessComparator.hpp new file mode 100644 index 00000000..083770aa --- /dev/null +++ b/src/Helpers/DereferenceLessComparator.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace Bloom { + template + requires std::is_pointer::value + struct DereferenceLessComparator + { + constexpr bool operator () (const Type& lhs, const Type& rhs) const { + return *lhs < *rhs; + } + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp index 11e9a109..a979b079 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp @@ -9,7 +9,7 @@ namespace Bloom::Widgets { ListScene::ListScene( - std::vector items, + ListScene::ListItemSetType&& items, QGraphicsView* parent ) : parent(parent) @@ -48,7 +48,7 @@ namespace Bloom::Widgets this->update(); } - void ListScene::setItems(const std::vector& items) { + void ListScene::setItems(const ListScene::ListItemSetType& items) { for (auto& item : this->items()) { this->removeItem(item); } @@ -58,23 +58,16 @@ namespace Bloom::Widgets for (const auto& listItem : this->listItems) { this->addItem(listItem); } - - this->sortItems(); } void ListScene::addListItem(ListItem* item) { - this->listItems.push_back(item); + this->listItems.insert(item); this->addItem(item); } - void ListScene::sortItems() { - std::sort( - this->listItems.begin(), - this->listItems.end(), - [] (const ListItem* itemA, const ListItem* itemB) { - return *itemA < *itemB; - } - ); + void ListScene::removeListItem(ListItem* item) { + this->listItems.erase(item); + this->removeItem(item); } void ListScene::setEnabled(bool enabled) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp index 37e967ab..65b368b5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -13,6 +13,7 @@ #include #include "ListItem.hpp" +#include "src/Helpers/DereferenceLessComparator.hpp" namespace Bloom::Widgets { @@ -21,18 +22,19 @@ namespace Bloom::Widgets Q_OBJECT public: + using ListItemSetType = std::set>; QMargins margins = QMargins(0, 0, 0, 10); ListScene( - std::vector items, + ListScene::ListItemSetType&& items, QGraphicsView* parent ); void refreshGeometry(); void setSelectionLimit(std::uint8_t selectionLimit); - void setItems(const std::vector& items); + void setItems(const ListScene::ListItemSetType& items); void addListItem(ListItem* item); - void sortItems(); + void removeListItem(ListItem* item); void setEnabled(bool enabled); signals: @@ -47,7 +49,7 @@ namespace Bloom::Widgets void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override; private: - std::vector listItems; + ListScene::ListItemSetType listItems; QGraphicsView* const parent; bool enabled = false; std::list selectedItems; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp index 2fdddd2b..20d2b359 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp @@ -3,7 +3,7 @@ namespace Bloom::Widgets { ListView::ListView( - const std::vector& items, + ListScene::ListItemSetType&& items, QWidget* parent ) : QGraphicsView(parent) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp index b8fce7c9..6567ab9e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp @@ -15,7 +15,7 @@ namespace Bloom::Widgets public: ListView( - const std::vector& items, + ListScene::ListItemSetType&& items, QWidget* parent ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp index 59cbbc7b..de8a6725 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp @@ -173,7 +173,6 @@ namespace Bloom::Widgets this->addSnapshot(std::move(snapshot)); } - this->snapshotListScene->sortItems(); this->snapshotListScene->refreshGeometry(); } ); @@ -218,7 +217,6 @@ namespace Bloom::Widgets this, [this] (MemorySnapshot snapshot) { this->addSnapshot(std::move(snapshot)); - this->snapshotListScene->sortItems(); this->snapshotListScene->refreshGeometry(); } ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp index f7ea954f..91c637bc 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp @@ -105,7 +105,7 @@ namespace Bloom::Widgets } this->registerListView = new ListView( - std::vector(this->registerGroupItems.begin(), this->registerGroupItems.end()), + ListScene::ListItemSetType(this->registerGroupItems.begin(), this->registerGroupItems.end()), this );