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

Method addOutputControl

app/src/DataModel/ProjectModel.cpp:4109–4176  ·  view source on GitHub ↗

* @brief Adds an output control, creating a new output group if needed. */

Source from the content-addressed store, hash-verified

4107 * @brief Adds an output control, creating a new output group if needed.
4108 */
4109void DataModel::ProjectModel::addOutputControl(const SerialStudio::OutputWidgetType type,
4110 int sourceId)
4111{
4112 int groupId = -1;
4113 const auto sel = m_selectedGroup.groupId;
4114 if (sel >= 0 && static_cast<size_t>(sel) < m_groups.size()
4115 && m_groups[sel].groupType == DataModel::GroupType::Output
4116 && (sourceId < 0 || m_groups[sel].sourceId == sourceId))
4117 groupId = sel;
4118
4119 if (groupId < 0) {
4120 for (const auto& g : std::as_const(m_groups)) {
4121 if (g.groupType != DataModel::GroupType::Output)
4122 continue;
4123
4124 if (sourceId >= 0 && g.sourceId != sourceId)
4125 continue;
4126
4127 groupId = g.groupId;
4128 m_selectedGroup = g;
4129 break;
4130 }
4131 }
4132
4133 if (groupId < 0) {
4134 addGroup(tr("Output Controls"), SerialStudio::NoGroupWidget, sourceId);
4135 auto& group = m_groups.back();
4136 group.groupType = DataModel::GroupType::Output;
4137 groupId = group.groupId;
4138 m_selectedGroup = group;
4139 }
4140
4141 auto& group = m_groups[groupId];
4142
4143 QString title;
4144 switch (type) {
4145 case SerialStudio::OutputButton:
4146 title = tr("New Button");
4147 break;
4148 case SerialStudio::OutputSlider:
4149 title = tr("New Slider");
4150 break;
4151 case SerialStudio::OutputToggle:
4152 title = tr("New Toggle");
4153 break;
4154 case SerialStudio::OutputTextField:
4155 title = tr("New Text Field");
4156 break;
4157 case SerialStudio::OutputKnob:
4158 title = tr("New Knob");
4159 break;
4160 }
4161
4162 DataModel::OutputWidget ow;
4163 ow.widgetId = static_cast<int>(group.outputWidgets.size());
4164 ow.groupId = groupId;
4165 ow.sourceId = group.sourceId;
4166 ow.title = title;

Callers 1

outputWidgetAddMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected