1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "QDS_Table.h"
25 class QDS_Table::DeleteFilter : public QObject
28 DeleteFilter( QObject* = 0 );
29 virtual ~DeleteFilter();
31 virtual bool eventFilter( QObject*, QEvent* );
34 QDS_Table::DeleteFilter::DeleteFilter( QObject* parent )
39 QDS_Table::DeleteFilter::~DeleteFilter()
43 bool QDS_Table::DeleteFilter::eventFilter( QObject* o, QEvent* e )
45 if ( e->type() == QEvent::DeferredDelete )
51 QDS_Table::QDS_Table( QWidget* parent, const char* name )
52 : QtxTable( parent, name ),
60 QDS_Table::QDS_Table( int r, int c, QWidget* parent, const char* name )
61 : QtxTable( r, c, parent, name ),
67 myRowEdit.resize( r );
68 myColEdit.resize( c );
71 QDS_Table::~QDS_Table()
75 QDS_Datum* QDS_Table::horizontalHeaderEditor() const
80 QDS_Datum* QDS_Table::verticalHeaderEditor() const
85 QDS_Datum* QDS_Table::headerEditor( const Orientation o ) const
87 return o == Horizontal ? myHorEdit : myVerEdit;
90 void QDS_Table::setVerticalHeaderEditor( QDS_Datum* dat )
92 setHeaderEditor( Vertical, dat );
95 void QDS_Table::setHorizontalHeaderEditor( QDS_Datum* dat )
97 setHeaderEditor( Horizontal, dat );
100 void QDS_Table::setHeaderEditor( QDS_Datum* dat )
102 setHeaderEditor( Vertical, dat );
103 setHeaderEditor( Horizontal, dat );
106 void QDS_Table::setHeaderEditor( const Orientation o, QDS_Datum* dat )
108 if ( headerEditor( o ) == dat )
111 if ( isHeaderEditing() )
114 if ( o == Horizontal )
122 QDS_Datum* QDS_Table::tableEditor() const
127 QDS_Datum* QDS_Table::rowEditor( const int row ) const
129 if ( row < 0 || row >= (int)myRowEdit.size() )
132 return myRowEdit.at( row );
135 QDS_Datum* QDS_Table::columnEditor( const int col ) const
137 if ( col < 0 || col >= (int)myColEdit.size() )
140 return myColEdit.at( col );
143 QDS_Datum* QDS_Table::cellEditor( const int row, const int col ) const
145 if ( !myCellEdit.contains( row ) )
148 const DatumMap& map = myCellEdit[row];
149 return map.contains( col ) ? map[col] : 0;
152 void QDS_Table::setTableEditor( QDS_Datum* dat )
154 if ( tableEditor() == dat )
157 if ( isEditing() && !cellEditor( currEditRow(), currEditCol() ) &&
158 !columnEditor( currEditCol() ) && !rowEditor( currEditRow() ) )
159 endEdit( currEditRow(), currEditCol(), false, false );
165 void QDS_Table::setRowEditor( const int row, QDS_Datum* dat )
167 if ( row < 0 || row >= (int)myRowEdit.size() || rowEditor( row ) == dat )
170 if ( isEditing() && row == currEditRow()&&
171 !cellEditor( currEditRow(), currEditCol() ) )
172 endEdit( currEditRow(), currEditCol(), false, false );
174 myRowEdit.insert( row, dat );
178 void QDS_Table::setColumnEditor( const int col, QDS_Datum* dat )
180 if ( col < 0 || col >= (int)myColEdit.size() || columnEditor( col ) == dat )
183 if ( isEditing() && col == currEditCol()&&
184 !cellEditor( currEditRow(), currEditCol() ) )
185 endEdit( currEditRow(), currEditCol(), false, false );
187 myColEdit.insert( col, dat );
191 void QDS_Table::setCellEditor( const int row, const int col, QDS_Datum* dat )
193 if ( row < 0 || row >= numRows() || col < 0 || col >= numCols() || cellEditor( row, col ) == dat )
196 if ( isEditing() && currEditRow() == row && currEditCol() == col && actualCellEditor( row, col ) != dat )
197 endEdit( currEditRow(), currEditCol(), false, false );
199 if ( !myCellEdit.contains( row ) )
200 myCellEdit.insert( row, DatumMap() );
202 myCellEdit[row].insert( col, dat );
206 QDS_Datum* QDS_Table::actualCellEditor( const int row, const int col ) const
208 QDS_Datum* dat = cellEditor( row, col );
210 dat = columnEditor( col );
212 dat = rowEditor( row );
218 void QDS_Table::setNumRows( int r )
221 QtxTable::setNumRows( r );
223 if ( isKeepEditors() )
224 myRowEdit.resize( QMAX( (int)myRowEdit.size(), r ) );
227 myRowEdit.resize( r );
228 for ( int i = r + 1; i <= old; i++ )
229 myCellEdit.remove( i );
233 void QDS_Table::setNumCols( int c )
236 QtxTable::setNumCols( c );
238 if ( isKeepEditors() )
239 myColEdit.resize( QMAX( (int)myColEdit.size(), c ) );
242 myColEdit.resize( c );
243 for ( CellMap::Iterator it = myCellEdit.begin(); it != myCellEdit.end(); ++it )
245 DatumMap& map = it.data();
246 for ( int i = c + 1; i <= old; i++ )
252 void QDS_Table::clearCellWidget( int row, int col )
254 QDS_Datum* dat = actualCellEditor( row, col );
258 QtxTable::clearCellWidget( row, col );
261 bool QDS_Table::isKeepEditors() const
266 void QDS_Table::setKeepEditors( const bool on )
271 QWidget* QDS_Table::createHeaderEditor( QHeader* header, const int sect, const bool init )
276 QDS_Datum* dat = headerEditor( header->orientation() );
277 QWidget* wid = dat ? dat->widget( QDS::Control ) : 0;
281 dat->setStringValue( header->label( sect ) );
284 dat->setProperty( "Selection", true );
287 wid = QtxTable::createHeaderEditor( header, sect, init );
292 QWidget* QDS_Table::createEditor( int row, int col, bool init ) const
294 QDS_Datum* dat = actualCellEditor( row, col );
295 QWidget* wid = dat ? dat->widget( QDS::Control ) : 0;
299 dat->setStringValue( text( row, col ) );
302 dat->setProperty( "Selection", true );
305 wid = QtxTable::createEditor( row, col, init );
310 void QDS_Table::endEdit( int row, int col, bool accept, bool )
312 QtxTable::endEdit( row, col, accept, true );
315 void QDS_Table::setCellContentFromEditor( int row, int col )
317 QDS_Datum* dat = actualCellEditor( row, col );
319 setText( row, col, dat->stringValue() );
321 QtxTable::setCellContentFromEditor( row, col );
324 void QDS_Table::setHeaderContentFromEditor( QHeader* header, const int sect, QWidget* editor )
329 QDS_Datum* dat = headerEditor( header->orientation() );
331 header->setLabel( sect, dat->stringValue() );
333 QtxTable::setHeaderContentFromEditor( header, sect, editor );
336 void QDS_Table::initEditor( QDS_Datum* dat )
343 static QGuardedPtr<DeleteFilter> _filter = 0;
345 _filter = new DeleteFilter( 0 );
347 if ( dat->widget( QDS::Control ) )
348 dat->widget( QDS::Control )->installEventFilter( _filter );