1#include "KDChartObjectFactory.h"
3#include <KDChartTable.h>
4#include <tqsargument.h>
8#include <KDChartTextPiece.h>
12#include "factories/TQtFactory.h"
13#include "factories/TQFontFactory.h"
16KDChartObjectFactory::KDChartObjectFactory()
18 registerClass( TQString::fromLatin1(
"KDChartWidget" ) );
19 registerClass( TQString::fromLatin1(
"KDChartParams" ),
new KDChartParams );
20 registerClass( TQString::fromLatin1(
"KDChartTableData" ) );
21 registerClass( TQString::fromLatin1(
"KDChartAxisParams" ),
new KDChartAxisParams );
22 registerClass( TQString::fromLatin1(
"KDChartEnums" ), 0,
new KDChartEnums );
23 registerClass( TQString::fromLatin1(
"KDChartTextPiece" ) );
24 registerClass( TQString::fromLatin1(
"KDChartCustomBox" ),
new KDChartCustomBox );
25 registerClass( TQString::fromLatin1(
"KDChartPropertySet" ),
new KDChartPropertySet );
26 registerClass( TQString::fromLatin1(
"KDFrame" ), TQString(),
new KDFrame );
28 registerClass( TQString::fromLatin1(
"TQt" ), TQString(),
new TQtFactory() );
29 registerClass( TQString::fromLatin1(
"TQFont" ), TQString(),
new TQFontFactory );
32TQObject* KDChartObjectFactory::create(
const TQString& className,
const TQSArgumentList& args, TQObject* )
34 if ( className == TQString::fromLatin1(
"KDChartWidget" ) )
35 return createKDChartWidget( args );
37 if ( className == TQString::fromLatin1(
"KDChartParams") )
38 return new KDChartParams();
40 else if ( className == TQString::fromLatin1(
"KDChartTableData") )
41 return createKDChartTableData( args );
43 else if ( className == TQString::fromLatin1(
"KDChartAxisParams") )
44 return new KDChartAxisParams();
47 else if ( className == TQString::fromLatin1(
"KDChartTextPiece" ) )
48 return createKDChartTextPiece( args );
50 else if ( className == TQString::fromLatin1(
"KDChartCustomBox" ) )
51 return createKDChartCustomBox( args );
53 else if ( className == TQString::fromLatin1(
"KDChartPropertySet" ) )
54 return createKDChartPropertySet( args );
60TQObject* KDChartObjectFactory::createKDChartWidget(
const TQSArgumentList& args )
62 if ( !checkArgCount(
"KDChartWidget", args.count(), 2, 2 ) )
return 0;
63 if ( !checkArgsIsTQtClass( args, 1,
"KDChartParams",
"KDChartWidget" ) )
return 0;
64 if ( !checkArgsIsTQtClass( args, 2,
"KDChartTableDataBase",
"KDChartWidget" ) )
return 0;
65 KDChartParams* params =
static_cast<KDChartParams*
>( args[0].qobject() );
66 KDChartTableDataBase* data =
static_cast<KDChartTableDataBase*
>( args[1].qobject() );
68 return new KDChartWidget( params, data );
72TQObject* KDChartObjectFactory::createKDChartTableData(
const TQSArgumentList& args )
74 if ( args.count() != 2 ) {
75 throwError( TQObject::tr(
"wrong number of arguments to KDChartTableData" ) );
78 TQSArgument arg1 = args[0];
79 TQSArgument arg2 = args[1];
81 if ( arg1.type() != TQSArgument::Variant || !isNumber(arg1.variant()) ) {
82 throwError( TQObject::tr(
"wrong type for argument 1 of KDChartTableData" ) );
85 if ( arg2.type() != TQSArgument::Variant || !isNumber(arg2.variant() ) ) {
86 throwError( TQObject::tr(
"wrong type for argument 2 of KDChartTableData" ) );
89 return new KDChartTableData( arg1.variant().toUInt(), arg2.variant().toUInt() );
93TQObject* KDChartObjectFactory::createKDChartTextPiece(
const TQSArgumentList& args )
95 if ( !checkArgCount(
"KDChartTextPiece", args.count(), 2, 2 ) )
return 0;
96 TQSArgument arg1 = args[0];
97 TQSArgument arg2 = args[1];
100 if ( !getString( args, 1, &str,
"KDChartTextPiece" ) )
return 0;
101 if ( !checkIsTQtVariant( args, 2, TQVariant::Font, TQString::fromLatin1(
"TQFont" ),
"KDChartTextPiece" ) )
return 0;
102 TQFont font = args[1].variant().toFont();
104 return new KDChartTextPiece( str, font );
107TQObject* KDChartObjectFactory::createKDChartCustomBox(
const TQSArgumentList& args )
111 if ( args.count() == 0 )
112 return new KDChartCustomBox();
115 if ( args[0].type() == TQSArgument::Variant && isNumber( args[0].variant() ) ) {
116 if ( args.count() < 8 ) {
117 throwError( TQObject::tr(
"Too few arguments to KDChartCustomBox" ) );
122 if ( !getNumber( args, 1, &rotation,
"KDChartCustomBox" ) )
return 0;
124 if (!checkArgsIsTQtClass( args, 2,
"KDChartTextPiece",
"KDChartCustomBox" ))
return 0;
125 KDChartTextPiece* content =
static_cast<KDChartTextPiece*
>( args[1].qobject() );
128 if ( !getNumber( args, 3, &fontSize,
"KDChartCustomBox" ) )
return 0;
131 bool fontScaleGlobal;
132 if ( !getBool( args, 4, &fontScaleGlobal,
"KDChartCustomBox" ) )
return 0;
135 if ( !getNumber( args, 5, &deltaX,
"KDChartCustomBox" ) )
return 0;
138 if ( !getNumber( args, 6, &deltaY,
"KDChartCustomBox" ) )
return 0;
141 if ( !getNumber( args, 7, &width,
"KDChartCustomBox" ) )
return 0;
144 if ( !getNumber( args, 8, &height,
"KDChartCustomBox" ) )
return 0;
146 TQColor color = TQt::black;
147 if ( args.count() >= 9 ) {
148 if ( !checkIsTQtVariant( args, 9, TQVariant::Color, TQString::fromLatin1(
"TQColor" ),
"KDChartCustomBox" ) )
return 0;
149 color = args[8].variant().toColor();
152 TQBrush paper = TQt::NoBrush;
153 if ( args.count() >= 10 ) {
154 if ( !checkIsTQtVariant( args, 10, TQVariant::Brush, TQString::fromLatin1(
"TQBrush" ),
"KDChartCustomBox" ) )
return 0;
155 paper = args[9].variant().toBrush();
158 uint area = KDChartEnums::AreaInnermost;
159 if ( args.count() >= 11 ) {
160 if ( !getNumber( args, 11, &area,
"KDChartCustomBox" ) )
return 0;
164 if ( args.count() >= 12 ) {
165 if ( !getNumber( args, 12, &tmp,
"KDChartCustomBox" ) )
return 0;
169 uint align = TQt::AlignTop + TQt::AlignLeft;
170 if ( args.count() >= 13 ) {
171 if ( !getNumber( args, 13, &align,
"KDChartCustomBox" ) )
return 0;
175 if ( args.count() >= 14 ) {
176 if ( !getNumber( args, 14, &dataRow,
"KDChartCustomBox" ) )
return 0;
180 if ( args.count() >= 15 ) {
181 if ( !getNumber( args, 15, &dataCol,
"KDChartCustomBox" ) )
return 0;
185 if ( args.count() >= 16 ) {
186 if ( !getNumber( args, 16, &data3rd,
"KDChartCustomBox" ) )
return 0;
189 uint deltaAlign = KDCHART_AlignAuto;
190 if ( args.count() >= 17 ) {
191 if ( !getNumber( args, 17, &deltaAlign,
"KDChartCustomBox" ) )
return 0;
194 bool deltaScaleGlobal =
true;
195 if ( args.count() >= 18 ) {
196 if ( !getBool( args, 18, &deltaScaleGlobal,
"KDChartCustomBox" ) )
return 0;
199 return new KDChartCustomBox( rotation, *content, fontSize, fontScaleGlobal, deltaX, deltaY,
200 width, height, color, paper, area, position, align, dataRow,
201 dataCol, data3rd, deltaAlign, deltaScaleGlobal );
204 if (!checkArgsIsTQtClass( args, 1,
"KDChartTextPiece",
"KDChartCustomBox" ))
return 0;
205 KDChartTextPiece* content =
static_cast<KDChartTextPiece*
>( args[0].qobject() );
207 if ( args.count() < 2 ) {
208 throwError( TQObject::tr(
"Too few arguments to KDChartCustomBox" ) );
213 if ( ! getNumber( args, 2, &fontSize,
"KDChartCustomBox" ) )
return 0;
215 bool fontScaleGlobal =
true;
216 if ( args.count() > 2 && !getBool( args, 3, &fontScaleGlobal,
"KDChartCustomBox" ) )
return 0;
218 if ( args.count() <= 3 )
219 return new KDChartCustomBox( *content, fontSize, fontScaleGlobal );
221 checkArgCount(
"KDChartCustomBox", args.count(), 7, 17 );
224 if ( !getNumber( args, 4, &deltaX,
"KDChartCustomBox" ) )
return 0;
227 if ( !getNumber( args, 5, &deltaY,
"KDChartCustomBox" ) )
return 0;
230 if ( !getNumber( args, 6, &width,
"KDChartCustomBox" ) )
return 0;
233 if ( !getNumber( args, 7, &height,
"KDChartCustomBox" ) )
return 0;
236 TQColor color = TQt::black;
237 if ( args.count() >= 8 ) {
238 if ( !checkIsTQtVariant( args, 8, TQVariant::Color, TQString::fromLatin1(
"TQColor" ),
"KDChartCustomBox" ) )
return 0;
239 color = args[7].variant().toColor();
242 TQBrush paper = TQt::NoBrush;
243 if ( args.count() >= 9 ) {
244 if ( !checkIsTQtVariant( args, 9, TQVariant::Brush, TQString::fromLatin1(
"TQBrush" ),
"KDChartCustomBox" ) )
return 0;
245 paper = args[8].variant().toBrush();
248 uint area = KDChartEnums::AreaInnermost;
249 if ( args.count() >= 10 ) {
250 if ( !getNumber( args, 10, &area,
"KDChartCustomBox" ) )
return 0;
254 if ( args.count() >= 11 ) {
255 if ( !getNumber( args, 11, &tmp,
"KDChartCustomBox" ) )
return 0;
259 uint align = TQt::AlignTop + TQt::AlignLeft;
260 if ( args.count() >= 12 ) {
261 if ( !getNumber( args, 12, &align,
"KDChartCustomBox" ) )
return 0;
265 if ( args.count() >= 13 ) {
266 if ( !getNumber( args, 13, &dataRow,
"KDChartCustomBox" ) )
return 0;
270 if ( args.count() >= 14 ) {
271 if ( !getNumber( args, 14, &dataCol,
"KDChartCustomBox" ) )
return 0;
275 if ( args.count() >= 15 ) {
276 if ( !getNumber( args, 15, &data3rd,
"KDChartCustomBox" ) )
return 0;
279 uint deltaAlign = KDCHART_AlignAuto;
280 if ( args.count() >= 16 ) {
281 if ( !getNumber( args, 16, &deltaAlign,
"KDChartCustomBox" ) )
return 0;
284 bool deltaScaleGlobal =
true;
285 if ( args.count() >= 17 ) {
286 if ( !getBool( args, 17, &deltaScaleGlobal,
"KDChartCustomBox" ) )
return 0;
290 return new KDChartCustomBox( *content, fontSize, fontScaleGlobal, deltaX, deltaY, width, height, color,
291 paper, area, position, align, dataRow, dataCol, data3rd, deltaAlign, deltaScaleGlobal );
294TQObject* KDChartObjectFactory::createKDChartPropertySet(
const TQSArgumentList& args )
296 if ( args.count() == 0 )
297 return new KDChartPropertySet();
300 if ( !getString( args, 1, &name,
"KDChartPropertySet" ) )
return 0;
302 if ( args.count() == 1 )
303 return new KDChartPropertySet( name );
306 if ( !getNumber( args, 2, &i,
"KDChartPropertySet" ) )
return 0;
307 if ( args.count() == 2 )
308 return new KDChartPropertySet( name, i );
310 if ( !checkArgCount(
"KDChartPropertySet", args.count(), 33, 33 ) )
return 0;
315 if ( !getNumber( args, 3,&lineWidth,
"KDChartPropertySet" ) )
return 0;
318 if ( !getNumber( args, 4,&idLineColor,
"KDChartPropertySet" ) )
return 0;
321 if ( !checkIsTQtVariant( args, 5, TQVariant::Color, TQString::fromLatin1(
"TQColor" ),
"KDChartPropertySet" ) )
return 0;
322 TQColor lineColor = args[4].variant().toColor();
325 if ( !getNumber( args, 6,&idLineStyle,
"KDChartPropertySet" ) )
return 0;
329 if ( !getNumber( args, 7,&i,
"KDChartPropertySet" ) )
return 0;
330 TQt::PenStyle lineStyle = (TQt::PenStyle) i;
333 if ( !getNumber( args, 8,&idShowMarker,
"KDChartPropertySet" ) )
return 0;
336 if ( !getBool( args, 9, &showMarker,
"KDChartPropertySet" ) )
return 0;
338 int idExtraLinesAlign;
339 if ( !getNumber( args, 10,&idExtraLinesAlign,
"KDChartPropertySet" ) )
return 0;
341 uint extraLinesAlign;
342 if ( !getNumber( args, 11,&extraLinesAlign,
"KDChartPropertySet" ) )
return 0;
344 int idExtraLinesInFront;
345 if ( !getNumber( args, 12,&idExtraLinesInFront,
"KDChartPropertySet" ) )
return 0;
347 bool extraLinesInFront;
348 if ( !getBool( args, 13, &extraLinesInFront,
"KDChartPropertySet" ) )
return 0;
350 int idExtraLinesLength;
351 if ( !getNumber( args, 14,&idExtraLinesLength,
"KDChartPropertySet" ) )
return 0;
353 int extraLinesLength;
354 if ( !getNumber( args, 15,&extraLinesLength,
"KDChartPropertySet" ) )
return 0;
356 int idExtraLinesWidth;
357 if ( !getNumber( args, 16,&idExtraLinesWidth,
"KDChartPropertySet" ) )
return 0;
360 if ( !getNumber( args, 17,&extraLinesWidth,
"KDChartPropertySet" ) )
return 0;
362 int idExtraLinesColor;
363 if ( !getNumber( args, 18,&idExtraLinesColor,
"KDChartPropertySet" ) )
return 0;
365 if ( !checkIsTQtVariant( args, 19, TQVariant::Color, TQString::fromLatin1(
"TQColor" ),
"KDChartPropertySet" ) )
return 0;
366 TQColor extraLinesColor = args[18].variant().toColor();
368 int idExtraLinesStyle;
369 if ( !getNumber( args, 20,&idExtraLinesStyle,
"KDChartPropertySet" ) )
return 0;
371 if ( !getNumber( args, 21,&i,
"KDChartPropertySet" ) )
return 0;
372 TQt::PenStyle extraLinesStyle = (TQt::PenStyle) i;
374 int idExtraMarkersAlign;
375 if ( !getNumber( args, 22,&idExtraMarkersAlign,
"KDChartPropertySet" ) )
return 0;
377 uint extraMarkersAlign;
378 if ( !getNumber( args, 23,&extraMarkersAlign,
"KDChartPropertySet" ) )
return 0;
380 int idExtraMarkersSize;
381 if ( !getNumber( args, 24,&idExtraMarkersSize,
"KDChartPropertySet" ) )
return 0;
383 if ( !checkIsTQtVariant( args, 25, TQVariant::Size, TQString::fromLatin1(
"TQSize" ),
"KDChartPropertySet" ) )
return 0;
384 TQSize extraMarkersSize = args[24].variant().toSize();
386 int idExtraMarkersColor;
387 if ( !getNumber( args, 26,&idExtraMarkersColor,
"KDChartPropertySet" ) )
return 0;
389 if ( !checkIsTQtVariant( args, 27, TQVariant::Color, TQString::fromLatin1(
"TQColor" ),
"KDChartPropertySet" ) )
return 0;
390 TQColor extraMarkersColor = args[26].variant().toColor();
392 int idExtraMarkersStyle;
393 if ( !getNumber( args, 28,&idExtraMarkersStyle,
"KDChartPropertySet" ) )
return 0;
395 int extraMarkersStyle;
396 if ( !getNumber( args, 29,&extraMarkersStyle,
"KDChartPropertySet" ) )
return 0;
399 if ( !getNumber( args, 30,&idShowBar,
"KDChartPropertySet" ) )
return 0;
402 if ( !getBool( args, 31, &showBar,
"KDChartPropertySet" ) )
return 0;
405 if ( !getNumber( args, 32,&idBarColor,
"KDChartPropertySet" ) )
return 0;
407 if ( !checkIsTQtVariant( args, 33, TQVariant::Color, TQString::fromLatin1(
"TQColor" ),
"KDChartPropertySet" ) )
return 0;
408 TQColor barColor = args[32].variant().toColor();
410 KDChartPropertySet* set =
new KDChartPropertySet;
416 set->setExtraLinesAlign( idExtraLinesAlign, extraLinesAlign );
417 set->setExtraLinesInFront( idExtraLinesInFront, extraLinesInFront );
418 set->setExtraLinesLength( idExtraLinesLength, extraLinesLength );
419 set->setExtraLinesWidth( idExtraLinesWidth, extraLinesWidth );
420 set->setExtraLinesColor( idExtraLinesColor, extraLinesColor );
421 set->setExtraLinesStyle( idExtraLinesStyle, extraLinesStyle );
422 set->setExtraMarkersAlign( idExtraMarkersAlign, extraMarkersAlign );
423 set->setExtraMarkersSize( idExtraMarkersSize, extraMarkersSize );
424 set->setExtraMarkersColor( idExtraMarkersColor, extraMarkersColor );
425 set->setExtraMarkersStyle( idExtraMarkersStyle, extraMarkersStyle );
432bool KDChartObjectFactory::isNumber(
const TQVariant& v )
434 return ( v.type() == TQVariant::Int || v.type() == TQVariant::UInt || v.type() == TQVariant::Double );
438bool KDChartObjectFactory::checkArgCount(
const TQString& className,
int count,
int min,
int max )
441 throwError( TQObject::tr(
"Too few arguments when creating %1 object." ).arg( className ) );
445 throwError( TQObject::tr(
"Too many arguments when creating %1 object." ).arg( className ) );
452bool KDChartObjectFactory::checkArgsIsTQtClass(
const TQSArgumentList& args,
int index,
const char* expected,
const char* constructing )
454 const TQSArgument& arg = args[index-1];
455 if ( arg.type() != TQSArgument::TQObjectPtr || !arg.qobject()->inherits( expected ) ) {
456 throwError( TQObject::tr(
"Invalid type for argument no %1 to %2, must be a %3" ).arg(index).arg(constructing).arg(expected) );
463bool KDChartObjectFactory::getString(
const TQSArgumentList& args,
int index, TQString* str,
const char* constructing )
465 const TQSArgument& arg = args[index-1];
466 if ( arg.type() != TQSArgument::Variant || arg.variant().type() != TQVariant::String ) {
467 throwError( TQObject::tr(
"Invalid type for argument %1 to %2, must be a string" ).arg(index).arg(constructing) );
471 *str = arg.variant().toString();
476bool KDChartObjectFactory::getNumber(
const TQSArgumentList& args,
int index,
double* number,
const char* constructing )
478 const TQSArgument& arg = args[index-1];
479 if ( arg.type() != TQSArgument::Variant || !isNumber(arg.variant()) ) {
480 throwError( TQObject::tr(
"Invalid type for argument %1 to %2, must be a number" ).arg(index).arg( constructing ) );
484 *number = arg.variant().toDouble();
489bool KDChartObjectFactory::getNumber(
const TQSArgumentList& args,
int index,
int* number,
const char* constructing )
492 bool ok = getNumber( args, index, &tmp, constructing );
493 *number =
static_cast<int>( tmp );
497bool KDChartObjectFactory::getNumber(
const TQSArgumentList& args,
int index, uint* number,
const char* constructing )
500 bool ok = getNumber( args, index, &tmp, constructing );
501 *number =
static_cast<uint
>( tmp );
507bool KDChartObjectFactory::getBool(
const TQSArgumentList& args,
int index,
bool* b,
const char* constructing )
509 const TQSArgument& arg = args[index-1];
510 if ( arg.type() != TQSArgument::Variant || arg.variant().type() != TQVariant::Bool ) {
511 throwError( TQObject::tr(
"Invalid type for argument %1 to %2, must be a boolean" ).arg(index).arg( constructing ) );
515 *b = arg.variant().toBool();
520bool KDChartObjectFactory::checkIsTQtVariant(
const TQSArgumentList& args,
int index, TQVariant::Type expected,
const TQString& variantName,
const char* constructing )
522 const TQSArgument& arg = args[index-1];
523 if ( arg.type() != TQSArgument::Variant || arg.variant().type() != expected ) {
524 throwError( TQObject::tr(
"Invalid type for argument %1 to %2, must be a %3").arg(index).arg(constructing).arg(variantName) );
Definition of global enums.
Header for all common chart parameters.
Property settings of a single KDChart data cell.
PositionFlag
The general position flag to specify a point of an area, for example this could be the anchor point w...
void setShowBar(int idShowBar, bool showBar)
Specify the ID of the property set specifying a boolean flag indicating whether this cell's bar is to...
void setName(const TQString &name)
Change the descriptive name of this property set.
void setLineWidth(int idLineWidth, int lineWidth)
Specify the ID of the property set specifying the line width to be used for drawing a line from this ...
void setLineColor(int idLineColor, const TQColor &lineColor)
Specify the ID of the property set specifying the line color to be used for drawing a line from this ...
void setShowMarker(int idShowMarker, bool showMarker)
Specify the ID of the property set specifying a boolean flag indicating whether a Marker is to be dis...
void setBarColor(int idBarColor, const TQColor &barColor)
Specify the ID of the property set specifying the bar color to be used for this cell or specify the b...
void setLineStyle(int idLineStyle, const TQt::PenStyle &lineStyle)
Specify the ID of the property set specifying the line style to be used for drawing a line from this ...