kchart

kchartParameterConfigPage.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001,2002,2003,2004 Laurent Montel <montel@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20
21#include "kchartParameterConfigPage.h"
22#include "kchartParameterConfigPage.moc"
23
24#include <tdeapplication.h>
25#include <tdelocale.h>
26#include <tqlayout.h>
27#include <tqlabel.h>
28#include <tqcheckbox.h>
29#include <tqlineedit.h>
30#include <tqspinbox.h>
31#include <tqbuttongroup.h>
32#include <tqradiobutton.h>
33#include <tqvbuttongroup.h>
34#include <tdefontdialog.h>
35#include <tqwhatsthis.h>
36
38#include "kchart_params.h"
39
40namespace KChart
41{
42
43KChartParameterConfigPage::KChartParameterConfigPage( KChartParams* params,
44 TQWidget* parent ) :
45 TQWidget( parent ),_params( params )
46{
47 // toplevel layout
48 TQVBoxLayout* toplevel = new TQVBoxLayout( this, 10 );
49
50 TQGridLayout* layout = new TQGridLayout( 1, 3 );
51 toplevel->addLayout( layout );
52
53 // The "Parameters" button group
54 TQButtonGroup* gb1 = new TQButtonGroup( 0, TQt::Vertical, i18n("Parameters"), this );
55 gb1->layout()->setSpacing(KDialog::spacingHint());
56 gb1->layout()->setMargin(KDialog::marginHint());
57 TQGridLayout *grid1 = new TQGridLayout(gb1->layout(),9,1);
58
59 grid = new TQCheckBox( i18n( "Grid" ), gb1 );
60 TQWhatsThis::add(grid, i18n("If this is checked, the grid is shown. If you uncheck this option, the grid will not be displayed anymore."));
61 grid1->addWidget(grid, 0, 0);
62 //gb1->insert(grid);
63
64 yaxis = new TQCheckBox( i18n( "Y-axis" ), gb1);
65 TQWhatsThis::add(yaxis, i18n("If this is checked, the Y-axis is shown. If you uncheck this option, the Y-axis and the Y grid lines will not be displayed anymore."));
66 connect( yaxis, TQ_SIGNAL( clicked() ), this, TQ_SLOT( axisChanged() ) );
67 grid1->addWidget(yaxis, 1, 0);
68 //gb1->insert(yaxis);
69
70 xaxis = new TQCheckBox( i18n( "X-axis" ), gb1 );
71 TQWhatsThis::add(xaxis, i18n("If this is checked, the X-axis is shown. If you uncheck this option, the X-axis and the X grid lines will not be displayed anymore."));
72 connect( xaxis, TQ_SIGNAL( clicked() ), this, TQ_SLOT( axisChanged() ) );
73 grid1->addWidget(xaxis, 2, 0);
74 //gb1->insert(xaxis);
75
76#if 0
77 xlabel = new TQCheckBox( i18n( "Has X-label" ), gb1 );
78 grid1->addWidget(xlabel,3,0);
79
80 yaxis2 = new TQCheckBox( i18n( "Y-axis 2" ), gb1 );
81 grid1->addWidget(yaxis2,4,0);
82#endif
83
84#if 0 // Moved to the Line page
85 lineMarker = new TQCheckBox( i18n( "Line marker" ), gb1 );
86 grid1->addWidget(lineMarker, 4, 0);
87#endif
88#if 0
89 llabel = new TQCheckBox( i18n( "Legend" ), gb1 );
90 grid1->addWidget(llabel,6,0);
91#endif
92
93 // The "Settings" button group
94 TQButtonGroup* gb2 = new TQButtonGroup( 0, TQt::Vertical,
95 i18n("Settings"), this );
96 gb2->layout()->setSpacing(KDialog::spacingHint());
97 gb2->layout()->setMargin(KDialog::marginHint());
98 TQGridLayout *grid2 = new TQGridLayout(gb2->layout(),8,1);
99
100 TQBoxLayout * l = new TQVBoxLayout( grid2 );
101
102 TQHBoxLayout * top = new TQHBoxLayout( l );
103 // The X axis title
104 TQLabel *tmpLabel = new TQLabel( i18n( "X-title:" ), gb2 );
105 top->addWidget(tmpLabel);
106 // The Y axis title
107 tmpLabel = new TQLabel( i18n( "Y-title:" ), gb2 );
108 top->addWidget(tmpLabel);
109
110 TQHBoxLayout * bottom = new TQHBoxLayout( l );
111 xtitle= new TQLineEdit( gb2 );
112 TQWhatsThis::add(xtitle, i18n("Write the title for the X-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab."));
113 bottom->addWidget(xtitle);
114 ytitle= new TQLineEdit( gb2 );
115 TQWhatsThis::add(ytitle, i18n("Write the title for the Y-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab."));
116 bottom->addWidget(ytitle);
117
118 // Linear or logarithmic scale
119 TQVButtonGroup *scaletype = new TQVButtonGroup(i18n("Scale Types"), gb2);
120 lin = new TQRadioButton( i18n("Linear scale"), scaletype);
121 TQWhatsThis::add(lin, i18n("This sets the Y-axis to be linear. This is default."));
122 log = new TQRadioButton( i18n("Logarithmic scale"), scaletype);
123 TQWhatsThis::add(log, i18n("This sets the Y-axis to be logarithmic."));
124 grid2->addWidget(scaletype, 1, 0);
125
126 // Decimal precision
127 TQVButtonGroup *precision = new TQVButtonGroup(i18n("Precision for Numerical Left Axis"), gb2);
128 grid2->addWidget(precision, 2, 0);
129 TQRadioButton * automatic_precision = new TQRadioButton( i18n("Automatic precision"), precision);
130 TQWhatsThis::add(automatic_precision, i18n("This sets the precision as automatic which means that KChart decides what precision to apply."));
131 automatic_precision->setChecked(true);
132 max = new TQRadioButton( i18n("Decimal precision:"), precision);
133 TQWhatsThis::add(max, i18n("This sets the Y-axis precision. For example, if you choose a precision of 2, the value 5 will be displayed as 5.00 alongside the Y-axis."));
134 connect(automatic_precision, TQ_SIGNAL(toggled(bool)), this,
135 TQ_SLOT(automatic_precision_toggled(bool)) );
136 maximum_length = new TQSpinBox(0, 15, 1, precision );
137 TQWhatsThis::add(maximum_length, i18n("Set the precision you want to display for the Y-axis, if you choose Decimal precision. The range is 0 to 15; 2 being the default."));
138 maximum_length->setValue(2);
139
140#if 0
141 tmpLabel = new TQLabel( i18n( "Y-label format:" ), gb2 );
142 grid2->addWidget(tmpLabel,0,1);
143
144 ylabel_fmt= new TQLineEdit( gb2 );
145 ylabel_fmt->setMaximumWidth(130);
146 grid2->addWidget(ylabel_fmt,1,1);
147 ylabel_fmt->setEnabled(false);
148
149 tmpLabel = new TQLabel( i18n( "Y-title 2:" ), gb2 );
150 grid2->addWidget(tmpLabel,2,1);
151
152 ytitle2= new TQLineEdit( gb2 );
153 ytitle2->setMaximumWidth(130);
154 grid2->addWidget(ytitle2,3,1);
155
156 tmpLabel = new TQLabel( i18n( "Y-label format 2:" ), gb2 );
157 grid2->addWidget(tmpLabel,4,1);
158
159 ylabel2_fmt= new TQLineEdit( gb2 );
160 ylabel2_fmt->setMaximumWidth(130);
161 grid2->addWidget(ylabel2_fmt,5,1);
162#endif
163 layout->addWidget(gb1,0,0);
164 layout->addWidget(gb2,0,1);
165
166#if 0
167 grid1->activate();
168 grid2->activate();
169#endif
170 /*connect( grid, TQ_SIGNAL( toggled( bool ) ),
171 this, TQ_SLOT( changeState( bool ) ) );*/
172 /*connect( xaxis, TQ_SIGNAL( toggled( bool ) ),
173 this, TQ_SLOT( changeXaxisState( bool ) ) );*/
174}
175
176
177 void KChartParameterConfigPage::changeXaxisState(bool /*state*/)
178{
179#if 0
180 if(state)
181 xlabel->setEnabled(true);
182 else
183 xlabel->setEnabled(false);
184#endif
185}
186
187void KChartParameterConfigPage::init()
188{
189 // PENDING(kalle) adapt these to KDChart
190 // grid->setChecked(_params->grid);
191 // xlabel->setChecked(_params->hasxlabel);
192
193 grid->setChecked(_params->showGrid());
194
195 xaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosBottom));
196 yaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosLeft));
197
198#if 0
199 llabel->setChecked(_params->legendPosition()!=KDChartParams::NoLegend);
200#endif
201
202#if 0
203 if ( _params->chartType() == KDChartParams::Line ) {
204 lineMarker->setEnabled(true);
205 lineMarker->setChecked(_params->lineMarker());
206 }
207 else {
208 lineMarker->setEnabled(false);
209 lineMarker->setChecked(false);
210 }
211#endif
212
213 // PENDING(kalle) Adapt this
214 // if(_params->has_yaxis2())
215 // {
216 // yaxis2->setChecked(_params->yaxis2);
217 // int len=_params->ylabel2_fmt.length();
218 // ylabel2_fmt->setText(_params->ylabel2_fmt.right(len-3));
219
220 // ytitle2->setText(_params->ytitle2);
221 // }
222 // else
223#if 0
224 {
225 yaxis2->setEnabled(false);
226 ylabel2_fmt->setEnabled(false);
227 ytitle2->setEnabled(false);
228 }
229
230 // PENDING(kalle) Adapt this
231 // xtitle->setText(_params->xtitle);
232 // ytitle->setText(_params->ytitle);
233 // int len=_params->ylabel_fmt.length();
234 // ylabel_fmt->setText(_params->ylabel_fmt.right(len-3));
235
236 // if(_params->xaxis)
237 // xlabel->setEnabled(true);
238 // else
239 xlabel->setEnabled(false);
240#endif
241
242 xtitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosBottom) );
243 ytitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosLeft) );
244 axisChanged();
245
246 // Linear / logarithmic Y axis
247 if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisCalcMode() ==
248 KDChartAxisParams::AxisCalcLinear )
249 lin->setChecked(true);
250 else
251 log->setChecked(true);
252
253 if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() ==
255 maximum_length->setEnabled(false);
256 else
257 {
258 max->setChecked(true);
259 maximum_length->setValue( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() );
260 }
261}
262
263
264void KChartParameterConfigPage::apply()
265{
266#if 0
267 _params->setLegendPosition(llabel->isChecked() ? KDChartParams::LegendRight : KDChartParams::NoLegend);
268#endif
269
270 _params->setAxisVisible(KDChartAxisParams::AxisPosBottom,xaxis->isChecked());
271 _params->setAxisVisible(KDChartAxisParams::AxisPosLeft,yaxis->isChecked());
272
273 _params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,
274 grid->isChecked() );
275 _params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,
276 grid->isChecked() );
277
278 _params->setAxisTitle( KDChartAxisParams::AxisPosBottom, xtitle->text() );
279 _params->setAxisTitle( KDChartAxisParams::AxisPosLeft, ytitle->text() );
280
281// PENDING(kalle) Adapt this
282 // _params->border=border->isChecked();
283 // _params->llabel=llabel->isChecked();
284 // if(xaxis->isChecked())
285 // _params->hasxlabel=xlabel->isChecked();
286 // if(_params->has_yaxis2())
287 // {
288 // _params->yaxis2=yaxis2->isChecked();
289 // if(!ylabel2_fmt->text().isEmpty())
290 // _params->ylabel2_fmt="%g "+ylabel2_fmt->text();
291 // _params->ytitle2=ytitle2->text();
292 // }
293
294
295 // PENDING(kalle) Adapt this
296 // if(grid->isChecked())
297 // _params->shelf=shelf->isChecked();
298 // _params->xtitle=xtitle->text();
299 // _params->ytitle=ytitle->text();
300 // if(!ylabel_fmt->text().isEmpty())
301 // _params->ylabel_fmt="%g "+ylabel_fmt->text();
302
303 // PENDING(kalle) Adapt this
304 // if(annotation->text().isEmpty()) {
305 // if(_params->annotation) {
306 // delete _params->annotation;
307 // _params->annotation=0;
308 // }
309 // }
310 // else
311 // {
312 // if(!_params->annotation)
313 // _params->annotation=new KChartAnnotationType;
314 // _params->annotation->note=annotation->text();
315 // _params->annotation->color=color->color();
316 // _params->annotation->point=element->value()-1;
317 // _params->setAnnotationFont( annotationFont );
318 // }
319
320#if 0
321 if( _params->chartType() == KDChartParams::Line )
322 _params->setLineMarker(lineMarker->isChecked());
323#endif
324
325 // Set the scale for the Y axis (linear / logarithmic)
326 {
327 KDChartAxisParams params;
328 params = _params->axisParams( KDChartAxisParams::AxisPosLeft );
329
330 if (lin->isChecked())
331 params.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear);
332 else
333 {
334 if(params.axisCalcMode() != KDChartAxisParams::AxisCalcLogarithmic)
335 {
336 // Since in this version of kdChart logarithmic scales only work for Line charts,
337 // lets switch now
338 _params->setChartType( KChartParams::Line );
339 }
340 params.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic);
341 }
342
343 if ( maximum_length->isEnabled() )
344 params.setAxisDigitsBehindComma( maximum_length->value() );
345 else
347
348 _params->setAxisParams( KDChartAxisParams::AxisPosLeft, params );
349 }
350}
351
352void KChartParameterConfigPage::automatic_precision_toggled(bool toggled)
353{
354 if (toggled)
355 maximum_length->setEnabled(false);
356 else
357 maximum_length->setEnabled(true);
358}
359
360void KChartParameterConfigPage::axisChanged()
361{
362 if ( !xaxis->isChecked() || !yaxis->isChecked() )
363 {
364 xtitle->setEnabled( false );
365 ytitle->setEnabled( false );
366 }
367 else
368 {
369 xtitle->setEnabled( true );
370 ytitle->setEnabled( true );
371 }
372}
373
374} //KChart namespace
Provide access to the chart axis parameters.
#define KDCHART_AXIS_LABELS_AUTO_DIGITS
Use this to specify that the number of digits to be shown on the axis labels behind the comma is to b...
access the chart axis parameters.
void setAxisCalcMode(AxisCalcMode axisCalcMode)
enum AxisCalcMode { AxisCalcLinear, AxisCalcLogarithmic }; The axis calculation mode.
void setAxisDigitsBehindComma(const int digits)
Specifies the number of digits to be printed behind the comma on the axis labels.
AxisCalcMode axisCalcMode() const
Returns the axis calculation mode configured in this params object.