mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-15 01:54:14 +02:00
Open and save projects as .qetz (zipped, opt-in)
Third stage of the zipped project file (#1440). A project is saved as a .qetz when its file name ends in .qetz -- Save As offers it as a second file type, and --resave, --set-titleblock, the script API's save() and the live-mode snapshot follow the name too. Saving a .qet project still writes a .qet; nothing changes unless the user picks .qetz. Opening recognises a .qetz by its content (a zip), not its name, and reads it as bytes: text mode would alter it on Windows. The project document is joined back and read by the same code as a .qet. Crash backups stay plain XML. Drag and drop, the open dialog and the numbering import accept .qetz; the database export names its file from the project's name without assuming ".qet". Parts are now written without added indentation (one line each): the symbol definitions are kept as read, whitespace included, and parts that gained indentation made the next save differ (five forum projects). Tests: tst_resaveunchanged::containerSavesTheSameProject (four examples saved as .qetz, then as .qet, equal the straight .qet; pictures checked to fail without the fix), tst_qetcontainer::noWhitespaceAdded. Outside ctest: 341 of 341 projects QET can open (examples, bugtracker, GitHub, forum) give the same .qet through a .qetz; 181.6 MB of .qet became 36.9 MB of .qetz. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Wga9B92BNurDEtxxtCDxf
This commit is contained in:
+15
-4
@@ -339,11 +339,16 @@ int ProjectView::tryClosingDiagrams()
|
||||
*/
|
||||
QString ProjectView::askUserForFilePath(bool assign) {
|
||||
// ask the user for a filepath in order to save the project
|
||||
const QString qet_filter = tr("Project QElectroTech (*.qet)", "filetypes allowed when saving a project file");
|
||||
const QString qetz_filter = tr("Zipped project QElectroTech (*.qetz)", "filetypes allowed when saving a project file");
|
||||
QString selected_filter = QETProject::isContainerPath(m_project->filePath()) ? qetz_filter : qet_filter;
|
||||
QString filepath = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr("Save as", "dialog title"),
|
||||
m_project -> currentDir() + "/" + tr("untitled") + ".qet",
|
||||
tr("Project QElectroTech (*.qet)", "filetypes allowed when saving a project file")
|
||||
m_project -> currentDir() + "/" + tr("untitled")
|
||||
+ (selected_filter == qetz_filter ? ".qetz" : ".qet"),
|
||||
qet_filter + ";;" + qetz_filter,
|
||||
&selected_filter
|
||||
);
|
||||
|
||||
// if no filepath is provided, return an empty string
|
||||
@@ -359,9 +364,15 @@ QString ProjectView::askUserForFilePath(bool assign) {
|
||||
// extension at all whenever the portal didn't (bugtracker #270).
|
||||
// Stripping any existing suffix first and re-appending it once is
|
||||
// correct either way.
|
||||
if (filepath.endsWith(".qet", Qt::CaseInsensitive))
|
||||
// A .qetz is kept as typed, or chosen through its filter.
|
||||
const bool zipped = filepath.endsWith(".qetz", Qt::CaseInsensitive)
|
||||
|| (selected_filter == qetz_filter
|
||||
&& !filepath.endsWith(".qet", Qt::CaseInsensitive));
|
||||
if (filepath.endsWith(".qetz", Qt::CaseInsensitive))
|
||||
filepath.chop(5);
|
||||
else if (filepath.endsWith(".qet", Qt::CaseInsensitive))
|
||||
filepath.chop(4);
|
||||
filepath += ".qet";
|
||||
filepath += zipped ? ".qetz" : ".qet";
|
||||
|
||||
if (assign) {
|
||||
// assign the provided filepath to the currently edited project
|
||||
|
||||
Reference in New Issue
Block a user