| 241 | } |
| 242 | |
| 243 | void MainWindow::loadFromXML(const QString& xml_text) |
| 244 | { |
| 245 | QDomDocument document; |
| 246 | try{ |
| 247 | QString errorMsg; |
| 248 | int errorLine; |
| 249 | if( ! document.setContent(xml_text, &errorMsg, &errorLine ) ) |
| 250 | { |
| 251 | throw std::runtime_error( tr("Error parsing XML (line %1): %2").arg(errorLine).arg(errorMsg).toStdString() ); |
| 252 | } |
| 253 | //--------------- |
| 254 | std::vector<QString> registered_ID; |
| 255 | for (const auto& it: _treenode_models) |
| 256 | { |
| 257 | registered_ID.push_back( it.first ); |
| 258 | } |
| 259 | std::vector<QString> error_messages; |
| 260 | bool done = VerifyXML(document, registered_ID, error_messages ); |
| 261 | |
| 262 | if( !done ) |
| 263 | { |
| 264 | QString merged_error; |
| 265 | for (const auto& err: error_messages) |
| 266 | { |
| 267 | merged_error += err + "\n"; |
| 268 | } |
| 269 | throw std::runtime_error( merged_error.toStdString() ); |
| 270 | } |
| 271 | } |
| 272 | catch( std::runtime_error& err) |
| 273 | { |
| 274 | QMessageBox messageBox; |
| 275 | messageBox.critical(this,"Error parsing the XML", err.what() ); |
| 276 | messageBox.show(); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | //--------------- |
| 281 | bool error = false; |
| 282 | QString err_message; |
| 283 | auto saved_state = _current_state; |
| 284 | auto prev_tree_model = _treenode_models; |
| 285 | |
| 286 | try { |
| 287 | auto document_root = document.documentElement(); |
| 288 | |
| 289 | if( document_root.hasAttribute("main_tree_to_execute")) |
| 290 | { |
| 291 | _main_tree = document_root.attribute("main_tree_to_execute"); |
| 292 | } |
| 293 | |
| 294 | auto custom_models = ReadTreeNodesModel( document_root ); |
| 295 | |
| 296 | for( const auto& model: custom_models) |
| 297 | { |
| 298 | onAddToModelRegistry( model.second ); |
| 299 | } |
| 300 | |