Improved register searching
This commit is contained in:
@@ -122,12 +122,10 @@ void RegisterGroupWidget::setAllRegistersVisible(bool visible) {
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterGroupWidget::filterRegisters(const std::string& keyword) {
|
||||
void RegisterGroupWidget::filterRegisters(const QString& keyword) {
|
||||
int matchingWidgetCount = 0;
|
||||
for (const auto& registerWidget : this->registerWidgets) {
|
||||
if (keyword.empty()
|
||||
|| (registerWidget->descriptor.name.value().find(keyword) != std::string::npos)
|
||||
) {
|
||||
if (keyword.isEmpty() || (registerWidget->searchKeywords.contains(keyword, Qt::CaseInsensitive))) {
|
||||
matchingWidgetCount++;
|
||||
registerWidget->setVisible(true);
|
||||
|
||||
@@ -142,7 +140,7 @@ void RegisterGroupWidget::filterRegisters(const std::string& keyword) {
|
||||
|
||||
} else {
|
||||
this->setVisible(true);
|
||||
if (!keyword.empty()) {
|
||||
if (!keyword.isEmpty()) {
|
||||
this->expand();
|
||||
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <QLabel>
|
||||
#include <QSize>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "TargetRegistersPaneWidget.hpp"
|
||||
#include "ItemWidget.hpp"
|
||||
@@ -40,7 +39,7 @@ namespace Bloom::Widgets
|
||||
void expand();
|
||||
void setAllRegistersVisible(bool visible);
|
||||
|
||||
void filterRegisters(const std::string& keyword);
|
||||
void filterRegisters(const QString& keyword);
|
||||
|
||||
private:
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
|
||||
@@ -18,7 +18,14 @@ RegisterWidget::RegisterWidget(
|
||||
TargetRegisterDescriptor descriptor,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget *parent
|
||||
): ItemWidget(parent), descriptor(std::move(descriptor)), insightWorker(insightWorker) {
|
||||
)
|
||||
: ItemWidget(parent)
|
||||
, descriptor(std::move(descriptor))
|
||||
, searchKeywords(QString::fromStdString(
|
||||
this->descriptor.name.value_or("") + this->descriptor.description.value_or("")
|
||||
).toLower())
|
||||
, insightWorker(insightWorker)
|
||||
{
|
||||
this->setObjectName("register-item");
|
||||
this->setFixedHeight(25);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QAction>
|
||||
#include <QSize>
|
||||
#include <QEvent>
|
||||
#include <QString>
|
||||
|
||||
#include "ItemWidget.hpp"
|
||||
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
||||
@@ -23,6 +24,7 @@ namespace Bloom::Widgets
|
||||
|
||||
public:
|
||||
Targets::TargetRegisterDescriptor descriptor;
|
||||
QString searchKeywords;
|
||||
std::optional<Targets::TargetRegister> currentRegister;
|
||||
|
||||
RegisterWidget(
|
||||
|
||||
@@ -124,8 +124,6 @@ TargetRegistersPaneWidget::TargetRegistersPaneWidget(
|
||||
}
|
||||
|
||||
void TargetRegistersPaneWidget::filterRegisters(const QString& keyword) {
|
||||
auto stdKeyword = keyword.toLower().toStdString();
|
||||
|
||||
for (const auto& registerGroupWidget : this->registerGroupWidgets) {
|
||||
// If the group name matches the keyword, then don't bother iterating through all the register widgets
|
||||
if (keyword.isEmpty() || registerGroupWidget->name.contains(keyword, Qt::CaseInsensitive)) {
|
||||
@@ -140,7 +138,7 @@ void TargetRegistersPaneWidget::filterRegisters(const QString& keyword) {
|
||||
}
|
||||
|
||||
} else {
|
||||
registerGroupWidget->filterRegisters(stdKeyword);
|
||||
registerGroupWidget->filterRegisters(keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user