MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / loadProjectArrays

Method loadProjectArrays

app/src/DataModel/ProjectModel.cpp:2612–2649  ·  view source on GitHub ↗

* @brief Deserializes groups, actions and sources arrays into m_groups/m_actions/m_sources. */

Source from the content-addressed store, hash-verified

2610 * @brief Deserializes groups, actions and sources arrays into m_groups/m_actions/m_sources.
2611 */
2612void DataModel::ProjectModel::loadProjectArrays(const QJsonObject& json,
2613 const QString& legacyParserCode)
2614{
2615 auto groups = json.value(Keys::Groups).toArray();
2616 for (int g = 0; g < groups.count(); ++g) {
2617 DataModel::Group group;
2618 group.groupId = g;
2619 if (DataModel::read(group, groups.at(g).toObject()))
2620 m_groups.push_back(group);
2621 }
2622
2623 auto actions = json.value(Keys::Actions).toArray();
2624 for (int a = 0; a < actions.count(); ++a) {
2625 DataModel::Action action;
2626 action.actionId = a;
2627 if (DataModel::read(action, actions.at(a).toObject()))
2628 m_actions.push_back(action);
2629 }
2630
2631 m_sources.clear();
2632 if (json.contains(Keys::Sources)) {
2633 auto sourcesArr = json.value(Keys::Sources).toArray();
2634 for (int s = 0; s < sourcesArr.count(); ++s) {
2635 DataModel::Source source;
2636 if (DataModel::read(source, sourcesArr.at(s).toObject()))
2637 m_sources.push_back(source);
2638 }
2639 }
2640
2641 if (m_sources.empty()) {
2642 seedDefaultSourceFromUi(legacyParserCode);
2643 return;
2644 }
2645
2646 if (m_sources[0].frameParserCode.isEmpty())
2647 m_sources[0].frameParserCode =
2648 legacyParserCode.isEmpty() ? FrameParser::defaultTemplateCode() : legacyParserCode;
2649}
2650
2651/**
2652 * @brief Builds a default Source[0] from the UI driver state when JSON has no sources array.

Callers

nothing calls this directly

Calls 7

readFunction · 0.85
emptyMethod · 0.80
isEmptyMethod · 0.80
valueMethod · 0.45
countMethod · 0.45
clearMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected