1 // File: ModuleBase_WidgetFeature.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetFeature.h>
7 #include <ModuleBase_WidgetValueFeature.h>
8 #include <ModuleBase_WidgetValue.h>
9 #include <ModuleBase_ResultValidators.h>
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
14 #include <Events_Loop.h>
15 #include <ModelAPI_Events.h>
17 #include <ModelAPI_Feature.h>
18 #include <ModelAPI_Data.h>
19 #include <ModelAPI_Object.h>
20 #include <ModelAPI_AttributeRefAttr.h>
21 #include <ModelAPI_Validator.h>
25 #include <QHBoxLayout>
28 ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
29 const Config_WidgetAPI* theData,
30 const std::string& theParentId)
31 : ModuleBase_ModelWidget(theParent, theData, theParentId)
33 //QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
34 //myObjectKinds = aKinds.split(" ");
37 myContainer = new QWidget(theParent);
38 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
39 aControlLay->setContentsMargins(0, 0, 0, 0);
41 QString aLabelText = QString::fromStdString(theData->widgetLabel());
42 myLabel = new QLabel(aLabelText, myContainer);
43 aControlLay->addWidget(myLabel);
45 myEditor = new QLineEdit(myContainer);
46 QString anObjName = QString::fromStdString(attributeID());
47 myEditor->setObjectName(anObjName);
48 myEditor->setReadOnly(true);
49 aControlLay->addWidget(myEditor);
51 QString aTTip = QString::fromStdString(theData->widgetTooltip());
52 myEditor->setToolTip(aTTip);
54 aControlLay->addWidget(myEditor);
55 aControlLay->setStretch(1, 1);
58 ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature()
62 bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue)
67 ModuleBase_WidgetValueFeature* aFeatureValue =
68 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
70 isDone = setObject(aFeatureValue->object());
75 bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject)
77 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
78 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
79 std::list<ModelAPI_Validator*> aValidators;
80 std::list<std::list<std::string> > anArguments;
81 aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
82 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
84 for(; aValidator != aValidators.end(); aValidator++) {
85 const ModuleBase_ResultValidator* aResValidator =
86 dynamic_cast<const ModuleBase_ResultValidator*>(*aValidator);
89 if (aResValidator->isValid(theObject)) {
99 myEditor->setText(theObject ? theObject->data()->name().c_str() : "");
100 emit valuesChanged();
104 bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const
106 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
109 boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
110 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
111 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
113 ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
114 aRef->setObject(myObject);
116 updateObject(theObject);
120 bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject)
122 boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
123 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
124 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
126 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
129 myEditor->setText(myObject ? myObject->data()->name().c_str() : "");
135 QWidget* ModuleBase_WidgetFeature::getControl() const
140 QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
142 QList<QWidget*> aList;
143 aList.append(myLabel);
144 aList.append(myEditor);