1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
/* -*- Mode: C++ -*-
KDChart - a multi-platform charting engine
*/
/****************************************************************************
** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB. All rights reserved.
**
** This file is part of the KDChart library.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid commercial KDChart licenses may use this file in
** accordance with the KDChart Commercial License Agreement provided with
** the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.klaralvdalens-datakonsult.se/?page=products for
** information about KDChart Commercial License Agreements.
**
** Contact [email protected] if any conditions of this
** licensing are not clear to you.
**
**********************************************************************/
#ifndef __KDCHARTVECTORTABLE_H__
#define __KDCHARTVECTORTABLE_H__
#include <tqvaluevector.h>
#include <tqshared.h>
#include <tqtable.h>
#include <KDChartDataIntern.h>
#include <KDChartTableBase.h>
class KDCHART_EXPORT KDChartVectorTablePrivate : public TQShared
{
public:
KDChartVectorTablePrivate() : TQShared() {
row_count = 0;
col_count = 0;
}
KDChartVectorTablePrivate( uint _rows, uint _cols ) : TQShared() {
matrix.resize( _rows * _cols, KDChartData() );
col_count = _cols;
row_count = _rows;
}
KDChartVectorTablePrivate( const KDChartVectorTablePrivate& _t ) :
TQShared(),
matrix( _t.matrix ),
col_count( _t.col_count ),
row_count( _t.row_count ) {}
~KDChartVectorTablePrivate() {}
void expand( uint _rows, uint _cols ) {
// Save the old table
TQValueVector<KDChartData> save( matrix );
// Delete old data, then resize
matrix.resize( 0 );
matrix.resize( _rows * _cols, KDChartData() );
// Copy over the old data
for( uint row = 0; row < TQMIN( row_count, _rows ); row++ )
for( uint col = 0; col < TQMIN( col_count, _cols ); col++ )
matrix[ row * _cols + col ].setAll( save[ row * col_count + col ] );
// set the new counts
col_count = _cols;
row_count = _rows;
}
KDChartData& cell( uint _row, uint _col ) {
Q_ASSERT( _row < row_count );
Q_ASSERT( _col < col_count );
return matrix[ static_cast < int > ( _row * col_count + _col ) ];
}
const KDChartData& cell( uint _row, uint _col ) const {
Q_ASSERT( _row < row_count );
Q_ASSERT( _col < col_count );
return matrix[ static_cast < int > ( _row * col_count + _col ) ];
}
void setCell( uint _row, uint _col, const KDChartData& _element ) {
Q_ASSERT( _row < row_count );
Q_ASSERT( _col < col_count );
matrix[ static_cast < int > ( _row * col_count + _col ) ].setAll( _element );
}
void clearCell( uint _row, uint _col ) {
Q_ASSERT( _row < row_count );
Q_ASSERT( _col < col_count );
matrix[ static_cast < int > ( _row * col_count + _col ) ].clearValue();
}
void clearAllCells() {
for ( uint r = 0; r < row_count; ++r )
for ( uint c = 0; c < col_count; ++c )
matrix[ r * col_count + c ].clearValue();
}
TQValueVector<KDChartData> matrix;
uint col_count;
uint row_count;
};
class KDCHART_EXPORT KDChartVectorTableData : public KDChartTableDataBase
{
Q_OBJECT
private:
typedef KDChartVectorTablePrivate Priv;
uint _usedRows, _usedCols;
public:
/**
* Typedefs
*/
typedef TQValueVector<KDChartData>::iterator Iterator;
typedef TQValueVector<KDChartData>::const_iterator ConstIterator;
typedef TQValueVector<int>::iterator RowIterator;
typedef TQValueVector<int>::const_iterator ConstRowIterator;
typedef TQValueVector<int>::iterator ColIterator;
typedef TQValueVector<int>::const_iterator ConstColIterator;
/**
* API
*/
KDChartVectorTableData() :
KDChartTableDataBase()
{
sh = new Priv;
_usedCols = 0;
_usedRows = 0;
}
KDChartVectorTableData( uint _rows, uint _cols ) :
KDChartTableDataBase()
{
sh = new Priv( _rows, _cols );
_usedRows = _rows;
_usedCols = _cols;
}
KDChartVectorTableData( const KDChartVectorTableData& _t ) :
KDChartTableDataBase( _t ) {
_useUsedRows = _t._useUsedRows;
_useUsedCols = _t._useUsedCols;
_usedRows = _t._usedRows;
_usedCols = _t._usedCols;
sh = _t.sh;
sh->ref();
setSorted( _t.sorted() );
}
virtual ~KDChartVectorTableData() {
if ( sh->deref() )
delete sh;
}
KDChartVectorTableData& operator=( const KDChartVectorTableData& t ) {
if ( &t == this )
return * this;
_useUsedRows = t._useUsedRows;
_useUsedCols = t._useUsedCols;
_usedRows = t._usedRows;
_usedCols = t._usedCols;
t.sh->ref();
if ( sh->deref() )
delete sh;
sh = t.sh;
setSorted( t.sorted() );
return *this;
}
public slots:
Iterator begin() {
return sh->matrix.begin();
}
ConstIterator begin() const {
return sh->matrix.begin();
}
Iterator end() {
return sh->matrix.end();
}
ConstIterator end() const {
return sh->matrix.end();
}
bool isEmpty() const {
return ( sh->col_count == 0 && sh->row_count == 0 );
}
uint cols() const {
return sh->col_count;
}
uint rows() const {
return sh->row_count;
}
// WARNING: The KDChartData class is an internal class now,
// and nobody supposed to use it any longer.
// Instead, please use cellCoord(), cellProp(), setCell(), setProp(), ...
// (khz, 2006-05-23)
/*
KDChartData& cell( uint _row, uint _col ) {
detach();
return sh->cell( _row, _col );
}
*/
virtual bool cellCoord( uint _row, uint _col,
TQVariant& _value,
int coordinate=1 ) const
{
if( _row >= sh->row_count || _col >= sh->col_count )
return false;
_value = sh->cell( _row, _col ).value( coordinate );
return true;
}
virtual bool cellProp( uint _row, uint _col,
int& _prop ) const
{
if( _row >= sh->row_count || _col >= sh->col_count )
return false;
_prop = sh->cell( _row, _col ).propertySet();
return true;
}
virtual void setCell( uint _row, uint _col,
const TQVariant& _value1,
const TQVariant& _value2=TQVariant() ) {
detach();
const KDChartData element( _value1, _value2 );
sh->setCell( _row, _col, element );
}
virtual void setProp( uint _row, uint _col,
int _propSet=0 )
{
sh->cell( _row, _col ).setPropertySet( _propSet );
}
void clearCell( uint _row, uint _col ) {
detach();
sh->clearCell( _row, _col );
}
void clearAllCells() {
detach();
sh->clearAllCells();
}
void expand( uint _rows, uint _cols ) {
detach();
sh->expand( _rows, _cols );
// adjust the usedRows / usedCols, if they had been set before
if( _useUsedCols )
setUsedCols( TQMIN( _usedCols, _cols ) );
if( _useUsedRows )
setUsedRows( TQMIN( _usedRows, _rows ) );
}
void setUsedRows( uint _rows ) {
Q_ASSERT( _rows <= rows() );
if( _usedRows < _rows )
setSorted( false );
_usedRows = _rows;
_useUsedRows = true;
}
uint usedRows() const {
return _useUsedRows ? _usedRows : rows();
}
void setUsedCols( uint _cols ) {
Q_ASSERT( _cols <= cols() );
if( _usedCols < _cols )
setSorted( false );
_usedCols = _cols;
_useUsedCols = true;
}
uint usedCols() const {
return _useUsedCols ? _usedCols : cols();
}
private:
/**
* Helpers
*/
void detach() {
if ( sh->count > 1 ) {
sh->deref();
sh = new Priv( *sh );
}
setSorted( false );
}
/**
* Variables
*/
Priv* sh;
};
#endif
// __KDCHARTLISTTABLE_H__
|