29#ifndef __KDCHARTLISTTABLE_H__
30#define __KDCHARTLISTTABLE_H__
32#include <tqvaluelist.h>
36#include <KDChartDataIntern.h>
39class KDCHART_EXPORT KDChartListTablePrivate :
public TQShared
42 KDChartListTablePrivate() : TQShared() {
47 KDChartListTablePrivate( uint _rows, uint _cols ) : TQShared() {
48 for ( uint i = 0; i < _rows; i++ )
49 row_list.append(
int() );
50 for ( uint j = 0; j < _cols; j++ )
51 col_list.append(
int() );
52 for ( uint k = 0; k < _rows * _cols; k++ )
53 matrix.append( KDChartData() );
58 KDChartListTablePrivate(
const KDChartListTablePrivate& _t ) :
61 row_list( _t.row_list ),
62 col_list( _t.col_list ),
63 col_count( _t.col_count ),
64 row_count( _t.row_count ) {}
65 ~KDChartListTablePrivate() {}
67 void expand( uint _rows, uint _cols ) {
68 if ( _rows > row_count ) {
69 for ( uint r = 0; r < _rows - row_count; ++r ) {
70 row_list.append(
int() );
71 for ( uint i = 0; i < col_count; ++i )
72 matrix.append( KDChartData() );
76 if ( _cols > col_count ) {
79 for ( uint c = 0; c < _cols - old; ++c ) {
80 col_list.append(
int() );
81 for ( uint i = 0; i < row_count; ++i )
82 matrix.insert( matrix.at( i * col_count + old + c ), KDChartData() );
87 const KDChartData& cell( uint _row, uint _col )
const
89 Q_ASSERT( _row < row_count && _col < col_count );
90 return matrix[
static_cast < int > ( _row * col_count + _col ) ];
92 KDChartData& cell( uint _row, uint _col )
94 Q_ASSERT( _row < row_count && _col < col_count );
95 return matrix[
static_cast < int > ( _row * col_count + _col ) ];
98 void setCell( uint _row, uint _col,
const KDChartData& _element )
100 Q_ASSERT( _row < row_count && _col < col_count );
101 matrix[
static_cast < int > ( _row * col_count + _col ) ].setAll( _element );
104 void clearCell( uint _row, uint _col ) {
105 Q_ASSERT( _row < row_count && _col < col_count );
106 matrix[
static_cast < int > ( _row * col_count + _col ) ].clearValue();
109 void clearAllCells() {
110 for ( uint r = 0; r < row_count; ++r )
111 for ( uint c = 0; c < col_count; ++c )
112 matrix[
static_cast < int > ( r * col_count + c ) ].clearValue();
115 int& row( uint _row ) {
116 Q_ASSERT( _row < row_count );
117 return row_list[ _row ];
120 const int& row( uint _row )
const {
121 Q_ASSERT( _row < row_count );
122 return row_list[ _row ];
125 void setRow( uint _row,
const int& _v ) {
126 Q_ASSERT( _row < row_count );
127 row_list[ _row ] = _v;
130 int& col( uint _col ) {
131 Q_ASSERT( _col < col_count );
132 return col_list[ _col ];
136 const int& col( uint _col )
const {
137 Q_ASSERT( _col < col_count );
138 return col_list[ _col ];
141 void setCol( uint _col,
const int& _v ) {
142 Q_ASSERT( _col < col_count );
143 col_list[ _col ] = _v;
146 void insertColumn( uint _c ) {
147 Q_ASSERT( _c <= col_count );
149 TQValueList < KDChartData > ::Iterator it;
150 for ( uint i = 0; i < row_count; ++i ) {
151 it = matrix.at( i * col_count + _c );
152 matrix.insert( it, KDChartData() );
155 TQValueList < int > ::Iterator it2 = col_list.at( _c );
156 col_list.insert( it2,
int() );
159 void insertRow( uint _r ) {
160 Q_ASSERT( _r <= row_count );
162 TQValueList < KDChartData > ::Iterator it = matrix.at( _r * col_count );
163 for ( uint i = 0; i < col_count; ++i )
164 matrix.insert( it, KDChartData() );
166 TQValueList < int > ::Iterator it2 = row_list.at( _r );
167 row_list.insert( it2,
int() );
170 void removeColumn( uint _c ) {
171 Q_ASSERT( _c < col_count );
173 TQValueList < KDChartData > ::Iterator it;
174 for ( uint i = 0; i < row_count; ++i ) {
175 it = matrix.at( i * col_count + _c );
179 TQValueList < int > ::Iterator it2 = col_list.at( _c );
180 col_list.remove( it2 );
183 void removeRow( uint _r ) {
184 Q_ASSERT( _r < row_count );
186 TQValueList < KDChartData > ::Iterator it = matrix.at( _r * col_count );
187 for ( uint i = 0; i < col_count; ++i )
188 it = matrix.remove( it );
190 TQValueList < int > ::Iterator it2 = row_list.at( _r );
191 row_list.remove( it2 );
194 TQValueList < KDChartData > matrix;
195 TQValueList < int > row_list;
196 TQValueList < int > col_list;
206 typedef KDChartListTablePrivate Priv;
207 uint _usedRows, _usedCols;
213 typedef TQValueList < KDChartData > ::Iterator Iterator;
214 typedef TQValueList < KDChartData > ::ConstIterator ConstIterator;
216 typedef TQValueList < int > ::Iterator RowIterator;
217 typedef TQValueList < int > ::ConstIterator ConstRowIterator;
219 typedef TQValueList < int > ::Iterator ColIterator;
220 typedef TQValueList < int > ::ConstIterator ConstColIterator;
225 KDChartListTableData() :
232 KDChartListTableData( uint _rows, uint _cols ) :
235 sh =
new Priv( _rows, _cols );
240 KDChartListTableData(
const KDChartListTableData& _t ) :
242 _useUsedRows = _t._useUsedRows;
243 _useUsedCols = _t._useUsedCols;
244 _usedRows = _t._usedRows;
245 _usedCols = _t._usedCols;
251 virtual ~KDChartListTableData() {
256 KDChartListTableData& operator=(
const KDChartListTableData& t ) {
259 _useUsedRows = t._useUsedRows;
260 _useUsedCols = t._useUsedCols;
261 _usedRows = t._usedRows;
262 _usedCols = t._usedCols;
272 return sh->matrix.begin();
275 ConstIterator begin()
const {
276 return sh->matrix.begin();
280 return sh->matrix.end();
283 ConstIterator end()
const {
284 return sh->matrix.end();
287 ColIterator colBegin() {
288 return sh->col_list.begin();
291 ConstColIterator colBegin()
const {
292 return sh->col_list.begin();
295 ColIterator colEnd() {
296 return sh->col_list.end();
299 ConstColIterator colEnd()
const
301 return sh->col_list.end();
304 RowIterator rowBegin() {
305 return sh->row_list.begin();
308 ConstRowIterator rowBegin()
const {
309 return sh->row_list.begin();
312 RowIterator rowEnd() {
313 return sh->row_list.end();
316 ConstRowIterator rowEnd()
const {
317 return sh->row_list.end();
320 bool isEmpty()
const {
321 return ( sh->col_count == 0 && sh->row_count == 0 );
325 return sh->col_count;
329 return sh->row_count;
332 virtual bool cellCoord( uint _row, uint _col,
334 int coordinate=1 )
const
336 if( _row >= sh->row_count || _col >= sh->col_count )
338 _value = sh->cell( _row, _col ).value( coordinate );
342 virtual bool cellProp( uint _row, uint _col,
345 if( _row >= sh->row_count || _col >= sh->col_count )
347 _prop = sh->cell( _row, _col ).propertySet();
351 virtual void setCell( uint _row, uint _col,
352 const TQVariant& _value1,
353 const TQVariant& _value2=TQVariant() )
356 const KDChartData element( _value1, _value2 );
357 sh->setCell( _row, _col, element );
360 virtual void setProp( uint _row, uint _col,
363 sh->cell( _row, _col ).setPropertySet( _propSet );
366 void clearCell( uint _row, uint _col ) {
368 sh->clearCell( _row, _col );
371 void clearAllCells() {
376 int& row( uint _row ) {
378 return sh->row( _row );
381 const int& row( uint _row )
const {
382 return sh->row( _row );
385 void setRow( uint _row,
const int& _v ) {
387 sh->setRow( _row, _v );
390 int& col( uint _col ) {
392 return sh->col( _col );
395 const int& col( uint _col )
const {
396 return sh->col( _col );
399 void setCol( uint _col,
const int& _v ) {
401 sh->setCol( _col, _v );
404 void insertColumn( uint _c ) {
406 sh->insertColumn( _c );
410 void insertRow( uint _r ) {
416 void removeColumn( uint _c ) {
418 sh->removeColumn( _c );
423 void removeRow( uint _r ) {
430 void expand( uint _rows, uint _cols ) {
432 sh->expand( _rows, _cols );
435 setUsedCols( TQMIN( _usedCols, _cols ) );
437 setUsedRows( TQMIN( _usedRows, _rows ) );
440 void setUsedRows( uint _rows ) {
441 Q_ASSERT( _rows <=
rows() );
442 if( _usedRows < _rows )
449 return _useUsedRows ? _usedRows :
rows();
452 void setUsedCols( uint _cols ) {
453 Q_ASSERT( _cols <=
cols() );
454 if( _usedCols < _cols )
461 return _useUsedCols ? _usedCols :
cols();
469 if ( sh->count > 1 ) {
471 sh =
new Priv( *sh );
Provides a table class holding all data values that are to be used in a chart.
KD Chart's build-in table data for an easy way of storing data values.
virtual uint usedCols() const
Returns the number of cols in the table that actually contain data.
virtual void setSorted(bool sorted)
Specified whether the table is sorted.
virtual uint cols() const =0
Returns the number of cols in the table.
KDChartTableDataBase()
Default constructor.
virtual uint rows() const =0
Returns the number of rows in the table.
virtual uint usedRows() const
Returns the number of rows in the table that actually contain data.
virtual bool sorted() const
Returns whether the table is sorted.