Salome HOME
Fix sketcher bugs
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.cpp
1 // File:        ModuleBase_ModelWidget.h
2 // Created:     25 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include "ModuleBase_ModelWidget.h"
6
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_Attribute.h>
9 #include <ModelAPI_Events.h>
10
11 #include "Config_WidgetAPI.h"
12
13 #include <Events_Loop.h>
14
15 #include <QWidget>
16
17 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, 
18   const Config_WidgetAPI* theData, 
19   const std::string& theParentId)
20  : QObject(theParent), myHasDefaultValue(false), myParentId(theParentId)
21 {
22   myAttributeID = theData ? theData->widgetId() : "";
23 }
24
25 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
26 {
27   return theObject->data()->attribute(attributeID())->isInitialized();
28 }
29
30 bool ModuleBase_ModelWidget::focusTo()
31 {
32   QList<QWidget*> aControls = getControls();
33   QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
34   for (; anIt != aLast; anIt++) {
35     QWidget* aWidget = *anIt;
36     if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
37       aWidget->setFocus();
38       break;
39     }
40   }
41   return true;
42 }
43
44
45 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
46 {
47   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
48   static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
49   ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
50 }