]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_TableDlg.h
Salome HOME
Merge from PortingMED3 07Apr11
[modules/visu.git] / src / VISU_I / VISU_TableDlg.h
1 //  Copyright (C) 2007-2010  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.
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 //  File   : VISU_TableDlg.h
21 //  Author : Vadim SANDLER
22 //  Module : VISU
23 //
24 #ifndef VISU_TABLEDLG_H
25 #define VISU_TABLEDLG_H
26
27 #include "VISU_I.hxx"
28
29 #include <SALOMEDSClient_Study.hxx>
30
31 #include <QDialog>
32 #include <QItemDelegate>
33 #include <QMap>
34
35 class QLabel;
36 class QLineEdit;
37 class QPushButton;
38 class QCheckBox;
39 class QComboBox;
40 class QTableWidget;
41
42 namespace VISU
43 {
44   class Table_i;
45 }
46
47 class VISU_I_EXPORT VISU_TableDlg : public QDialog
48
49   Q_OBJECT
50
51   class TableWidget;
52   class WidgetCointainer;
53
54   enum { tcTitle, tcTable, tcControls, tcButtons };
55
56 public:
57
58   enum { ttNone, ttInt, ttReal, ttAll, ttAuto };
59   enum { teNone      = 0x00,
60          teAddRemove = 0x01,
61          teEditData  = 0x02,
62          teRowColumn = 0x04,
63          teAll       = teAddRemove | teEditData | teRowColumn
64   };
65
66   VISU_TableDlg( QWidget* parent, 
67                  _PTR(Study) study, 
68                  VISU::Table_i* table,
69                  bool allowEdition = false,
70                  int which = ttAuto, 
71                  Qt::Orientation orient = Qt::Horizontal,
72                  bool showColumnTitles = true );
73   ~VISU_TableDlg();
74
75 protected:
76   void keyPressEvent( QKeyEvent* e );
77
78 private slots:
79   void help(); 
80
81 private:
82   QString tableTitle( int type );
83
84 private:
85   typedef QMap<int, TableWidget*>      TableMap;
86   typedef QMap<int, WidgetCointainer*> ContMap;
87
88   TableMap               myTableMap;
89   ContMap                myContMap;
90   QCheckBox*             myEditCheck;
91   QCheckBox*             myUpdateCheck;
92   QPushButton*           myOKBtn;
93   QPushButton*           myHelpBtn;
94
95   _PTR(Study)            myStudy;
96   VISU::Table_i*         myTable;
97 };
98  
99 class VISU_I_EXPORT VISU_TableDlg::TableWidget : public QWidget
100 {
101   Q_OBJECT
102
103 public:
104   TableWidget( QWidget* parent = 0, Qt::Orientation orientation = Qt::Horizontal );
105   ~TableWidget();
106
107   void    initialize( _PTR(Study) study, VISU::Table_i* table, int type );
108
109   void    setTableTitle( const QString& title );
110   QString getTableTitle();
111   void    setNumRows( const int num );
112   int     getNumRows();
113   void    setNumCols( const int num );
114   int     getNumCols();
115   void    setRowTitles( QStringList& tlts );
116   void    getRowTitles( QStringList& tlts );
117   void    setColTitles( QStringList& tlts );
118   void    getColTitles( QStringList& tlts );
119   void    setUnitsTitle( const QString& tlt );
120   void    setUnits( QStringList& units );
121   void    getUnits( QStringList& units );
122   void    setRowData( int row, QStringList& data );
123   void    getRowData( int row, QStringList& data );
124
125   bool    eventFilter( QObject* o, QEvent* e);
126
127 public slots:
128   void    setEditEnabled( bool enable );
129   void    showColumnTitles( bool showTitles );
130
131   void    updateButtonsState();
132   void    addRow();
133   void    addCol();
134   void    delRow();
135   void    delCol();
136   void    adjustTable();
137   void    selectAll();
138   void    clearTable();
139
140   void    columnClicked( int );
141   void    rowClicked( int );
142
143 protected:
144   void    updateTableFromServant( bool adjust );
145
146 private:
147   _PTR(Study)            myStudy;
148   VISU::Table_i*         myTableObj;
149   _PTR(GenericAttribute) myAttr;
150   int                    myType;
151
152   QLineEdit*       myTitleEdit;
153   QTableWidget*    myTable;
154   QPushButton*     myAddRowBtn;
155   QPushButton*     myAddColBtn;
156   QPushButton*     myDelRowBtn;
157   QPushButton*     myDelColBtn;
158   QPushButton*     myAdjustBtn;
159   QPushButton*     mySelectAllBtn;
160   QPushButton*     myClearBtn;
161   QLabel*          mySortPolicyLabel;
162   QComboBox*       mySortPolicyCombo;
163   Qt::Orientation  myOrientation;
164 };
165
166 class VISU_I_EXPORT NumDelegateItem: public QItemDelegate
167 {
168 public:
169   enum NumValidator{ NV_Int, NV_Real };
170
171   NumDelegateItem( QObject* parent, NumValidator mode = NV_Int );
172   virtual ~NumDelegateItem();
173
174   virtual QWidget* createEditor( QWidget* parent,
175                                  const QStyleOptionViewItem& option,
176                                  const QModelIndex& index ) const;
177   virtual void     setEditorData( QWidget* editor,
178                                   const QModelIndex& index ) const;
179 private:
180   int myMode;
181 };
182
183 #endif // VISU_TABLEDLG_H
184