diff --git a/mapeditor/inspector/herospellwidget.cpp b/mapeditor/inspector/herospellwidget.cpp
index 21217e45a..c7e37e3ed 100644
--- a/mapeditor/inspector/herospellwidget.cpp
+++ b/mapeditor/inspector/herospellwidget.cpp
@@ -98,10 +98,81 @@ void HeroSpellWidget::on_customizeSpells_toggled(bool checked)
{
hero.removeAllSpells();
}
+ ui->filter->clear();
+ ui->filter->setEnabled(checked);
ui->tabWidget->setEnabled(checked);
initSpellLists();
}
+void HeroSpellWidget::on_filter_textChanged(const QString & keyword)
+{
+ if (keyword.toStdString().find_first_not_of(' ') == std::string::npos)
+ {
+ const auto exists = QString::fromStdString(".*");
+ showItemIfMatches(exists);
+ }
+ else
+ {
+ const auto doesNotContainKeyword = QString::fromStdString("^((?!") + keyword + QString::fromStdString(").)*$");
+ hideItemIfMatches(doesNotContainKeyword);
+
+ const auto containsKeyword = QString::fromStdString(".*") + keyword + QString::fromStdString(".*");
+ showItemIfMatches(containsKeyword);
+ }
+
+ hideEmptySpellLists();
+}
+
+void HeroSpellWidget::showItemIfMatches(const QString & match)
+{
+ toggleHiddenForItemIfMatches(match, false);
+}
+
+void HeroSpellWidget::hideItemIfMatches(const QString & match)
+{
+ toggleHiddenForItemIfMatches(match, true);
+}
+
+void HeroSpellWidget::toggleHiddenForItemIfMatches(const QString & match, bool hidden)
+{
+ QListWidget * spellLists[] = { ui->spellList1, ui->spellList2, ui->spellList3, ui->spellList4, ui->spellList5 };
+ for (const QListWidget * list : spellLists)
+ {
+ const auto items = list->findItems(match, Qt::MatchRegularExpression);
+ for (QListWidgetItem * item : items)
+ {
+ item->setHidden(hidden);
+ }
+ }
+}
+
+void HeroSpellWidget::hideEmptySpellLists()
+{
+
+ QListWidget * spellLists[] = { ui->spellList1, ui->spellList2, ui->spellList3, ui->spellList4, ui->spellList5 };
+ auto toggleSpellListVisibility = [&](const QListWidget * list, bool visible)
+ {
+ auto * parent = list->parentWidget();
+ int index = ui->tabWidget->indexOf(parent);
+ ui->tabWidget->setTabVisible(index, visible);
+ };
+
+ for (const QListWidget * list : spellLists)
+ {
+ const auto allItems = list->findItems("*", Qt::MatchWildcard);
+ bool isListEmpty = true;
+ for (QListWidgetItem * item : allItems)
+ {
+ if (!item->isHidden())
+ {
+ isListEmpty = false;
+ break;
+ }
+ }
+ toggleSpellListVisibility(list, !isListEmpty);
+ }
+}
+
HeroSpellDelegate::HeroSpellDelegate(CGHeroInstance & h)
: BaseInspectorItemDelegate()
, hero(h)
diff --git a/mapeditor/inspector/herospellwidget.h b/mapeditor/inspector/herospellwidget.h
index 3fb88700d..321a69ca3 100644
--- a/mapeditor/inspector/herospellwidget.h
+++ b/mapeditor/inspector/herospellwidget.h
@@ -31,6 +31,7 @@ public:
private slots:
void on_customizeSpells_toggled(bool checked);
+ void on_filter_textChanged(const QString & keyword);
private:
Ui::HeroSpellWidget * ui;
@@ -38,6 +39,10 @@ private:
CGHeroInstance & hero;
void initSpellLists();
+ void showItemIfMatches(const QString & match);
+ void hideItemIfMatches(const QString & match);
+ void toggleHiddenForItemIfMatches(const QString & match, bool hidden);
+ void hideEmptySpellLists();
};
class HeroSpellDelegate : public BaseInspectorItemDelegate
diff --git a/mapeditor/inspector/herospellwidget.ui b/mapeditor/inspector/herospellwidget.ui
index 8eb5cdb87..4bafbcf30 100644
--- a/mapeditor/inspector/herospellwidget.ui
+++ b/mapeditor/inspector/herospellwidget.ui
@@ -51,6 +51,9 @@
+ -
+
+
-
@@ -99,6 +102,9 @@
true
+
+ true
+
@@ -137,6 +143,9 @@
true
+
+ true
+
@@ -175,6 +184,9 @@
true
+
+ true
+
@@ -213,6 +225,9 @@
true
+
+ true
+
@@ -251,6 +266,9 @@
true
+
+ true
+