]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ModelWidget.cpp
Salome HOME
Issue #115 The "computed" xml attribute processing
[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, const Config_WidgetAPI* theData,
18                                                const std::string& theParentId)
19     : QObject(theParent),
20       myParentId(theParentId)
21 {
22   myIsComputedDefault = false;
23   myAttributeID = theData ? theData->widgetId() : "";
24 }
25
26 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
27 {
28   return theObject->data()->attribute(attributeID())->isInitialized();
29 }
30
31 void ModuleBase_ModelWidget::setAttributeComputedState(ObjectPtr theObject) const
32 {
33   if(myIsComputedDefault)
34     theObject->data()->attribute(attributeID())->setComputedDefault();
35 }
36
37 bool ModuleBase_ModelWidget::focusTo()
38 {
39   QList<QWidget*> aControls = getControls();
40   QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
41   for (; anIt != aLast; anIt++) {
42     QWidget* aWidget = *anIt;
43     if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
44       aWidget->setFocus();
45       break;
46     }
47   }
48   return true;
49 }
50
51 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
52 {
53   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
54   static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
55   ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
56 }