MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / getSaveFileName

Method getSaveFileName

src/Gui/FileDialog.cpp:516–644  ·  view source on GitHub ↗

* This is a convenience static function that will return a file name selected by the user. The file * does not have to exist. */

Source from the content-addressed store, hash-verified

514 * does not have to exist.
515 */
516QString FileDialog::getSaveFileName(
517 QWidget* parent,
518 const QString& caption,
519 const QString& startPath,
520 const FilterList& filters,
521 qsizetype* selectedFilterIndex,
522 Options options
523)
524{
525 ActionDisabler actionDisabler {};
526 qsizetype actuallySelectedFilterIndex = selectedFilterIndex != nullptr ? *selectedFilterIndex
527 : -1;
528 QString suggestedPath = startPath;
529 bool hasFilename = false;
530 if (suggestedPath.isEmpty()) {
531 suggestedPath = getPreferredDialogDirectory();
532 }
533 else {
534 QFileInfo fi(suggestedPath);
535 if (fi.isRelative()) {
536 suggestedPath = getPreferredDialogDirectory();
537 suggestedPath += QStringLiteral("/");
538 suggestedPath += fi.fileName();
539 fi.setFile(suggestedPath);
540 }
541 // If the startPath points to a directory (path ends with separator, or points
542 // to existing dir), don't touch it and don't use QFileDialog::selectFile() later.
543 if (!(fi.fileName().isEmpty() || fi.isDir())) {
544 // If there is a file name at the end, make sure it matches one of the patterns
545 // of the preselected filter, if applicable.
546 hasFilename = true;
547 if (actuallySelectedFilterIndex >= 0) {
548 FileDialogInternal::normalizeSavePath(
549 suggestedPath,
550 filters[actuallySelectedFilterIndex]
551 );
552 }
553 }
554 }
555
556 QString windowTitle = caption;
557 if (windowTitle.isEmpty()) {
558 windowTitle = FileDialog::tr("Save As");
559 }
560
561 options |= QFileDialog::HideNameFilterDetails;
562
563 QString file;
564 if (DialogOptions::dontUseNativeFileDialog()) {
565 const bool showPatterns = FileDialogInternal::getPreferShowFilterPatterns();
566 const auto qtFilterList = toQtFilterList(filters, showPatterns);
567 QList<QUrl> urls = fetchSidebarUrls();
568
569 options |= QFileDialog::DontUseNativeDialog;
570
571 FileDialog dlg(parent);
572 dlg.setOptions(options);
573 dlg.setWindowTitle(windowTitle);

Callers 15

exportCsvMethod · 0.80
SetOutputFileNameMethod · 0.80
SaveDialogMethod · 0.80
ActivatedMethod · 0.80
makeCamoticsFileMethod · 0.80
on_exportMethod · 0.80
exportCSVMethod · 0.80
exportMethod · 0.80
addtolibraryMethod · 0.80
saveTemplateMethod · 0.80
get_filepathFunction · 0.80

Calls 15

toQtFilterListFunction · 0.85
toQtFilterFunction · 0.85
isRelativeMethod · 0.80
isDirMethod · 0.80
setOptionsMethod · 0.80
setAcceptModeMethod · 0.80
selectFileMethod · 0.80
toStdStringMethod · 0.80
isEmptyMethod · 0.45
fileNameMethod · 0.45
setFileMethod · 0.45

Tested by

no test coverage detected