| 97 | } |
| 98 | |
| 99 | bool TextEditor::save() |
| 100 | { |
| 101 | if (m_filename.isEmpty() || m_encoding.isEmpty()) { |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | QFile file(m_filename); |
| 106 | file.open(QIODevice::WriteOnly); |
| 107 | file.resize(0); |
| 108 | |
| 109 | auto codec = QStringConverter::encodingForName(m_encoding.toLocal8Bit()); |
| 110 | if (!codec.has_value()) |
| 111 | return false; |
| 112 | QStringEncoder encoder(codec.value()); |
| 113 | |
| 114 | QString data = toPlainText().replace("\n", "\r\n"); |
| 115 | |
| 116 | file.write(encoder.encode(data)); |
| 117 | document()->setModified(false); |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | const QString& TextEditor::filename() const |
| 123 | { |
no test coverage detected