Skip to content

Commit 68a5f8e

Browse files
committed
debugger/iiomodel: Background population of all device/channel nodes.
Populate the IIOTree nodes in different QEvents to prevent the application from freezing. I also retain the previous commit's functionality, allowing a node to be loaded on demand by selecting or expanding it. Signed-off-by: andreidanila1 <andrei.danila@analog.com>
1 parent a064d81 commit 68a5f8e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/generic-plugins/plugins/debugger/include/debugger/iiomodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class IIOModel : public QObject
4141

4242
// Lazily builds IIOWidget children for a device, trigger, or channel item.
4343
void populateChildren(IIOStandardItem *item);
44+
void scheduleFullPopulation();
4445

4546
Q_SIGNALS:
4647
void emitLog(QDateTime timestamp, bool isRead, QString path, QString oldValue, QString newValue,
@@ -55,6 +56,7 @@ class IIOModel : public QObject
5556
void populateDeviceChildren(IIOStandardItem *item);
5657
void populateChannelChildren(IIOStandardItem *item);
5758
void buildEntries();
59+
void processNextInQueue();
5860
QStandardItem *createPlaceholderItem();
5961

6062
/**
@@ -91,6 +93,7 @@ class IIOModel : public QObject
9193
int m_currentChannelIndex;
9294

9395
QList<IIOWidget *> m_ctxList;
96+
QList<IIOStandardItem *> m_populationQueue;
9497
};
9598
} // namespace scopy::debugger
9699

packages/generic-plugins/plugins/debugger/src/iioexplorer/iiomodel.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "iiomodel.h"
2323
#include <QLoggingCategory>
24+
#include <QTimer>
2425

2526
#define BUFFER_SIZE 256
2627
#define SEPARATOR "/"
@@ -67,6 +68,9 @@ void IIOModel::iioTreeSetup()
6768

6869
// Pre-populate m_entries with attr names so SearchBar autocomplete works immediately
6970
buildEntries();
71+
72+
// Starts background population so the full tree is available without user interaction
73+
scheduleFullPopulation();
7074
}
7175

7276
void IIOModel::setupCtx()
@@ -214,6 +218,38 @@ void IIOModel::populateChannelChildren(IIOStandardItem *item)
214218
}
215219
}
216220

221+
void IIOModel::scheduleFullPopulation()
222+
{
223+
// Collect all device/trigger and channel items in tree order.
224+
// Channel items are added after their parent device so that device attrs
225+
// are populated before channel attrs, matching the visual tree order.
226+
for(int i = 0; i < m_rootItem->rowCount(); ++i) {
227+
auto *devItem = dynamic_cast<IIOStandardItem *>(m_rootItem->child(i));
228+
if(!devItem) {
229+
continue;
230+
}
231+
if(devItem->type() == IIOStandardItem::Device || devItem->type() == IIOStandardItem::Trigger) {
232+
m_populationQueue.append(devItem);
233+
for(int j = 0; j < devItem->rowCount(); ++j) {
234+
auto *chnlItem = dynamic_cast<IIOStandardItem *>(devItem->child(j));
235+
if(chnlItem && chnlItem->type() == IIOStandardItem::Channel) {
236+
m_populationQueue.append(chnlItem);
237+
}
238+
}
239+
}
240+
}
241+
QTimer::singleShot(0, this, &IIOModel::processNextInQueue);
242+
}
243+
244+
void IIOModel::processNextInQueue()
245+
{
246+
if(m_populationQueue.isEmpty()) {
247+
return;
248+
}
249+
populateChildren(m_populationQueue.takeFirst());
250+
QTimer::singleShot(0, this, &IIOModel::processNextInQueue);
251+
}
252+
217253
void IIOModel::buildEntries()
218254
{
219255
uint devCount = iio_context_get_devices_count(m_ctx);

0 commit comments

Comments
 (0)