| 235 | } |
| 236 | |
| 237 | void Element::fromXMLNode(const tinyxml2::XMLElement *xmlNode, const ElementPtr &parentOfNode) { |
| 238 | if (nullptr == xmlNode) |
| 239 | return; |
| 240 | // BLOG("This Node is %s", std::string(xmlNode->GetText()).c_str()); |
| 241 | int indexOfNode = 0; |
| 242 | tinyxml2::XMLError err = xmlNode->QueryIntAttribute("index", &indexOfNode); |
| 243 | if (err == tinyxml2::XML_SUCCESS) { |
| 244 | this->_index = indexOfNode; |
| 245 | } |
| 246 | const char *boundingBoxStr = "get attribute failed"; |
| 247 | err = xmlNode->QueryStringAttribute("bounds", &boundingBoxStr); |
| 248 | if (err == tinyxml2::XML_SUCCESS) { |
| 249 | int xl, yl, xr, yr; |
| 250 | if (sscanf(boundingBoxStr, "[%d,%d][%d,%d]", &xl, &yl, &xr, &yr) == 4) { |
| 251 | this->_bounds = std::make_shared<Rect>(xl, yl, xr, yr); |
| 252 | if (this->_bounds->isEmpty()) |
| 253 | this->_bounds = Rect::RectZero; |
| 254 | } |
| 255 | } |
| 256 | const char *text = "attribute text get failed"; // need copy |
| 257 | err = xmlNode->QueryStringAttribute("text", &text); |
| 258 | if (err == tinyxml2::XML_SUCCESS) { |
| 259 | this->_text = std::string(text); // copy |
| 260 | } |
| 261 | const char *resource_id = "attribute resource_id get failed"; // need copy |
| 262 | err = xmlNode->QueryStringAttribute("resource-id", &resource_id); |
| 263 | if (err == tinyxml2::XML_SUCCESS) { |
| 264 | this->_resourceID = std::string(resource_id); // copy |
| 265 | } |
| 266 | const char *tclassname = "attribute class name get failed"; // need copy |
| 267 | err = xmlNode->QueryStringAttribute("class", &tclassname); |
| 268 | if (err == tinyxml2::XML_SUCCESS) { |
| 269 | this->_classname = std::string(tclassname); // copy |
| 270 | } |
| 271 | const char *pkgname = "attribute package name get failed"; // need copy |
| 272 | err = xmlNode->QueryStringAttribute("package", &pkgname); |
| 273 | if (err == tinyxml2::XML_SUCCESS) { |
| 274 | this->_packageName = std::string(pkgname); // copy |
| 275 | } |
| 276 | const char *content_desc = "attribute content description get failed"; // need copy |
| 277 | err = xmlNode->QueryStringAttribute("content-desc", &content_desc); |
| 278 | if (err == tinyxml2::XML_SUCCESS) { |
| 279 | this->_contentDesc = std::string(content_desc); // copy |
| 280 | } |
| 281 | bool checkable = false; |
| 282 | err = xmlNode->QueryBoolAttribute("checkable", &checkable); |
| 283 | if (err == tinyxml2::XML_SUCCESS) { |
| 284 | this->_checkable = checkable; |
| 285 | } |
| 286 | bool clickable = false; |
| 287 | err = xmlNode->QueryBoolAttribute("clickable", &clickable); |
| 288 | if (err == tinyxml2::XML_SUCCESS) { |
| 289 | this->_clickable = clickable; |
| 290 | } |
| 291 | if (clickable) |
| 292 | _allClickableFalse = false; |
| 293 | bool checked = false; |
| 294 | err = xmlNode->QueryBoolAttribute("checked", &checked); |
no test coverage detected