| 158 | |
| 159 | |
| 160 | bool ModelsRepositoryDialog::parseXML(const QString &filename, |
| 161 | ModelsByFile& models_by_file, |
| 162 | QString* error_message) |
| 163 | { |
| 164 | TreeNodeModel models; |
| 165 | QDomDocument doc; |
| 166 | doc.LoadFile( filename.toStdString().c_str() ); |
| 167 | |
| 168 | if (doc.Error()) |
| 169 | { |
| 170 | (*error_message) = ("The XML was not correctly loaded"); |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | auto strEqual = [](const char* str1, const char* str2) -> bool { |
| 175 | return strcmp(str1, str2) == 0; |
| 176 | }; |
| 177 | |
| 178 | QDomElement* xml_root = doc.documentElement(); |
| 179 | if (!xml_root || !strEqual(xml_root->Name(), "root")) |
| 180 | { |
| 181 | (*error_message) = ("The XML must have a root node called <root>"); |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | auto meta_root = xml_root.firstChildElement("TreeNodesModel"); |
| 186 | |
| 187 | if (!meta_root) |
| 188 | { |
| 189 | (*error_message) = ("Expecting <TreeNodesModel> under <root>"); |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | for( QDomElement node = meta_root.firstChildElement(); |
| 194 | node != nullptr; |
| 195 | node = node.nextSiblingElement() ) |
| 196 | { |
| 197 | models.insert( buildTreeNodeModel(node, true) ); |
| 198 | } |
| 199 | models_by_file.insert( std::make_pair(filename, models) ); |
| 200 | |
| 201 | return true; |
| 202 | } |
| 203 | |
| 204 | bool ModelsRepositoryDialog::parseFile(const QString &filename, ModelsByFile &models_by_file) |
| 205 | { |