Skip to content

Commit

Permalink
fix searching for channels in the modify & export views
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Mar 6, 2024
1 parent b1a1e52 commit 8c1c5ff
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 67 deletions.
5 changes: 1 addition & 4 deletions src/asammdf/gui/dialogs/advanced_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,7 @@ def _match_double_clicked(self, item):
new_item = item

iterator = QtWidgets.QTreeWidgetItemIterator(self.selection)
while iterator.value():
item = iterator.value()
if item is None:
break
while item := iterator.value():

data = tuple(item.text(i) for i in range(self.columns))
selection.add(data)
Expand Down
35 changes: 15 additions & 20 deletions src/asammdf/gui/widgets/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,7 @@ def _get_filtered_channels(self):
total = 0

if self.filter_view.currentText() == "Internal file structure":
while iterator.value():
item = iterator.value()
while item := iterator.value():

group, index = item.entry
if index != 0xFFFFFFFFFFFFFFFF:
Expand All @@ -916,8 +915,7 @@ def _get_filtered_channels(self):

iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
group, index = item.entry
Expand Down Expand Up @@ -955,7 +953,7 @@ def raster_search(self, event):
name = list(result)[0]
self.raster_channel.setCurrentText(name)

def filter_changed(self, item, column):
def filter_changed(self, item, column=0):
name = item.text(0)
if item.checkState(0) == QtCore.Qt.CheckState.Checked:
self._selected_filter.add(name)
Expand Down Expand Up @@ -1015,8 +1013,6 @@ def search(self, event=None):

if (dg_cntr, ch_cntr) in result:
item.setCheckState(0, QtCore.Qt.CheckState.Checked)
else:
item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)

iterator += 1
ch_cntr += 1
Expand All @@ -1025,8 +1021,7 @@ def search(self, event=None):
iterator = QtWidgets.QTreeWidgetItemIterator(widget)

signals = set()
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
signals.add(item.entry)
Expand All @@ -1036,28 +1031,32 @@ def search(self, event=None):
signals = signals | set(result)

widget.clear()
self._selected_filter.clear()

uuid = os.urandom(6).hex()

items = []
for entry in signals:
gp_index, ch_index = entry
ch = mdf.groups[gp_index].channels[ch_index]
channel = MinimalTreeItem(entry, ch.name, strings=[ch.name], origin_uuid=self.uuid)
channel = MinimalTreeItem(entry, ch.name, strings=[ch.name], origin_uuid=uuid)
channel.setCheckState(0, QtCore.Qt.CheckState.Checked)
items.append(channel)
self._selected_filter.add(ch.name)

if len(items) < 30000:
items = natsorted(items, key=lambda x: x.name)
else:
items.sort(key=lambda x: x.name)

widget.addTopLevelItems(items)
self.update_selected_filter_channels()

else:
iterator = QtWidgets.QTreeWidgetItemIterator(widget)
while item := iterator.value():
if item.entry in result:
item.setCheckState(0, QtCore.Qt.CheckState.Checked)
else:
item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)

iterator += 1
except:
Expand All @@ -1074,8 +1073,6 @@ def update_channel_tree(self, *args):
if not count:
self.filter_tree.clear()
return
elif self.filter_tree.topLevelItemCount():
return
else:
uuid = os.urandom(6).hex()

Expand All @@ -1102,8 +1099,7 @@ def update_channel_tree(self, *args):

iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
signals.add(item.entry)
Expand Down Expand Up @@ -1850,8 +1846,7 @@ def load_filter_list(self, event=None, file_name=None):
iterator = QtWidgets.QTreeWidgetItemIterator(self.filter_tree)

if self.filter_view.currentText() == "Internal file structure":
while iterator.value():
item = iterator.value()
while item := iterator.value():
if item.parent() is None:
iterator += 1
continue
Expand All @@ -1864,9 +1859,9 @@ def load_filter_list(self, event=None, file_name=None):
item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)

iterator += 1

elif self.filter_view.currentText() == "Natural sort":
while iterator.value():
item = iterator.value()
while item := iterator.value():

channel_name = item.text(0)
if channel_name in channels:
Expand Down
61 changes: 22 additions & 39 deletions src/asammdf/gui/widgets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,15 @@ def _update_channel_tree(self, index=None, widget=None, force=False):
signals = set()

if widget.mode == "Internal file structure":
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.entry[1] != 0xFFFFFFFFFFFFFFFF:
if item.checkState(0) == QtCore.Qt.CheckState.Checked:
signals.add(item.entry)

iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
signals.add(item.entry)
Expand Down Expand Up @@ -820,8 +818,7 @@ def search(self, event=None):
dg_cntr = -1
ch_cntr = 0

while iterator.value():
item = iterator.value()
while item := iterator.value():
if item.parent() is None:
iterator += 1
dg_cntr += 1
Expand All @@ -841,8 +838,7 @@ def search(self, event=None):
iterator = QtWidgets.QTreeWidgetItemIterator(widget)

