1 // File: ModuleBase_WidgetFeature.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetFeature.h>
7 #include <Config_Keywords.h>
8 #include <Config_WidgetAPI.h>
10 #include <Events_Loop.h>
11 #include <Model_Events.h>
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_AttributeRefAttr.h>
20 #include <QHBoxLayout>
23 ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
24 const Config_WidgetAPI* theData)
25 : ModuleBase_ModelWidget(theParent, theData)
27 QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
28 myFeatureKinds = aKinds.split(" ");
30 myContainer = new QWidget(theParent);
31 QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
32 aControlLay->setContentsMargins(0, 0, 0, 0);
34 QString aLabelText = QString::fromStdString(theData->widgetLabel());
35 myLabel = new QLabel(aLabelText, myContainer);
36 aControlLay->addWidget(myLabel);
38 myEditor = new QLineEdit(myContainer);
39 QString anObjName = QString::fromStdString(attributeID());
40 myEditor->setObjectName(anObjName);
41 myEditor->setReadOnly(true);
42 aControlLay->addWidget(myEditor);
44 QString aTTip = QString::fromStdString(theData->widgetTooltip());
45 myEditor->setToolTip(aTTip);
47 aControlLay->addWidget(myEditor);
48 aControlLay->setStretch(1, 1);
51 ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature()
55 bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
57 if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str()))
60 myFeature = theFeature;
61 myEditor->setText(theFeature ? theFeature->data()->getName().c_str() : "");
66 bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const
68 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
69 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
70 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
72 ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
73 aRef->setFeature(myFeature);
74 theFeature->execute();
75 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
80 bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature)
82 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
83 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
84 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
86 myFeature = aRef->feature();
87 myEditor->setText(myFeature ? myFeature->data()->getName().c_str() : "");
91 QWidget* ModuleBase_WidgetFeature::getControl() const
96 QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
98 QList<QWidget*> aList;
99 aList.append(myLabel);
100 aList.append(myEditor);