QStandardItemModel 遍歷勾選的項
rowCount()不能傳入 m_model->index(0, 0)根節點,無法獲取行數;
不傳,或者傳入一個空QModelIndex對象,可以獲取到第一級節點的數量;
QMap<QString,QVariantMap> mapSelectVideo;
int rootRowCount = m_model->rowCount();
for (int i= 0;i<rootRowCount;i++)
{
QModelIndex rootIndex = m_model->index(i, 0);
RecursiveFindCheckedVideo(rootIndex, mapSelectVideo);
}
void SelectVideoTree::RecursiveFindCheckedVideo(QModelIndex& parent, QMap<QString, QVariantMap>& mapSelectFile)
{
if (parent.isValid())
{
int rowCount = m_model->rowCount(parent);
for (int i = 0; i < rowCount; ++i)
{
QModelIndex childIndex = m_model->index(i, 0, parent);
QStandardItem* pItem = m_model->itemFromIndex(childIndex);
if (pItem)
{
QVariantMap info = pItem->data().toMap();
if (info.value("type") == "2")//視頻文件
{
mapSelectFile.insert(info.value("location").toString(), info);
}
else
{
RecursiveFindCheckedVideo(childIndex, mapSelectFile); // 遞歸遍歷子項
}
}
}
}
}