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>
10 #include <ModuleBase_Tools.h>
12 #include <Config_Keywords.h>
13 #include <Config_WidgetAPI.h>
15 #include <Events_Loop.h>
16 #include <ModelAPI_Events.h>
18 #include <ModelAPI_Feature.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Object.h>
21 #include <ModelAPI_AttributeRefAttr.h>
22 #include <ModelAPI_Validator.h>
26 #include <QHBoxLayout>
29 ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
30 const Config_WidgetAPI* theData,
31 const std::string& theParentId)
32 : ModuleBase_ModelWidget(theParent, theData, theParentId)
34 //QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
35 //myObjectKinds = aKinds.split(" ");
38 myContainer = new QWidget(theParent);
39 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
40 aControlLay->setContentsMargins(0, 0, 0, 0);
42 QString aLabelText = QString::fromStdString(theData->widgetLabel());
43 myLabel = new QLabel(aLabelText, myContainer);
44 aControlLay->addWidget(myLabel);
46 myEditor = new QLineEdit(myContainer);
47 QString anObjName = QString::fromStdString(attributeID());
48 myEditor->setObjectName(anObjName);
49 myEditor->setReadOnly(true);
50 aControlLay->addWidget(myEditor);
52 QString aTTip = QString::fromStdString(theData->widgetTooltip());
53 myEditor->setToolTip(aTTip);
55 aControlLay->addWidget(myEditor);
56 aControlLay->setStretch(1, 1);
59 ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature()
63 bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue)
68 ModuleBase_WidgetValueFeature* aFeatureValue =
69 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
71 isDone = setObject(aFeatureValue->object());
76 bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSendEvent)
78 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
79 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
80 std::list<ModelAPI_Validator*> aValidators;
81 std::list<std::list<std::string> > anArguments;
82 aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
83 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
85 for(; aValidator != aValidators.end(); aValidator++) {
86 const ModuleBase_ResultValidator* aResValidator =
87 dynamic_cast<const ModuleBase_ResultValidator*>(*aValidator);
90 if (aResValidator->isValid(theObject)) {
99 myObject = ModuleBase_Tools::feature(theObject);
100 myEditor->setText(theObject ? theObject->data()->name().c_str() : "");
102 emit valuesChanged();
106 bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const
108 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
111 boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
112 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
113 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
115 ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
116 aRef->setObject(myObject);
118 updateObject(theObject);
122 bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject)
124 boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
125 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
126 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
128 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
131 myEditor->setText(myObject ? myObject->data()->name().c_str() : "");
137 QWidget* ModuleBase_WidgetFeature::getControl() const
142 QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
144 QList<QWidget*> aList;
145 aList.append(myLabel);
146 aList.append(myEditor);