2121
2222#include " iiomodel.h"
2323#include < QLoggingCategory>
24+ #include < pluginbase/preferences.h>
2425
2526#define BUFFER_SIZE 256
2627#define SEPARATOR " /"
@@ -55,8 +56,10 @@ void IIOModel::iioTreeSetup()
5556 uint device_channels_count = iio_device_get_channels_count (m_currentDevice);
5657 for (m_currentChannelIndex = 0 ; m_currentChannelIndex < device_channels_count; ++m_currentChannelIndex) {
5758 setupCurrentChannel ();
59+ generateChannelAttributes ();
5860 m_currentDeviceItem->appendRow (m_currentChannelItem);
5961 }
62+ generateDeviceAttributes ();
6063
6164 // add device to ctx
6265 m_rootItem->appendRow (m_currentDeviceItem);
@@ -73,7 +76,7 @@ void IIOModel::setupCtx()
7376{
7477 m_ctxList = IIOWidgetBuilder (m_parent).context (m_ctx).buildAll ();
7578 m_rootItem = createIIOStandardItem (m_ctxList, m_rootString, " " , m_rootString, IIOStandardItem::Context);
76- // m_rootItem = new IIOStandardItem(m_ctxList, m_rootString, m_rootString, IIOStandardItem::Context );
79+ m_rootItem-> setContext (m_ctx );
7780 m_rootItem->setEditable (false );
7881}
7982
@@ -85,6 +88,7 @@ void IIOModel::generateCtxAttributes()
8588 auto *attrItem = createIIOStandardItem ({ctxWidget}, ctxWidget->getRecipe ().data , " " ,
8689 m_rootString + SEPARATOR + ctxWidget->getRecipe ().data ,
8790 IIOStandardItem::ContextAttribute);
91+ attrItem->setContext (m_ctx);
8892 attrItem->setEditable (false );
8993 m_rootItem->appendRow (attrItem);
9094 }
@@ -131,11 +135,59 @@ void IIOModel::setupCurrentChannel()
131135
132136 m_currentChannelItem->setEditable (false );
133137 m_entries.insert (m_currentChannelName);
138+ }
139+
140+ void IIOModel::generateDeviceAttributes ()
141+ {
142+ uint attrCount = iio_device_get_attrs_count (m_currentDevice);
143+ for (uint j = 0 ; j < attrCount; ++j) {
144+ const char *attrName = iio_device_get_attr (m_currentDevice, j);
145+ if (!attrName) {
146+ continue ;
147+ }
148+ m_entries.insert (attrName);
149+ auto *attrItem = createIIOStandardItem (
150+ {}, attrName, " " , m_rootString + SEPARATOR + m_currentDeviceName + SEPARATOR + attrName,
151+ IIOStandardItem::DeviceAttribute);
152+ attrItem->setDevice (m_currentDevice);
153+ attrItem->setEditable (false );
154+ m_currentDeviceItem->appendRow (attrItem);
155+ }
134156
135- // Add placeholder child so the expand arrow is visible in the tree view
136- ssize_t attrCount = iio_channel_get_attrs_count (m_currentChannel);
137- if (attrCount > 0 ) {
138- m_currentChannelItem->appendRow (createPlaceholderItem ());
157+ if (Preferences::get (" debugger_v2_include_debugfs" ).toBool ()) {
158+ uint dbgAttrCount = iio_device_get_debug_attrs_count (m_currentDevice);
159+ for (uint j = 0 ; j < dbgAttrCount; ++j) {
160+ const char *attrName = iio_device_get_debug_attr (m_currentDevice, j);
161+ if (!attrName) {
162+ continue ;
163+ }
164+ m_entries.insert (attrName);
165+ auto *attrItem = createIIOStandardItem (
166+ {}, attrName, " " , m_rootString + SEPARATOR + m_currentDeviceName + SEPARATOR + attrName,
167+ IIOStandardItem::DeviceAttribute);
168+ attrItem->setDevice (m_currentDevice);
169+ attrItem->setEditable (false );
170+ m_currentDeviceItem->appendRow (attrItem);
171+ }
172+ }
173+ }
174+
175+ void IIOModel::generateChannelAttributes ()
176+ {
177+ uint attrCount = iio_channel_get_attrs_count (m_currentChannel);
178+ for (uint i = 0 ; i < attrCount; ++i) {
179+ const char *attrName = iio_channel_get_attr (m_currentChannel, i);
180+ if (!attrName) {
181+ continue ;
182+ }
183+ m_entries.insert (attrName);
184+ auto *attrItem = createIIOStandardItem ({}, attrName, " " ,
185+ m_rootString + SEPARATOR + m_currentDeviceName + SEPARATOR +
186+ m_currentChannelName + SEPARATOR + attrName,
187+ IIOStandardItem::ChannelAttribute);
188+ attrItem->setChannel (m_currentChannel);
189+ attrItem->setEditable (false );
190+ m_currentChannelItem->appendRow (attrItem);
139191 }
140192}
141193
@@ -151,6 +203,11 @@ void IIOModel::populateChildren(IIOStandardItem *item)
151203 populateDeviceChildren (item);
152204 } else if (type == IIOStandardItem::Channel) {
153205 populateChannelChildren (item);
206+ } else if (type == IIOStandardItem::DeviceAttribute || type == IIOStandardItem::ChannelAttribute) {
207+ auto *parentItem = dynamic_cast <IIOStandardItem *>(item->QStandardItem ::parent ());
208+ if (parentItem) {
209+ populateChildren (parentItem);
210+ }
154211 }
155212}
156213
@@ -165,23 +222,17 @@ void IIOModel::populateDeviceChildren(IIOStandardItem *item)
165222 IIOWidgetBuilder (m_parent).device (dev).includeAvailableAttributes (true ).buildAll ();
166223 item->setIIOWidgets (devWidgets);
167224
168- uint debug_attr_idx = 0 ;
169- for (int j = 0 ; j < devWidgets.size (); ++j) {
170- QString device_attr = iio_device_get_attr (dev, j);
171- if (device_attr.isEmpty ()) {
172- device_attr = iio_device_get_debug_attr (dev, debug_attr_idx++);
173- }
174- if (device_attr.isEmpty ()) {
225+ // Assign widgets to existing attribute children (created eagerly in generateDeviceAttributes)
226+ int widgetIdx = 0 ;
227+ for (int i = 0 ; i < item->rowCount (); ++i) {
228+ auto *child = dynamic_cast <IIOStandardItem *>(item->child (i));
229+ if (!child || child->type () == IIOStandardItem::Channel) {
175230 continue ;
176231 }
177-
178- m_entries.insert (device_attr);
179- auto *attrItem =
180- createIIOStandardItem ({devWidgets[j]}, devWidgets[j]->getRecipe ().data , " " ,
181- item->path () + SEPARATOR + device_attr, IIOStandardItem::DeviceAttribute);
182- attrItem->setDevice (dev);
183- attrItem->setEditable (false );
184- item->appendRow (attrItem);
232+ if (widgetIdx < devWidgets.size ()) {
233+ child->setIIOWidgets ({devWidgets[widgetIdx]});
234+ ++widgetIdx;
235+ }
185236 }
186237}
187238
@@ -192,25 +243,16 @@ void IIOModel::populateChannelChildren(IIOStandardItem *item)
192243 return ;
193244 }
194245
195- // Remove placeholder if present (it's a plain QStandardItem, not IIOStandardItem)
196- if (item->rowCount () > 0 && !dynamic_cast <IIOStandardItem *>(item->child (0 ))) {
197- item->removeRow (0 );
198- }
199-
200246 QList<IIOWidget *> chnlWidgets =
201247 IIOWidgetBuilder (m_parent).channel (ch).includeAvailableAttributes (true ).buildAll ();
202248 item->setIIOWidgets (chnlWidgets);
203249
204- for (int i = 0 ; i < chnlWidgets.size (); ++i) {
205- QString attr_name = iio_channel_get_attr (ch, i);
206- m_entries.insert (attr_name);
207- QString attrName = chnlWidgets[i]->getRecipe ().data ;
208- auto *attr_item =
209- createIIOStandardItem ({chnlWidgets[i]}, attrName, " " , item->path () + SEPARATOR + attrName,
210- IIOStandardItem::ChannelAttribute);
211- attr_item->setChannel (ch);
212- attr_item->setEditable (false );
213- item->appendRow (attr_item);
250+ // Assign widgets to existing attribute children (created eagerly in generateChannelAttributes)
251+ for (int i = 0 ; i < item->rowCount () && i < chnlWidgets.size (); ++i) {
252+ auto *child = dynamic_cast <IIOStandardItem *>(item->child (i));
253+ if (child) {
254+ child->setIIOWidgets ({chnlWidgets[i]});
255+ }
214256 }
215257}
216258
@@ -249,14 +291,6 @@ void IIOModel::buildEntries()
249291 }
250292}
251293
252- QStandardItem *IIOModel::createPlaceholderItem ()
253- {
254- auto *placeholder = new QStandardItem ();
255- placeholder->setEnabled (false );
256- placeholder->setEditable (false );
257- return placeholder;
258- }
259-
260294IIOStandardItem *IIOModel::createIIOStandardItem (QList<IIOWidget *> widgets, QString name, QString id, QString path,
261295 IIOStandardItem::Type type)
262296{
0 commit comments