1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <ModuleBase_WidgetConcealedObjects.h>
22 #include <ModuleBase_Tools.h>
24 #include <ModelAPI_Result.h>
25 #include <ModelAPI_AttributeReference.h>
26 #include <ModelAPI_AttributeRefList.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Validator.h>
29 #include <ModelAPI_Tools.h>
31 #include <Config_WidgetAPI.h>
33 #include <QGridLayout>
36 #include <QTableWidget>
37 #include <QHeaderView>
39 #include <QVBoxLayout>
41 const int DEFAULT_NAME_COLUMN_WIDTH = 200;
43 ModuleBase_WidgetConcealedObjects::ModuleBase_WidgetConcealedObjects(QWidget* theParent,
44 const Config_WidgetAPI* theData)
45 : ModuleBase_ModelWidget(theParent, theData)
47 myBaseShapeAttribute = theData->getProperty("base_shape_attribute");
48 QGridLayout* aMainLay = new QGridLayout(this);
49 ModuleBase_Tools::adjustMargins(aMainLay);
51 myView = new QTableWidget(this);
52 aMainLay->addWidget(myView);
54 myView->setColumnCount(2);
55 myView->horizontalHeader()->setVisible(false);
56 myView->verticalHeader()->setVisible(false);
59 ModuleBase_WidgetConcealedObjects::~ModuleBase_WidgetConcealedObjects()
63 bool ModuleBase_WidgetConcealedObjects::storeValueCustom()
67 DataPtr aData = myFeature->data();
68 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
69 anAttributeList->clear();
70 int aSize1 = anAttributeList->size(false);
71 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
73 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
74 if (aButton->isChecked())
75 anAttributeList->append(myConcealedResults[i]);
77 int aSize = anAttributeList->size(false);
81 bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
83 FeaturePtr aBaseFeature;
86 anObject = ModuleBase_Tools::getObject(myFeature->attribute(myBaseShapeAttribute));
87 if (anObject.get() != NULL)
88 aBaseFeature = ModelAPI_Feature::feature(anObject);
90 if (myBaseFeature != aBaseFeature) {
91 myView->setRowCount(0);
92 myConcealedResults.clear();
93 myBaseFeature = aBaseFeature;
94 if (myBaseFeature.get()) {
95 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
96 ModelAPI_Tools::getConcealedResults(myBaseFeature, aResults);
97 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator anIt = aResults.begin(),
98 aLast = aResults.end();
99 for (; anIt != aLast; anIt++) {
100 ResultPtr aResult = *anIt;
102 int aRowId = myView->rowCount();
104 myConcealedResults[aRowId] = aResult;
109 DataPtr aData = myFeature->data();
110 AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
111 int aSize = anAttributeList->size();
112 for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
113 ResultPtr aResult = myConcealedResults[i];
115 dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
116 bool isChecked = anAttributeList->isInList(aResult);
118 bool aBlocked = aButton->blockSignals(true);
119 aButton->setChecked(isChecked);
120 aButton->blockSignals(aBlocked);
125 QList<QWidget*> ModuleBase_WidgetConcealedObjects::getControls() const
127 QList<QWidget*> result;
132 void ModuleBase_WidgetConcealedObjects::addViewRow(
133 const std::shared_ptr<ModelAPI_Result>& theResult)
135 int anId = myView->rowCount();
136 myView->setRowCount(anId+1);
138 QWidget* aVisibilityWdg = new QWidget(this);
139 QVBoxLayout* aVisibilityLay = new QVBoxLayout(aVisibilityWdg);
140 aVisibilityLay->setContentsMargins(2, 2, 2, 2);
141 QCheckBox* aVisibilityBtn = new QCheckBox(aVisibilityWdg);
142 aVisibilityLay->addWidget(aVisibilityBtn, 0, Qt::AlignHCenter);
143 connect(aVisibilityBtn, SIGNAL(toggled(bool)), this, SLOT(onItemToggled(bool)));
144 aVisibilityBtn->setChecked(false);
146 myView->setCellWidget(anId, 0, aVisibilityWdg);
147 myView->setItem(anId, 1, new QTableWidgetItem(theResult->data()->name().c_str()));
150 myView->setColumnWidth(0, myView->verticalHeader()->defaultSectionSize());
151 myView->setColumnWidth(1, DEFAULT_NAME_COLUMN_WIDTH);
155 void ModuleBase_WidgetConcealedObjects::onItemToggled(bool theState)
157 emit valuesChanged();
158 updateObject(myFeature);