Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / ParaViewPlugin / VectBoolSpreadSheet.h
1 // Copyright (C) 2010-2022  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay
20
21 #include <QTableWidget>
22 #include <QItemDelegate>
23 #include <QStringListModel>
24 #include <QAbstractTableModel>
25 #include <QListView>
26 #include <QStyledItemDelegate>
27
28 class OnOffDelegate : public QStyledItemDelegate//QItemDelegate
29 {
30   Q_OBJECT
31   public:
32   OnOffDelegate(QObject *parent=0);
33   void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
34 };
35
36 class VectBoolSpreadSheet : public QTableView
37 {
38   Q_OBJECT
39 public:
40   VectBoolSpreadSheet(QWidget *parent);
41   ~VectBoolSpreadSheet();
42   void init();
43   void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
44 public slots:
45   void nbOfRowsHasChanged(int newNbOfRows);
46   void selectUnselectAllFired();
47 private:
48   OnOffDelegate *_delegate;
49 };
50
51 class VectBoolModel : public QAbstractTableModel
52 {
53   Q_OBJECT
54 public:
55   VectBoolModel(int maxSize, int nbRows);
56   std::size_t getSize() const { return _activated.size(); }
57   bool getStatusAt(int pos) const { return _activated[pos]; }
58   void setStatusAt(int pos, bool val) { _activated[pos]=val; }
59   int rowCount( const QModelIndex & parent = QModelIndex() ) const;
60   int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
61   bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
62   QVariant data(const QModelIndex &index, int role) const;
63   QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
64   // non const methods.
65   bool setCurrentItems(const QStringList& dts, const QStringList& its, const QStringList& tts);
66   int getNbOfActivatedTimeSteps() const;
67 public:
68   void setNumberOfRows(int newNbOfRows);
69   void selectUnselectAll();
70 signals:
71   void nbOfTimeStepsOnChanged(int newNbOfTimeStepsOn, int totalNbOfTS);
72 private:
73   void setCurSize(int sz);
74   int curSize() const;
75 private:
76   std::vector<bool> _activated;
77   QStringList _dts,_its,_tts;
78   int _cur_size;
79   int _nb_rows;
80 };