Salome HOME
IWorkshop interface for Module is created
[modules/shaper.git] / src / ModuleBase / ModuleBase_SelectorWidget.cpp
1 // File:        ModuleBase_SelectorWidget.h
2 // Created:     2 June 2014
3 // Author:      Vitaly Smetannikov
4
5
6 #include "ModuleBase_SelectorWidget.h"
7 #include "ModuleBase_IWorkshop.h"
8
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_AttributeReference.h>
11 #include <Config_WidgetAPI.h>
12
13 #include <QWidget>
14 #include <QLayout>
15 #include <QLabel>
16 #include <QLineEdit>
17 #include <QToolButton>
18
19
20 ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, 
21                                                      ModuleBase_IWorkshop* theWorkshop, 
22                                                      const Config_WidgetAPI* theData)
23 : ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop)
24 {
25   myFeatureAttributeID = theData->widgetId();
26
27   myContainer = new QWidget(theParent);
28   QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
29
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));
35
36   aLayout->addWidget(myLabel);
37
38   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
39   myTextLine = new QLineEdit(myContainer);
40   myTextLine->setReadOnly(true);
41   myTextLine->setToolTip(aToolTip);
42
43   aLayout->addWidget(myTextLine);
44
45   myActivateBtn = new QToolButton(myContainer);
46   myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
47   myActivateBtn->setCheckable(true);
48   myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
49
50   aLayout->addWidget(myActivateBtn);
51
52   connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
53 }
54
55 //********************************************************************
56 ModuleBase_SelectorWidget::~ModuleBase_SelectorWidget()
57 {
58 }
59
60 //********************************************************************
61 bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature)
62 {
63   DataPtr aData = theFeature->data();
64   boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
65     boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
66
67   return true;
68 }
69
70 //********************************************************************
71 bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
72 {
73   DataPtr aData = theFeature->data();
74   boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
75     boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
76   
77   return true;
78 }
79
80 //********************************************************************
81 bool ModuleBase_SelectorWidget::canFocusTo(const std::string& theAttributeName)
82 {
83   return false;
84 }
85
86 //********************************************************************
87 void ModuleBase_SelectorWidget::focusTo()
88 {
89 }
90
91 //********************************************************************
92 QList<QWidget*> ModuleBase_SelectorWidget::getControls() const
93 {
94   QList<QWidget*> aControls;
95   aControls.append(myLabel);
96   aControls.append(myTextLine);
97   aControls.append(myActivateBtn);
98   return aControls;
99 }
100
101 //********************************************************************
102 void ModuleBase_SelectorWidget::onSelectionChanged()
103 {
104   QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
105   int aCount = aFeatures.size();
106 }