1 // File: ModuleBase_SelectorWidget.h
2 // Created: 2 June 2014
3 // Author: Vitaly Smetannikov
6 #include "ModuleBase_SelectorWidget.h"
7 #include "ModuleBase_IWorkshop.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_AttributeReference.h>
11 #include <Config_WidgetAPI.h>
17 #include <QToolButton>
20 ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent,
21 ModuleBase_IWorkshop* theWorkshop,
22 const Config_WidgetAPI* theData)
23 : ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop)
25 myFeatureAttributeID = theData->widgetId();
27 myContainer = new QWidget(theParent);
28 QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
30 aLayout->setContentsMargins(0, 0, 0, 0);
31 QString aLabelText = QString::fromStdString(theData->widgetLabel());
32 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
33 myLabel = new QLabel(aLabelText, myContainer);
34 myLabel->setPixmap(QPixmap(aLabelIcon));
36 aLayout->addWidget(myLabel);
38 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
39 myTextLine = new QLineEdit(myContainer);
40 myTextLine->setReadOnly(true);
41 myTextLine->setToolTip(aToolTip);
43 aLayout->addWidget(myTextLine);
45 myActivateBtn = new QToolButton(myContainer);
46 myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
47 myActivateBtn->setCheckable(true);
48 myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
50 aLayout->addWidget(myActivateBtn);
52 connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
55 //********************************************************************
56 ModuleBase_SelectorWidget::~ModuleBase_SelectorWidget()
60 //********************************************************************
61 bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature)
63 DataPtr aData = theFeature->data();
64 boost::shared_ptr<ModelAPI_AttributeReference> aRef =
65 boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
70 //********************************************************************
71 bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
73 DataPtr aData = theFeature->data();
74 boost::shared_ptr<ModelAPI_AttributeReference> aRef =
75 boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
80 //********************************************************************
81 bool ModuleBase_SelectorWidget::canFocusTo(const std::string& theAttributeName)
86 //********************************************************************
87 void ModuleBase_SelectorWidget::focusTo()
91 //********************************************************************
92 QList<QWidget*> ModuleBase_SelectorWidget::getControls() const
94 QList<QWidget*> aControls;
95 aControls.append(myLabel);
96 aControls.append(myTextLine);
97 aControls.append(myActivateBtn);
101 //********************************************************************
102 void ModuleBase_SelectorWidget::onSelectionChanged()
104 QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
105 int aCount = aFeatures.size();