cleanup folder tree
This commit is contained in:
+20
-11
@@ -187,14 +187,13 @@ void cMainWindow::displayData()
|
|||||||
|
|
||||||
QStandardItem* findItem(QStandardItemModel* lpModel, QModelIndex parent, const QString& text)
|
QStandardItem* findItem(QStandardItemModel* lpModel, QModelIndex parent, const QString& text)
|
||||||
{
|
{
|
||||||
// qDebug() << lpModel->rowCount(parent);
|
|
||||||
|
|
||||||
for(int x = 0;x < lpModel->rowCount(parent);x++)
|
for(int x = 0;x < lpModel->rowCount(parent);x++)
|
||||||
{
|
{
|
||||||
// qDebug() << lpModel->data(index, Qt::UserRole+2).toString();
|
|
||||||
QModelIndex index = lpModel->index(x, 0, parent);
|
QModelIndex index = lpModel->index(x, 0, parent);
|
||||||
if(lpModel->data(index, Qt::UserRole+2).toString() == text)
|
if(lpModel->data(index, Qt::UserRole+2).toString() == text)
|
||||||
|
{
|
||||||
return(lpModel->itemFromIndex(index));
|
return(lpModel->itemFromIndex(index));
|
||||||
|
}
|
||||||
|
|
||||||
if(lpModel->hasChildren(index))
|
if(lpModel->hasChildren(index))
|
||||||
{
|
{
|
||||||
@@ -220,18 +219,28 @@ void cMainWindow::cleanFolderTree(const QString& folder)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QModelIndex indexSource = m_lpFolderViewModel->indexFromItem(lpItem);
|
QModelIndex indexSource = m_lpFolderViewModel->indexFromItem(lpItem);
|
||||||
qDebug() << indexSource.row();
|
QModelIndex indexParent = indexSource.parent();
|
||||||
|
|
||||||
QStandardItem* lpItem1 = m_lpFolderViewModel->itemFromIndex(indexSource);
|
QString szFolder = folder;
|
||||||
qDebug() << lpItem1->text();
|
|
||||||
|
|
||||||
QModelIndex indexFilter = m_lpFolderSortFilterProxyModel->mapFromSource(indexSource);
|
while(indexParent.isValid() && !folder.isEmpty())
|
||||||
qDebug() << indexFilter.row();
|
{
|
||||||
|
m_lpFolderViewModel->removeRow(indexSource.row(), indexParent);
|
||||||
|
|
||||||
qDebug() << lpItem->text();
|
if(!szFolder.contains("/"))
|
||||||
|
break;
|
||||||
|
|
||||||
if(indexFilter.isValid())
|
szFolder = szFolder.left(szFolder.lastIndexOf("/"));
|
||||||
m_lpFolderSortFilterProxyModel->removeRow(indexFilter.row());
|
|
||||||
|
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)
|
void cMainWindow::closeEvent(QCloseEvent *event)
|
||||||
|
|||||||
@@ -26,7 +26,22 @@ QString cThumbnailSortFilterProxyModel::filterPath()
|
|||||||
|
|
||||||
bool cThumbnailSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool cThumbnailSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
|
if(m_szPath.isEmpty())
|
||||||
|
return(true);
|
||||||
|
|
||||||
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||||
QString tmp = sourceModel()->data(index0, Qt::UserRole+2).toString();
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user