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 "VectBoolWidget.h"
22 #include "VectBoolSpreadSheet.h"
24 #include <QHBoxLayout>
25 #include <QVBoxLayout>
26 #include <QGridLayout>
27 #include <QPushButton>
35 NbOfActiveTSDisplay::NbOfActiveTSDisplay(QWidget *parent):QLabel(parent),_nb_of_items_on(0),_total_nb_of_items(0)
37 setFont(QFont("Arial",8,QFont::Bold));
38 setTextFormat(Qt::AutoText);
41 void NbOfActiveTSDisplay::display(int nbOfItemsOn, int totalNbOfItems)
43 _nb_of_items_on=nbOfItemsOn;
44 _total_nb_of_items=totalNbOfItems;
45 setText(QString("%1/%2").arg(_nb_of_items_on).arg(_total_nb_of_items));
48 void NbOfActiveTSDisplay::totalNbOfItemsChanged(int totalNbOfItems)
50 _total_nb_of_items=totalNbOfItems;
51 setText(QString("%1/%2").arg(_nb_of_items_on).arg(_total_nb_of_items));
54 VectBoolItem::VectBoolItem(QObject *parent, int pos, VectBoolModel *model):QObject(parent),_pos(pos),_old_status(true),_model(model)
58 bool VectBoolItem::isActivated() const
60 return _model->getStatusAt(_pos);
63 void VectBoolItem::activated(bool val)
65 _model->setStatusAt(_pos,val);
69 void VectBoolItem::theModelHasChanged()
71 bool val(isActivated());
79 VectBoolWidget::VectBoolWidget(QWidget *parent, int nbOfItems):QFrame(parent)
81 QSizePolicy sizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
82 sizePolicy.setHorizontalStretch(0);
83 sizePolicy.setVerticalStretch(0);
84 sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
85 this->setSizePolicy(sizePolicy);
86 this->setFrameShape(QFrame::StyledPanel);
87 this->setFrameShadow(QFrame::Raised);
88 _horizontal_layout=new QHBoxLayout(this);
89 _horizontal_layout->setSpacing(6);
90 _horizontal_layout->setContentsMargins(11,11,11,11);
91 _spreadsheet_container=new QFrame(this);
92 QSizePolicy sizePolicy1(QSizePolicy::Expanding,QSizePolicy::Expanding);
93 sizePolicy1.setHorizontalStretch(0);
94 sizePolicy1.setVerticalStretch(0);
95 sizePolicy1.setHeightForWidth(_spreadsheet_container->sizePolicy().hasHeightForWidth());
96 _spreadsheet_container->setSizePolicy(sizePolicy1);
97 _grid_layout=new QGridLayout(_spreadsheet_container);
98 _grid_layout->setSpacing(6);
99 _grid_layout->setContentsMargins(11,11,11,11);
100 _horizontal_layout->addWidget(_spreadsheet_container);
101 _group_box=new QGroupBox(this);
102 QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Expanding);
103 sizePolicy2.setHorizontalStretch(0);
104 sizePolicy2.setVerticalStretch(0);
105 sizePolicy2.setHeightForWidth(_group_box->sizePolicy().hasHeightForWidth());
106 _group_box->setSizePolicy(sizePolicy2);
108 _vertical_layout=new QVBoxLayout(_group_box);
109 _vertical_layout->setSpacing(6);
110 _vertical_layout->setContentsMargins(11,11,11,11);
111 _nb_of_time_steps_on=new NbOfActiveTSDisplay(_group_box);
112 _nb_of_time_steps_on->setMaximumSize(QSize(40,16777215));
113 _vertical_layout->addWidget(_nb_of_time_steps_on);
114 _nb_of_rows_selecter=new QSlider(_group_box);
115 QSizePolicy sizePolicy3(QSizePolicy::Expanding,QSizePolicy::Expanding);
116 sizePolicy3.setHorizontalStretch(0);
117 sizePolicy3.setVerticalStretch(0);
118 sizePolicy3.setHeightForWidth(_nb_of_rows_selecter->sizePolicy().hasHeightForWidth());
119 _nb_of_rows_selecter->setSizePolicy(sizePolicy3);
120 _nb_of_rows_selecter->setOrientation(Qt::Vertical);
121 _vertical_layout->addWidget(_nb_of_rows_selecter);
122 _sel_unsel_all=new QPushButton(_group_box);
123 _sel_unsel_all->setMaximumSize(QSize(40,16777215));
124 _sel_unsel_all->setText(QString("Sel All"));
125 QFont font("Andale Mono");
126 font.setPointSize(5);
127 _sel_unsel_all->setFont(font);
128 _vertical_layout->addWidget(_sel_unsel_all);
130 _horizontal_layout->addWidget(_group_box);
132 _vbw=new VectBoolSpreadSheet(_spreadsheet_container);
133 QSizePolicy sizePolicy4(QSizePolicy::Expanding,QSizePolicy::Expanding);
134 sizePolicy4.setHorizontalStretch(0);
135 sizePolicy4.setVerticalStretch(0);
136 sizePolicy4.setHeightForWidth(_vbw->sizePolicy().hasHeightForWidth());
137 _vbw->setSizePolicy(sizePolicy4);
138 _nb_of_rows_selecter->setSizePolicy(sizePolicy3);
139 _nb_of_rows_selecter->setMinimum(1);
140 _nb_of_rows_selecter->setMaximum(GetMaxTickValueOfSlider(nbOfItems));
141 _nb_of_rows_selecter->setTickInterval(1);
142 _nb_of_rows_selecter->setTickPosition(QSlider::TicksRight);
143 connect(_nb_of_rows_selecter,SIGNAL(valueChanged(int)),_vbw,SLOT(nbOfRowsHasChanged(int)));
144 connect(_sel_unsel_all,SIGNAL(clicked()),_vbw,SLOT(selectUnselectAllFired()));
145 _grid_layout->addWidget(_vbw);
147 _vbm=new VectBoolModel(nbOfItems,1);
148 _vbw->setModel(_vbm);
149 connect(this->_vbm,SIGNAL(nbOfTimeStepsOnChanged(int,int)),_nb_of_time_steps_on,SLOT(display(int,int)));
150 _vbm->selectUnselectAll();
151 _nb_of_rows_selecter->setValue(_nb_of_rows_selecter->maximum());
153 for(int i=0;i<nbOfItems;i++)
155 VectBoolItem* item = new VectBoolItem(this,i,_vbm);
156 _items["000"+QString::number(i)]=item;
157 connect(_vbm, SIGNAL(nbOfTimeStepsOnChanged(int,int)), item, SLOT(theModelHasChanged()));
161 void VectBoolWidget::setItems(const QStringList& dts, const QStringList& its, const QStringList& tts)
163 int curNbOfItems(dts.size());
164 if(curNbOfItems>getNumberOfBoolItems())
166 std::cerr << "ERROR ! Internal Error in VectBoolWidget::setItems ! Current number of items is bigger than the current one !" << std::endl;
167 std::cerr << curNbOfItems << " "<<getNumberOfBoolItems()<<std::endl;
170 if(_vbm->setCurrentItems(dts,its,tts))
172 _nb_of_rows_selecter->setMaximum(GetMaxTickValueOfSlider(curNbOfItems));
173 _nb_of_rows_selecter->setValue(_nb_of_rows_selecter->maximum());
174 _nb_of_time_steps_on->display(_vbm->getNbOfActivatedTimeSteps(),dts.size());
178 int VectBoolWidget::getNumberOfBoolItems() const
180 return (int)_vbm->getSize();
183 int VectBoolWidget::GetMaxTickValueOfSlider(int val)
185 double valf((double)val);
186 double ret(sqrt(valf));
194 VectBoolWidget::~VectBoolWidget()