| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "lc_filedialogservice.h" |
| |
|
| | #include <QApplication> |
| | #include <QCheckBox> |
| | #include <QDir> |
| | #include <QFileDialog> |
| | #include <QGridLayout> |
| | #include <QMessageBox> |
| |
|
| | #include "lc_layerexportoptions.h" |
| | #include "rs_debug.h" |
| | #include "rs_settings.h" |
| |
|
| | class QCheckBox; |
| |
|
| | namespace { |
| |
|
| | |
| | QStringList filtersStringList = { |
| | |
| | "Drawing Exchange DXF 2007 (*.dxf)", |
| | "Drawing Exchange DXF 2004 (*.dxf)", |
| | "Drawing Exchange DXF 2000 (*.dxf)", |
| | "Drawing Exchange DXF R14 (*.dxf)", |
| | "Drawing Exchange DXF R12 (*.dxf)", |
| |
|
| | #ifdef DWGSUPPORT |
| | "DWG Drawing (*.dwg)", |
| | #endif |
| |
|
| | "LFF Font (*.lff)", |
| | "QCAD Font (*.cxf)" |
| |
|
| | #ifdef JWW_WRITE_SUPPORT |
| | , "JWW Drawing (*.jww)" |
| | #endif |
| | }; |
| |
|
| | QList<RS2::FormatType> filtersTypeList = |
| | { |
| | |
| | RS2::FormatDXFRW, |
| | RS2::FormatDXFRW2004, |
| | RS2::FormatDXFRW2000, |
| | RS2::FormatDXFRW14, |
| | RS2::FormatDXFRW12, |
| |
|
| | #ifdef DWGSUPPORT |
| | RS2::FormatDWG, |
| | #endif |
| |
|
| | RS2::FormatLFF, |
| | RS2::FormatCXF |
| |
|
| | #ifdef JWW_WRITE_SUPPORT |
| | , RS2::FormatJWW |
| | #endif |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | [[maybe_unused]] const int numberOf_openFileModes = 0; |
| |
|
| | const QStringList filterSettingsPaths = |
| | { |
| | "/SaveDrawingFilter", |
| | "/SaveDrawingFilter", |
| | "/SaveDrawingFilter" |
| | }; |
| |
|
| | const QStringList fileIOSettingsPaths = |
| | { |
| | "/Save", |
| | "/Save", |
| | "/Save" |
| | }; |
| |
|
| | const int defaultFilters_indices[] = |
| | { |
| | |
| | 0, |
| | 0, |
| | 0 |
| | }; |
| |
|
| | const QStringList fileDialogTitles = |
| | { |
| | |
| | "Save Drawing as", |
| | "Export selected layer(s)", |
| | "Export visible layer(s)" |
| | }; |
| |
|
| |
|
| | void updateFileExtension(LC_FileDialogService::FileDialogResult& result, const QString& selectedFilter) { |
| | QString saveFileExtension = selectedFilter.mid (selectedFilter.lastIndexOf ('.')); |
| | saveFileExtension.chop(1); |
| | result.fileExtension = saveFileExtension; |
| | if (!result.fileName.endsWith(result.fileExtension, Qt::CaseInsensitive)) { |
| | result.filePath += result.fileExtension; |
| | } |
| | if (result.fileName.endsWith(saveFileExtension)) { |
| | result.fileName.resize(result.fileName.size() - result.fileExtension.size()); |
| | } |
| | } |
| |
|
| | RS2::FormatType getFormatType(const QString& formatString){ |
| | int index = filtersStringList.indexOf(formatString); |
| | return (index >= 0 && index < filtersTypeList.count()) ? filtersTypeList.at(index) : RS2::FormatDXFRW; |
| | } |
| |
|
| | std::pair<QString, QString> readDefaultDirFilter() { |
| | LC_GROUP_GUARD("Paths"); |
| | { |
| | QString defaultDir = LC_GET_STR("Save", QDir::toNativeSeparators(QDir::homePath())); |
| | QString defaultFilter = LC_GET_STR("SaveDrawingFilter", filtersStringList.at(0)); |
| | return {defaultDir, defaultFilter}; |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | LC_FileDialogService::FileDialogResult LC_FileDialogService::getFileDetails (FileDialogMode const& fileDialogMode){ |
| | RS_DEBUG->print("LC_FileDialogService::getFileName"); |
| |
|
| | std::pair<QString, QString> defaultDirFilter = readDefaultDirFilter(); |
| |
|
| | auto saveFileDialog = std::make_unique<QFileDialog>( nullptr, |
| | fileDialogTitles.at (fileDialogMode), |
| | defaultDirFilter.first, |
| | filtersStringList.join(";;")); |
| |
|
| | saveFileDialog->selectNameFilter (defaultDirFilter.second); |
| | saveFileDialog->setAcceptMode (QFileDialog::AcceptSave); |
| | saveFileDialog->setOption (QFileDialog::HideNameFilterDetails, false); |
| |
|
| | bool useQtFileDialog = LC_GET_ONE_BOOL("Defaults","UseQtFileOpenDialog"); |
| | saveFileDialog->setOption (QFileDialog::DontUseNativeDialog, useQtFileDialog); |
| |
|
| | |
| | std::unique_ptr<QCheckBox> checkBox_combinedSave; |
| |
|
| | if ((fileDialogMode == ExportLayersSelected) || (fileDialogMode == ExportLayersVisible)) { |
| | saveFileDialog->setOption (QFileDialog::DontUseNativeDialog, true); |
| | QLayout* layout = saveFileDialog->layout(); |
| | if (layout != nullptr) { |
| | checkBox_combinedSave = std::make_unique<QCheckBox>(QObject::tr("Combine all layers")); |
| | |
| |
|
| | auto* exportOptionsWidget = new LC_LayerExportOptionsWidget(saveFileDialog.get()); |
| | auto* gridLayout = dynamic_cast<QGridLayout*>(layout); |
| | if (gridLayout != nullptr) { |
| | gridLayout->addWidget(exportOptionsWidget, 5, 0, 1, 3); |
| | } |
| | } |
| | } |
| |
|
| | FileDialogResult result{}; |
| | while (true) { |
| | if (saveFileDialog->QFileDialog::exec() == QDialog::Accepted) { |
| | result.filePath = QDir::toNativeSeparators(QFileInfo(saveFileDialog->QFileDialog::selectedFiles().at(0)).absoluteFilePath()); |
| | result.dirPath = QFileInfo(result.filePath).absolutePath(); |
| | result.fileName = QFileInfo(result.filePath).fileName(); |
| |
|
| | const QString selectedFilter = saveFileDialog->QFileDialog::selectedNameFilter(); |
| | result.fileType = getFormatType(selectedFilter); |
| |
|
| | |
| | updateFileExtension(result, selectedFilter); |
| |
|
| | |
| | if (QFileInfo::exists(result.filePath)) { |
| | int replaceFileResponse = QMessageBox::warning( |
| | QApplication::activeWindow(), |
| | fileDialogTitles.at(fileDialogMode), |
| | QObject::tr(R"(File "%1" already exists. Do you want to replace it?)").arg(result.fileName), |
| | QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel |
| | ); |
| |
|
| | if (replaceFileResponse != QMessageBox::Yes) |
| | continue; |
| | } |
| |
|
| | if (checkBox_combinedSave != nullptr) |
| | result.checkState = checkBox_combinedSave->checkState(); |
| |
|
| | LC_GROUP_GUARD("Paths"); |
| | { |
| | LC_SET(fileIOSettingsPaths.at(fileDialogMode), result.dirPath); |
| | LC_SET(filterSettingsPaths.at(fileDialogMode), selectedFilter); |
| | } |
| |
|
| | break; |
| | } else { |
| | result = {}; |
| | break; |
| | } |
| | } |
| |
|
| | RS_DEBUG->print("LC_FileDialogService::getFileName: OK"); |
| | return result; |
| | } |
| |
|