Bug 109037 - svg export please (but only if convient and using QPainter)
Summary: svg export please (but only if convient and using QPainter)
Status: RESOLVED FIXED
Alias: None
Product: kalzium
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources FreeBSD
: NOR wishlist
Target Milestone: ---
Assignee: Carsten Niehaus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-13 20:23 UTC by Alan Horkan
Modified: 2007-03-29 17:25 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Horkan 2005-07-13 20:23:58 UTC
Version:            (using KDE KDE 3.4.1)
Installed from:    Compiled From Sources
OS:                FreeBSD

http://www.livejournal.com/users/cniehaus/8585.html?thread=22409#t22409

I dont know much about QT but I was interested to learn about how KChart uses built in functionality of QPainter to export SVG. If it is feasible it would be really great if Kalzium could allow SVG export of things link the Periodic Table, or the Atom Models and allow people to incorporate them into their science reports and things like that.  


(Now to prove I read the TODO ask requested)
http://websvn.kde.org/trunk/KDE/kdeedu/kalzium/TODO?rev=432227&view=markup
The Kalzium TODO file suggests CSV and HTML export so I hope SVG can be added to that list.  
There is also a typo in TODO 
s/chemitry-nobel-prize/chemistry-nobel-prize/

Interoperability with and reuse of KChart components might be another way to benefit both programs rather than rolling your own custom graphing solution.
Comment 1 Carsten Niehaus 2005-07-14 17:14:02 UTC
Good idea. Give us some time :)
Comment 2 Alan Horkan 2005-07-14 19:08:20 UTC
No hurry, I'm glad you accepted the idea.  

I'm looking for ways to help promote SVG and OpenClipart.org because I believe it is important to not just use open standards but promote them to hold back proprietary standards.  I am also interested in seeing Karbon 14 succeed and being able to work well with other KDE applications could help create more interest in it and in SVG.  
When I realised QT provided built in SVG support it seemed like a perfect opportunity to encourage various KDE applications to embrace SVG and I filed a few other requests and included the words [SVG Everywhere] in the summaries.  I'm looking for other places to suggest SVG too if you have any good ideas.  

I should have pointed you directly to the kchart svg exporter:
http://websvn.kde.org/trunk/koffice/filters/kchart/svg/ 

Thanks again and although I would love to see this added I dont want to rush you or distract you from the main purpose of Kalzuim with this tangent.  
Comment 3 Carsten Niehaus 2005-07-24 11:39:38 UTC
Now the following formats are supported:

BMP
EPS
Jpeg2000
Jpeg
Portable Bitmap Image
Portable Pixmap Image
Portable Graymap Image
PCX
PNG

That is at least a good start I would say :)
Comment 4 Alan Horkan 2005-07-24 17:22:39 UTC
That is an excellent start, particularly Encapsulated Postscript (EPS) support is good as that is what most Vector Graphics applications use for document interchange but being able to work directly with SVG would be even better.  
With Microsoft coming out with XAML/WVG soon I think it is more important than ever to promote standards like SVG, but like I said before no pressure, no hurry.  
Comment 5 Inge Wallin 2005-08-16 18:16:56 UTC
However, all those formats are not provided by kchart.  They are provided by filter chains in the KOffice libs.  Kchart itself only provides PNG and SVG.
Comment 6 Carsten Niehaus 2007-03-29 11:27:39 UTC
Just a status-update:

Ok, we finally depend on Qt 4.3. I am now trying to implement this using some new fancy stuff in it :-)
Comment 7 cniehaus 2007-03-29 12:47:12 UTC
SVN commit 647745 by cniehaus:

I added File->Save As...

Now the table is "screenshot'ed" and saved in a file the user selects.
Have not yet tried the SVG-thing, no idea if that is easy to do or not.

cf http://doc.trolltech.com/4.3/qsvggenerator.html

CCBUG:109037


 M  +21 -1     kalzium.cpp  
 M  +2 -0      kalzium.h  
 M  +2 -2      periodictableview.h  


--- trunk/KDE/kdeedu/kalzium/src/kalzium.cpp #647744:647745
@@ -72,8 +72,11 @@
 #include <kicon.h>
 #include <kservicetypetrader.h>
 #include <kurl.h>
+#include <kfiledialog.h>
 
+#include <QFileDialog>
 
+
 #define PeriodicTableView_MARGIN          5
 #define IDS_ELEMENTINFO     7
 
@@ -195,16 +198,18 @@
 #else
     m_EQSolverAction->setEnabled( false );
 #endif
-
+    
     // tools actions
     m_pPlotAction = actionCollection()->addAction( "tools_plotdata" );
     m_pPlotAction->setText( i18n( "&Plot Data..." ) );
     m_pPlotAction->setIcon( KIcon( "plot" ) );
     connect( m_pPlotAction, SIGNAL( triggered() ), this, SLOT( slotPlotData() ) );
+
     m_pIsotopeTableAction= actionCollection()->addAction( "tools_isotopetable" );
     m_pIsotopeTableAction->setText( i18n( "&Isotope Table..." ) );
     m_pIsotopeTableAction->setIcon(  KIcon( "isotopemap" ) );
     connect( m_pIsotopeTableAction, SIGNAL( triggered() ), this, SLOT( slotIsotopeTable() ) );
