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 <Model_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 myFeatureKinds = 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 = setFeature(aFeatureValue->feature());
71 bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
73 if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str()))
76 myFeature = theFeature;
77 myEditor->setText(theFeature ? theFeature->data()->getName().c_str() : "");
82 bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const
84 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
85 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
86 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
88 ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
89 aRef->setFeature(myFeature);
90 theFeature->execute();
91 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
96 bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature)
98 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
99 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
100 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
102 myFeature = aRef->feature();
103 myEditor->setText(myFeature ? myFeature->data()->getName().c_str() : "");
107 QWidget* ModuleBase_WidgetFeature::getControl() const
112 QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
114 QList<QWidget*> aList;
115 aList.append(myLabel);
116 aList.append(myEditor);