filters
svgexport.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qpicture.h>
00021 #include <qpainter.h>
00022
00023 #include <kmessagebox.h>
00024
00025 #include <KoFilterChain.h>
00026 #include <KoStore.h>
00027
00028 #include <kgenericfactory.h>
00029
00030 #include "kchart_part.h"
00031
00032 #include "svgexport.h"
00033
00034
00035 typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory;
00036 K_EXPORT_COMPONENT_FACTORY( libkchartsvgexport, SvgExportFactory( "svgexport" ) )
00037
00038 SvgExport::SvgExport(KoFilter *, const char *, const QStringList&)
00039 : KoFilter()
00040 {
00041 }
00042
00043 SvgExport::~SvgExport()
00044 {
00045 }
00046
00047
00048 KoFilter::ConversionStatus
00049 SvgExport::convert(const QCString& from, const QCString& to)
00050 {
00051
00052 if ( from != "application/x-kchart" || to != "image/svg+xml" )
00053 return KoFilter::NotImplemented;
00054
00055
00056 KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
00057 if ( !storeIn ) {
00058 KMessageBox::error( 0, i18n("Failed to read data." ),
00059 i18n( "SVG Export Error" ) );
00060 return KoFilter::FileNotFound;
00061 }
00062
00063
00064 QDomDocument domIn;
00065 domIn.setContent( storeIn );
00066 QDomElement docNode = domIn.documentElement();
00067
00068
00069 KChart::KChartPart kchartDoc;
00070 if ( !kchartDoc.loadXML(0, domIn) ) {
00071 KMessageBox::error( 0, i18n( "Malformed XML data." ),
00072 i18n( "SVG Export Error" ) );
00073 return KoFilter::WrongFormat;
00074 }
00075
00076
00077 QPicture picture;
00078 QPainter painter(&picture);
00079 QRect rect(QPoint(0, 0), QPoint(500, 400));
00080 kchartDoc.paintContent(painter, rect, false);
00081 painter.end();
00082
00083
00084 if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
00085 KMessageBox::error( 0, i18n( "Failed to write file." ),
00086 i18n( "SVG Export Error" ) );
00087 }
00088
00089 return KoFilter::OK;
00090 }
00091
00092
00093 #include <svgexport.moc>
|