+
     m_pGlossaryAction = actionCollection()->addAction( "tools_glossary" );
     m_pGlossaryAction->setText(i18n( "&Glossary..." ) );
     m_pGlossaryAction->setIcon( KIcon( "glossary" ) );
@@ -252,6 +257,7 @@
 
 
     // the standard actions
+    KStandardAction::saveAs(this, SLOT(slotExportTable()), actionCollection());
     KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollection());
     KStandardAction::quit( kapp, SLOT (closeAllWindows()),actionCollection() );
 
@@ -316,6 +322,20 @@
 	addDockWidget( Qt::BottomDockWidgetArea, m_InfoDock );
 }
 
+void Kalzium::slotExportTable()
+{
+    QPixmap pix = QPixmap::grabWidget( m_PeriodicTableView );
+
+    QString fileName = QFileDialog::getSaveFileName(this, i18n("Save Kalziums Tables in..."),
+            QString(), 
+            i18n("Images (*.png *.xpm *.jpg)"));
+
+//    QString fn = KFileDialog::getSaveFileName( ); //this methods causes an assert right now...
+
+    pix.save( fileName );
+
+}
+
 void Kalzium::slotGlossary()
 {
 	m_glossarydlg->show();
--- trunk/KDE/kdeedu/kalzium/src/kalzium.h #647744:647745
@@ -168,6 +168,8 @@
 
 		void slotPlotData();
 
+        void slotExportTable();
+
 		void slotUpdateSettings();
 
 		/**
--- trunk/KDE/kdeedu/kalzium/src/periodictableview.h #647744:647745
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2003-2005, 2006 by Carsten Niehaus                            *
+ *   Copyright (C) 2003-2007 by Carsten Niehaus                            *
  *   cniehaus@kde.org                                                      *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -36,7 +36,7 @@
 #include <chemicaldataobject.h>
 
 /**
- * A PeriodicTableView is the widget on where we paint a periodic table.
+ * A PeriodicTableView is the widget on which we paint a periodic table.
  *
  * It does not contain any code for painting, as all the painting routines
  * belongs to KalziumPainter.
Comment 8 cniehaus 2007-03-29 17:25:17 UTC
SVN commit 647807 by cniehaus:

Ok, the SVG-renderer is in place. Currently, I am getting an assertion
when I start a KFileDialog. That is why the name of the svg-file is
still hardcoded. I will fix that as soon as my kdelibs is fixed. But it
already works, here is a demo-svg:

http://websvn.kde.org/trunk/KDE/kdeedu/kalzium/ideas/svg-testoutput.svg?view=log

BUG:109037


 M  +8 -5      kalzium.cpp  
 M  +14 -0     periodictableview.cpp  
 M  +5 -0      periodictableview.h  


--- trunk/KDE/kdeedu/kalzium/src/kalzium.cpp #647806:647807
@@ -74,7 +74,7 @@
 #include <kurl.h>
 #include <kfiledialog.h>
 
-#include <QFileDialog>
+#include <QSvgGenerator>
 
 
 #define PeriodicTableView_MARGIN          5
@@ -326,13 +326,16 @@
 {
     QPixmap pix = QPixmap::grabWidget( m_PeriodicTableView );
 
-    QString fileName = QFileDialog::getSaveFileName(this, i18n("Save Kalziums Tables in..."),
-            QString(), 
-            i18n("Images (*.png *.xpm *.jpg)"));
+    m_PeriodicTableView->generateSvg( "/home/kde4/test2.svg" );
+    
 
+//X     QString fileName = QFileDialog::getSaveFileName(this, i18n("Save Kalziums Tables in..."),
+//X             QString(), 
+//X             i18n("Images (*.png *.xpm *.jpg)"));
+
 //    QString fn = KFileDialog::getSaveFileName( ); //this methods causes an assert right now...
 
-    pix.save( fileName );
+//X     pix.save( fileName );
 
 }
 
--- trunk/KDE/kdeedu/kalzium/src/periodictableview.cpp #647806:647807
@@ -42,6 +42,7 @@
 #include <QColor>
 #include <QRect>
 #include <QDrag>
+#include <QSvgGenerator>
 
 PeriodicTableView::PeriodicTableView( QWidget *parent )
   : QWidget( parent )
@@ -106,6 +107,19 @@
 	return m_painter->mode();
 }
 
+void PeriodicTableView::generateSvg(const QString& filename)
+{
+        QSvgGenerator *svgGen = new QSvgGenerator();
+
+        QFile* file = new QFile();
+
+        svgGen->setFileName( filename );
+
+        m_painter->begin( svgGen );
+        m_painter->drawAll();
+        m_painter->end();
+}
+
 void PeriodicTableView::paintEvent( QPaintEvent * e )
 {
 	if ( doFullDraw )
--- trunk/KDE/kdeedu/kalzium/src/periodictableview.h #647806:647807
@@ -73,6 +73,11 @@
 		 */
 		void setValueLimit( int value, ChemicalDataObject::BlueObelisk type );
 
+        /**
+        * Generate a SVG from the current table and save it in the file @p filename
+        */
+        void generateSvg(const QString& filename);
+
 		/**
 		 * Sets the scheme to use.
 		 * @param nr is the index of the new scheme