Clear read-only state when a project is saved to a writable file (#217)

Saving a read-only project to a writable location (e.g. Save As to /tmp)
left it marked read-only, so it stayed uneditable until closed and
reopened. Two issues in QETProject::write():

- The guard refused to write whenever QFileInfo(path).isWritable() was
  false. For a Save As to a *new* file that test is always false (the file
  doesn't exist yet), so it could wrongly block saving a read-only project
  elsewhere. Now it checks the directory's writability for a new file.
- After a successful write the read-only flag was never cleared. Since the
  file was just written, it is writable, so clear it (setReadOnly(false)
  emits readOnlyChanged, re-enabling editing live).

Fixes #217.
This commit is contained in:
Shane Ringrose
2026-06-12 06:09:48 +12:00
parent e7787daa2c
commit a8e408ad39
+18 -4
View File
@@ -1006,16 +1006,30 @@ QETResult QETProject::write()
if (m_file_path.isEmpty())
return(QString("unable to save project to file: no filepath was specified"));
// if the project was opened read-only
// and the file is still non-writable, do not save the project
if (isReadOnly() && !QFileInfo(m_file_path).isWritable())
return(QString("the file %1 was opened read-only and thus will not be written").arg(m_file_path));
// If the project was opened read-only, only refuse when the target
// really can't be written: an existing file that is not writable, or a
// new file (e.g. "Save As" to another location) whose directory is not
// writable. A non-existent file reports isWritable() == false, so the
// old check wrongly blocked saving a read-only project elsewhere.
if (isReadOnly()) {
const QFileInfo file_info(m_file_path);
const bool can_write = file_info.exists()
? file_info.isWritable()
: QFileInfo(file_info.absolutePath()).isWritable();
if (!can_write)
return(QString("the file %1 was opened read-only and thus will not be written").arg(m_file_path));
}
QDomDocument xml_project(toXml());
QString error_message;
if (!QET::writeXmlFile(xml_project, m_file_path, &error_message))
return(error_message);
// The project has just been written to a writable file (e.g. saved to
// a new location with "Save As"), so it is no longer read-only.
if (isReadOnly())
setReadOnly(false);
//title block variables should be updated after file save dialog is confirmed, before file is saved.
m_project_properties.addValue("saveddate", QLocale::system().toString(QDate::currentDate(), QLocale::ShortFormat));
m_project_properties.addValue("saveddate-us", QDate::currentDate().toString("yyyy-MM-dd"));