#include "ModuleBase_SelectorWidget.h"
#include "ModuleBase_IWorkshop.h"
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_AttributeReference.h>
#include <QToolButton>
#include <QString>
#include <QEvent>
+#include <QDockWidget>
ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent,
}
//********************************************************************
-bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature)
+bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const
{
DataPtr aData = theFeature->data();
boost::shared_ptr<ModelAPI_AttributeReference> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
- aRef->setFeature(mySelectedFeature);
-
+ FeaturePtr aFeature = aRef->value();
+ if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
+ aRef->setValue(mySelectedFeature);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ }
return true;
}
bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(myFeatureAttributeID);
+ bool isBlocked = this->blockSignals(true);
mySelectedFeature = aRef->value();
updateSelectionName();
- return true;
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::canFocusTo(const std::string& theAttributeName)
-{
- return false;
-}
-//********************************************************************
-void ModuleBase_SelectorWidget::focusTo()
-{
+ this->blockSignals(isBlocked);
+ return true;
}
//********************************************************************
return;
// TODO: Check that the selection corresponds to selection type
+ // TODO: Use the feature kind definition like SKETCH_KIND instead of the direct text
+ if (aFeature->getKind().compare("Sketch") != 0)
+ return;
+
mySelectedFeature = aFeature;
if (mySelectedFeature) {
updateSelectionName();
activateSelection(false);
+ raisePanel();
} else {
myTextLine->setText("");
}
}
//********************************************************************
-void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable)
+void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable) const
{
QWidget* aParent = myContainer->parentWidget();
QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
myActivateBtn->setDown(toActivate);
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::raisePanel() const
+{
+ QWidget* aParent = myContainer->parentWidget();
+ QWidget* aLastPanel = 0;
+ while (!aParent->inherits("QDockWidget")) {
+ aLastPanel = aParent;
+ aParent = aParent->parentWidget();
+ if (!aParent) return;
+ }
+ if (aParent->inherits("QDockWidget")) {
+ QDockWidget* aTabWgt = (QDockWidget*) aParent;
+ aTabWgt->raise();
+ }
}
\ No newline at end of file