1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ModuleBase_WidgetConcealedObjects.h>
21 #include <ModuleBase_Tools.h>
23 #include <ModelAPI_Result.h>
24 #include <ModelAPI_AttributeReference.h>
25 #include <ModelAPI_AttributeRefList.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
28 #include <ModelAPI_Tools.h>
30 #include <Config_WidgetAPI.h>
32 #include <QGridLayout>
35 #include <QTableWidget>
36 #include <QHeaderView>
38 #include <QVBoxLayout>
40 const int DEFAULT_NAME_COLUMN_WIDTH = 200;
42 ModuleBase_WidgetConcealedObjects::ModuleBase_WidgetConcealedObjects(QWidget* theParent,
43 const Config_WidgetAPI* theData)
44 : ModuleBase_ModelWidget(theParent, theData)
46 myBaseShapeAttribute = theData->getProperty("base_shape_attribute");
47 QGridLayout* aMainLay = new QGridLayout(this);
48 ModuleBase_Tools::adjustMargins(aMainLay);
50 myView = new QTableWidget(this);
51 aMainLay->addWidget(myView);
53 myView->setColumnCount(2);
54 myView->horizontalHeader()->setVisible(false);
55 myView->verticalHeader()->setVisible(false);
58 ModuleBase_WidgetConcealedObjects::~ModuleBase_WidgetConcealedObjects()
62 bool ModuleBase_WidgetConcealedObjects::storeValueCustom()
66 DataPtr aData = myFeature->data();
67 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
68 anAttributeList->clear();
69 int aSize1 = anAttributeList->size(false);
70 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
72 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
73 if (aButton->isChecked())
74 anAttributeList->append(myConcealedResults[i]);
76 int aSize = anAttributeList->size(false);
80 bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
82 FeaturePtr aBaseFeature;
85 anObject = ModuleBase_Tools::getObject(myFeature->attribute(myBaseShapeAttribute));
86 if (anObject.get() != NULL)
87 aBaseFeature = ModelAPI_Feature::feature(anObject);
89 if (myBaseFeature != aBaseFeature) {
90 myView->setRowCount(0);
91 myConcealedResults.clear();
92 myBaseFeature = aBaseFeature;
93 if (myBaseFeature.get()) {
94 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
95 ModelAPI_Tools::getConcealedResults(myBaseFeature, aResults);
96 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator anIt = aResults.begin(),
97 aLast = aResults.end();
98 for (; anIt != aLast; anIt++) {
99 ResultPtr aResult = *anIt;
101 int aRowId = myView->rowCount();
103 myConcealedResults[aRowId] = aResult;
108 DataPtr aData = myFeature->data();
109 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
110 int aSize = anAttributeList->size();
111 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
112 ResultPtr aResult = myConcealedResults[i];
114 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
115 bool isChecked = anAttributeList->isInList(aResult);
117 bool aBlocked = aButton->blockSignals(true);
118 aButton->setChecked(isChecked);
119 aButton->blockSignals(aBlocked);
124 QList<QWidget*> ModuleBase_WidgetConcealedObjects::getControls() const
126 QList<QWidget*> result;
131 void ModuleBase_WidgetConcealedObjects::addViewRow(
132 const std::shared_ptr<ModelAPI_Result>& theResult)
134 int anId = myView->rowCount();
135 myView->setRowCount(anId+1);
137 QWidget* aVisibilityWdg = new QWidget(this);
138 QVBoxLayout* aVisibilityLay = new QVBoxLayout(aVisibilityWdg);
139 aVisibilityLay->setContentsMargins(2, 2, 2, 2);
140 QCheckBox* aVisibilityBtn = new QCheckBox(aVisibilityWdg);
141 aVisibilityLay->addWidget(aVisibilityBtn, 0, Qt::AlignHCenter);
142 connect(aVisibilityBtn, SIGNAL(toggled(bool)), this, SLOT(onItemToggled(bool)));
143 aVisibilityBtn->setChecked(false);
145 myView->setCellWidget(anId, 0, aVisibilityWdg);
146 myView->setItem(anId, 1, new QTableWidgetItem(theResult->data()->name().c_str()));
149 myView->setColumnWidth(0, myView->verticalHeader()->defaultSectionSize());
150 myView->setColumnWidth(1, DEFAULT_NAME_COLUMN_WIDTH);
154 void ModuleBase_WidgetConcealedObjects::onItemToggled(bool theState)
156 emit valuesChanged();
157 updateObject(myFeature);