diff --git a/navigatorappitem.h b/navigatorappitem.h --- a/navigatorappitem.h +++ b/navigatorappitem.h @@ -45,6 +45,9 @@ void scheduleTOCBuild(); TOC *mToc; + + static QMap< QString,NavigatorAppItem* > s_menuItemsMap; + }; } diff --git a/navigatorappitem.cpp b/navigatorappitem.cpp --- a/navigatorappitem.cpp +++ b/navigatorappitem.cpp @@ -29,35 +29,69 @@ using namespace KHC; +QMap< QString,NavigatorAppItem* > NavigatorAppItem::s_menuItemsMap; + NavigatorAppItem::NavigatorAppItem( DocEntry *entry, QTreeWidgetItem *parent ) : NavigatorItem( entry, parent ), mToc( nullptr ) { + auto iter = s_menuItemsMap.find(entry->url()); + if (iter == s_menuItemsMap.end()) + { + s_menuItemsMap.insert(entry->url(), this); + } } NavigatorAppItem::NavigatorAppItem( DocEntry *entry, QTreeWidget *parent, QTreeWidgetItem *after ) : NavigatorItem( entry, parent, after ), mToc( nullptr ) { + auto iter = s_menuItemsMap.find(entry->url()); + if (iter == s_menuItemsMap.end()) + { + s_menuItemsMap.insert(entry->url(), this); + } } NavigatorAppItem::NavigatorAppItem( DocEntry *entry, QTreeWidgetItem *parent, QTreeWidgetItem *after ) : NavigatorItem( entry, parent, after ), mToc( nullptr ) { + auto iter = s_menuItemsMap.find(entry->url()); + if (iter == s_menuItemsMap.end()) + { + s_menuItemsMap.insert(entry->url(), this); + } } NavigatorAppItem::~NavigatorAppItem() { + auto iter = s_menuItemsMap.find(entry()->url()); + if ((iter != s_menuItemsMap.end()) && (iter.value() == this)) + { + s_menuItemsMap.erase(iter); + } + delete mToc; } void NavigatorAppItem::itemExpanded( bool open ) { if ( open ) { - scheduleTOCBuild(); + QUrl expanded_url(entry()->url()); + expanded_url.setFragment(QString()); + + auto iter = s_menuItemsMap.find(expanded_url.toString()); + if (iter != s_menuItemsMap.end()) + { + iter.value()->scheduleTOCBuild(); + } + else + { + scheduleTOCBuild(); + } } }