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>
11 #include "Config_WidgetAPI.h"
13 #include <Events_Loop.h>
18 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
19 const std::string& theParentId)
21 myParentId(theParentId)
23 myIsComputedDefault = false;
24 myAttributeID = theData ? theData->widgetId() : "";
27 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
29 return theObject->data()->attribute(attributeID())->isInitialized();
32 bool ModuleBase_ModelWidget::focusTo()
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) {
46 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
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);
53 void ModuleBase_ModelWidget::processFocus(QWidget* theWidget)
55 theWidget->setFocusPolicy(Qt::StrongFocus);
56 theWidget->installEventFilter(this);
57 myFocusInWidgets.append(theWidget);
60 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
62 QWidget* aWidget = dynamic_cast<QWidget*>(theObject);
63 if (theEvent->type() == QEvent::FocusIn && myFocusInWidgets.contains(aWidget)) {
64 emit focusInWidget(this);
67 // pass the event on to the parent class
68 return QObject::eventFilter(theObject, theEvent);