From 1eb338bda4fd99a4db24005f62a073a2866c9689 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 26 Mar 2015 19:05:31 +0300 Subject: [PATCH] Update Config after merging with master --- src/Config/Config_Common.cpp | 2 +- src/Config/Config_Common.h | 2 ++ src/Config/Config_Keywords.h | 1 + src/Config/Config_ValidatorReader.cpp | 42 +++++++++++++++++---------- src/Config/Config_ValidatorReader.h | 8 +++++ 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index 8ffc9e126..8c8cde427 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -69,7 +69,7 @@ bool isWidgetNode(xmlNodePtr theNode) { if(!isElementNode(theNode)) return false; - // it's parent is "feature" or "source" + // it's parent is "feature" or "source" or a page ("box", "case") if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL)) return false; diff --git a/src/Config/Config_Common.h b/src/Config/Config_Common.h index 52fc1e172..1850f8a7b 100644 --- a/src/Config/Config_Common.h +++ b/src/Config/Config_Common.h @@ -43,6 +43,8 @@ CONFIG_EXPORT bool isElementNode(xmlNodePtr theNode); */ CONFIG_EXPORT bool isNode(xmlNodePtr theNode, const char* theNodeName, ...); +//#define isNode(p) _isNode(p, NULL) + /*! * Checks if the given node is attribute node. * Attribute node represents a widget, that is able to store/restore diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index afb80188b..bc115a764 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -19,6 +19,7 @@ const static char* NODE_FEATURE = "feature"; const static char* NODE_SOURCE = "source"; const static char* NODE_VALIDATOR = "validator"; const static char* NODE_SELFILTER = "selection_filter"; +const static char* NODE_XMLPARENT = "libxml_parent"; // Widgets const static char* WDG_INFO = "label"; diff --git a/src/Config/Config_ValidatorReader.cpp b/src/Config/Config_ValidatorReader.cpp index d03dff58d..ef969cd55 100644 --- a/src/Config/Config_ValidatorReader.cpp +++ b/src/Config/Config_ValidatorReader.cpp @@ -42,11 +42,26 @@ void Config_ValidatorReader::processNode(xmlNodePtr theNode) processSelectionFilter(theNode); } else if (isNode(theNode, NODE_FEATURE, NULL)) { storeAttribute(theNode, _ID); + } else if (isWidgetNode(theNode)) { + storeAttribute(theNode, _ID); + // Store widget name to restore it's id on validator/selector processing + myCurrentWidget = getNodeName(theNode); } //Process SOURCE nodes. Config_XMLReader::processNode(theNode); } +void Config_ValidatorReader::cleanup(xmlNodePtr theNode) +{ + if (isNode(theNode, NODE_FEATURE, NULL)) { + cleanupAttribute(theNode, _ID); + } else if (isWidgetNode(theNode)) { + cleanupAttribute(NODE_XMLPARENT, _ID); + // Cleanup widget name when leave the widget node. + myCurrentWidget = ""; + } +} + bool Config_ValidatorReader::processChildren(xmlNodePtr aNode) { return true; @@ -63,14 +78,12 @@ void Config_ValidatorReader::processValidator(xmlNodePtr theNode) getParametersInfo(theNode, aValidatorId, aParameters); aMessage->setValidatorId(aValidatorId); aMessage->setValidatorParameters(aParameters); - //TODO(sbh): update feature/attribute id restoring - // when "cleanup" technique will be available (v. >= 1.1.0) - xmlNodePtr aFeatureOrWdgNode = theNode->parent; - if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { - aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); - } else { - aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); - aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID)); + std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID); + aMessage->setFeatureId(aFeatureId); + // parent is attribute (widget) + if (!myCurrentWidget.empty()) { + std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID); + aMessage->setAttributeId(aParentId); } aEvLoop->send(aMessage); } @@ -86,13 +99,12 @@ void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode) getParametersInfo(theNode, aSelectionFilterId, aParameters); aMessage->setSelectionFilterId(aSelectionFilterId); aMessage->setFilterParameters(aParameters); - - xmlNodePtr aFeatureOrWdgNode = theNode->parent; - if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { - aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); - } else { - aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); - aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID)); + std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID); + aMessage->setFeatureId(aFeatureId); + // parent is attribute (widget) + if (!myCurrentWidget.empty()) { + std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID); + aMessage->setAttributeId(aParentId); } aEvLoop->send(aMessage); } diff --git a/src/Config/Config_ValidatorReader.h b/src/Config/Config_ValidatorReader.h index f2ac6293d..59f6acffb 100644 --- a/src/Config/Config_ValidatorReader.h +++ b/src/Config/Config_ValidatorReader.h @@ -45,6 +45,11 @@ class Config_ValidatorReader : public Config_XMLReader */ virtual bool processChildren(xmlNodePtr aNode); + /*! + * Cleans the cached information about parent feature or attribute (widget) + */ + virtual void cleanup(xmlNodePtr theNode); + /*! * \brief Retrieves all the necessary info from the validator node. * Sends ValidatorLoaded event @@ -55,6 +60,9 @@ class Config_ValidatorReader : public Config_XMLReader * Sends SelectionFilterLoaded event */ void processSelectionFilter(xmlNodePtr theNode); + + private: + std::string myCurrentWidget; }; #endif /* CONFIG_VALIDATORREADER_H_ */ -- 2.39.2