Salome HOME
Update copyrights
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetConcealedObjects.cpp
index 0e5f4d9e6e939acb2590eab668109f83fc16dabc..5154ea04a4410abce48dca8522c6c22579351dcf 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_WidgetConcealedObjects.cpp
-// Created:     29 Jul 2016
-// Author:      Natalia ERMOLAEVA
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include <ModuleBase_WidgetConcealedObjects.h>
 #include <ModuleBase_Tools.h>
@@ -21,7 +34,8 @@
 #include <QWidget>
 #include <QTableWidget>
 #include <QHeaderView>
-#include <QToolButton>
+#include <QCheckBox>
+#include <QVBoxLayout>
 
 const int DEFAULT_NAME_COLUMN_WIDTH = 200;
 
@@ -54,7 +68,8 @@ bool ModuleBase_WidgetConcealedObjects::storeValueCustom()
   anAttributeList->clear();
   int aSize1 = anAttributeList->size(false);
   for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
-    QToolButton* aButton = dynamic_cast<QToolButton*>(myView->cellWidget(i, 0));;
+    QCheckBox* aButton =
+        dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
     if (aButton->isChecked())
       anAttributeList->append(myConcealedResults[i]);
   }
@@ -89,18 +104,18 @@ bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
       }
     }
   }
-  
+
   DataPtr aData = myFeature->data();
   AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
   int aSize = anAttributeList->size();
   for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
     ResultPtr aResult = myConcealedResults[i];
-    QToolButton* aButton = dynamic_cast<QToolButton*>(myView->cellWidget(i, 0));
+    QCheckBox* aButton =
+        dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0)->findChild<QCheckBox*>());
     bool isChecked = anAttributeList->isInList(aResult);
 
     bool aBlocked = aButton->blockSignals(true);
     aButton->setChecked(isChecked);
-    this->updateItemIcon(aButton);
     aButton->blockSignals(aBlocked);
   }
   return true;
@@ -113,18 +128,21 @@ QList<QWidget*> ModuleBase_WidgetConcealedObjects::getControls() const
   return result;
 }
 
-void ModuleBase_WidgetConcealedObjects::addViewRow(const std::shared_ptr<ModelAPI_Result>& theResult)
+void ModuleBase_WidgetConcealedObjects::addViewRow(
+                                const std::shared_ptr<ModelAPI_Result>& theResult)
 {
   int anId = myView->rowCount();
   myView->setRowCount(anId+1);
 
-  QToolButton* aVisibilityBtn = new QToolButton(this);
+  QWidget* aVisibilityWdg = new QWidget(this);
+  QVBoxLayout* aVisibilityLay = new QVBoxLayout(aVisibilityWdg);
+  aVisibilityLay->setContentsMargins(2, 2, 2, 2);
+  QCheckBox* aVisibilityBtn = new QCheckBox(aVisibilityWdg);
+  aVisibilityLay->addWidget(aVisibilityBtn, 0, Qt::AlignHCenter);
   connect(aVisibilityBtn, SIGNAL(toggled(bool)), this, SLOT(onItemToggled(bool)));
-  aVisibilityBtn->setCheckable(true);
   aVisibilityBtn->setChecked(false);
-  updateItemIcon(aVisibilityBtn);
 
-  myView->setCellWidget(anId, 0, aVisibilityBtn);
+  myView->setCellWidget(anId, 0, aVisibilityWdg);
   myView->setItem(anId, 1, new QTableWidgetItem(theResult->data()->name().c_str()));
 
   if (anId == 1) {
@@ -139,10 +157,3 @@ void ModuleBase_WidgetConcealedObjects::onItemToggled(bool theState)
   updateObject(myFeature);
 }
 
-void ModuleBase_WidgetConcealedObjects::updateItemIcon(QToolButton* theButton)
-{
-  bool isChecked = theButton->isChecked();
-  theButton->setIcon(isChecked ? QIcon(":icons/concealed_on.png")
-                               : QIcon(":icons/concealed_off.png"));
-  theButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
-}