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
|
/*
**************************************************************************
description
--------------------
copyright : (C) 2002 by Andreas Zehender
email : zehender@kde.org
**************************************************************************
**************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
**************************************************************************/
#include "pmpolynomedit.h"
#include "pmpolynom.h"
#include "pmpolynomexponents.h"
#include "pmlineedits.h"
#include "pmformulalabel.h"
#include <layout.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqlabel.h>
#include <klocale.h>
#include <kdialog.h>
PMPolynomEdit::PMPolynomEdit( TQWidget* parent, const char* name )
: Base( parent, name )
{
m_pDisplayedObject = 0;
m_currentOrder = 0;
m_readOnly = false;
}
void PMPolynomEdit::createTopWidgets( )
{
Base::createTopWidgets( );
TQHBoxLayout* hl = new TQHBoxLayout( topLayout( ) );
hl->addWidget( new TQLabel( i18n( "Order" ), this ) );
m_pOrder = new TQSpinBox( 2, 7, 1, this );
hl->addWidget( m_pOrder );
hl->addStretch( 1 );
connect( m_pOrder, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( slotOrderChanged( int ) ) );
topLayout( )->addWidget( new TQLabel( i18n( "Formula:" ), this ) );
m_pPolyWidget = new TQWidget( this );
topLayout( )->addWidget( m_pPolyWidget );
m_pSturm = new TQCheckBox( i18n( "Sturm" ), this );
topLayout( )->addWidget( m_pSturm );
connect( m_pSturm, TQT_SIGNAL( clicked( ) ), TQT_SIGNAL( dataChanged( ) ) );
}
void PMPolynomEdit::displayObject( PMObject* o )
{
if( o->isA( "Polynom" ) )
{
bool readOnly = o->isReadOnly( );
m_readOnly = readOnly;
m_pDisplayedObject = ( PMPolynom* ) o;
displayCoefficients( m_pDisplayedObject->coefficients( ),
m_pDisplayedObject->polynomOrder( ),
m_pDisplayedObject->polynomOrder( ) );
m_pSturm->setChecked( m_pDisplayedObject->sturm( ) );
m_pSturm->setEnabled( !readOnly );
if( m_pDisplayedObject->polynomOrder( ) == 2 )
m_pSturm->hide( );
else
m_pSturm->show( );
bool sb = m_pOrder->signalsBlocked( );
m_pOrder->blockSignals( true );
m_pOrder->setValue( m_pDisplayedObject->polynomOrder( ) );
m_pOrder->blockSignals( sb );
Base::displayObject( o );
}
else
kdError( PMArea ) << "PMPolynomEdit: Can't display object\n";
}
void PMPolynomEdit::displayCoefficients( const PMVector& co, int cOrder,
int dOrder )
{
TQValueList<PMPolynomExponents>& polynom
= PMPolynomExponents::polynom( dOrder );
if( dOrder != m_currentOrder )
{
if( m_currentOrder > 0 )
{
if( m_pPolyWidget->layout( ) )
delete m_pPolyWidget->layout( );
m_labels.setAutoDelete( true );
m_labels.clear( );
m_labels.setAutoDelete( false );
m_edits.setAutoDelete( true );
m_edits.clear( );
m_edits.setAutoDelete( false );
}
int nedit = polynom.count( );
int nr = ( nedit + 2 ) / 3;
int i;
TQGridLayout* gl = new TQGridLayout( m_pPolyWidget, nr * 2 - 1, 9, 0 );
TQLabel* l = 0;
PMFloatEdit* edit;
PMFormulaLabel* fl;
TQValueList<PMPolynomExponents>::ConstIterator it = polynom.begin( );
TQString text;
int row, col;
TQString plus( "+" );
for( i = 0; it != polynom.end( ); i++, ++it )
{
row = ( i / 3 ) * 2;
col = ( i % 3 ) * 3;
if( i != 0 )
{
l = new TQLabel( plus, m_pPolyWidget );
m_labels.append( l );
gl->addWidget( l, row, col );
l->show( );
}
edit = new PMFloatEdit( m_pPolyWidget );
connect( edit, TQT_SIGNAL( dataChanged( ) ), TQT_SIGNAL( dataChanged( ) ) );
m_edits.append( edit );
gl->addWidget( edit, row, col + 1 );
edit->show( );
edit->setReadOnly( m_readOnly );
fl = new PMFormulaLabel( *it, m_pPolyWidget );
m_labels.append( fl );
gl->addWidget( fl, row, col + 2 );
fl->show( );
}
for( i = 0; i < ( nr - 1 ); i++ )
gl->addRowSpacing( i * 2 + 1, KDialog::spacingHint( ) );
emit sizeChanged( );
}
m_currentOrder = dOrder;
if( dOrder == cOrder )
{
TQPtrListIterator<PMFloatEdit> eit( m_edits );
int i;
for( i = 0; *eit; ++eit, ++i )
( *eit )->setValue( co[i] );
}
else if( dOrder > cOrder )
{
TQValueList<PMPolynomExponents>::ConstIterator dit = polynom.begin( );
TQValueList<PMPolynomExponents>& cpoly
= PMPolynomExponents::polynom( cOrder );
TQValueList<PMPolynomExponents>::ConstIterator cit = cpoly.begin( );
TQPtrListIterator<PMFloatEdit> eit( m_edits );
int i = 0;
for( ; ( dit != polynom.end( ) ) && ( cit != cpoly.end( ) ); ++dit, ++eit )
{
if( *dit == *cit )
{
( *eit )->setValue( co[i] );
i++;
cit++;
}
else
( *eit )->setValue( 0.0 );
}
if( ( dit != polynom.end( ) ) || ( cit != cpoly.end( ) ) )
kdError( PMArea ) << "displayExponents is buggy!\n";
}
else // dOrder < cOrder
{
TQValueList<PMPolynomExponents>::ConstIterator dit = polynom.begin( );
TQValueList<PMPolynomExponents>& cpoly
= PMPolynomExponents::polynom( cOrder );
TQValueList<PMPolynomExponents>::ConstIterator cit = cpoly.begin( );
TQPtrListIterator<PMFloatEdit> eit( m_edits );
int i = 0;
for( ; ( dit != polynom.end( ) ) && ( cit != cpoly.end( ) ); ++cit, ++i )
{
if( *dit == *cit )
{
( *eit )->setValue( co[i] );
++eit;
++dit;
}
}
if( ( dit != polynom.end( ) ) || ( cit != cpoly.end( ) ) )
kdError( PMArea ) << "displayExponents is buggy!\n";
}
}
PMVector PMPolynomEdit::coefficients( ) const
{
TQPtrListIterator<PMFloatEdit> eit( m_edits );
int num = m_edits.count( );
PMVector v( num );
int i;
for( i = 0 ; *eit; ++eit, ++i )
v[i] = ( *eit )->value( );
return v;
}
void PMPolynomEdit::saveContents( )
{
if( m_pDisplayedObject )
{
m_pDisplayedObject->setPolynomOrder( m_pOrder->value( ) );
m_pDisplayedObject->setCoefficients( coefficients( ) );
Base::saveContents( );
m_pDisplayedObject->setSturm( m_pSturm->isChecked( ) );
}
}
bool PMPolynomEdit::isDataValid( )
{
TQPtrListIterator<PMFloatEdit> eit( m_edits );
for( ; *eit; ++eit )
if( !( *eit )->isDataValid( ) )
return false;
return Base::isDataValid( );
}
void PMPolynomEdit::slotOrderChanged( int order )
{
if( order == 2 )
m_pSturm->hide( );
else
m_pSturm->show( );
displayCoefficients( coefficients( ), m_currentOrder, order );
}
#include "pmpolynomedit.moc"
|