myFeatureId = std::string(); // Feature unique id
myIsObligatory = true;
myIsConcealment = false;
- myCaseId = std::string();
}
Config_AttributeMessage::~Config_AttributeMessage()
this->myIsObligatory = theObligatory;
}
-const std::string& Config_AttributeMessage::caseId() const
+const std::list<std::pair<std::string, std::string> >& Config_AttributeMessage::getCases() const
{
- return myCaseId;
+ return myCases;
}
-const std::string& Config_AttributeMessage::switchId() const
+void Config_AttributeMessage::setCases(const std::list<std::pair<std::string, std::string> >& theCases)
{
- return mySwitchId;
-}
-
-void Config_AttributeMessage::setCaseId(const std::string& theId)
-{
- this->myCaseId = theId;
-}
-
-void Config_AttributeMessage::setSwitchId(const std::string& theId)
-{
- this->mySwitchId = theId;
+ myCases = theCases;
}
#include <Events_Message.h>
#include <string>
+#include <list>
/*!
* \class Config_AttributeMessage
std::string myFeatureId; ///< Attribute's feature's unique id
bool myIsObligatory; ///< Required to be set by user, else it's feature is invalid.
bool myIsConcealment; ///< If true, conceals features used as input
- std::string myCaseId; ///< Attribute's case's id, if it placed inside a paged containers
- std::string mySwitchId; ///< Attribute's switch id, if it placed inside a paged containers
+ ///< a list of pairs, if the attribute is placed inside paged containers: (case, switch)
+ std::list<std::pair<std::string, std::string> > myCases;
- public:
+public:
/// Same event as Config_FeatureMessage::MODEL_EVENT()
inline static const char* MODEL_EVENT()
{
CONFIG_EXPORT bool isObligatory() const;
/// Returns true if attribute should conceal input features
CONFIG_EXPORT bool isConcealment() const;
- /// Returns id of a case which contain the attribute
- CONFIG_EXPORT const std::string& caseId() const;
- /// Returns id of a switch which contain the attribute
- CONFIG_EXPORT const std::string& switchId() const;
+ /// Returns container of ids of pair of a case and switches
+ CONFIG_EXPORT const std::list<std::pair<std::string, std::string> >& getCases() const;
+ /// Sets ids of pair of a case and switches
+ CONFIG_EXPORT void setCases(const std::list<std::pair<std::string, std::string> >& theCases);
/// Set attribute's unique id
CONFIG_EXPORT void setAttributeId(const std::string& theId);
CONFIG_EXPORT void setConcealment(bool isConcealment);
/// Set attribute's obligatory state
CONFIG_EXPORT void setObligatory(bool isObligatory);
- /// Set attribute's case
- CONFIG_EXPORT void setCaseId(const std::string& id);
- /// Set attribute's switch
- CONFIG_EXPORT void setSwitchId(const std::string& id);
};
#endif // ATTRIBUTE_MESSAGE_H
return false;\r
}\r
\r
-bool hasParentRecursive(xmlNodePtr theNode, const std::vector<const char*>& theNodeNames)\r
+xmlNodePtr hasParentRecursive(xmlNodePtr theNode, const std::vector<const char*>& theNodeNames)\r
{\r
if (!hasParent(theNode)) {\r
- return false; // have no parents at all\r
+ return 0; // have no parents at all\r
}\r
xmlNodePtr aNode = theNode->parent;\r
const xmlChar* aName = aNode->name;\r
if (!aName || !isElementNode(aNode)) {\r
- return false;\r
+ return 0;\r
}\r
for (size_t anIndex = 0; anIndex < theNodeNames.size(); ++anIndex) {\r
if (!xmlStrcmp(aName, (const xmlChar *) theNodeNames[anIndex]))\r
- return true;\r
+ return aNode;\r
}\r
return hasParentRecursive(aNode, theNodeNames);\r
}\r
\r
-bool hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...)\r
+xmlNodePtr hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...)\r
{\r
std::vector<const char*> aNodeNames;\r
va_list args; // define argument list variable\r
/*!
* Checks if the given node has any valid parent in hierarchy with any of the given node names.
*/
-CONFIG_EXPORT bool hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...);
+CONFIG_EXPORT xmlNodePtr hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...);
/*!
aMessage->setAttributeId(anAttributeID);
aMessage->setObligatory(getBooleanAttribute(theNode, ATTR_OBLIGATORY, true));
aMessage->setConcealment(getBooleanAttribute(theNode, ATTR_CONCEALMENT, false));
- if (hasParentRecursive(theNode, WDG_CHECK_GROUP, NULL)) {
- const char* kWdgCase = WDG_CHECK_GROUP;
- const char* kWdgSwitch = WDG_CHECK_GROUP;
- aMessage->setCaseId(restoreAttribute(kWdgCase, _ID));
- aMessage->setSwitchId(restoreAttribute(kWdgSwitch, _ID));
- }
- // nested "paged" widgets are not allowed, this issue may be resolved here:
- else if (hasParentRecursive(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, NULL)) {
- const char* kWdgCase = hasParentRecursive(theNode, WDG_SWITCH_CASE, NULL)
- ? WDG_SWITCH_CASE
- : WDG_TOOLBOX_BOX;
- const char* kWdgSwitch = hasParentRecursive(theNode, WDG_SWITCH_CASE, NULL)
- ? WDG_SWITCH
- : WDG_TOOLBOX;
- aMessage->setCaseId(restoreAttribute(kWdgCase, _ID));
- aMessage->setSwitchId(restoreAttribute(kWdgSwitch, _ID));
+
+ std::list<std::pair<std::string, std::string> > aCases;
+ xmlNodePtr aCaseNode = hasParentRecursive(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, WDG_CHECK_GROUP, NULL);
+ while(aCaseNode) {
+ std::string aCaseNodeID = getProperty(aCaseNode, _ID);
+ std::string aSwitchNodeID = "";
+ const xmlChar* aName = aCaseNode->name;
+ xmlNodePtr aSwitchNode;
+ if (!xmlStrcmp(aName, (const xmlChar *) WDG_SWITCH_CASE)) {
+ aSwitchNode = hasParentRecursive(aCaseNode, WDG_SWITCH, NULL);
+ }
+ else if (!xmlStrcmp(aName, (const xmlChar *) WDG_TOOLBOX_BOX)) {
+ aSwitchNode = hasParentRecursive(aCaseNode, WDG_TOOLBOX, NULL);
+ }
+ if (!xmlStrcmp(aName, (const xmlChar *) WDG_CHECK_GROUP)) {
+ /// the box is optional, attribute is in case if the optional attribute value is not empty
+ aSwitchNode = aCaseNode;
+ }
+ if (aSwitchNode)
+ aSwitchNodeID = getProperty(aSwitchNode, _ID);
+
+ aCases.push_back(std::make_pair(aSwitchNodeID, aCaseNodeID));
+ aCaseNode = hasParentRecursive(aSwitchNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, WDG_CHECK_GROUP, NULL);
}
+ aMessage->setCases(aCases);
Events_Loop::loop()->send(aMessage);
}
// container pages, like "case" or "box"
if(aMsgAttr->isConcealment()) {
validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
}
- if (!aMsgAttr->caseId().empty()) {
- validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(),
- aMsgAttr->switchId(), aMsgAttr->caseId());
+ const std::list<std::pair<std::string, std::string> >& aCases = aMsgAttr->getCases();
+ if (!aCases.empty()) {
+ validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases);
}
}
}
}
void Model_ValidatorsFactory::registerCase(std::string theFeature, std::string theAttribute,
- std::string theSwitchId, std::string theCaseId)
+ const std::list<std::pair<std::string, std::string> >& theCases)
{
- std::map<std::string, std::map<std::string, std::pair<std::string, std::set<std::string> > > >
+ std::map<std::string, std::map<std::string, std::map<std::string, std::set<std::string> > > >
::iterator aFindFeature = myCases.find(theFeature);
if (aFindFeature == myCases.end()) {
- myCases[theFeature] = std::map<std::string, std::pair<std::string, std::set<std::string> > >();
+ myCases[theFeature] = std::map<std::string, std::map<std::string, std::set<std::string> > >();
aFindFeature = myCases.find(theFeature);
}
- std::map<std::string, std::pair<std::string, std::set<std::string> > >::iterator aFindAttrID =
+ std::map<std::string, std::map<std::string, std::set<std::string> > >::iterator aFindAttrID =
aFindFeature->second.find(theAttribute);
+
if (aFindAttrID == aFindFeature->second.end()) {
aFindFeature->second[theAttribute] =
- std::pair<std::string, std::set<std::string> >(theSwitchId, std::set<std::string>());
+ std::map<std::string, std::set<std::string> >();
aFindAttrID = aFindFeature->second.find(theAttribute);
}
- aFindAttrID->second.second.insert(theCaseId);
+ std::list<std::pair<std::string, std::string> >::const_iterator aCasesIt = theCases.begin(),
+ aCasesLast = theCases.end();
+ std::map<std::string, std::set<std::string> > aFindCases = aFindAttrID->second;
+ for (; aCasesIt != aCasesLast; aCasesIt++) {
+ std::pair<std::string, std::string> aCasePair = *aCasesIt;
+ std::string aSwitch = aCasePair.first;
+ if (aFindAttrID->second.find(aSwitch) == aFindAttrID->second.end()) {
+ aFindAttrID->second[aSwitch] = std::set<std::string>();
+ }
+ aFindAttrID->second[aSwitch].insert(aCasePair.second);
+ }
}
bool Model_ValidatorsFactory::isCase(FeaturePtr theFeature, std::string theAttribute)
{
- std::map<std::string, std::map<std::string, std::pair<std::string, std::set<std::string> > > >
+ bool anInCase = true;
+ std::map<std::string, std::map<std::string, std::map<std::string, std::set<std::string> > > >
::iterator aFindFeature = myCases.find(theFeature->getKind());
if (aFindFeature != myCases.end()) {
- std::map<std::string, std::pair<std::string, std::set<std::string> > >::iterator
+ std::map<std::string, std::map<std::string, std::set<std::string> > >::iterator
aFindAttrID = aFindFeature->second.find(theAttribute);
if (aFindAttrID != aFindFeature->second.end()) {
- // the the switch-attribute that contains the case value
- AttributeStringPtr aSwitch = theFeature->string(aFindAttrID->second.first);
- if (aSwitch.get()) {
- // the second has the case identifier
- return aFindAttrID->second.second.find(aSwitch->value()) !=
- aFindAttrID->second.second.end();
+ std::map<std::string, std::set<std::string> >::iterator
+ aCasesIt = aFindAttrID->second.begin(), aCasesLast = aFindAttrID->second.end();
+ for (; aCasesIt != aCasesLast && anInCase; aCasesIt++) {
+ // the the switch-attribute that contains the case value
+ AttributeStringPtr aSwitch = theFeature->string(aCasesIt->first);
+ if (aSwitch.get()) {
+ // the second has the case identifier
+ anInCase = aCasesIt->second.find(aSwitch->value()) != aCasesIt->second.end();
+ }
}
}
}
- return true; // if no additional conditions, this attribute is the case to be validated
+ return anInCase; // if no additional conditions, this attribute is the case to be validated
}
/// Map from feature kind to map of attribute IDs to pair
// (switchId (ID of the attribute) and case Ids (possible values of the switch attribute))
std::map<std::string, std::map<std::string,
- std::pair<std::string, std::set<std::string> > > > myCases;
+ std::map<std::string, std::set<std::string> > > > myCases;
public:
/// Registers the instance of the validator by the ID
/// Returns true that it was registered that attribute conceals the referenced result
virtual bool isConcealed(std::string theFeature, std::string theAttribute);
+ /// register the case-attribute (\a myCases set definition)
+ //virtual void registerCase(std::string theFeature, std::string theAttribute,
+ // std::string theSwitchId, std::string theCaseId);
+
/// register the case-attribute (\a myCases set definition)
virtual void registerCase(std::string theFeature, std::string theAttribute,
- std::string theSwitchId, std::string theCaseId);
+ const std::list<std::pair<std::string, std::string> >& theCases);
/// Returns true if the attribute must be checked (the case is selected)
virtual bool isCase(FeaturePtr theFeature, std::string theAttribute);
/// Register the case-attribute: this attribute is checked only if its case is selected
virtual void registerCase(std::string theFeature, std::string theAttribute,
- std::string theSwitchId, std::string theCaseId) = 0;
+ const std::list<std::pair<std::string, std::string> >& theCases) = 0;
/// Returns true if the attribute must be checked (the case is selected)
virtual bool isCase(FeaturePtr theFeature, std::string theAttribute) = 0;
{
storeValue();
updateControlsVisibility();
+
+ if (!isEditingMode())
+ emit focusOutWidget(this);
}
void ModuleBase_WidgetCheckGroupBox::addPageStretch()