Skip to content

Instantly share code, notes, and snippets.

@pashango2
Last active November 19, 2016 20:10
Show Gist options
  • Save pashango2/2b088270a844cf207d79e0087da7cd1a to your computer and use it in GitHub Desktop.
Save pashango2/2b088270a844cf207d79e0087da7cd1a to your computer and use it in GitHub Desktop.
def model_row_iter(model, start_index=QModelIndex()):
""" モデルのrowイテレータを返す
:type start_index: QModelIndex
:type model: QAbstractItemModel
"""
if start_index.isValid():
yield start_index
while True:
row = start_index.row()
if row >= model.rowCount(start_index.parent()) - 1:
break
start_index = model.index(row + 1, 0, start_index.parent())
yield start_index
if model.rowCount(start_index) > 0:
for _ in model_row_iter(model, model.index(0, 0, start_index)):
yield _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment