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

Method on_buttonUpload_clicked

bt_editor/sidepanel_editor.cpp:224–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222
223
224void SidepanelEditor::on_buttonUpload_clicked()
225{
226 QDomDocument doc;
227
228 QDomElement root = doc.createElement( "root" );
229 doc.appendChild( root );
230
231 QDomElement root_models = doc.createElement("TreeNodesModel");
232
233 for(const auto& tree_it: _tree_nodes_model)
234 {
235 const auto& ID = tree_it.first;
236 const auto& model = tree_it.second;
237
238 if( BuiltinNodeModels().count(ID) != 0 )
239 {
240 continue;
241 }
242
243 QDomElement node = doc.createElement( QString::fromStdString(toStr(model.type)) );
244
245 if( !node.isNull() )
246 {
247 node.setAttribute("ID", ID.toStdString().c_str());
248 for(const auto& port_it: model.ports)
249 {
250 node.appendChild(writePortModel(port_it.first, port_it.second, doc));
251 }
252 }
253 root_models.appendChild(node);
254 }
255 root.appendChild(root_models);
256
257 //-------------------------------------
258 QSettings settings;
259 QString directory_path = settings.value("SidepanelEditor.lastSaveDirectory",
260 QDir::currentPath() ).toString();
261
262 auto fileName = QFileDialog::getSaveFileName(this,"Save BehaviorTree to file",
263 directory_path,"BehaviorTree files (*.xml)");
264 if (fileName.isEmpty()){
265 return;
266 }
267 if (!fileName.endsWith(".xml"))
268 {
269 fileName += ".xml";
270 }
271
272
273 QFile file(fileName);
274 if (file.open(QIODevice::WriteOnly)) {
275 QTextStream stream(&file);
276 stream << doc.toString(4) << endl;
277 }
278
279 directory_path = QFileInfo(fileName).absolutePath();
280 settings.setValue("SidepanelEditor.lastSaveDirectory", directory_path);
281

Callers

nothing calls this directly

Calls 2

toStrFunction · 0.85
writePortModelFunction · 0.85

Tested by

no test coverage detected