void FileManager::moveFileToFolder(QString originPath, QString originName,QString newPath,QString newName) { if(QString::compare(originPath,newPath)==0 && QString::compare(originName,newName)==0) return; copyFileToFolder(originPath,originName, newPath, newName); historyFromPath.push(originPath); historyFromName.push(originName); historyToPath.push(newPath); historyToName.push(newName); historyType.push_back("folder"); deleteFile(originPath + "/" + originName); }
void FileManager::copyFileToFolder(QString originPath, QString originName,QString newPath,QString rename,int digits) { QFileInfo* info = new QFileInfo(originPath + "/" + originName); QString name = generateName(newPath,rename,info->completeSuffix(),digits); copyFileToFolder(originPath,originName, newPath, name); historyFromPath.push(originPath); historyFromName.push(originName); historyToPath.push(newPath); historyToName.push(name); historyType.push_back("folder"); delete info; }
void VegetationWidget::slotImportTree() { QFileDialog* selectedFiles = new QFileDialog(this); selectedFiles->setFileMode(QFileDialog::ExistingFiles); selectedFiles->setLabelText(QFileDialog::FileName, QWidget::tr("文件")); selectedFiles->setLabelText(QFileDialog::FileType, QWidget::tr("文件")); selectedFiles->setLabelText(QFileDialog::Accept, QWidget::tr("确定")); selectedFiles->setLabelText(QFileDialog::Reject, QWidget::tr("取消")); QStringList fileNameFilters; fileNameFilters.push_back("files(*.osgb *.png *.tga)"); selectedFiles->setNameFilters(fileNameFilters); int retCode = selectedFiles->exec(); if (retCode) { std::string plantDir = g_SystemContext._workContextDir; plantDir.append(CONTEXT_DIR); plantDir.append("/Plant/"); QString treeDir = chineseTextUTF8ToQString(plantDir + "Tree/"); QStringList list = selectedFiles->selectedFiles(); bool findSameFileName = false; bool converSameFile = false; QList< QString > sameInListView; QList< QString > notSameInListView; for (int i = 0; i < list.size(); i++) { QFileInfo fileInfo(list[i]); QString fileName = fileInfo.fileName(); QString fileFullName = treeDir; fileFullName.append(fileName); if (QFile::exists(fileFullName)) { findSameFileName = true; sameInListView.push_back(fileName); } else notSameInListView.push_back(fileName); } if (findSameFileName) { QMessageBox messageBox(this); messageBox.setWindowTitle(QWidget::tr("提示")); messageBox.setIcon(QMessageBox::Question); messageBox.setText(QWidget::tr("发现同名的资源文件,是否覆盖?")); QPushButton *yesButton = messageBox.addButton(QWidget::tr("覆盖"), QMessageBox::YesRole); QPushButton *noButton = messageBox.addButton(QWidget::tr("跳过"), QMessageBox::NoRole); messageBox.exec(); if (messageBox.clickedButton() == yesButton) converSameFile = true; } copyFileToFolder(list, treeDir, converSameFile); buildList(); } }
void FileManager::moveFileToFolder(QString originPath, QString originName,QString newPath,QString rename,int digits) { copyFileToFolder(originPath,originName,newPath,rename,digits); deleteFile(originPath + "/" + originName); }