-
Notifications
You must be signed in to change notification settings - Fork 38
fix: issues of unsupported file formats. #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: issues of unsupported file formats. #188
Conversation
For the "Save As" module, there should be corresponding error prompts for unsupported file formats. For the export module, unsupported file formats should not be displayed to avoid misleading users. 另存为模块,不支持的文件格式要有相应的错误提示。导出模块,不支持的文件格式不显示出来,避免误导用户。 Bug: https://pms.uniontech.com/bug-view-328141.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds explicit error handling for unsupported image formats when saving, and hides unsupported formats from the export dialog while making the format combobox index selection more robust, including a new localized error message. Sequence diagram for unsupported format handling in Save AssequenceDiagram
actor User
participant SaveAsDialog
participant FileHander
participant FileHanderPrivate
participant QImage
participant ErrorDialog
User->>SaveAsDialog: clickSaveAs(fileWithUnsupportedExt)
SaveAsDialog->>FileHander: saveToImage(context, file, format)
FileHander->>QImage: save(file, format, imageQuility)
QImage-->>FileHander: saveResult(false)
FileHander->>FileHander: log qWarning
FileHander->>FileHanderPrivate: setError(EUnSupportFile, localizedMessage)
FileHanderPrivate-->>FileHander: errorSet
FileHander-->>SaveAsDialog: return false
SaveAsDialog->>ErrorDialog: show(localizedMessage)
ErrorDialog-->>User: displayUnsupportedFormatError
Updated class diagram for file saving and export image dialogclassDiagram
class FileHander {
+bool saveToImage(PageContext* context, QString file, QString stuff)
-void logSaveFailure(QString file)
}
class FileHanderPrivate {
+void setError(int errorCode, QString message)
}
class PageContext
class CExportImageDialog {
-DComboBox* m_formatCombox
-DSlider* m_qualitySlider
+void initUI()
+void showEvent(QShowEvent* event)
-void removeUnsupportedFormats()
-void adjustFormatIndex(QString formatFilter)
}
class DrawApp {
+QStringList writableFormatNameFilters()
}
class DComboBox {
+void addItems(QStringList items)
+int count()
}
class DSlider
class QShowEvent
FileHander --> FileHanderPrivate : uses
CExportImageDialog --> DrawApp : uses
CExportImageDialog --> DComboBox : owns
CExportImageDialog --> DSlider : owns
CExportImageDialog --> QShowEvent : overrides
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- The logic for hiding unsupported formats in the export dialog (hard-coded removal of AVIF/HEIC) is now duplicated/special-cased; consider centralizing the list or a helper that both
writableFormatNameFilters()and the UI use so the supported/unsupported formats stay consistent in one place. - In
CExportImageDialog::showEvent, the index is derived from the fullwritableFormatNameFilters()list but applied to the combobox that has had some formats removed; it would be more robust to compute the index against the combobox’s actual items (or a pre-filtered list) instead of clamping when out of range.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic for hiding unsupported formats in the export dialog (hard-coded removal of AVIF/HEIC) is now duplicated/special-cased; consider centralizing the list or a helper that both `writableFormatNameFilters()` and the UI use so the supported/unsupported formats stay consistent in one place.
- In `CExportImageDialog::showEvent`, the index is derived from the full `writableFormatNameFilters()` list but applied to the combobox that has had some formats removed; it would be more robust to compute the index against the combobox’s actual items (or a pre-filtered list) instead of clamping when out of range.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码的改动主要涉及图像保存功能的错误处理、UI层对导出格式列表的过滤以及国际化文本的添加。整体来看,代码逻辑是正确的,能够解决潜在的用户体验问题(如保存失败无提示、选择不支持的格式)。 以下是从语法逻辑、代码质量、代码性能和代码安全四个方面提出的详细审查和改进意见: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结与代码优化示例代码整体改动是正向的,主要是增强了健壮性。以下是针对 // 建议优化后的 filehander.cpp 片段
bool FileHander::saveToImage(PageContext *context, const QString &file, const QString &stuff, int imageQuality) // 建议修正参数名 imageQuility -> imageQuality
{
// ...前置代码保持不变...
if (image.isNull()) {
return false;
} else {
// 如果是 JPEG,使用 QImageWriter 以便更好地控制压缩比
if (stuff.contains("jpeg", Qt::CaseInsensitive) || stuff.contains("jpg", Qt::CaseInsensitive)) {
QImageWriter w(file, stuff.toLocal8Bit());
w.setCompression(1);
bool ret = w.write(image);
if (!ret) {
qWarning() << "Save image (Writer):" << file << "FAILED! Error:" << w.errorString();
d_pri()->setError(EUnSupportFile, tr("Unable to save \"%1\", unsupported file format").arg(info.fileName()));
}
return ret;
} else {
bool ret = image.save(file, stuff.toLocal8Bit(), imageQuality);
if (!ret) {
qWarning() << "Save image (Default):" << file << "FAILED!";
d_pri()->setError(EUnSupportFile, tr("Unable to save \"%1\", unsupported file format").arg(info.fileName()));
}
return ret;
}
}
return false;
}针对 如果不想硬编码字符串,可以尝试检查后缀名,而不是完整的过滤器字符串: // 示例:通过后缀名过滤,稍微灵活一些
QStringList unwantedSuffixes = {"avif", "heic", "heif"};
// 使用 removeIf (C++17/Qt 5.14+) 或手动遍历
for (int i = writeableFormats.size() - 1; i >= 0; --i) {
const QString &fmt = writeableFormats[i];
bool shouldRemove = false;
for (const QString &suffix : unwantedSuffixes) {
if (fmt.contains(suffix, Qt::CaseInsensitive)) {
shouldRemove = true;
break;
}
}
if (shouldRemove) {
writeableFormats.removeAt(i);
}
}不过,考虑到 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lichaofan2008, max-lvs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
2abfcab
into
linuxdeepin:release/eagle
For the "Save As" module, there should be corresponding error prompts for unsupported file formats. For the export module, unsupported file formats should not be displayed to avoid misleading users.
另存为模块,不支持的文件格式要有相应的错误提示。导出模块,不支持的文件格式不显示出来,避免误导用户。
Bug: https://pms.uniontech.com/bug-view-328141.html
Summary by Sourcery
Handle unsupported image formats consistently in save and export flows.
Bug Fixes: