| 2141 | |
| 2142 | |
| 2143 | Attribute *Module::add_attribute( |
| 2144 | const std::string &title, |
| 2145 | const utility::JsonStore &value, |
| 2146 | const utility::JsonStore &role_data) { |
| 2147 | Attribute *attr = nullptr; |
| 2148 | |
| 2149 | if (role_data.contains("combo_box_options")) { |
| 2150 | |
| 2151 | // we need to do some specific type checking if the caller is trying |
| 2152 | // to create a combo box (string choice) attribute |
| 2153 | const auto &opts = role_data["combo_box_options"]; |
| 2154 | if (!opts.is_array()) { |
| 2155 | throw std::runtime_error("combo_box_options must be a list of strings."); |
| 2156 | } |
| 2157 | |
| 2158 | if (!value.is_string()) { |
| 2159 | throw std::runtime_error( |
| 2160 | "Attr providing combo_box_optionsrole data must have string type value."); |
| 2161 | } |
| 2162 | |
| 2163 | std::vector<std::string> options; |
| 2164 | auto cs = opts.begin(); |
| 2165 | while (cs != opts.end()) { |
| 2166 | if (!cs.value().is_string()) { |
| 2167 | throw std::runtime_error("combo_box_options must be a list of strings."); |
| 2168 | } |
| 2169 | options.push_back(cs.value().get<std::string>()); |
| 2170 | cs++; |
| 2171 | } |
| 2172 | |
| 2173 | attr = static_cast<Attribute *>( |
| 2174 | add_string_choice_attribute(title, title, value.get<std::string>(), options)); |
| 2175 | |
| 2176 | } else if (role_data.contains("qml_code")) { |
| 2177 | |
| 2178 | attr = static_cast<Attribute *>( |
| 2179 | add_qml_code_attribute(title, role_data["qml_code"].get<std::string>())); |
| 2180 | |
| 2181 | } else if (role_data.contains("menu_paths")) { |
| 2182 | |
| 2183 | attr = static_cast<Attribute *>(add_action_attribute(title, title)); |
| 2184 | |
| 2185 | } else if (value.is_number_integer()) { |
| 2186 | |
| 2187 | attr = static_cast<Attribute *>(add_integer_attribute(title, title, value.get<int>())); |
| 2188 | |
| 2189 | } else if (value.is_number_float()) { |
| 2190 | |
| 2191 | attr = static_cast<Attribute *>(add_float_attribute(title, title, value.get<float>())); |
| 2192 | |
| 2193 | } else if (value.is_boolean()) { |
| 2194 | |
| 2195 | attr = static_cast<Attribute *>(add_boolean_attribute(title, title, value.get<bool>())); |
| 2196 | |
| 2197 | } else if (value.is_string()) { |
| 2198 | |
| 2199 | attr = static_cast<Attribute *>( |
| 2200 | add_string_attribute(title, title, value.get<std::string>())); |
no test coverage detected