Fix Save writing a .qetz beside an opened .qet: keep the .qet

A project opened from a .qet was saved as a .qetz beside it, with a
notice, and the .qet left as it was: a project kept in git did not stay
a .qet. Save now writes the format the project was opened in; only Save
As changes it (scorpio810, discussion #1512). A .qetz is saved as a
.qetz as before.

The save-beside path goes: the flag set on opening, the .qetz path made
from the .qet's, write()'s switch to it and back on failure, and the
notice and replace question in ProjectView::doSave().

tst_resaveunchanged::qetSavedAsQetzBeside becomes qetSavedAsQet: Save of
an opened .qet writes no .qetz and the .qet holds what a plain save of
it holds (it fails without the fix: a .qetz is written beside).
tst_changedondisk makes its .qetz with Save As, as Save no longer does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-18 22:56:22 +13:00
parent 8c5a16d50e
commit 89c3979957
6 changed files with 23 additions and 96 deletions
+6 -46
View File
@@ -197,8 +197,6 @@ QETProject::QETProject(KAutoSaveFile *backup, QObject *parent) :
}
//Set the real path, instead of the path of the backup.
setFilePath(backup->managedFile().path());
//A project read from a .qet is saved as a .qetz beside it
m_opened_from_qet = !isContainerPath(m_file_path);
delete backup;
//Set the project to read only mode if the file it.
@@ -506,8 +504,6 @@ QETProject::ProjectState QETProject::openFile(QFile *file)
//from a .qet only, a .qetz is a zip of parts
if (!content.startsWith("PK\x03\x04"))
m_opened_content = content;
//A project read from a .qet is saved as a .qetz beside it
m_opened_from_qet = !content.startsWith("PK\x03\x04");
QDomDocument xml_project;
// PreserveSpacingOnlyNodes: without it, a text node that is entirely
// whitespace -- e.g. a title-block custom variable deliberately set to
@@ -1176,8 +1172,6 @@ void QETProject::setFilePath(const QString &filepath)
}
m_next_backup_slot = 0;
m_file_path = filepath;
//A path chosen is saved to as it is
m_opened_from_qet = false;
QFileInfo fi(m_file_path);
if (fi.isWritable()) {
@@ -2750,20 +2744,6 @@ bool QETProject::writeContainerFile(const QString &path, QString *error)
kept.isEmpty() ? QHash<QString, QByteArray>() : m_container_files);
}
/**
@brief QETProject::besideContainerPath
@return the .qetz a project read from a .qet is saved to: the same
name, beside it
*/
QString QETProject::besideContainerPath() const
{
QString path = m_file_path;
if (path.endsWith(QStringLiteral(".qet"), Qt::CaseInsensitive)) {
path.chop(4);
}
return path + QStringLiteral(".qetz");
}
/**
@brief QETProject::writeCopyForOlderVersions
Write this project as a .qet at @p path, which a QElectroTech that
@@ -2793,16 +2773,6 @@ void QETProject::rememberDiskState()
m_disk_mtime = info.exists() ? info.lastModified() : QDateTime();
}
/**
@brief QETProject::writeTarget
@return the file write() writes to: the .qetz beside a project read
from a .qet, else the project's own file
*/
QString QETProject::writeTarget() const
{
return m_opened_from_qet ? besideContainerPath() : m_file_path;
}
/**
@brief QETProject::changedOnDisk
@param when set to the modification time of the file now on disk
@@ -2813,7 +2783,7 @@ QString QETProject::writeTarget() const
*/
bool QETProject::changedOnDisk(QDateTime *when) const
{
const QString target = writeTarget();
const QString target = m_file_path;
if (target.isEmpty() || target != m_disk_path || m_disk_size < 0)
return false;
const QFileInfo info(target);
@@ -2874,20 +2844,10 @@ QETResult QETProject::write(bool overwrite_changed)
if (!m_locked_out_path.isEmpty() && m_locked_out_path == m_file_path)
return(tr("%1 was opened read-only because someone else has it open. Use Save As to keep your changes in another file.").arg(m_file_path));
//A project read from a .qet is saved as a .qetz beside it; the
//.qet stays as it was (stage D1). If the .qetz cannot be written
//(a read-only folder), the project stays the .qet it was.
const QString opened_qet = m_opened_from_qet ? m_file_path : QString();
if (m_opened_from_qet) {
setFilePath(besideContainerPath());
}
const auto failed = [this, &opened_qet](const QString &error) {
const QString message = tr("Cannot save %1: %2").arg(m_file_path, error);
if (!opened_qet.isEmpty()) {
setFilePath(opened_qet);
m_opened_from_qet = true;
}
return(QETResult(message));
//Saved in the format it was opened in: a .qet stays a .qet, and
//only Save As changes it (#1512)
const auto failed = [this](const QString &error) {
return(QETResult(tr("Cannot save %1: %2").arg(m_file_path, error)));
};
// If the project was opened read-only, only refuse when the target
@@ -2961,7 +2921,7 @@ QETResult QETProject::write(bool overwrite_changed)
if (isReadOnly())
setReadOnly(false);
//The file may be a new one (Save As, a .qet saved as .qetz): the lock
//The file may be a new one (Save As): the lock
//follows it. A project that had none (new, or opened read-only for
//another's lock) takes one now. Never stops the save: it is done.
if (ProjectLock::mayTake()) {