diff --git a/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp b/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp index 92277c0eba7e1277a658e8ed685156d70bd100bc..d8ff3fd78b6d76c4b8d0ca7d805260e8bccd4681 100644 --- a/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp +++ b/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp @@ -54,6 +54,26 @@ namespace armarx::skills::gui } } + // check if search strings occur in the skill name in order + bool + matches(std::string skillName, std::vector<std::string>& searches) + { + size_t index = 0; + for (std::string& substring : searches) + { + size_t occurance = skillName.find(substring, index); + if (occurance == std::string::npos) + { + return false; + } + + + // we found an occurance + index = occurance; + } + return true; + } + void SkillManagerWrapper::filterSkillUpdate( std::map<skills::manager::dto::SkillID, skills::manager::dto::SkillDescription>& update) @@ -64,13 +84,21 @@ namespace armarx::skills::gui return; } - // TODO: whitespace to wildcard + std::vector<std::string> substrings; + + { + std::vector<std::string> rawSubstrings = simox::alg::split(currentSkillSearch); + for (auto& string : rawSubstrings) + { + substrings.push_back(simox::alg::to_lower(string)); + } + } - std::string key = simox::alg::to_lower(this->currentSkillSearch); for (auto it = update.begin(); it != update.end();) { - if (simox::alg::to_lower(skills::SkillID::FromIce(it->first).skillName).find(key)) + if (not matches(simox::alg::to_lower(skills::SkillID::FromIce(it->first).skillName), + substrings)) { it = update.erase(it); } diff --git a/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.cpp b/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.cpp index 9909cc1675edf8ae1ae94a33ae878bde21955498..c1b100130e4eef7e0e49e287d163e6f880f4f523 100644 --- a/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.cpp +++ b/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.cpp @@ -27,6 +27,7 @@ namespace armarx::skills::gui void SkillTreeWidget::updateSkills() { + setSortingEnabled(false); const auto skills = memory->fetchSkills(); // update tree view. Remove non-existing elements @@ -76,6 +77,7 @@ namespace armarx::skills::gui // update tree view. Add new elements for (const auto& [providerId, providedSkills] : skills) { + bool newProvider = false; QTreeWidgetItem* providerItem = nullptr; for (int i = 0; i < this->topLevelItemCount(); ++i) { @@ -94,6 +96,8 @@ namespace armarx::skills::gui { providerItem = new QTreeWidgetItem(this); providerItem->setText(0, QString::fromStdString(providerId.providerName)); + // expand new items + newProvider = true; } for (const auto& [skillId, skill] : providedSkills) @@ -118,7 +122,16 @@ namespace armarx::skills::gui skillItem->setText(0, QString::fromStdString(skillId.skillName)); } } + + if (newProvider && PROVIDER_EXPANDED_DEFAULT) + { + providerItem->setExpanded(true); + } } + + setSortingEnabled(true); + sortByColumn(0, Qt::AscendingOrder); + sortByColumn(1, Qt::AscendingOrder); } void diff --git a/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.h b/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.h index c076d2101f0016056f13dd4a75adc7022fa5a50a..61ec5cc85314d0318a951e8216a620d1f1d9a7c8 100644 --- a/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.h +++ b/source/RobotAPI/libraries/skills_gui/skills/SkillTreeWidget.h @@ -51,6 +51,8 @@ namespace armarx::skills::gui private: SelectedSkill selectedSkill; + static const constexpr bool PROVIDER_EXPANDED_DEFAULT = true; + void setupUi(); void connectSignals(); };