1 // File: ModuleBase_ModelWidget.h
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include "ModuleBase_ModelWidget.h"
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_Attribute.h>
9 #include <ModelAPI_Events.h>
10 #include <ModelAPI_Session.h>
12 #include <Config_Keywords.h>
13 #include <Config_WidgetAPI.h>
15 #include <Events_Loop.h>
20 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
21 const std::string& theParentId)
23 myParentId(theParentId)
25 myIsComputedDefault = false;
26 myIsObligatory = theData ? theData->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
27 myAttributeID = theData ? theData->widgetId() : "";
30 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
32 return theObject->data()->attribute(attributeID())->isInitialized();
35 void ModuleBase_ModelWidget::enableFocusProcessing()
37 QList<QWidget*> aMyControls = getControls();
38 foreach(QWidget* eachControl, aMyControls) {
39 if(!myFocusInWidgets.contains(eachControl)) {
40 enableFocusProcessing(eachControl);
45 bool ModuleBase_ModelWidget::focusTo()
47 QList<QWidget*> aControls = getControls();
48 QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
49 for (; anIt != aLast; anIt++) {
50 QWidget* aWidget = *anIt;
51 if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
60 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
62 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
63 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
64 ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
67 void ModuleBase_ModelWidget::enableFocusProcessing(QWidget* theWidget)
69 theWidget->setFocusPolicy(Qt::StrongFocus);
70 theWidget->installEventFilter(this);
71 myFocusInWidgets.append(theWidget);
74 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
76 QWidget* aWidget = dynamic_cast<QWidget*>(theObject);
77 if (theEvent->type() == QEvent::MouseButtonRelease &&
78 myFocusInWidgets.contains(aWidget)) {
79 emit focusInWidget(this);
81 // pass the event on to the parent class
82 return QObject::eventFilter(theObject, theEvent);