signals = set()
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
signals.add((item.text(0), *item.entry))
Expand All @@ -854,6 +850,7 @@ def search(self, event=None):
signals = signals | names

widget.clear()
self._selected_filter = {e[0] for e in signals}

items = []
for name, gp_index, ch_index in signals:
Expand All @@ -868,13 +865,12 @@ def search(self, event=None):
else:
items.sort(key=lambda x: x.name)
widget.addTopLevelItems(items)
for item in items:
self.filter_changed(item)

self.update_selected_filter_channels()

else:
iterator = QtWidgets.QTreeWidgetItemIterator(widget)
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.entry in result:
item.setCheckState(0, QtCore.Qt.CheckState.Checked)
Expand Down Expand Up @@ -952,8 +948,7 @@ def to_config(self):

signals = []
if self.channel_view.currentText() == "Internal file structure":
while iterator.value():
item = iterator.value()
while item := iterator.value():
if item.parent() is None:
iterator += 1
continue
Expand All @@ -963,8 +958,7 @@ def to_config(self):

iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
signals.append(item.text(0))
Expand Down Expand Up @@ -1235,8 +1229,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False):
iterator = QtWidgets.QTreeWidgetItemIterator(self.channels_tree)

if self.channel_view.currentText() == "Internal file structure":
while iterator.value():
item = iterator.value()
while item := iterator.value():
if item.parent() is None:
iterator += 1
continue
Expand All @@ -1250,8 +1243,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False):

iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():

channel_name = item.text(0)
if channel_name in channels:
Expand Down Expand Up @@ -1546,8 +1538,7 @@ def show_info(self, item, column):
def clear_filter(self):
iterator = QtWidgets.QTreeWidgetItemIterator(self.filter_tree)

while iterator.value():
item = iterator.value()
while item := iterator.value():
item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)

if item.parent() is None:
Expand All @@ -1559,33 +1550,29 @@ def clear_channels(self):
iterator = QtWidgets.QTreeWidgetItemIterator(self.channels_tree)

if self.channel_view.currentIndex() == 1:
while iterator.value():
item = iterator.value()
while item := iterator.value():
if item.parent() is None:
item.setExpanded(False)
else:
item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():
item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
iterator += 1

def select_all_channels(self):
iterator = QtWidgets.QTreeWidgetItemIterator(self.channels_tree)

if self.channel_view.currentIndex() == 1:
while iterator.value():
item = iterator.value()
while item := iterator.value():
if item.parent() is None:
item.setExpanded(False)
else:
item.setCheckState(0, QtCore.Qt.CheckState.Checked)
iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():
item.setCheckState(0, QtCore.Qt.CheckState.Checked)
iterator += 1

Expand Down Expand Up @@ -1692,8 +1679,7 @@ def _create_window(self, event=None, window_type=None):
signals = []

if self.channel_view.currentIndex() == 1:
while iterator.value():
item = iterator.value()
while item := iterator.value():
if item.parent() is None:
iterator += 1
continue
Expand All @@ -1717,8 +1703,7 @@ def _create_window(self, event=None, window_type=None):

iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
group, index = item.entry
Expand Down Expand Up @@ -2606,8 +2591,7 @@ def _get_filtered_channels(self):
channels = []

if self.filter_view.currentText() == "Internal file structure":
while iterator.value():
item = iterator.value()
while item := iterator.value():

group, index = item.entry

Expand All @@ -2617,8 +2601,7 @@ def _get_filtered_channels(self):

iterator += 1
else:
while iterator.value():
item = iterator.value()
while item := iterator.value():

if item.checkState(0) == QtCore.Qt.CheckState.Checked:
group, index = item.entry
Expand Down Expand Up @@ -2993,7 +2976,7 @@ def raster_search(self, event):
name = list(result)[0]
self.raster_channel.setCurrentText(name)

def filter_changed(self, item, column):
def filter_changed(self, item, column=0):
name = item.text(0)
if self.filter_view.currentText() == "Internal file structure":
if item.checkState(0) == QtCore.Qt.CheckState.Checked and item.parent() is not None:
Expand Down
3 changes: 1 addition & 2 deletions src/asammdf/gui/widgets/mdi_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -3480,8 +3480,7 @@ def _load_plot_window(self, window_info):
plot.cursor_info.set_precision(window_info["configuration"]["cursor_precision"])

iterator = QtWidgets.QTreeWidgetItemIterator(plot.channel_selection)
while iterator.value():
item = iterator.value()
while item := iterator.value():
iterator += 1

if item.type() == item.Group:
Expand Down
3 changes: 1 addition & 2 deletions src/asammdf/gui/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,7 @@ def open_menu(self):
count = 0
enabled = 0
iterator = QtWidgets.QTreeWidgetItemIterator(self)
while iterator.value():
cur_item = iterator.value()
while cur_item := iterator.value():
if cur_item.type() == ChannelsTreeItem.Channel:
count += 1
if cur_item.checkState(self.NameColumn) == QtCore.Qt.CheckState.Checked:
Expand Down

0 comments on commit 8c1c5ff

Please sign in to comment.