Salome HOME
Copyright update 2022
[modules/geom.git] / src / CurveCreator / CurveCreator_TreeView.h
1 // Copyright (C) 2013-2022  CEA/DEN, EDF R&D, OPEN CASCADE
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
20 #ifndef CURVECREATOR_TREEVIEW_H
21 #define CURVECREATOR_TREEVIEW_H
22
23 #include <QTreeView>
24 #include <QAbstractItemModel>
25
26 class CurveCreator_ICurve;
27
28 class CurveCreator_TreeViewModel : public QAbstractItemModel
29 {
30 public:
31   CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent, bool toDrawColorIcon );
32   virtual int   columnCount(const QModelIndex & parent = QModelIndex()) const;
33   virtual int   rowCount(const QModelIndex & parent = QModelIndex()) const;
34   virtual QVariant      data(const QModelIndex & index, int role = Qt::DisplayRole) const;
35   virtual QModelIndex   index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
36   virtual QModelIndex   parent(const QModelIndex & theIndex) const;
37 //  virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole);
38
39   QModelIndex sectionIndex( int theSection ) const;
40   QModelIndex nbPointsIndex( int theSection ) const;
41   QModelIndex pointIndex( int theSection, int thePoint ) const;
42
43   bool    isSection( const QModelIndex& theIndx ) const;
44   int     getSection( const QModelIndex& theIndx ) const;
45   int     getPoint( const QModelIndex& theIndx ) const;
46
47   void    setCurve( CurveCreator_ICurve* theCurve );
48
49 private:
50   enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT };
51 private:
52   CurveCreator_ICurve*          myCurve;
53   bool                         myDrawColorIcon;
54   QMap<IconType, QPixmap>      myCachedIcons;
55 };
56
57 class CurveCreator_TreeView : public QTreeView
58 {
59   Q_OBJECT
60 public:
61   enum SelectionType{ ST_NOSEL, ST_POINTS, ST_POINTS_ONE_SECTION, ST_SECTIONS, ST_MIXED };
62 public:
63   explicit CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent = 0, bool toDrawColorIcon = true);
64   SelectionType getSelectionType() const;
65   QList<int> getSelectedSections() const;
66
67   void    pointsAdded( int theSection, int thePoint, int thePointsCnt=1 );
68   void    pointDataChanged( int theSection, int thePoint );
69   void    pointsRemoved(int theSection, int thePoint, int thePointsCnt=1 );
70
71   void    sectionAdded( int theSection );
72   void    sectionChanged(int theSection , int aSectCnt = 1);
73   void    sectionsRemoved( int theSection, int theSectionCnt=1 );
74   void    sectionsSwapped( int theSection, int theOffset );
75
76   void    setSelectedSections( const QList<int>& theList );
77
78   void    setCurve( CurveCreator_ICurve* theCurve );
79
80   void    reset();
81
82 signals:
83   void    selectionChanged();
84   void    sectionEntered(int);
85
86 protected slots:
87   void onActivated( QModelIndex theIndx );
88 protected:
89   void setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent );
90   void swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond );
91   void getIndexInfo( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent );
92
93 };
94
95 #endif // CURVECREATOR_TREEVIEW_H