MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / on_actionSave_triggered

Method on_actionSave_triggered

bt_editor/mainwindow.cpp:479–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477}
478
479void 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
524void MainWindow::onAutoArrange()
525{

Callers

nothing calls this directly

Calls 1

containsValidTreeMethod · 0.80

Tested by

no test coverage detected