From 56bba27ae3ac47d2ed85711e7574793ca567e7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 20 Oct 2025 00:23:11 +0200 Subject: [PATCH] Give save filter only formats that are supported --- libXISF | 2 +- src/mainwindow.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libXISF b/libXISF index c6581e1..556bb22 160000 --- a/libXISF +++ b/libXISF @@ -1 +1 @@ -Subproject commit c6581e11220cfce71aef1c77a9797b9bf8838c31 +Subproject commit 556bb22d2675ee6072c6224fef3da0fb5d93db41 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 076a540..9506a26 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -57,12 +58,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) for(auto format : supportedFormats) { QMimeType mimeType = db.mimeTypeForName(format); - _saveFilter.append(mimeType.filterString() + ";;"); _openFilter.append("*."); _openFilter.append(mimeType.suffixes().join(" *.")); _openFilter.append(" "); nameFilter.append(mimeType.suffixes()); } + auto supportedWrite = QImageWriter::supportedMimeTypes(); + for(auto format : supportedWrite) + { + QMimeType mimeType = db.mimeTypeForName(format); + _saveFilter.append(mimeType.filterString() + ";;"); + } + _openFilter.append("*.fit *.fits *.fts *.fz *.xisf *.cr2 *.cr3 *.nef *.dng)"); _openFilter.append(tr(";;All files (*)")); nameFilter.append({"fit", "fits", "fts", "fz", "xisf", "cr2", "cr3", "nef", "dng"}); @@ -618,7 +625,7 @@ void MainWindow::saveAs() _lastDir, _saveFilter, &selectedFilter); - auto filterToFormat = [](const QString &file, const QString &filter) -> const char* + auto filterToFormat = [](const QString &file, const QString &filter) -> const QString { QString suffix = QFileInfo(file).suffix(); if(!suffix.compare("jpg", Qt::CaseInsensitive) || !suffix.compare("jpeg", Qt::CaseInsensitive))return "jpeg"; @@ -628,6 +635,10 @@ void MainWindow::saveAs() if(filter.contains("png"))return "png"; if(filter.contains("fits"))return "fits"; if(filter.contains("xisf"))return "xisf"; + QRegularExpression suf("\\(\\*\\.([a-zA-Z]+).*\\)"); + auto match = suf.match(filter); + if(match.hasMatch()) + return match.captured(1); return "jpeg"; }; @@ -643,7 +654,7 @@ void MainWindow::saveAs() { QImage img = m_image->renderToImage(); if(!img.isNull()) - img.save(file, filterToFormat(file, selectedFilter)); + img.save(file, filterToFormat(file, selectedFilter).toLatin1().data()); } } }