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>
10 #include <Config_Keywords.h>
11 #include <Config_WidgetAPI.h>
13 #include <Events_Loop.h>
14 #include <ModelAPI_Events.h>
16 #include <ModelAPI_Feature.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Object.h>
19 #include <ModelAPI_AttributeRefAttr.h>
23 #include <QHBoxLayout>
26 ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
27 const Config_WidgetAPI* theData)
28 : ModuleBase_ModelWidget(theParent, theData)
30 QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
31 myObjectKinds = aKinds.split(" ");
33 myContainer = new QWidget(theParent);
34 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
35 aControlLay->setContentsMargins(0, 0, 0, 0);
37 QString aLabelText = QString::fromStdString(theData->widgetLabel());
38 myLabel = new QLabel(aLabelText, myContainer);
39 aControlLay->addWidget(myLabel);
41 myEditor = new QLineEdit(myContainer);
42 QString anObjName = QString::fromStdString(attributeID());
43 myEditor->setObjectName(anObjName);
44 myEditor->setReadOnly(true);
45 aControlLay->addWidget(myEditor);
47 QString aTTip = QString::fromStdString(theData->widgetTooltip());
48 myEditor->setToolTip(aTTip);
50 aControlLay->addWidget(myEditor);
51 aControlLay->setStretch(1, 1);
54 ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature()
58 bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue)
63 ModuleBase_WidgetValueFeature* aFeatureValue =
64 dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
66 isDone = setObject(aFeatureValue->object());
71 bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject)
74 //if (!myObjectKinds.contains(theObject->getKind().c_str()))
78 myEditor->setText(theObject ? theObject->data()->name().c_str() : "");
83 bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const
85 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
88 boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
89 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
90 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
92 ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
93 aRef->setObject(myObject);
95 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
100 bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject)
102 boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
103 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
104 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
106 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
109 myEditor->setText(myObject ? myObject->data()->name().c_str() : "");
115 QWidget* ModuleBase_WidgetFeature::getControl() const
120 QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
122 QList<QWidget*> aList;
123 aList.append(myLabel);
124 aList.append(myEditor);