@@ -124,7 +124,7 @@ void IIOExplorerInstrument::setupUi()
124124
125125 m_iioModel = new IIOModel (m_context, " context0" , m_treeView);
126126 m_searchBar = new SearchBar (m_iioModel->getEntries (), this );
127- m_mapStack = new MapStackedWidget ( details_container);
127+ m_mapStack = new LazyStackedWidget ( this , details_container);
128128 m_watchListView = new WatchListView (watch_list);
129129
130130 watch_list->layout ()->addWidget (m_watchListView);
@@ -143,7 +143,7 @@ void IIOExplorerInstrument::setupUi()
143143 m_treeView->expand (m_proxyModel->index (0 , 0 ));
144144 m_currentlySelectedItem =
145145 dynamic_cast <IIOStandardItem *>(m_iioModel->getModel ()->invisibleRootItem ()->child (0 ));
146- showOrBuildPage (m_currentlySelectedItem);
146+ m_mapStack-> show (m_currentlySelectedItem-> path () );
147147
148148 details_container->layout ()->addWidget (m_mapStack);
149149 tree_view_container->layout ()->addWidget (m_searchBar);
@@ -219,45 +219,63 @@ void IIOExplorerInstrument::connectSignalsAndSlots()
219219 });
220220}
221221
222- void IIOExplorerInstrument::showOrBuildPage (IIOStandardItem *item )
222+ QWidget * IIOExplorerInstrument::createWidget ( const QString &key )
223223{
224+ QStringList pathList = key.split (' /' , Qt::SkipEmptyParts);
225+ QStandardItem *root = m_iioModel->getModel ()->invisibleRootItem ()->child (0 );
226+ IIOStandardItem *iioRoot = dynamic_cast <IIOStandardItem *>(root);
227+ if (!iioRoot) {
228+ qWarning (CAT_IIODEBUGGER) << " Cannot find the model root." ;
229+ return nullptr ;
230+ }
231+
232+ IIOStandardItem *item = findItemByPath (iioRoot, pathList);
224233 if (!item) {
225- return ;
234+ qWarning (CAT_IIODEBUGGER) << " Could not find item for key:" << key;
235+ return nullptr ;
226236 }
227237
228- if (!m_mapStack->contains (item->path ())) {
229- // Ensure the item's IIOWidgets and attribute children exist before building the page
230- m_iioModel->populateChildren (item);
238+ m_iioModel->populateChildren (item);
231239
232- auto *page = new DetailsPage (item, m_uri, m_mapStack);
233- m_mapStack->add (item->path (), page);
240+ auto *page = new DetailsPage (item, m_uri, m_mapStack);
234241
235- connect (page, &DetailsPage::pathSelected, this , [this ](QString path) {
236- QStringList pathList = path.split (' /' , Qt::SkipEmptyParts);
237- QStandardItem *root = m_iioModel->getModel ()->invisibleRootItem ()->child (0 );
238- IIOStandardItem *iioRoot = dynamic_cast <IIOStandardItem *>(root);
239- if (!iioRoot) {
240- qWarning (CAT_IIODEBUGGER) << " Cannot find the model root." ;
241- return ;
242- }
243- IIOStandardItem *foundItem = findItemByPath (iioRoot, pathList);
244- if (!foundItem) {
245- qWarning (CAT_IIODEBUGGER) << " Could not find the item with path:" << path;
246- return ;
247- }
248- selectItem (foundItem);
249- });
242+ connect (page, &DetailsPage::pathSelected, this , [this ](QString path) {
243+ QStringList pathList = path.split (' /' , Qt::SkipEmptyParts);
244+ QStandardItem *root = m_iioModel->getModel ()->invisibleRootItem ()->child (0 );
245+ IIOStandardItem *iioRoot = dynamic_cast <IIOStandardItem *>(root);
246+ if (!iioRoot) {
247+ qWarning (CAT_IIODEBUGGER) << " Cannot find the model root." ;
248+ return ;
249+ }
250+ IIOStandardItem *foundItem = findItemByPath (iioRoot, pathList);
251+ if (!foundItem) {
252+ qWarning (CAT_IIODEBUGGER) << " Could not find the item with path:" << path;
253+ return ;
254+ }
255+ selectItem (foundItem);
256+ });
250257
251- connect (page->readBtn (), &QPushButton::clicked, this , &IIOExplorerInstrument::onReadAllClicked);
252- connect (page->addToWatchlistBtn (), &QPushButton::clicked, this ,
253- &IIOExplorerInstrument::onWatchlistToggleClicked);
254- }
258+ connect (page->readBtn (), &QPushButton::clicked, this , &IIOExplorerInstrument::onReadAllClicked);
259+ connect (page->addToWatchlistBtn (), &QPushButton::clicked, this ,
260+ &IIOExplorerInstrument::onWatchlistToggleClicked);
255261
256- m_mapStack-> show (item-> path ()) ;
257- m_currentDetailsPage = qobject_cast<DetailsPage *>(m_mapStack-> get (item-> path ()));
262+ return page ;
263+ }
258264
259- if (m_currentDetailsPage) {
260- m_currentDetailsPage->setAddToWatchlistState (!item->isWatched ());
265+ void IIOExplorerInstrument::onShow (const QString &key, QWidget *widget)
266+ {
267+ Q_UNUSED (key)
268+ m_currentDetailsPage = qobject_cast<DetailsPage *>(widget);
269+ if (m_currentDetailsPage && m_currentlySelectedItem) {
270+ m_currentDetailsPage->setAddToWatchlistState (!m_currentlySelectedItem->isWatched ());
271+ }
272+ }
273+
274+ void IIOExplorerInstrument::onRemove (const QString &key, QWidget *widget)
275+ {
276+ Q_UNUSED (key)
277+ if (m_currentDetailsPage == widget) {
278+ m_currentDetailsPage = nullptr ;
261279 }
262280}
263281
@@ -461,7 +479,7 @@ void IIOExplorerInstrument::applySelection(const QItemSelection &selected, const
461479 m_currentlySelectedItem = iioItem;
462480
463481 if (iioItem) {
464- showOrBuildPage (iioItem);
482+ m_mapStack-> show (iioItem-> path () );
465483 m_watchListView->currentTreeSelectionChanged (iioItem);
466484 }
467485}
@@ -491,7 +509,7 @@ void IIOExplorerInstrument::selectItem(IIOStandardItem *item)
491509 m_currentlySelectedItem = item;
492510 auto sourceModel = qobject_cast<QStandardItemModel *>(m_proxyModel->sourceModel ());
493511 recursiveExpandItem (sourceModel->invisibleRootItem (), item);
494- showOrBuildPage (item);
512+ m_mapStack-> show (item-> path () );
495513}
496514
497515void IIOExplorerInstrument::setupCodeGeneratorWindow ()
0 commit comments