Merge pull request #1543 from ispyisail/fix/save-keeps-qet
Linux build and tests / Build and test (Qt 6, Debug) (push) Failing after 1m54s

Fix Save writing a .qetz beside an opened .qet: keep the .qet
This commit is contained in:
ispyisail
2026-10-19 15:07:41 +13:00
committed by GitHub
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.
@@ -511,8 +509,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
@@ -1201,8 +1197,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()) {
@@ -2774,20 +2768,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
@@ -2817,16 +2797,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
@@ -2837,7 +2807,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);
@@ -2898,20 +2868,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
@@ -2985,7 +2945,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()) {