C++ (Qt)void MainWindow::contextMenuDelete(){ QModelIndex index = ui.treeView->currentIndex(); if(!index.isValid()) return; if(dirmodel->fileInfo(index).isDir()) { dirmodel->rmdir(index);// dirmodel->remove(index); } else if( dirmodel->fileInfo(index).isFile() ) dirmodel->remove(index); if( dirmodel->fileInfo(ui.treeView->indexBelow(index)).isFile() ) { index = ui.treeView->indexBelow(index); } else { index = ui.treeView->indexAbove(index); }}
C++ (Qt) if(dirmodel->fileInfo(index).isDir()) {// if(!dirmodel->hasChildren(index)) if(!dirmodel->rowCount(index)) dirmodel->rmdir(index); }
if(!dirmodel->hasChildren(index))
bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const{ return (rowCount(parent) > 0) && (columnCount(parent) > 0);}
C++ (Qt)bool QAbstractItemModel::canFetchMore(const QModelIndex & parent) constvoid QAbstractItemModel::fetchMore(const QModelIndex & parent)
C++ (Qt) if( !managerModel->rowCount( index ) ) { managerModel->rmdir( index ); } if( QDir( managerModel->filePath( index ) ).exists() ) { m_managerView->expand( index ); QMessageBox* pmbx = new QMessageBox( QMessageBox::Warning, "Manager", "Directory is not empty!", QMessageBox::Cancel ); pmbx->exec(); delete pmbx; }
C++ (Qt)bool managerModel::hasChildren( const QModelIndex & parent ) const{ return QDir(filePath(parent)).count() > 2;}
C++ (Qt) if( m_managerModel->hasChildren(index) ) { m_managerView->expand(index); QMessageBox* pmbx = new QMessageBox(QMessageBox::Warning, tr( "Content Manager" ), tr( "Directory is not empty!" ), QMessageBox::Cancel); pmbx->exec(); delete pmbx; } else { m_managerModel->rmdir(index); }
C++ (Qt) QMessageBox::warning(0, tr( "Content Manager" ), tr( "Directory is not empty!" ), QMessageBox::Cancel);
C++ (Qt) if(m_managerModel->fileInfo(index).isDir()) { if( m_managerModel->hasChildren(index) ) { m_managerView->expand(index); QMessageBox::warning(0, tr( "Content Manager" ), tr( "Directory is not empty!" ), QMessageBox::Cancel); } else { m_managerModel->rmdir(index); } }