1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: CollectionPlugin_WidgetField.cpp
4 // Created: 16 Nov 2016
5 // Author: Vitaly SMETANNIKOV
7 #include "CollectionPlugin_WidgetField.h"
11 #include <QFormLayout>
16 #include <QTableWidget>
17 #include <QPushButton>
18 #include <QHeaderView>
20 CollectionPlugin_WidgetField::
21 CollectionPlugin_WidgetField(QWidget* theParent, const Config_WidgetAPI* theData):
22 ModuleBase_ModelWidget(theParent, theData)
24 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
26 // Types definition controls
27 QWidget* aTypesWgt = new QWidget(this);
28 QFormLayout* aTypesLayout = new QFormLayout(aTypesWgt);
29 aTypesLayout->setContentsMargins(0, 0, 0, 0);
30 aMainLayout->addWidget(aTypesWgt);
33 myShapeTypeCombo = new QComboBox(aTypesWgt);
34 QStringList aShapeTypes;
35 aShapeTypes << tr("Vertices") << tr("Edges") << tr("Faces")
36 << tr("Solids") << tr("Results") << tr("Parts");
37 myShapeTypeCombo->addItems(aShapeTypes);
38 aTypesLayout->addRow(tr("Type of shapes"), myShapeTypeCombo);
41 myFieldTypeCombo = new QComboBox(aTypesWgt);
42 QStringList aFieldTypes;
43 aFieldTypes << tr("Double") << tr("Integer") << tr("Boolean")
45 myFieldTypeCombo->addItems(aFieldTypes);
46 aTypesLayout->addRow(tr("Type of field"), myFieldTypeCombo);
48 // Number of components
49 myNbComponentsSpn = new QSpinBox(aTypesWgt);
50 myNbComponentsSpn->setMinimum(1);
51 aTypesLayout->addRow(tr("Nb. of components"), myNbComponentsSpn);
54 QFrame* aStepFrame = new QFrame(this);
55 aStepFrame->setFrameShape(QFrame::Box);
56 aStepFrame->setFrameStyle(QFrame::StyledPanel);
57 QGridLayout* aStepLayout = new QGridLayout(aStepFrame);
58 aMainLayout->addWidget(aStepFrame);
61 aStepLayout->addWidget(new QLabel(tr("Current step"), aStepFrame), 0, 0);
62 myCurStepLbl = new QLabel("1", aStepFrame);
63 QFont aFont = myCurStepLbl->font();
65 myCurStepLbl->setFont(aFont);
66 aStepLayout->addWidget(myCurStepLbl, 0, 1);
69 QWidget* aSliderWidget = new QWidget(aStepFrame);
70 aStepLayout->addWidget(aSliderWidget, 1, 0, 1, 2);
71 QHBoxLayout* aSliderLayout = new QHBoxLayout(aSliderWidget);
72 aSliderLayout->setContentsMargins(0, 0, 0, 0);
74 aSliderLayout->addWidget(new QLabel("1", aSliderWidget));
76 myStepSlider = new QSlider(Qt::Horizontal, aSliderWidget);
77 myStepSlider->setTickPosition(QSlider::TicksBelow);
78 myStepSlider->setRange(1, 1);
79 myStepSlider->setPageStep(myStepSlider->singleStep());
80 aSliderLayout->addWidget(myStepSlider, 1);
82 myMaxLbl = new QLabel("1", aSliderWidget);
83 aSliderLayout->addWidget(myMaxLbl);
86 aStepLayout->addWidget(new QLabel(tr("Stamp"), aStepFrame), 2, 0);
87 myStampSpn = new QSpinBox(aStepFrame);
88 aStepLayout->addWidget(myStampSpn, 2, 1);
91 myDataTbl = new QTableWidget(2, 2, aStepFrame);
92 myDataTbl->verticalHeader()->hide();
93 myDataTbl->horizontalHeader()->hide();
94 myDataTbl->setRowHeight(0, 25);
95 myDataTbl->setRowHeight(1, 25);
97 QTableWidgetItem* aItem = new QTableWidgetItem("Shape");
98 aItem->setBackgroundColor(Qt::lightGray);
99 aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
100 myDataTbl->setItem(0, 0, aItem);
102 aItem = new QTableWidgetItem("Comp 1");
103 aItem->setBackgroundColor(Qt::lightGray);
104 myDataTbl->setItem(0, 1, aItem);
106 aItem = new QTableWidgetItem("Default value");
107 aItem->setBackgroundColor(Qt::lightGray);
108 aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
109 myDataTbl->setItem(1, 0, aItem);
111 aItem = new QTableWidgetItem("0");
112 aItem->setBackgroundColor(Qt::lightGray);
113 myDataTbl->setItem(1, 1, aItem);
115 aStepLayout->addWidget(myDataTbl, 3, 0, 1, 2);
118 QWidget* aBtnWgt = new QWidget(this);
119 aMainLayout->addWidget(aBtnWgt);
120 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
121 aBtnLayout->setContentsMargins(0, 0, 0, 0);
123 QPushButton* aAddBtn = new QPushButton(tr("Add step"), aBtnWgt);
124 aBtnLayout->addWidget(aAddBtn);
126 aBtnLayout->addStretch(1);
128 QPushButton* aRemoveBtn = new QPushButton(tr("Remove step"), aBtnWgt);
129 aBtnLayout->addWidget(aRemoveBtn);
131 connect(myNbComponentsSpn, SIGNAL(valueChanged(int)), SLOT(onNbCompChanged(int)));
132 connect(aAddBtn, SIGNAL(clicked(bool)), SLOT(onAddStep()));
133 connect(aRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemoveStep()));
134 connect(myStepSlider, SIGNAL(valueChanged(int)), SLOT(onStepMove(int)));
137 QList<QWidget*> CollectionPlugin_WidgetField::getControls() const
139 QList<QWidget*> aControls;
140 // this control will accept focus and will be highlighted in the Property Panel
141 //aControls.push_back(myComboBox);
145 bool CollectionPlugin_WidgetField::storeValueCustom()
147 //AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
148 //AttributeIntegerPtr aValueAttribute =
149 // std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
150 //aValueAttribute->setValue(myComboBox->currentIndex());
151 //updateObject(myFeature);
155 bool CollectionPlugin_WidgetField::restoreValueCustom()
157 //AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
158 //AttributeIntegerPtr aValueAttribute =
159 // std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
161 //bool isBlocked = myComboBox->blockSignals(true);
162 //myComboBox->setCurrentIndex(aValueAttribute->value());
163 //myComboBox->blockSignals(isBlocked);
168 void CollectionPlugin_WidgetField::onNbCompChanged(int theVal)
170 int aOldCol = myDataTbl->columnCount() - 1;
171 int aNbRows = myDataTbl->rowCount();
172 myDataTbl->setColumnCount(theVal + 1);
173 int aDif = theVal - aOldCol;
174 QTableWidgetItem* aItem = 0;
175 for (int i = 0; i < aDif; i++) {
176 for (int j = 0; j < aNbRows; j++) {
177 aItem = new QTableWidgetItem();
179 aItem->setText(QString("Comp %1").arg(i + aOldCol + 1));
183 aItem->setBackgroundColor(Qt::lightGray);
184 myDataTbl->setItem(j, i + aOldCol + 1, aItem);
189 void CollectionPlugin_WidgetField::onAddStep()
191 int aMax = myStepSlider->maximum();
193 myStepSlider->setMaximum(aMax);
194 myMaxLbl->setText(QString::number(aMax));
196 myStepSlider->setValue(aMax);
199 void CollectionPlugin_WidgetField::onRemoveStep()
201 int aMax = myStepSlider->maximum();
203 myStepSlider->setMaximum(aMax);
204 myMaxLbl->setText(QString::number(aMax));
207 void CollectionPlugin_WidgetField::clearData()
209 int aNbRows = myDataTbl->rowCount();
210 int aNbCol = myDataTbl->columnCount();
213 for (int i = 1; i < aNbCol; i++) {
214 aDefValue = myDataTbl->item(1, i)->text();
215 for (int j = 2; j < aNbRows; j++) {
216 myDataTbl->item(j, i)->setText(aDefValue);
221 void CollectionPlugin_WidgetField::onStepMove(int theStep)
223 myCurStepLbl->setText(QString::number(theStep));