1 // Copyright (C) 2010-2016 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
19 // Author : Anthony Geay
21 #include "pqAbstractFieldsWidget.h"
23 #include "pqArrayListDomain.h"
24 #include "pqTreeWidget.h"
25 #include "pqTreeWidgetItemObject.h"
27 #include <QGridLayout>
28 #include <QHeaderView>
29 //-----------------------------------------------------------------------------
30 pqAbstractFieldsWidget::pqAbstractFieldsWidget(
31 vtkSMProxy *smproxy, vtkSMProperty *smproperty, QWidget *parentObject)
32 : Superclass(smproxy, parentObject)
35 this->visibleHeader = true;
36 this->setShowLabel(false);
39 QGridLayout* gridLayout = new QGridLayout(this);
42 this->TreeWidget = new pqTreeWidget(this);
43 gridLayout->addWidget(this->TreeWidget);
46 //-----------------------------------------------------------------------------
47 pqAbstractFieldsWidget::~pqAbstractFieldsWidget()
49 delete this->TreeWidget;
52 void pqAbstractFieldsWidget::initializeTreeWidget(vtkSMProxy *smproxy, vtkSMProperty *smproperty)
54 // Load Tree Widget Items
55 this->loadTreeWidgetItems();
57 // Connect Property Domain to the fieldDomain property,
58 // so setFieldDomain is called when the domain changes.
59 vtkSMDomain* arraySelectionDomain = smproperty->GetDomain("array_list");
60 new pqArrayListDomain(this,"fieldsDomain", smproxy, smproperty, arraySelectionDomain);
62 // Connect property to field QProperty using a biderectionnal property link
63 this->addPropertyLink(this, "fields", SIGNAL(fieldsChanged()),
66 // Call slot when the tree is changed
67 QObject::connect(this->TreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
68 this, SLOT(onItemChanged(QTreeWidgetItem*, int)));
72 //-----------------------------------------------------------------------------
73 QSize pqAbstractFieldsWidget::sizeHint() const
75 // TreeWidget sizeHintForRow is too low, correcting to +3.
76 int pix = (this->TreeWidget->sizeHintForRow(0) + 3) * this->NItems;
78 this->TreeWidget->getContentsMargins(margin, margin + 1, margin + 2, margin + 3);
79 int h = pix + margin[1] + margin[3];
80 if (this->visibleHeader)
82 h += this->TreeWidget->header()->frameSize().height();
88 //-----------------------------------------------------------------------------
89 void pqAbstractFieldsWidget::onItemChanged(QTreeWidgetItem* item, int column) const
98 //-----------------------------------------------------------------------------
99 QList< QList< QVariant> > pqAbstractFieldsWidget::getFields() const
101 // Put together a Field list, using ItemMap
102 QList< QList< QVariant> > ret;
103 QList< QVariant > field;
104 QMap<QString, pqTreeWidgetItemObject*>::const_iterator it;
105 for (it = this->ItemMap.begin(); it != this->ItemMap.end(); it++)
108 field.append(it.key());
109 field.append(it.value()->isChecked());
115 //-----------------------------------------------------------------------------
116 void pqAbstractFieldsWidget::setFields(QList< QList< QVariant> > fields)
118 // Update each item checkboxes, using fields names and ItemMap
119 QMap<QString, pqTreeWidgetItemObject*>::iterator it;
120 foreach (QList< QVariant> field, fields)
122 it = this->ItemMap.find(field[0].toString());
123 if (it == this->ItemMap.end())
125 qDebug("Found an unknow Field in pqAbstractFieldsWidget::setFields, ignoring");
128 it.value()->setChecked(field[1].toBool());
132 //-----------------------------------------------------------------------------
133 void pqAbstractFieldsWidget::setFieldsDomain(QList< QList< QVariant> > fields)
135 // Block signals so the reloading does not trigger
136 // UncheckPropertyModified event
137 this->blockSignals(true);
139 // Load the tree widget
140 this->loadTreeWidgetItems();
142 // Set fields checkboxes
143 this->setFields(fields);
146 this->blockSignals(false);