Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / GUITOOLS / VisuGUI_TableDlg.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : VisuGUI_TableDlg.h
23 //  Author : Vadim SANDLER
24 //  Module : VISU
25 //
26 #ifndef VisuGUI_TABLE_DLG_H
27 #define VisuGUI_TABLE_DLG_H
28
29 #include <QDialog>
30 #include <QLineEdit>
31 #include <QPushButton>
32 #include <QItemDelegate>
33
34 class QTableWidget;
35 class VisuGUI_TableWidget;
36
37 #include <SALOMEDSClient_SObject.hxx>
38
39 #include "VisuGUITools.h"
40
41 class VISU_GUITOOLS_EXPORT VisuGUI_TableDlg : public QDialog
42
43   Q_OBJECT
44
45 public:
46
47   enum { ttNone, ttInt, ttReal, ttBoth, ttAuto };
48
49   VisuGUI_TableDlg( QWidget* parent, 
50                     _PTR(SObject) obj, 
51                     bool edit = false,
52                     int which = ttAuto, 
53                     Qt::Orientation orient = Qt::Horizontal,
54                     bool showColumnTitles = true );
55   ~VisuGUI_TableDlg();
56
57 private:
58   void keyPressEvent( QKeyEvent* e );
59
60 public slots:
61   void onOK();
62   void onHelp(); 
63
64 private:
65   void initDlg();
66
67 private:
68   VisuGUI_TableWidget*   myIntTable;
69   VisuGUI_TableWidget*   myRealTable;
70   QPushButton*           myOKBtn;
71   QPushButton*           myCancelBtn;
72   QPushButton*           myHelpBtn;
73
74   _PTR(SObject) myObject;
75 };
76  
77 class VISU_GUITOOLS_EXPORT VisuGUI_TableWidget : public QWidget
78 {
79   Q_OBJECT
80 public:
81   VisuGUI_TableWidget( QWidget* parent = 0, 
82                        const char* name = 0, 
83                        bool edit = false, 
84                        Qt::Orientation orient = Qt::Horizontal,
85                        bool showColumnTitles = true );
86   ~VisuGUI_TableWidget();
87
88   void    setTableTitle( const QString& title );
89   QString getTableTitle();
90   void    setNumRows( const int num );
91   int     getNumRows();
92   void    setNumCols( const int num );
93   int     getNumCols();
94   void    setRowTitles( QStringList& tlts );
95   void    getRowTitles( QStringList& tlts );
96   void    setColTitles( QStringList& tlts );
97   void    getColTitles( QStringList& tlts );
98   void    setUnitsTitle( const QString& tlt );
99   void    setUnits( QStringList& units );
100   void    getUnits( QStringList& units );
101   void    setRowData( int row, QStringList& data );
102   void    getRowData( int row, QStringList& data );
103
104   QTableWidget*     getTable()     { return myTable; } 
105   QLineEdit*       getTitleEdit() { return myTitleEdit; }
106
107   bool    eventFilter( QObject* o, QEvent* e);
108
109 public slots:
110   void updateButtonsState();
111   void addRow();
112   void addCol();
113   void delRow();
114   void delCol();
115   void adjustTable();
116   void selectAll();
117   void clearTable();
118
119 private:
120   QLineEdit*       myTitleEdit;
121   QTableWidget*    myTable;
122   QPushButton*     myAddRowBtn;
123   QPushButton*     myAddColBtn;
124   QPushButton*     myDelRowBtn;
125   QPushButton*     myDelColBtn;
126   QPushButton*     myAdjustBtn;
127   QPushButton*     mySelectAllBtn;
128   QPushButton*     myClearBtn;
129   Qt::Orientation  myOrientation;
130 };
131
132 class VISU_GUITOOLS_EXPORT NumDelegateItem: public QItemDelegate
133 {
134 public:
135   enum NumValidator{ NV_Int, NV_Real };
136
137   NumDelegateItem( QObject* parent, NumValidator mode = NV_Int );
138   virtual ~NumDelegateItem();
139
140   virtual QWidget * createEditor( QWidget * parent,
141                                   const QStyleOptionViewItem & option,
142                                   const QModelIndex & index ) const;
143   virtual void setEditorData( QWidget * editor,
144                               const QModelIndex & index ) const;
145 private:
146   int         myMode;
147 };
148
149 #endif // VisuGUI_TABLE_DLG_H
150