1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetConcealedObjects.cpp
4 // Created: 29 Jul 2016
5 // Author: Natalia ERMOLAEVA
7 #include <ModuleBase_WidgetConcealedObjects.h>
8 #include <ModuleBase_Tools.h>
10 #include <ModelAPI_Result.h>
11 #include <ModelAPI_AttributeReference.h>
12 #include <ModelAPI_AttributeRefList.h>
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_Validator.h>
15 #include <ModelAPI_Tools.h>
17 #include <Config_WidgetAPI.h>
19 #include <QGridLayout>
22 #include <QTableWidget>
23 #include <QHeaderView>
25 #include <QVBoxLayout>
27 const int DEFAULT_NAME_COLUMN_WIDTH = 200;
29 ModuleBase_WidgetConcealedObjects::ModuleBase_WidgetConcealedObjects(QWidget* theParent,
30 const Config_WidgetAPI* theData)
31 : ModuleBase_ModelWidget(theParent, theData)
33 myBaseShapeAttribute = theData->getProperty("base_shape_attribute");
34 QGridLayout* aMainLay = new QGridLayout(this);
35 ModuleBase_Tools::adjustMargins(aMainLay);
37 myView = new QTableWidget(this);
38 aMainLay->addWidget(myView);
40 myView->setColumnCount(2);
41 myView->horizontalHeader()->setVisible(false);
42 myView->verticalHeader()->setVisible(false);
45 ModuleBase_WidgetConcealedObjects::~ModuleBase_WidgetConcealedObjects()
49 bool ModuleBase_WidgetConcealedObjects::storeValueCustom()
53 DataPtr aData = myFeature->data();
54 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
55 anAttributeList->clear();
56 int aSize1 = anAttributeList->size(false);
57 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
59 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
60 if (aButton->isChecked())
61 anAttributeList->append(myConcealedResults[i]);
63 int aSize = anAttributeList->size(false);
67 bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
69 FeaturePtr aBaseFeature;
72 anObject = ModuleBase_Tools::getObject(myFeature->attribute(myBaseShapeAttribute));
73 if (anObject.get() != NULL)
74 aBaseFeature = ModelAPI_Feature::feature(anObject);
76 if (myBaseFeature != aBaseFeature) {
77 myView->setRowCount(0);
78 myConcealedResults.clear();
79 myBaseFeature = aBaseFeature;
80 if (myBaseFeature.get()) {
81 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
82 ModelAPI_Tools::getConcealedResults(myBaseFeature, aResults);
83 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator anIt = aResults.begin(),
84 aLast = aResults.end();
85 for (; anIt != aLast; anIt++) {
86 ResultPtr aResult = *anIt;
88 int aRowId = myView->rowCount();
90 myConcealedResults[aRowId] = aResult;
95 DataPtr aData = myFeature->data();
96 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
97 int aSize = anAttributeList->size();
98 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
99 ResultPtr aResult = myConcealedResults[i];
101 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
102 bool isChecked = anAttributeList->isInList(aResult);
104 bool aBlocked = aButton->blockSignals(true);
105 aButton->setChecked(isChecked);
106 aButton->blockSignals(aBlocked);
111 QList<QWidget*> ModuleBase_WidgetConcealedObjects::getControls() const
113 QList<QWidget*> result;
118 void ModuleBase_WidgetConcealedObjects::addViewRow(
119 const std::shared_ptr<ModelAPI_Result>& theResult)
121 int anId = myView->rowCount();
122 myView->setRowCount(anId+1);
124 QWidget* aVisibilityWdg = new QWidget(this);
125 QVBoxLayout* aVisibilityLay = new QVBoxLayout(aVisibilityWdg);
126 aVisibilityLay->setContentsMargins(2, 2, 2, 2);
127 QCheckBox* aVisibilityBtn = new QCheckBox(aVisibilityWdg);
128 aVisibilityLay->addWidget(aVisibilityBtn, 0, Qt::AlignHCenter);
129 connect(aVisibilityBtn, SIGNAL(toggled(bool)), this, SLOT(onItemToggled(bool)));
130 aVisibilityBtn->setChecked(false);
132 myView->setCellWidget(anId, 0, aVisibilityWdg);
133 myView->setItem(anId, 1, new QTableWidgetItem(theResult->data()->name().c_str()));
136 myView->setColumnWidth(0, myView->verticalHeader()->defaultSectionSize());
137 myView->setColumnWidth(1, DEFAULT_NAME_COLUMN_WIDTH);
141 void ModuleBase_WidgetConcealedObjects::onItemToggled(bool theState)
143 emit valuesChanged();
144 updateObject(myFeature);