| 309 | } |
| 310 | |
| 311 | void BehaviorTreeDataModel::readStyle() |
| 312 | { |
| 313 | QFile style_file(":/NodesStyle.json"); |
| 314 | |
| 315 | if (!style_file.open(QIODevice::ReadOnly)) |
| 316 | { |
| 317 | qWarning("Couldn't open NodesStyle.json"); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | QByteArray bytearray = style_file.readAll(); |
| 322 | style_file.close(); |
| 323 | QJsonParseError error; |
| 324 | QJsonDocument json_doc( QJsonDocument::fromJson( bytearray, &error )); |
| 325 | |
| 326 | if(json_doc.isNull()){ |
| 327 | qDebug()<<"Failed to create JSON doc: " << error.errorString(); |
| 328 | return; |
| 329 | } |
| 330 | if(!json_doc.isObject()){ |
| 331 | qDebug()<<"JSON is not an object."; |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | QJsonObject toplevel_object = json_doc.object(); |
| 336 | |
| 337 | if(toplevel_object.isEmpty()){ |
| 338 | qDebug()<<"JSON object is empty."; |
| 339 | return; |
| 340 | } |
| 341 | QString model_type_name( QString::fromStdString(toStr(_model.type)) ); |
| 342 | |
| 343 | for (const auto& model_name: { model_type_name, _model.registration_ID} ) |
| 344 | { |
| 345 | if( toplevel_object.contains(model_name) ) |
| 346 | { |
| 347 | auto category_style = toplevel_object[ model_name ].toObject() ; |
| 348 | if( category_style.contains("icon")) |
| 349 | { |
| 350 | _style_icon = category_style["icon"].toString(); |
| 351 | } |
| 352 | if( category_style.contains("caption_color")) |
| 353 | { |
| 354 | _style_caption_color = category_style["caption_color"].toString(); |
| 355 | } |
| 356 | if( category_style.contains("caption_alias")) |
| 357 | { |
| 358 | _style_caption_alias = category_style["caption_alias"].toString(); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | const QString& BehaviorTreeDataModel::registrationName() const |
| 365 | { |