| 477 | } |
| 478 | |
| 479 | void MainWindow::on_actionSave_triggered() |
| 480 | { |
| 481 | for (auto& it: _tab_info) |
| 482 | { |
| 483 | auto& container = it.second; |
| 484 | if( !container->containsValidTree() ) |
| 485 | { |
| 486 | QMessageBox::warning(this, tr("Oops!"), |
| 487 | tr("Malformed behavior tree. File can not be saved"), |
| 488 | QMessageBox::Cancel); |
| 489 | return; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | if( _tab_info.size() == 1 ) |
| 494 | { |
| 495 | _main_tree = _tab_info.begin()->first; |
| 496 | } |
| 497 | |
| 498 | QSettings settings; |
| 499 | QString directory_path = settings.value("MainWindow.lastSaveDirectory", |
| 500 | QDir::currentPath() ).toString(); |
| 501 | |
| 502 | auto fileName = QFileDialog::getSaveFileName(this, "Save BehaviorTree to file", |
| 503 | directory_path, "BehaviorTree files (*.xml)"); |
| 504 | if (fileName.isEmpty()){ |
| 505 | return; |
| 506 | } |
| 507 | if (!fileName.endsWith(".xml")) |
| 508 | { |
| 509 | fileName += ".xml"; |
| 510 | } |
| 511 | |
| 512 | QString xml_text = saveToXML(); |
| 513 | |
| 514 | QFile file(fileName); |
| 515 | if (file.open(QIODevice::WriteOnly)) { |
| 516 | QTextStream stream(&file); |
| 517 | stream << xml_text << endl; |
| 518 | } |
| 519 | |
| 520 | directory_path = QFileInfo(fileName).absolutePath(); |
| 521 | settings.setValue("MainWindow.lastSaveDirectory", directory_path); |
| 522 | } |
| 523 | |
| 524 | void MainWindow::onAutoArrange() |
| 525 | { |
nothing calls this directly
no test coverage detected