1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #ifndef YACSGui_TABLE_HEADER
22 #define YACSGui_TABLE_HEADER
25 #include <qvaluevector.h>
26 #include <qtoolbutton.h>
30 typedef std::list<int> IntListVal;
31 typedef std::list<double> DoubleListVal;
34 * Class, intended to create table with different types of values entered to columns.
35 * The following types are possible: int, double (created as spinboxes),
36 * string (created as lineedit) and it's possible to specify combobox.
38 class YACSGui_Table : public QtxTable
43 /*enum, defines types of columns
45 typedef enum { String, Int, Double, Combo, ComboSelect } CellType;
48 YACSGui_Table( const int numRows, const int numCols, QWidget*, CellType = Int );
49 virtual ~YACSGui_Table();
52 * Returns type assigned to all cells of the table by default
54 CellType defCellType() const;
57 * Set type of cells, which will be set to table by default
59 void setDefCellType( CellType );
62 * Returns type of given cell, if cell type is not set
63 * evidently then returns type of cell which is set by default.
64 * Parameters: int - row number
66 * bool - returns true if it is possible to determine column type, otherwise - false
68 CellType cellType( const int, const int, bool& ) const;
71 * Set type for cell at the table
72 * Parameters: int - row number, if row < 0 ( i.e. row is not defined),
73 * set the same types for all rows in the given column
75 * CellType - cell type
77 void setCellType( const int, const int, CellType );
81 * Returns value by default for given type
83 QString defValue( CellType ) const;
86 * Sets value by default for given type
88 void setDefValue( CellType, const QString& );
91 * Returns value by default for given row and column (i.e. cell)
93 QString defValue( const int, const int ) const;
96 * Sets value by default for given row and column (i.e. cell)
98 void setDefValue( const int, const int, const QString& );
102 * This method finishes ediitng the cell contents in a cell specified by currEditRow() and currEditCol().
103 * Modifications are accepted or rejected depending on <accept> parameter value
105 void stopEdit( const bool );
109 * Returns list of double values for given column. If value is not defined
110 * in row of the table then 0 will be added to the list
111 * and parameter bool will return false
112 * Paramrters: first int - column number
113 * second int - It is an index of string starting from which
114 * all following strings are ignored, i.e. their
115 * values are not added to the list
116 * ok - returns true if all values from the strings
117 * had been sucessfully casted to double.
119 DoubleListVal doubles( const int, const int = 0, bool* ok = 0 ) const;
122 * Fill given column with values, given at list. If size of list is lesser that number
123 * of rows in the table then the rest rows are filled by values set by parameter def.
124 * Parameters: col - column number
125 * DoubleListVal- list of values
126 * def- value for rows which are not given at list
127 * Resize - determines if need to change number of rows in the table
128 * according to given list size
130 void setDoubles( const int, const DoubleListVal&, const double, const bool = false );
133 * Returns list of integer values for given column. If value is not defined
134 * in row of the table then 0 will be added to the list
135 * and parameter bool will return false
136 * Paramrters: first int - column number
137 * ok - returns true if all values from the strings
138 * had been sucessfully casted to double.
140 IntListVal integers( const int, bool* ok = 0 ) const;
143 * Fill given column with values, given at list. If size of list is lesser that number
144 * of rows in the table then the rest rows are filled by values set by parameter def.
145 * Parameters: col - column number
146 * DoubleListVal- list of values
147 * def- value for string which are not given at list
148 * Resize - determines if need to change number of rows in the table
149 * according to given list size
151 void setIntegers( const int, const IntListVal&, const int, const bool = false );
154 * Returns list of string values for given column into QStringList. If value is not defined
155 * in row of the table then QString::null will be added to the list
156 * Paramrters: first int - column number
157 * QStringList - list of string values
159 void strings( const int, QStringList& ) const;
162 * Fill given column with values, given at list.
163 * Parameters: col - column number
164 * DoubleListVal- list of values
165 * Resize - determines if need to change number of rows in the table
166 * according to given list size
168 void setStrings( const int, const QStringList&, const bool = false );
171 * Returns list of integer values for given column. If value is not defined
172 * in row of the table then -1 will be added to the list
173 * Paramrters: int - column number
175 IntListVal valueComboBox( const int ) const;
178 * Returns values of integer of item for given row and column
180 int intValue( const int, const int, bool* ok = 0 ) const;
183 * Returns values of double of item for given row and column
185 double doubleValue( const int, const int, bool* ok = 0 ) const;
188 * Returns values of integer of item for given row and column
190 int intValueCombo( const int, const int ) const;
193 * Allow getting value of special table field: when this field is true,
194 * the contents of the cell being edited are synchroinized with the contents of
195 * the cell editor widget, and valueChanged() signal is emitted each time the
196 * editor contents change - for instance, each time the user types a character
197 * in a line edit that is used as a cell editor.
199 bool isEditorSync() const;
202 * Allow setting value of special table field: when this field is true,
203 * the contents of the cell being edited are synchroinized with the contents of
204 * the cell editor widget, and valueChanged() signal is emitted each time the
205 * eidtor contents change - for instance, eahc time the user types a character
206 * in a line edit that is used as a cell editor.
208 void setEditorSync( const bool );
211 * Returns values(true/false) of item for given row and column
212 * Parameters: first int - row - row number
213 * second int - col - column number
215 bool readOnly( const int, const int ) const;
218 * Sets flag read only for given row and column.
219 * Parameters: first int - row - row number, if row < 0 ( i.e. row is not defined),
220 * set the read only flag for all rows in the given column
221 * second int - col - column number
223 void setReadOnly( const int, const int, const bool );
226 * Rebuilds table items if necessary, for instance when the number of rows
227 * or columns changes.
232 * Generates list of strings for given row and column (i.e. cell) which will be used at combobox
233 * Parameters: int - row - row number, if row < 0 ( i.e. row is not defined),
234 * set the same parameters for all rows in the given column
235 * int - col - column number
236 * Text - values for combobox for given column separated by ";"
238 void setParams( const int, const int, const QString& );
241 * Returns list of strings for indexes of row and column (i.e. cell) which defines it's combobox contents
242 * Parameters: int - row - row number
243 * int - col - column number
245 QStringList Params( int, int ) const;
248 * Returns number of selected row
250 int selectedRow() const;
252 virtual QRect cellGeometry ( int row, int col ) const;
255 void itemCreated( const int, const int );
256 void selectButtonClicked( const int, const int );
260 * Sets the number of the columns at the table. called method update()
262 virtual void setNumCols( int c );
265 * Sets the number of the rows at the table. called method update()
267 virtual void setNumRows( int r );
270 * Inserts "count" empty rows at row "row"
272 virtual void insertRows( int row, int count = 1 );
275 * Inserts "count" empty columns at column "col"
277 virtual void insertColumns( int col, int count = 1 );
280 * Redefine this slot to show/hide the cell's selection control
282 virtual void setCurrentCell ( int row, int col );
284 void onSelectButton();
288 * creates new item for tables with type,
289 * defined by CellType and by value, defined by default at row row and column col
291 virtual QTableItem* createItem( const int, const int, CellType ) const;
293 * Returns type of the table item
295 virtual CellType itemType( QTableItem* ) const;
297 virtual void endEdit( int row, int col, bool accept, bool replace );
300 virtual void columnWidthChanged( int col );
302 virtual void rowHeightChanged( int row );
306 * slot which is called when syncronization is enabled - it
307 * receives new value from editor and saves it ro cell and emits valueChanged()
313 * change number of strings according to count when resize == true,
314 * otherwise retur miniman value from count or numRows
316 int updateSize( const int, const bool );
321 QMap<CellType, QString> myTDefValues;
323 QMap<int, QMap<int, QString> > myRCDefValues; // row <-> ( column <-> DefValue )
325 QMap<int, QMap<int, QStringList> > myRCComboBoxParam; // row <-> ( column <-> Params )
327 QValueVector<CellType> myColTypes;
328 QMap<int, QMap<int, CellType> > myCellTypes; //column <-> ( row <-> cellType )
333 * The YACSGui_TableItem class provides the cell content for YACSGui_Table cells.
335 class YACSGui_TableItem : public QTableItem
338 YACSGui_TableItem( QTable*, YACSGui_Table::CellType );
339 virtual ~YACSGui_TableItem();
342 * Returns type of item
344 YACSGui_Table::CellType type() const;
347 * Sets text for current item
349 virtual void setText( const QString& );
352 * This virtual function creates an editor which the user can interact with to edit the cell's contents.
354 virtual QWidget* createEditor() const;
357 * Updates cell contents after cell editing has been finished. Retrieves values from the editor widget.
359 virtual void setContentFromEditor( QWidget* );
362 * Returns flag read only for item.
364 bool readOnly() const;
367 * Sets flag read only for item.
369 void setReadOnly( const bool );
373 YACSGui_Table::CellType myType;
379 * The YACSGui_TableComboSelectItem class provides the cell content with combo box and selection control for YACSGui_Table cells.
381 class YACSGui_TableComboSelectItem : public YACSGui_TableItem
384 YACSGui_TableComboSelectItem( QTable*, bool );
385 virtual ~YACSGui_TableComboSelectItem();
388 * Sets text for current item
390 virtual void setText( const QString& );
393 * This virtual function creates an editor which the user can interact with to edit the cell's contents.
395 virtual QWidget* createEditor() const;
398 * Updates cell contents after cell editing has been finished. Retrieves values from the editor widget.
400 virtual void setContentFromEditor( QWidget* );
402 virtual void showEditor( bool theIsEditing = false );
403 virtual void hideEditor();
405 QToolButton* selectButton() const { return mySelectBtn; }
407 void showText( QString theText );
410 void createSelectButton();
411 void placeEditor( bool theIsEditing );
412 void updateSelectButtonState();
414 QToolButton* mySelectBtn;