| 138 | } |
| 139 | |
| 140 | CartesianPlot* PlotTemplateDialog::generatePlot() { |
| 141 | const QString path = templatePath(); |
| 142 | if (path.isEmpty()) { |
| 143 | updateErrorMessage(i18n("No templates found.")); |
| 144 | return nullptr; |
| 145 | } |
| 146 | |
| 147 | QFile file(path); |
| 148 | if (!file.exists()) { |
| 149 | updateErrorMessage(i18n("File does not exist.")); |
| 150 | return nullptr; |
| 151 | } |
| 152 | |
| 153 | if (!file.open(QIODevice::OpenModeFlag::ReadOnly)) { |
| 154 | updateErrorMessage(i18n("Unable to read the file")); |
| 155 | return nullptr; |
| 156 | } |
| 157 | |
| 158 | XmlStreamReader reader(&file); |
| 159 | |
| 160 | while (!(reader.isStartDocument() || reader.atEnd())) |
| 161 | reader.readNext(); |
| 162 | |
| 163 | if (reader.atEnd()) { |
| 164 | DEBUG("XML error: No start document token found"); |
| 165 | updateErrorMessage(i18n("Failed to load the selected plot template")); |
| 166 | return nullptr; |
| 167 | } |
| 168 | |
| 169 | reader.readNext(); |
| 170 | if (!reader.isDTD()) { |
| 171 | DEBUG("XML error: No DTD token found"); |
| 172 | updateErrorMessage(i18n("Failed to load the selected plot template")); |
| 173 | return nullptr; |
| 174 | } |
| 175 | |
| 176 | reader.readNext(); |
| 177 | if (!reader.isStartElement() || reader.name() != QLatin1String("PlotTemplate")) { |
| 178 | DEBUG("XML error: No PlotTemplate found"); |
| 179 | updateErrorMessage(i18n("Failed to load the selected plot template")); |
| 180 | return nullptr; |
| 181 | } |
| 182 | |
| 183 | bool ok; |
| 184 | int xmlVersion = reader.readAttributeInt(QLatin1String("xmlVersion"), &ok); |
| 185 | if (!ok) { |
| 186 | DEBUG("XML error: xmlVersion found"); |
| 187 | updateErrorMessage(i18n("Failed to load the selected plot template")); |
| 188 | return nullptr; |
| 189 | } |
| 190 | Project::setXmlVersion(xmlVersion); |
| 191 | reader.readNext(); |
| 192 | |
| 193 | while (!((reader.isStartElement() && reader.name() == QLatin1String("cartesianPlot")) || reader.atEnd())) |
| 194 | reader.readNext(); |
| 195 | |
| 196 | if (reader.atEnd()) { |
| 197 | updateErrorMessage(i18n("XML error: No cartesianPlot found")); |
no test coverage detected