]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ModelWidget.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 <QEvent>
16 #include <QWidget>
17
18 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
19                                                const std::string& theParentId)
20     : QObject(theParent),
21       myParentId(theParentId)
22 {
23   myIsComputedDefault = false;
24   myAttributeID = theData ? theData->widgetId() : "";
25 }
26
27 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
28 {
29   return theObject->data()->attribute(attributeID())->isInitialized();
30 }
31
32 bool ModuleBase_ModelWidget::focusTo()
33 {
34   QList<QWidget*> aControls = getControls();
35   QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
36   for (; anIt != aLast; anIt++) {
37     QWidget* aWidget = *anIt;
38     if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
39       aWidget->setFocus();
40       break;
41     }
42   }
43   return true;
44 }
45
46 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
47 {
48   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
49   static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
50   ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
51 }
52
53 void ModuleBase_ModelWidget::processFocus(QWidget* theWidget)
54 {
55   theWidget->setFocusPolicy(Qt::StrongFocus);
56   theWidget->installEventFilter(this);
57   myFocusInWidgets.append(theWidget);
58 }
59
60 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
61 {
62   QWidget* aWidget = dynamic_cast<QWidget*>(theObject);
63   if (theEvent->type() == QEvent::FocusIn && myFocusInWidgets.contains(aWidget)) {
64     emit focusInWidget(this);
65     return true;
66   } else {
67     // pass the event on to the parent class
68     return QObject::eventFilter(theObject, theEvent);
69   }
70 }