15 #ifndef BORNAGAIN_GUI_VIEW_COMMON_ITEMSTACKPRESENTER_H
16 #define BORNAGAIN_GUI_VIEW_COMMON_ITEMSTACKPRESENTER_H
18 #include "Base/Util/Assert.h"
21 #include <QStackedWidget>
39 void setItem(U* item,
bool* isNew =
nullptr);
68 T* widget = itemWidget(item);
74 m_stackedWidget->addWidget(widget);
75 m_itemToWidget[item] = widget;
78 m_stackedWidget->setCurrentWidget(widget);
79 if (widget->isHidden())
82 widget->setItem(item);
88 return dynamic_cast<T*
>(m_stackedWidget->currentWidget());
94 if (m_single_widget) {
95 if (!m_itemToWidget.empty())
96 return m_itemToWidget.first();
98 return m_itemToWidget[item];
107 if (m_stackedWidget->currentWidget())
108 m_stackedWidget->currentWidget()->hide();
119 T* widget = m_itemToWidget[item];
123 typename QMap<SessionItem*, T*>::iterator it = m_itemToWidget.begin();
124 while (it != m_itemToWidget.end()) {
125 if (it.value() == widget)
126 it = m_itemToWidget.erase(it);
131 m_stackedWidget->removeWidget(widget);
138 typename QMap<SessionItem*, T*>::iterator it = m_itemToWidget.begin();
139 while (it != m_itemToWidget.end()) {
140 m_stackedWidget->removeWidget(it.value());
144 m_itemToWidget.clear();
The ItemStackPresenter templated class extends ItemStackWidget so it could operate with SesionItem ed...
ItemStackPresenter(bool single_widget=false)
void removeWidgetForItem(SessionItem *item) override
bool m_single_widget
Different items will be served by same widget.
void setItem(U *item, bool *isNew=nullptr)
Shows the widget for given item (and hides previous one). If no widget yet exists,...
QMap< SessionItem *, T * > m_itemToWidget
void removeWidgets() override
T * itemWidget(SessionItem *item)
Base class for a GUI data item.