13#include "kchart_part.h"
14#include "kchart_view.h"
15#include "kchart_factory.h"
16#include "kchartWizard.h"
17#include "kchart_params.h"
19#include "kdchart/KDChartTable.h"
21#include <KoTemplateChooseDia.h>
24#include <KoXmlWriter.h>
25#include <KoOasisStore.h>
26#include <KoOasisLoadingContext.h>
28#include <kstandarddirs.h>
33#include <tqtextstream.h>
53KChartPart::KChartPart( TQWidget *parentWidget,
const char *widgetName,
54 TQObject* parent,
const char* name,
56 : KoChart::Part( parentWidget, widgetName, parent, name, singleViewMode ),
58 m_parentWidget( parentWidget ),
59 m_rowLabels(), m_colLabels()
61 kdDebug(35001) <<
"Constructor started!" << endl;
63 setInstance( KChartFactory::global(),
false );
64 setTemplateType(
"kchart_template" );
70 m_params =
new KChartParams(
this );
71 m_params->setChartType( KChartParams::Bar );
72 m_params->setBarChartSubType( KChartParams::BarNormal );
73 m_params->setThreeDBars(
true );
82 m_params->setDataDirection( KChartParams::DataColumns );
85 (void)
new WizardExt(
this );
86 m_bCanChangeValue =
true;
89 m_displayData = m_currentData;
96KChartPart::~KChartPart()
105bool KChartPart::initDoc(InitDocFlags flags, TQWidget* parentWidget)
109 kdDebug(35001) <<
"================================================================" << endl;
110 kdDebug(35001) <<
"InitDOC: flags = " << flags << endl;
111 kdDebug(35001) <<
"================================================================" << endl;
120 if (flags == KoDocument::InitDocEmbedded) {
126 if (flags == KoDocument::InitDocEmpty) {
131 KoTemplateChooseDia::ReturnType ret;
132 KoTemplateChooseDia::DialogType dlgtype;
137 if (flags == KoDocument::InitDocFileNew )
138 dlgtype = KoTemplateChooseDia::OnlyTemplates;
140 dlgtype = KoTemplateChooseDia::Everything;
141 ret = KoTemplateChooseDia::choose( KChartFactory::global(), f,
142 dlgtype,
"kchart_template",
145 if ( ret == KoTemplateChooseDia::File ) {
147 return openURL( url );
149 else if ( ret == KoTemplateChooseDia::Empty ) {
153 else if ( ret == KoTemplateChooseDia::Template ) {
159 TQFileInfo fileInfo( f );
160 TQString fileName( fileInfo.dirPath(
true ) +
"/" +
161 fileInfo.baseName() +
".chrt" );
164 bool ok = loadNativeFormat( fileName );
166 showLoadingErrorDialog();
175void KChartPart::initEmpty()
187void KChartPart::initNullChart()
194 m_currentData.expand(2, 2);
195 m_params->setFirstRowAsLabel(
false);
196 m_params->setFirstColAsLabel(
false);
199 m_colLabels << TQString(
"");
200 m_rowLabels << TQString(
"");
204 m_params->setDrawSolidExcessArrows(
true);
208void KChartPart::generateBarChartTemplate()
213 kdDebug()<<
"KChartPart::initTestChart()\n";
216 if (m_currentData.rows() == 0) {
218 m_currentData.expand( 4, 4 );
219 m_currentData.setUsedRows( 4 );
220 m_currentData.setUsedCols( 4 );
221 for (row = 0; row < 4; row++) {
222 for (col = 0; col < 4; col++) {
223 m_currentData.setCell(row, col,
224 static_cast <double> (row + col));
228 m_colLabels << i18n(
"Column %1").arg(col + 1);
233 m_rowLabels << i18n(
"Row %1").arg(row + 1);
239 m_params->setDrawSolidExcessArrows(
true);
243KoView* KChartPart::createViewInstance( TQWidget* parent,
const char* name )
245 return new KChartView(
this, parent, name );
253void KChartPart::paintContent( TQPainter& painter,
const TQRect& rect,
260 Q_ASSERT( m_params != 0 );
263 xAxisParms = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
274 numDatasets = createDisplayData();
277 TQStringList longLabels;
278 TQStringList shortLabels;
279 createLabelsAndLegend(longLabels, shortLabels);
283 m_params->setAxisParams(KDChartAxisParams::AxisPosBottom, xAxisParms);
289 if ( m_params->chartType() == KChartParams::Bar) {
290 if ( m_params->barNumLines() > 0 ) {
297 m_params->setAdditionalChartType( KDChartParams::Line );
299 const int numBarDatasets = numDatasets - m_params->barNumLines();
302 m_params->setChartSourceMode( KDChartParams::DataEntry,
303 0, numBarDatasets - 1,
305 m_params->setChartSourceMode( KDChartParams::DataEntry,
306 numBarDatasets, numDatasets - 1,
311 m_params->setAdditionalChartType( KDChartParams::NoType );
326 if ( m_bufferPixmap.width() < rect.width()
327 || m_bufferPixmap.height() < rect.height() )
329 m_bufferPixmap.resize( rect.size() );
332 TQPainter bufferPainter( &m_bufferPixmap );
335 KDChart::paint( &bufferPainter, m_params, &m_displayData, 0, &rect );
343 painter.drawPixmap( 0, 0, m_bufferPixmap );
363int KChartPart::createDisplayData()
369 if ( !canChangeValue() ) {
370 if ( m_params->firstRowAsLabel() )
372 if ( m_params->firstColAsLabel() )
382 if (m_params->dataDirection() == KChartParams::DataRows) {
385 numDatasets = m_currentData.usedRows() - rowOffset;
386 m_displayData.expand( numDatasets,
387 m_currentData.usedCols() - colOffset );
390 for (uint row = rowOffset; row < m_currentData.usedRows(); row++) {
391 for (uint col = colOffset; col < m_currentData.usedCols(); col++) {
392 if ( m_currentData.cellContent( row, col,
393 value1, value2, prop ) ) {
394 m_displayData.setCell(row - rowOffset, col - colOffset,
396 m_displayData.setProp(row - rowOffset, col - colOffset,
407 numDatasets = m_currentData.usedCols() - colOffset;
408 m_displayData.expand( numDatasets,
409 m_currentData.usedRows() - rowOffset );
412 for (uint row = colOffset; row < m_currentData.usedCols(); row++) {
413 for (uint col = rowOffset; col < m_currentData.usedRows(); col++) {
414 if ( m_currentData.cellContent( col, row,
415 value1, value2, prop ) ) {
416 m_displayData.setCell(row - colOffset, col - rowOffset,
418 m_displayData.setProp(row - colOffset, col - rowOffset,
430 if (m_params->chartType() == KChartParams::HiLo) {
431 KDChartTableData tmpData = m_displayData;
434 m_displayData.expand(tmpData.usedRows(), 4);
435 for (uint row = 0; row < tmpData.usedRows(); row++) {
436 double minVal = DBL_MAX;
437 double maxVal = -DBL_MAX;
443 for (uint col = 0; col < tmpData.usedCols(); col++) {
444 double data = tmpData.cellVal(row, col).toDouble();
451 m_displayData.setCell(row, 0, minVal);
452 m_displayData.setCell(row, 1, maxVal);
453 m_displayData.setCell(row, 2, tmpData.cellVal(row, 0).toDouble());
454 m_displayData.setCell(row, 3,
455 tmpData.cellVal(row, tmpData.usedCols() - 1).toDouble());
463void KChartPart::createLabelsAndLegend( TQStringList &longLabels,
464 TQStringList &shortLabels )
469 const uint dataColumnCount = m_currentData.cols();
470 const uint dataRowCount = m_currentData.rows();
471 const uint columnLabelCount = m_colLabels.count();
472 const uint rowLabelCount = m_rowLabels.count();
475 if (m_params->chartType() == KChartParams::HiLo) {
483 if (m_params->dataDirection() == KChartParams::DataRows) {
487 for ( uint row = 0; row < dataRowCount ; row++ ) {
489 TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString();
492 shortLabels << label.left( 3 );
498 for ( uint col = 0; col < dataColumnCount; col++ ) {
500 TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString();
502 longLabels << m_colLabels[col];
503 shortLabels << m_colLabels[col].left( 3 );
507 else if (m_params->dataDirection() == KChartParams::DataRows) {
511 for ( uint col = 0; col < dataColumnCount; col++ ) {
513 TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString();
516 shortLabels << label.left( 3 );
520 for ( uint row = 0; row < dataRowCount; row++ ) {
521 TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString();
523 m_params->setLegendText( row, label );
530 for ( uint row = 0; row < dataRowCount; row++ ) {
532 TQString label = (row < rowLabelCount) ? m_rowLabels[row] : TQString();
535 shortLabels << label.left( 3 );
539 for ( uint col = 0; col < dataColumnCount ; col++ ) {
540 TQString label = (col < columnLabelCount) ? m_colLabels[col] : TQString();
542 m_params->setLegendText( col, label );
552void KChartPart::analyzeHeaders()
555 analyzeHeaders( m_currentData );
557 doSetData( m_currentData,
558 m_params->firstRowAsLabel(), m_params->firstColAsLabel());
567void KChartPart::analyzeHeaders(
const KDChartTableData& data )
571 bool isStringTopLeft = (data.cellVal( 0, 0 ).type() == TQVariant::String);
574 bool isStringFirstRow =
true;
575 for ( uint col = 1; isStringFirstRow && col < data.cols(); col++ ) {
576 isStringFirstRow = (data.cellVal( 0, col ).type() == TQVariant::String);
585 if ( data.rows() == 1 )
586 isStringFirstRow =
false;
590 bool isStringFirstCol =
true;
591 for ( uint row = 1; isStringFirstCol && row < data.rows(); row++ ) {
592 isStringFirstCol = (data.cellVal( row, 0 ).type() == TQVariant::String);
598 if ( data.cols() == 1 )
599 isStringFirstRow =
false;
602 bool hasColHeader =
false;
603 bool hasRowHeader =
false;
606 if ( isStringFirstCol && isStringTopLeft
607 || isStringFirstCol && isStringFirstRow )
611 if ( isStringFirstRow && isStringTopLeft
612 || isStringFirstCol && isStringFirstRow )
615 m_params->setFirstRowAsLabel( hasRowHeader );
616 m_params->setFirstColAsLabel( hasColHeader );
618 doSetData(data, hasRowHeader, hasColHeader);
623void KChartPart::doSetData(
const KDChartTableData& data,
625 bool firstColHeader )
643 if ( firstColHeader ) {
644 for( row = rowStart; row < data.rows(); row++ ) {
645 m_rowLabels << data.cellVal( row, 0 ).toString();
649 for( row = rowStart; row < data.rows(); row++ )
654 m_params->setLegendSource( KDChartParams::LegendAutomatic );
659 if ( firstRowHeader ) {
660 for( col = colStart; col < data.cols(); col++ ) {
661 m_colLabels << data.cellVal( 0, col ).toString();
665 for( col = colStart; col < data.cols(); col++ )
670 m_currentData = data;
678void KChartPart::resizeData(
int rows,
int cols )
680 m_currentData.expand( rows, cols );
681 m_currentData.setUsedRows( rows );
682 m_currentData.setUsedCols( cols );
686void KChartPart::setCellData(
int row,
int column,
const TQVariant &val)
688 m_currentData.setCell( row, column, val );
692bool KChartPart::showWizard( TQString &dataArea )
694 KChartWizard *wizard =
new KChartWizard(
this, m_parentWidget,
"wizard" );
696 connect( wizard, TQ_SIGNAL(finished()),
this, TQ_SLOT(slotModified()) );
698 wizard->setDataArea( dataArea );
700 bool ret = wizard->exec();
707void KChartPart::initLabelAndLegend()
718void KChartPart::setChartDefaults()
724 yAxis = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
728 TDEGlobal::locale()->thousandsSeparator() );
730 m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, yAxis );
736 xAxis = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
742 m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, xAxis );
745 m_params->setLineColor();
750 m_params->setFrame( KDChartEnums::AreaInnermost, frame, 0, 0, 0, 0 );
763void KChartPart::loadConfig( TDEConfig *conf )
765 conf->setGroup(
"ChartParameters");
801 m_params->setLineMarker(conf->readBoolEntry(
"lineMarker",
802 m_params->lineMarker()));
803 m_params->setThreeDBarDepth( conf->readDoubleNumEntry(
"_3d_depth",
804 m_params->threeDBarDepth() ) );
805 m_params->setThreeDBarAngle( conf->readNumEntry(
"_3d_angle",
806 m_params->threeDBarAngle() ) );
809 leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
811 rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight );
813 bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
822 m_params->setOutlineDataColor( conf->readColorEntry(
"LineColor", 0 ) );
823 m_params->setAxisParams( KDChartAxisParams::AxisPosLeft,
825 m_params->setAxisParams( KDChartAxisParams::AxisPosRight,
827 m_params->setAxisParams( KDChartAxisParams::AxisPosBottom,
851 m_params->setChartType( (KChartParams::ChartType)conf->readNumEntry(
"type", m_params->chartType() ) );
866void KChartPart::defaultConfig( )
869 m_params =
new KChartParams(
this );
874void KChartPart::saveConfig( TDEConfig *conf )
876 conf->setGroup(
"ChartParameters");
904 conf->writeEntry(
"_3d_depth", m_params->threeDBarDepth() );
905 conf->writeEntry(
"_3d_angle", m_params->threeDBarAngle() );
908 leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
910 rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight );
912 bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
913 conf->writeEntry(
"LineColor", m_params->outlineDataColor() );
914 conf->writeEntry(
"XTitleColor", bottomparams.
axisLineColor() );
915 conf->writeEntry(
"YTitleColor", leftparams.
axisLineColor() );
916 conf->writeEntry(
"YTitle2Color", rightparams.
axisLineColor() );
946 conf->writeEntry(
"type", (
int) m_params->chartType() );
956 conf->writeEntry(
"lineMarker", (
int) m_params->lineMarker());
964bool KChartPart::loadOasis(
const TQDomDocument& doc,
965 KoOasisStyles& oasisStyles,
966 const TQDomDocument& ,
969 kdDebug(35001) <<
"kchart loadOasis called" << endl;
974 TQDomElement content = doc.documentElement();
975 TQDomElement bodyElem ( KoDom::namedItemNS( content,
976 KoXmlNS::office,
"body" ) );
977 if ( bodyElem.isNull() ) {
978 kdError(32001) <<
"No office:body found!" << endl;
979 setErrorMessage( i18n(
"Invalid OASIS OpenDocument file. No office:body tag found." ) );
984 TQDomElement officeChartElem = KoDom::namedItemNS( bodyElem,
985 KoXmlNS::office,
"chart" );
986 if ( officeChartElem.isNull() ) {
987 kdError(32001) <<
"No office:chart found!" << endl;
988 TQDomElement childElem;
990 forEachElement( childElem, bodyElem ) {
991 localName = childElem.localName();
994 if ( localName.isEmpty() )
995 setErrorMessage( i18n(
"Invalid OASIS OpenDocument file. No tag found inside office:body." ) );
997 setErrorMessage( i18n(
"This document is not a chart, but %1. Please try opening it with the appropriate application." ).arg( KoDocument::tagNameToDocumentType( localName ) ) );
1002 TQDomElement chartElem = KoDom::namedItemNS( officeChartElem,
1003 KoXmlNS::chart,
"chart" );
1004 if ( chartElem.isNull() ) {
1005 setErrorMessage( i18n(
"Invalid OASIS OpenDocument file. No chart:chart tag found." ) );
1010 KoOasisLoadingContext loadingContext(
this, oasisStyles, store );
1016 styleStack.setTypeProperties(
"chart" );
1017 loadingContext.fillStyleStack( chartElem, KoXmlNS::chart,
"style-name" );
1019 const TQString fillColor = styleStack.attributeNS( KoXmlNS::draw,
"fill-color" );
1020 kdDebug() <<
"fillColor=" << fillColor << endl;
1022 styleStack.restore();
1027 TQString errorMessage;
1028 bool ok = m_params->loadOasis( chartElem, loadingContext, errorMessage,
1031 setErrorMessage( errorMessage );
1038 TQDomElement tableElem = KoDom::namedItemNS( chartElem,
1039 KoXmlNS::table,
"table" );
1040 if ( !tableElem.isNull() ) {
1041 ok = loadOasisData( tableElem );
1050bool KChartPart::loadOasisData(
const TQDomElement& tableElem )
1052 int numberHeaderColumns = 0;
1053 TQDomElement tableHeaderColumns = KoDom::namedItemNS( tableElem,
1055 "table-header-columns" );
1058 forEachElement( elem, tableHeaderColumns ) {
1059 if ( elem.localName() ==
"table-column" ) {
1060 int repeated = elem.attributeNS( KoXmlNS::table,
"number-columns-repeated", TQString() ).toInt();
1061 numberHeaderColumns += TQMAX( 1, repeated );
1066 Q_ASSERT( numberHeaderColumns == 1 );
1068 int numberDataColumns = 0;
1069 TQDomElement tableColumns = KoDom::namedItemNS( tableElem, KoXmlNS::table,
"table-columns" );
1070 forEachElement( elem, tableColumns ) {
1071 if ( elem.localName() ==
"table-column" ) {
1072 int repeated = elem.attributeNS( KoXmlNS::table,
"number-columns-repeated", TQString() ).toInt();
1073 numberDataColumns += TQMAX( 1, repeated );
1078 m_colLabels.clear();
1079 TQDomElement tableHeaderRows = KoDom::namedItemNS( tableElem, KoXmlNS::table,
"table-header-rows" );
1080 if ( tableHeaderRows.isNull() )
1081 kdWarning(35001) <<
"No table-header-rows element found!" << endl;
1082 TQDomElement tableHeaderRow = KoDom::namedItemNS( tableHeaderRows, KoXmlNS::table,
"table-row" );
1083 if ( tableHeaderRow.isNull() )
1084 kdWarning(35001) <<
"No table-row inside table-header-rows!" << endl;
1087 forEachElement( elem, tableHeaderRow ) {
1088 if ( elem.localName() ==
"table-cell" ) {
1090 if ( cellNum > numberHeaderColumns ) {
1091 TQDomElement pElem = KoDom::namedItemNS( elem, KoXmlNS::text,
"p" );
1092 m_colLabels.append( pElem.text() );
1096 numberDataColumns = TQMAX( numberDataColumns, cellNum - numberHeaderColumns );
1097 if ( (
int)m_colLabels.count() != numberDataColumns )
1098 kdWarning(35001) <<
"Got " << m_colLabels.count()
1099 <<
" column titles, expected " << numberDataColumns
1103 int numberDataRows = 0;
1104 TQDomElement tableRows = KoDom::namedItemNS( tableElem, KoXmlNS::table,
"table-rows" );
1106 m_rowLabels.clear();
1107 forEachElement( elem, tableRows ) {
1108 if ( elem.localName() ==
"table-row" ) {
1109 int repeated = elem.attributeNS( KoXmlNS::table,
"number-rows-repeated", TQString() ).toInt();
1110 Q_ASSERT( repeated <= 1 );
1111 numberDataRows += TQMAX( 1, repeated );
1112 if ( numberHeaderColumns > 0 ) {
1113 TQDomElement firstCell = KoDom::namedItemNS( elem, KoXmlNS::table,
"table-cell" );
1114 TQDomElement pElem = KoDom::namedItemNS( firstCell, KoXmlNS::text,
"p" );
1115 m_rowLabels.append( pElem.text() );
1120 kdDebug(35001) <<
"numberHeaderColumns=" << numberHeaderColumns
1121 <<
" numberDataColumns=" << numberDataColumns
1122 <<
" numberDataRows=" << numberDataRows << endl;
1124 if ( (
int)m_rowLabels.count() != numberDataRows)
1125 kdWarning(35001) <<
"Got " << m_rowLabels.count()
1126 <<
" row labels, expected " << numberDataRows << endl;
1128 m_currentData.expand( numberDataRows, numberDataColumns );
1129 m_currentData.setUsedCols( numberDataColumns );
1130 m_currentData.setUsedRows( numberDataRows );
1134 TQDomElement rowElem;
1135 forEachElement( rowElem, tableRows ) {
1136 if ( rowElem.localName() ==
"table-row" ) {
1139 TQDomElement cellElem;
1140 forEachElement( cellElem, rowElem ) {
1141 if ( cellElem.localName() ==
"table-cell" ) {
1143 if ( cellNum > numberHeaderColumns ) {
1144 TQString valueType = cellElem.attributeNS( KoXmlNS::office,
"value-type", TQString() );
1145 if ( valueType !=
"float" )
1146 kdWarning(35001) <<
"Don't know how to handle value-type " << valueType << endl;
1148 TQString value = cellElem.attributeNS( KoXmlNS::office,
"value", TQString() );
1149 double val = value.toDouble();
1151 m_currentData.setCell( row, col, val );
1165bool KChartPart::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
1167 manifestWriter->addManifestEntry(
"content.xml",
"text/xml" );
1168 KoOasisStore oasisStore( store );
1170 KoXmlWriter* contentWriter = oasisStore.contentWriter();
1171 if ( !contentWriter )
1174 KoGenStyles mainStyles;
1176 KoXmlWriter* bodyWriter = oasisStore.bodyWriter();
1177 bodyWriter->startElement(
"office:body" );
1178 bodyWriter->startElement(
"office:chart" );
1179 bodyWriter->startElement(
"chart:chart" );
1184 m_params->saveOasis( bodyWriter, mainStyles );
1187 saveOasisData( bodyWriter, mainStyles );
1190 bodyWriter->endElement();
1191 bodyWriter->endElement();
1192 bodyWriter->endElement();
1194 contentWriter->startElement(
"office:automatic-styles" );
1195 writeAutomaticStyles( *contentWriter, mainStyles );
1196 contentWriter->endElement();
1198 oasisStore.closeContentWriter();
1203 if ( !store->open(
"styles.xml" ) )
1205 manifestWriter->addManifestEntry(
"styles.xml",
"text/xml" );
1206 saveOasisDocumentStyles( store, mainStyles, savingContext, saveFlag,
1207 headerFooterContent );
1208 if ( !store->close() )
1216void KChartPart::saveOasisData( KoXmlWriter* bodyWriter,
1217 KoGenStyles& mainStyles )
const
1219 Q_UNUSED( mainStyles );
1221 const int cols = m_currentData.usedCols()
1222 ? TQMIN(m_currentData.usedCols(), m_currentData.cols())
1223 : m_currentData.cols();
1224 const int rows = m_currentData.usedRows()
1225 ? TQMIN(m_currentData.usedRows(), m_currentData.rows())
1226 : m_currentData.rows();
1228 bodyWriter->startElement(
"table:table" );
1229 bodyWriter->addAttribute(
"table:name",
"local-table" );
1232 bodyWriter->startElement(
"table:table-header-columns" );
1233 bodyWriter->startElement(
"table:table-column" );
1234 bodyWriter->endElement();
1235 bodyWriter->endElement();
1238 bodyWriter->startElement(
"table:table-columns" );
1239 bodyWriter->startElement(
"table:table-column" );
1240 bodyWriter->addAttribute(
"table:number-columns-repeated", cols );
1241 bodyWriter->endElement();
1242 bodyWriter->endElement();
1245 bodyWriter->startElement(
"table:table-header-rows" );
1246 bodyWriter->startElement(
"table:table-row" );
1249 bodyWriter->startElement(
"table:table-cell" );
1250 bodyWriter->addAttribute(
"office:value-type",
"string" );
1251 bodyWriter->startElement(
"text:p" );
1252 bodyWriter->endElement();
1253 bodyWriter->endElement();
1259 TQStringList::const_iterator colLabelIt = m_colLabels.begin();
1260 for (
int col = 0; col < cols ; ++col ) {
1261 if ( colLabelIt != m_colLabels.end() ) {
1262 bodyWriter->startElement(
"table:table-cell" );
1263 bodyWriter->addAttribute(
"office:value-type",
"string" );
1264 bodyWriter->startElement(
"text:p" );
1265 bodyWriter->addTextNode( *colLabelIt );
1266 bodyWriter->endElement();
1267 bodyWriter->endElement();
1272 bodyWriter->endElement();
1273 bodyWriter->endElement();
1274 bodyWriter->startElement(
"table:table-rows" );
1276 TQStringList::const_iterator rowLabelIt = m_rowLabels.begin();
1277 for (
int row = 0; row < rows ; ++row ) {
1278 bodyWriter->startElement(
"table:table-row" );
1280 if ( rowLabelIt != m_rowLabels.end() ) {
1282 bodyWriter->startElement(
"table:table-cell" );
1283 bodyWriter->addAttribute(
"office:value-type",
"string" );
1285 bodyWriter->startElement(
"text:p" );
1286 bodyWriter->addTextNode( *rowLabelIt );
1287 bodyWriter->endElement();
1289 bodyWriter->endElement();
1293 for (
int col = 0; col < cols; ++col ) {
1294 TQVariant value( m_currentData.cellVal( row, col ) );
1298 switch ( value.type() ) {
1299 case TQVariant::Invalid:
1301 case TQVariant::String:
1303 valStr = value.toString();
1305 case TQVariant::Double:
1307 valStr = TQString::number( value.toDouble(),
'g', DBL_DIG );
1309 case TQVariant::DateTime:
1314 kdDebug(35001) <<
"ERROR: cell " << row <<
"," << col
1315 <<
" has unknown type." << endl;
1320 bodyWriter->startElement(
"table:table-cell" );
1321 if ( !valType.isEmpty() ) {
1322 bodyWriter->addAttribute(
"office:value-type", valType );
1323 if ( value.type() == TQVariant::Double )
1324 bodyWriter->addAttribute(
"office:value", valStr );
1326 bodyWriter->startElement(
"text:p" );
1327 bodyWriter->addTextNode( valStr );
1328 bodyWriter->endElement();
1330 bodyWriter->endElement();
1332 bodyWriter->endElement();
1335 bodyWriter->endElement();
1336 bodyWriter->endElement();
1339void KChartPart::writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles )
const
1341 TQValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_AUTO );
1342 TQValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
1343 for ( ; it != styles.end() ; ++it ) {
1344 (*it).style->writeStyle( &contentWriter, mainStyles,
"style:style", (*it).name,
"style:chart-properties" );
1353TQDomDocument KChartPart::saveXML()
1355 TQDomElement tmpElem;
1361 TQDomDocument doc = m_params->saveXML(
false );
1366 TQDomElement docRoot = doc.documentElement();
1369 TQDomElement aux = doc.createElement(
"KChartAuxiliary" );
1370 docRoot.appendChild( aux );
1373 tmpElem = doc.createElement(
"direction" );
1374 tmpElem.setAttribute(
"value", (
int) m_params->dataDirection() );
1375 aux.appendChild( tmpElem );
1377 tmpElem = doc.createElement(
"dataaslabel" );
1378 tmpElem.setAttribute(
"firstrow",
1379 m_params->firstRowAsLabel() ?
"true" :
"false" );
1380 tmpElem.setAttribute(
"firstcol",
1381 m_params->firstColAsLabel() ?
"true" :
"false" );
1382 aux.appendChild( tmpElem );
1384 tmpElem = doc.createElement(
"barnumlines" );
1385 tmpElem.setAttribute(
"value", (
int) m_params->barNumLines() );
1386 aux.appendChild( tmpElem );
1389 TQDomElement data = doc.createElement(
"data" );
1390 docRoot.appendChild( data );
1392 int cols = m_currentData.usedCols()
1393 ? TQMIN(m_currentData.usedCols(), m_currentData.cols())
1394 : m_currentData.cols();
1395 int rows = m_currentData.usedRows()
1396 ? TQMIN(m_currentData.usedRows(), m_currentData.rows())
1397 : m_currentData.rows();
1398 data.setAttribute(
"cols", cols );
1399 data.setAttribute(
"rows", rows );
1400 kdDebug(35001) <<
" writing " << cols <<
"," << rows <<
" (cols,rows)." << endl;
1402 for (
int i=0; i!=rows; ++i) {
1403 for (
int j=0; j!=cols; ++j) {
1404 TQDomElement e = doc.createElement(
"cell" );
1405 data.appendChild( e );
1407 TQVariant value( m_currentData.cellVal( i,j ) );
1408 switch ( value.type() ) {
1409 case TQVariant::Invalid: valType =
"NoValue";
break;
1410 case TQVariant::String: valType =
"String";
break;
1411 case TQVariant::Double: valType =
"Double";
break;
1412 case TQVariant::DateTime: valType =
"DateTime";
break;
1414 valType =
"(unknown)";
1415 kdDebug(35001) <<
"ERROR: cell " << i <<
"," << j
1416 <<
" has unknown type." << endl;
1420 e.setAttribute(
"valType", valType );
1423 switch ( value.type() ) {
1424 case TQVariant::String: e.setAttribute(
"value", value.toString() );
1426 case TQVariant::Double: e.setAttribute(
"value", TQString::number( value.toDouble() ) );
1428 case TQVariant::DateTime:e.setAttribute(
"value",
"" );
1431 e.setAttribute(
"value",
"" );
1432 if( TQVariant::Invalid != value.type() )
1433 kdDebug(35001) <<
"ERROR: cell " << i <<
"," << j
1434 <<
" has unknown type." << endl;
1444bool KChartPart::loadXML( TQIODevice*,
const TQDomDocument& doc )
1446 kdDebug(35001) <<
"kchart loadXML called" << endl;
1452 bool result = m_params->loadXML( doc );
1456 result = loadAuxiliary(doc) && loadData( doc, m_currentData );
1460 result = loadOldXML( doc );
1465 TQStringList legendLabels;
1467 params = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
1472 while ((str = m_params->legendText(index++)) != TQString())
1473 legendLabels << str;
1475 if (m_params->dataDirection() == KChartParams::DataRows) {
1477 m_rowLabels = legendLabels;
1480 m_colLabels = legendLabels;
1486 m_params->setDrawSolidExcessArrows(
true);
1496bool KChartPart::loadAuxiliary(
const TQDomDocument& doc )
1498 TQDomElement chart = doc.documentElement();
1499 TQDomElement aux = chart.namedItem(
"KChartAuxiliary").toElement();
1506 TQDomNode node = aux.firstChild();
1509 while (!node.isNull()) {
1511 TQDomElement e = node.toElement();
1514 node = node.nextSibling();
1519 if ( e.tagName() ==
"direction" ) {
1520 if ( e.hasAttribute(
"value") ) {
1524 int dir = e.attribute(
"value").toInt(&ok);
1526 dir = (int) KChartParams::DataColumns;
1529 m_params->setDataDirection( (KChartParams::DataDirection) dir );
1532 kdDebug(35001) <<
"Error in direction tag." << endl;
1537 else if ( e.tagName() ==
"dataaslabel" ) {
1540 if ( e.hasAttribute(
"firstrow") ) {
1542 val = e.attribute(
"firstrow");
1543 if ( val ==
"true" )
1544 m_params->setFirstRowAsLabel(
true );
1546 m_params->setFirstRowAsLabel(
false );
1549 kdDebug(35001) <<
"Error in barnumlines tag." << endl;
1550 m_params->setFirstRowAsLabel(
false );
1553 if ( e.hasAttribute(
"firstcol") ) {
1555 val = e.attribute(
"firstcol");
1556 if ( val ==
"true" )
1557 m_params->setFirstColAsLabel(
true );
1559 m_params->setFirstColAsLabel(
false );
1562 kdDebug(35001) <<
"Error in barnumlines tag." << endl;
1563 m_params->setFirstColAsLabel(
false );
1568 else if ( e.tagName() ==
"barnumlines" ) {
1569 if ( e.hasAttribute(
"value") ) {
1573 int barNumLines = e.attribute(
"value").toInt(&ok);
1579 m_params->setBarNumLines( barNumLines );
1582 kdDebug(35001) <<
"Error in barnumlines tag." << endl;
1587 else if ( e.tagName() ==
"..." ) {
1592 node = node.nextSibling();
1599bool KChartPart::loadData(
const TQDomDocument& doc,
1600 KDChartTableData& m_currentData )
1602 kdDebug(35001) <<
"kchart loadData called" << endl;
1604 TQDomElement chart = doc.documentElement();
1605 TQDomElement data = chart.namedItem(
"data").toElement();
1607 int cols = data.attribute(
"cols").toInt(&ok);
1608 kdDebug(35001) <<
"cols readed as:" << cols << endl;
1613 int rows = data.attribute(
"rows").toInt(&ok);
1618 kdDebug(35001) << rows <<
" x " << cols << endl;
1619 m_currentData.expand(rows, cols);
1620 m_currentData.setUsedCols( cols );
1621 m_currentData.setUsedRows( rows );
1622 kdDebug(35001) <<
"Expanded!" << endl;
1623 TQDomNode n = data.firstChild();
1624 for (
int i=0; i!=rows; i++) {
1625 for (
int j=0; j!=cols; j++) {
1627 kdDebug(35001) <<
"Some problems, there is less data than it should be!" << endl;
1630 TQDomElement e = n.toElement();
1631 if ( !e.isNull() && e.tagName() ==
"cell" ) {
1634 if ( e.hasAttribute(
"value") && e.hasAttribute(
"valType") ) {
1635 TQString valueType = e.attribute(
"valType").lower();
1636 if (
"string" == valueType ) {
1637 t = e.attribute(
"value");
1639 else if (
"double" == valueType ) {
1641 double val = e.attribute(
"value").toDouble(&bOk);
1651 if (
"novalue" != valueType )
1652 kdDebug(35001) <<
"ERROR: cell " << i <<
"," << j <<
" has unknown type '" << valueType <<
"'." << endl;
1657 m_currentData.setCell(i,j, t );
1676 n = n.nextSibling();
1692bool KChartPart::loadOldXML(
const TQDomDocument& doc )
1694 kdDebug(35001) <<
"kchart loadOldXML called" << endl;
1695 if ( doc.doctype().name() !=
"chart" )
1698 kdDebug(35001) <<
"Ok, it is a chart" << endl;
1700 TQDomElement chart = doc.documentElement();
1701 if ( chart.attribute(
"mime" ) !=
"application/x-kchart" && chart.attribute(
"mime" ) !=
"application/vnd.kde.kchart" )
1704 kdDebug(35001) <<
"Mimetype ok" << endl;
1707 TQDomElement data = chart.namedItem(
"data").toElement();
1709 int cols = data.attribute(
"cols").toInt(&ok);
1710 kdDebug(35001) <<
"cols readed as:" << cols << endl;
1711 if (!ok) {
return false; }
1712 int rows = data.attribute(
"rows").toInt(&ok);
1713 if (!ok) {
return false; }
1714 kdDebug(35001) << rows <<
" x " << cols << endl;
1715 m_currentData.expand(rows, cols);
1716 kdDebug(35001) <<
"Expanded!" << endl;
1717 TQDomNode n = data.firstChild();
1718 TQMemArray<int> tmpExp(rows*cols);
1719 TQMemArray<bool> tmpMissing(rows*cols);
1721 for (
int i=0; i!=rows; i++) {
1722 for (
int j=0; j!=cols; j++) {
1724 kdDebug(35001) <<
"Some problems, there is less data than it should be!" << endl;
1728 TQDomElement e = n.toElement();
1729 if ( !e.isNull() && e.tagName() ==
"cell" ) {
1731 double val = e.attribute(
"value").toDouble(&ok);
1732 if (!ok) {
return false; }
1733 kdDebug(35001) << i <<
" " << j <<
"=" << val << endl;
1734 KoChart::Value t( val );
1736 m_currentData.setCell(i,j,t);
1737 if ( e.hasAttribute(
"hide" ) ) {
1738 tmpMissing[cols*j+i] = (bool)e.attribute(
"hide").toInt( &ok );
1742 tmpMissing[cols*j+i] =
false;
1744 if ( e.hasAttribute(
"dist" ) ) {
1745 tmpExp[cols*j+i] = e.attribute(
"dist").toInt( &ok );
1749 tmpExp[cols*j+i] = 0;
1752 n = n.nextSibling();
1756 m_params->missing=tmpMissing;
1757 m_params->explode=tmpExp;
1784 TQDomElement params = chart.namedItem(
"params" ).toElement();
1785 if ( params.hasAttribute(
"type" ) ) {
1786 int type=params.attribute(
"type").toInt( &ok );
1792 m_params->setChartType(KChartParams::Line);
1795 m_params->setChartType(KChartParams::Area);
1798 m_params->setChartType(KChartParams::Bar);
1801 m_params->setChartType(KChartParams::HiLo);
1813 m_params->setChartType(KChartParams::Line);
1816 m_params->setChartType(KChartParams::HiLo);
1819 m_params->setChartType(KChartParams::Bar);
1822 m_params->setChartType(KChartParams::Area);
1825 m_params->setChartType(KChartParams::Bar);
1828 m_params->setChartType(KChartParams::Area);
1831 m_params->setChartType(KChartParams::Bar);
1834 m_params->setChartType(KChartParams::Area);
1837 m_params->setChartType(KChartParams::Line);
1841 m_params->setChartType(KChartParams::Pie);
1849 if ( params.hasAttribute(
"subtype" ) ) {
1850 m_params->stack_type = (KChartStackType)params.attribute(
"subtype").toInt( &ok );
1854 if ( params.hasAttribute(
"hlc_style" ) ) {
1855 m_params->hlc_style = (KChartHLCStyle)params.attribute(
"hlc_style").toInt( &ok );
1859 if ( params.hasAttribute(
"hlc_cap_width" ) ) {
1860 m_params->hlc_cap_width = (short)params.attribute(
"hlc_cap_width" ).toShort( &ok );
1865 TQDomElement title = params.namedItem(
"title" ).toElement();
1866 if ( !title.isNull()) {
1867 TQString t = title.text();
1870 TQDomElement titlefont = params.namedItem(
"titlefont" ).toElement();
1871 if ( !titlefont.isNull()) {
1872 TQDomElement font = titlefont.namedItem(
"font" ).toElement();
1873 if ( !font.isNull() )
1874 m_params->setTitleFont(toFont(font));
1876 TQDomElement xtitle = params.namedItem(
"xtitle" ).toElement();
1877 if ( !xtitle.isNull()) {
1878 TQString t = xtitle.text();
1881 TQDomElement xtitlefont = params.namedItem(
"xtitlefont" ).toElement();
1882 if ( !xtitlefont.isNull()) {
1883 TQDomElement font = xtitlefont.namedItem(
"font" ).toElement();
1884 if ( !font.isNull() )
1885 m_params->setXTitleFont(toFont(font));
1887 TQDomElement ytitle = params.namedItem(
"ytitle" ).toElement();
1888 if ( !ytitle.isNull()) {
1889 TQString t = ytitle.text();
1892 TQDomElement ytitle2 = params.namedItem(
"ytitle2" ).toElement();
1893 if ( !ytitle2.isNull()) {
1894 TQString t = ytitle2.text();
1895 m_params->ytitle2=t;
1897 TQDomElement ytitlefont = params.namedItem(
"ytitlefont" ).toElement();
1898 if ( !ytitlefont.isNull()) {
1899 TQDomElement font = ytitlefont.namedItem(
"font" ).toElement();
1900 if ( !font.isNull() )
1901 m_params->setYTitleFont(toFont(font));
1903 TQDomElement ylabelfmt = params.namedItem(
"ylabelfmt" ).toElement();
1904 if ( !ylabelfmt.isNull()) {
1905 TQString t = ylabelfmt.text();
1906 m_params->ylabel_fmt=t;
1908 TQDomElement ylabel2fmt = params.namedItem(
"ylabel2fmt" ).toElement();
1909 if ( !ylabel2fmt.isNull()) {
1910 TQString t = ylabel2fmt.text();
1911 m_params->ylabel2_fmt=t;
1913 TQDomElement labelfont = params.namedItem(
"labelfont" ).toElement();
1914 if ( !labelfont.isNull()) {
1915 TQDomElement font = labelfont.namedItem(
"font" ).toElement();
1916 if ( !font.isNull() )
1917 m_params->setLabelFont(toFont(font));
1920 TQDomElement yaxisfont = params.namedItem(
"yaxisfont" ).toElement();
1921 if ( !yaxisfont.isNull()) {
1922 TQDomElement font = yaxisfont.namedItem(
"font" ).toElement();
1923 if ( !font.isNull() )
1924 m_params->setYAxisFont(toFont(font));
1927 TQDomElement xaxisfont = params.namedItem(
"xaxisfont" ).toElement();
1928 if ( !xaxisfont.isNull()) {
1929 TQDomElement font = xaxisfont.namedItem(
"font" ).toElement();
1930 if ( !font.isNull() )
1931 m_params->setXAxisFont(toFont(font));
1933 TQDomElement annotationFont = params.namedItem(
"annotationfont").toElement();
1934 if ( !annotationFont.isNull()) {
1935 TQDomElement font = annotationFont.namedItem(
"font" ).toElement();
1936 if ( !font.isNull() )
1937 m_params->setAnnotationFont(toFont(font));
1940 TQDomElement yaxis = params.namedItem(
"yaxis" ).toElement();
1941 if ( !yaxis.isNull()) {
1942 if (yaxis.hasAttribute(
"yinterval" )) {
1943 m_params->requested_yinterval= yaxis.attribute(
"yinterval").toDouble( &ok );
1944 if ( !ok )
return false;
1946 if (yaxis.hasAttribute(
"ymin" )) {
1947 m_params->requested_ymin= yaxis.attribute(
"ymin").toDouble( &ok );
1948 if ( !ok )
return false;
1950 if (yaxis.hasAttribute(
"ymax" ) ) {
1951 m_params->requested_ymax= yaxis.attribute(
"ymax").toDouble( &ok );
1952 if ( !ok )
return false;
1957 TQDomElement graph = params.namedItem(
"graph" ).toElement();
1958 if (!graph.isNull()) {
1959 if (graph.hasAttribute(
"grid" )) {
1960 bool b=(bool) graph.attribute(
"grid").toInt( &ok );
1962 m_params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,b );
1963 if (!ok)
return false;
1965 if (graph.hasAttribute(
"xaxis" )) {
1966 bool b=(bool) graph.attribute(
"xaxis").toInt( &ok );
1967 if (!ok)
return false;
1968 m_params->setAxisVisible(KDChartAxisParams::AxisPosBottom,b);
1970 if (graph.hasAttribute(
"yaxis" )) {
1971 bool b=(bool) graph.attribute(
"yaxis").toInt( &ok );
1972 if (!ok)
return false;
1973 m_params->setAxisVisible(KDChartAxisParams::AxisPosLeft,b);
1977 if (graph.hasAttribute(
"shelf" )) {
1978 m_params->shelf=(bool) graph.attribute(
"shelf").toInt( &ok );
1979 if (!ok)
return false;
1982 if (graph.hasAttribute(
"yaxis2" )) {
1983 bool b=(bool) graph.attribute(
"yaxis2").toInt( &ok );
1984 if (!ok)
return false;
1985 m_params->setAxisVisible(KDChartAxisParams::AxisPosRight,b);
1990 if (graph.hasAttribute(
"ystyle" )) {
1991 m_params->yval_style=(bool) graph.attribute(
"ystyle").toInt( &ok );
1992 if (!ok)
return false;
1994 if (graph.hasAttribute(
"border" )) {
1995 m_params->border=(bool) graph.attribute(
"border").toInt( &ok );
1996 if (!ok)
return false;
1998 if (graph.hasAttribute(
"transbg" )) {
1999 m_params->transparent_bg=(bool) graph.attribute(
"transbg").toInt( &ok );
2000 if (!ok)
return false;
2002 if (graph.hasAttribute(
"xlabel" )) {
2003 m_params->hasxlabel=(bool) graph.attribute(
"xlabel").toInt( &ok );
2004 if (!ok)
return false;
2006 if ( graph.hasAttribute(
"xlabel_spacing" ) ) {
2007 m_params->xlabel_spacing = (short)graph.attribute(
"xlabel_spacing" ).toShort( &ok );
2011 if ( graph.hasAttribute(
"ylabel_density" ) ) {
2012 m_params->ylabel_density = (short)graph.attribute(
"ylabel_density" ).toShort( &ok );
2016 if (graph.hasAttribute(
"line")) {
2017 m_params->label_line=(bool) graph.attribute(
"line").toInt( &ok );
2018 if (!ok)
return false;
2020 if (graph.hasAttribute(
"percent")) {
2021 m_params->percent_labels=(KChartPercentType) graph.attribute(
"percent").toInt( &ok );
2022 if (!ok)
return false;
2024 if (graph.hasAttribute(
"cross")) {
2025 m_params->cross=(bool) graph.attribute(
"cross").toInt( &ok );
2026 if (!ok)
return false;
2028 if (graph.hasAttribute(
"thumbnail")) {
2029 m_params->thumbnail=(bool) graph.attribute(
"thumbnail").toInt( &ok );
2030 if (!ok)
return false;
2032 if (graph.hasAttribute(
"thumblabel")) {
2033 m_params->thumblabel= graph.attribute(
"thumblabel");
2035 if (graph.hasAttribute(
"thumbval")) {
2036 m_params->thumbval=(bool) graph.attribute(
"thumbval").toDouble( &ok );
2044 TQDomElement graphparams = params.namedItem(
"graphparams" ).toElement();
2045 if (!graphparams.isNull()) {
2046 if (graphparams.hasAttribute(
"dept3d" )) {
2047 m_params->_3d_depth=graphparams.attribute(
"dept3d").toDouble( &ok );
2048 if (!ok)
return false;
2050 if (graphparams.hasAttribute(
"angle3d" )) {
2051 m_params->_3d_angle=graphparams.attribute(
"angle3d").toShort( &ok );
2052 if (!ok)
return false;
2054 if (graphparams.hasAttribute(
"barwidth" )) {
2055 m_params->bar_width=graphparams.attribute(
"barwidth").toShort( &ok );
2056 if (!ok)
return false;
2058 if (graphparams.hasAttribute(
"colpie" )) {
2059 m_params->colPie=graphparams.attribute(
"colpie").toInt( &ok );
2060 if (!ok)
return false;
2062 if (graphparams.hasAttribute(
"other_threshold" )) {
2063 m_params->other_threshold=graphparams.attribute(
"other_threshold").toShort( &ok );
2067 if (graphparams.hasAttribute(
"offsetCol" )) {
2068 m_params->offsetCol = graphparams.attribute(
"offsetCol").toInt( &ok );
2072 if (graphparams.hasAttribute(
"hard_size" )) {
2073 m_params->hard_size = (bool)graphparams.attribute(
"hard_size").toInt( &ok );
2077 if (graphparams.hasAttribute(
"hard_graphheight" )) {
2078 m_params->hard_graphheight = graphparams.attribute(
"hard_graphheight").toInt( &ok );
2082 if (graphparams.hasAttribute(
"hard_graphwidth" )) {
2083 m_params->hard_graphwidth = graphparams.attribute(
"hard_graphwidth").toInt( &ok );
2087 if (graphparams.hasAttribute(
"hard_xorig" )) {
2088 m_params->hard_xorig = graphparams.attribute(
"hard_xorig").toInt( &ok );
2092 if (graphparams.hasAttribute(
"hard_yorig" )) {
2093 m_params->hard_yorig = graphparams.attribute(
"hard_yorig").toInt( &ok );
2097 if (graphparams.hasAttribute(
"labeldist" )) {
2098 m_params->label_dist=graphparams.attribute(
"labeldist").toInt( &ok );
2099 if (!ok)
return false;
2103 TQDomElement graphcolor = params.namedItem(
"graphcolor" ).toElement();
2104 if (!graphcolor.isNull()) {
2105 if (graphcolor.hasAttribute(
"bgcolor" )) {
2106 m_params->BGColor= TQColor( graphcolor.attribute(
"bgcolor" ) );
2108 if (graphcolor.hasAttribute(
"gridcolor" )) {
2109 m_params->GridColor= TQColor( graphcolor.attribute(
"gridcolor" ) );
2111 if (graphcolor.hasAttribute(
"linecolor" )) {
2112 m_params->LineColor= TQColor( graphcolor.attribute(
"linecolor" ) );
2114 if (graphcolor.hasAttribute(
"plotcolor" )) {
2115 m_params->PlotColor= TQColor( graphcolor.attribute(
"plotcolor" ) );
2117 if (graphcolor.hasAttribute(
"volcolor" )) {
2118 m_params->VolColor= TQColor( graphcolor.attribute(
"volcolor" ) );
2120 if (graphcolor.hasAttribute(
"titlecolor" )) {
2121 m_params->TitleColor= TQColor( graphcolor.attribute(
"titlecolor" ) );
2123 if (graphcolor.hasAttribute(
"xtitlecolor" )) {
2124 m_params->XTitleColor= TQColor( graphcolor.attribute(
"xtitlecolor" ) );
2126 if (graphcolor.hasAttribute(
"ytitlecolor" )) {
2127 m_params->YTitleColor= TQColor( graphcolor.attribute(
"ytitlecolor" ) );
2129 if (graphcolor.hasAttribute(
"ytitle2color" )) {
2130 m_params->YTitle2Color= TQColor( graphcolor.attribute(
"ytitle2color" ) );
2132 if (graphcolor.hasAttribute(
"xlabelcolor" )) {
2133 m_params->XLabelColor= TQColor( graphcolor.attribute(
"xlabelcolor" ) );
2135 if (graphcolor.hasAttribute(
"ylabelcolor" )) {
2136 m_params->YLabelColor= TQColor( graphcolor.attribute(
"ylabelcolor" ) );
2138 if (graphcolor.hasAttribute(
"ylabel2color" )) {
2139 m_params->YLabel2Color= TQColor( graphcolor.attribute(
"ylabel2color" ) );
2143 TQDomElement annotation = params.namedItem(
"annotation" ).toElement();
2144 if (!annotation.isNull()) {
2145 m_params->annotation=
new KChartAnnotationType;
2146 if (annotation.hasAttribute(
"color" )) {
2147 m_params->annotation->color= TQColor( annotation.attribute(
"color" ) );
2149 if (annotation.hasAttribute(
"point" )) {
2150 m_params->annotation->point=annotation.attribute(
"point").toDouble( &ok );
2151 if (!ok)
return false;
2155 TQDomElement note = params.namedItem(
"note" ).toElement();
2156 if ( !note.isNull()) {
2157 TQString t = note.text();
2158 m_params->annotation->note=t;
2161 TQDomElement scatter = params.namedItem(
"scatter" ).toElement();
2162 if ( !scatter.isNull() ) {
2163 m_params->scatter =
new KChartScatterType;
2164 if ( scatter.hasAttribute(
"point" ) ) {
2165 m_params->scatter->point = scatter.attribute(
"point" ).toDouble( &ok );
2169 if ( scatter.hasAttribute(
"val" ) ) {
2170 m_params->scatter->val = scatter.attribute(
"val" ).toDouble( &ok );
2174 if ( scatter.hasAttribute(
"width" ) ) {
2175 m_params->scatter->width = scatter.attribute(
"val" ).toUShort( &ok );
2179 if ( scatter.hasAttribute(
"color" )) {
2180 m_params->scatter->color= TQColor( scatter.attribute(
"color" ) );
2182 if ( scatter.hasAttribute(
"ind" ) ) {
2183 m_params->scatter->ind = (KChartScatterIndType)scatter.attribute(
"ind" ).toInt( &ok );
2189 TQDomElement legend = chart.namedItem(
"legend").toElement();
2190 if (!legend.isNull()) {
2191 int number = legend.attribute(
"number").toInt(&ok);
2192 if (!ok) {
return false; }
2193 TQDomNode name = legend.firstChild();
2194 m_params->legend.clear();
2195 for(
int i=0; i<number; i++) {
2196 if (name.isNull()) {
2197 kdDebug(35001) <<
"Some problems, there is less data than it should be!" << endl;
2200 TQDomElement element = name.toElement();
2201 if ( !element.isNull() && element.tagName() ==
"name" ) {
2202 TQString t = element.text();
2203 m_params->legend+=t;
2204 name = name.nextSibling();
2209 TQDomElement xlbl = chart.namedItem(
"xlbl").toElement();
2210 if (!xlbl.isNull()) {
2211 int number = xlbl.attribute(
"number").toInt(&ok);
2212 if (!ok) {
return false; }
2213 TQDomNode label = xlbl.firstChild();
2214 m_params->xlbl.clear();
2215 for (
int i=0; i<number; i++) {
2216 if (label.isNull()) {
2217 kdDebug(35001) <<
"Some problems, there is less data than it should be!" << endl;
2220 TQDomElement element = label.toElement();
2221 if ( !element.isNull() && element.tagName() ==
"label" ) {
2222 TQString t = element.text();
2224 label = label.nextSibling();
2229 TQDomElement backgroundPixmap = chart.namedItem(
"backgroundPixmap" ).toElement();
2230 if ( !backgroundPixmap.isNull() ) {
2231 if ( backgroundPixmap.hasAttribute(
"name" ) )
2232 m_params->backgroundPixmapName = backgroundPixmap.attribute(
"name" );
2233 if ( backgroundPixmap.hasAttribute(
"isDirty" ) ) {
2234 m_params->backgroundPixmapIsDirty = (bool)backgroundPixmap.attribute(
"isDirty" ).toInt( &ok );
2238 if ( backgroundPixmap.hasAttribute(
"scaled" ) ) {
2239 m_params->backgroundPixmapScaled = (bool)backgroundPixmap.attribute(
"scaled" ).toInt( &ok );
2243 if ( backgroundPixmap.hasAttribute(
"centered" ) ) {
2244 m_params->backgroundPixmapCentered = (bool)backgroundPixmap.attribute(
"centered" ).toInt( &ok );
2248 if ( backgroundPixmap.hasAttribute(
"intensity" ) ) {
2249 m_params->backgroundPixmapIntensity = backgroundPixmap.attribute(
"intensity" ).toFloat( &ok );
2255 TQDomElement extcolor = chart.namedItem(
"extcolor").toElement();
2256 if (!extcolor.isNull()) {
2257 unsigned int number = extcolor.attribute(
"number").toInt(&ok);
2258 if (!ok) {
return false; }
2259 TQDomNode color = extcolor.firstChild();
2261 for (
unsigned int i=0; i<number; i++) {
2262 if (color.isNull()) {
2263 kdDebug(35001) <<
"Some problems, there is less data than it should be!" << endl;
2266 TQDomElement element = color.toElement();
2267 if ( !element.isNull()) {
2268 if (element.hasAttribute(
"name" )) {
2269 m_params->ExtColor.setColor(i,TQColor( element.attribute(
"name" ) ));
2271 color = color.nextSibling();
2276 if ( !m_params->backgroundPixmapName.isNull() ) {
2277 m_params->backgroundPixmap.load( locate(
"wallpaper",
2278 m_params->backgroundPixmapName ));
2279 m_params->backgroundPixmapIsDirty =
true;
2287void KChartPart::slotModified()
2289 kdDebug(35001) <<
"slotModified called!" << endl;
2295bool KChartPart::showEmbedInitDialog(TQWidget* )
2304#include "kchart_part.moc"
Definition of a single entry-point to the charting engine for applications that wish to provide their...
access the chart axis parameters.
TQColor axisLabelsColor() const
Returns the axis labels colour.
TQColor axisGridColor() const
Returns the axis grid color.
void setAxisLabelStringLists(TQStringList *axisLabelStringList, TQStringList *axisShortLabelStringList, const TQString &valueStart=TQString(), const TQString &valueEnd=TQString())
Specifies a TQStringList which the axis label texts are to be taken from, the second parameter (if no...
void setAxisLineColor(TQColor axisLineColor)
Specifies the axis line colour.
void setAxisFirstLabelText(const TQString &axisFirstLabelText=TQString())
Sets a special text that is to be displayed instead_of the first axis label IF the parameter is not a...
void setAxisGridColor(TQColor axisGridColor)
Specifies the axis grid colour.
void setAxisLastLabelText(const TQString &axisLastLabelText=TQString())
Sets a special text that is to be displayed instead_of the last axis label IF the parameter is not a ...
void setAxisShowGrid(bool axisShowGrid)
Specifies whether a grid should be drawn at the chart data area.
TQStringList axisLabelStringList() const
Returns a TQStringList containing the label texts to be used.
TQColor axisLineColor() const
Returns the axis line colour.
void setAxisLabelsColor(TQColor axisLabelsColor)
Specifies the axis labels colour.
void setAxisLabelsRadix(const TQString &decimalPoint, const TQString &thousandsPoint)
Specifies the way how the axis label strings will be formatted.
static void paint(TQPainter *, KDChartParams *, KDChartTableDataBase *, KDChartDataRegionList *regions=0, const TQRect *rect=0, bool mustCalculateGeometry=true)
Paints a chart with the specified parameters on the specified painter.
The main class of KDFrame.
void setBackground(TQBrush background=TQBrush(TQt::NoBrush))
Specifies the brush to be used to fill the inner area of this frame, calling this methode without pas...