diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 034c799..c6328cb 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -187,14 +187,13 @@ void cMainWindow::displayData() QStandardItem* findItem(QStandardItemModel* lpModel, QModelIndex parent, const QString& text) { -// qDebug() << lpModel->rowCount(parent); - for(int x = 0;x < lpModel->rowCount(parent);x++) { -// qDebug() << lpModel->data(index, Qt::UserRole+2).toString(); QModelIndex index = lpModel->index(x, 0, parent); if(lpModel->data(index, Qt::UserRole+2).toString() == text) + { return(lpModel->itemFromIndex(index)); + } if(lpModel->hasChildren(index)) { @@ -220,18 +219,28 @@ void cMainWindow::cleanFolderTree(const QString& folder) return; QModelIndex indexSource = m_lpFolderViewModel->indexFromItem(lpItem); - qDebug() << indexSource.row(); + QModelIndex indexParent = indexSource.parent(); - QStandardItem* lpItem1 = m_lpFolderViewModel->itemFromIndex(indexSource); - qDebug() << lpItem1->text(); + QString szFolder = folder; - QModelIndex indexFilter = m_lpFolderSortFilterProxyModel->mapFromSource(indexSource); - qDebug() << indexFilter.row(); + while(indexParent.isValid() && !folder.isEmpty()) + { + m_lpFolderViewModel->removeRow(indexSource.row(), indexParent); - qDebug() << lpItem->text(); + if(!szFolder.contains("/")) + break; - if(indexFilter.isValid()) - m_lpFolderSortFilterProxyModel->removeRow(indexFilter.row()); + szFolder = szFolder.left(szFolder.lastIndexOf("/")); + + indexSource = indexParent; + indexParent = indexSource.parent(); + QStandardItem* lpItem = m_lpFolderViewModel->itemFromIndex(indexSource); + if(!lpItem) + break; + + if(m_pictureList.hasPath(lpItem->data(Qt::UserRole+2).toString())) + break; + } } void cMainWindow::closeEvent(QCloseEvent *event) diff --git a/cthumbnailsortfilterproxymodel.cpp b/cthumbnailsortfilterproxymodel.cpp index 02cb5ef..693dd95 100644 --- a/cthumbnailsortfilterproxymodel.cpp +++ b/cthumbnailsortfilterproxymodel.cpp @@ -26,7 +26,22 @@ QString cThumbnailSortFilterProxyModel::filterPath() bool cThumbnailSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { + if(m_szPath.isEmpty()) + return(true); + QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); QString tmp = sourceModel()->data(index0, Qt::UserRole+2).toString(); - return(sourceModel()->data(index0, Qt::UserRole+2).toString().startsWith(m_szPath)); + + QString szPath = sourceModel()->data(index0, Qt::UserRole+2).toString(); + + if(!szPath.startsWith(m_szPath)) + return(false); + + if(szPath.length() == m_szPath.length()) + return(true); + + if(szPath.mid(m_szPath.length(), 1) == "/") + return(true); + + return(false); }