Index: trunk/BNC/qwtpolar/qwt_polar_renderer.cpp
===================================================================
--- trunk/BNC/qwtpolar/qwt_polar_renderer.cpp	(revision 4272)
+++ trunk/BNC/qwtpolar/qwt_polar_renderer.cpp	(revision 8127)
@@ -11,5 +11,4 @@
 #include "qwt_polar_layout.h"
 #include <qwt_legend.h>
-#include <qwt_legend_item.h>
 #include <qwt_dyngrid_layout.h>
 #include <qwt_text_label.h>
@@ -17,4 +16,6 @@
 #include <qpainter.h>
 #include <qprinter.h>
+#include <qprintdialog.h>
+#include <qfiledialog.h>
 #include <qimagewriter.h>
 #include <qfileinfo.h>
@@ -115,17 +116,37 @@
 
     const QString fmt = format.toLower();
-    if ( format == "pdf" || format == "ps" )
-    {
+    if ( format == "pdf" )
+    {
+#ifndef QT_NO_PRINTER
         QPrinter printer;
+        printer.setColorMode( QPrinter::Color );
         printer.setFullPage( true );
         printer.setPaperSize( sizeMM, QPrinter::Millimeter );
         printer.setDocName( title );
         printer.setOutputFileName( fileName );
-        printer.setOutputFormat( ( format == "pdf" )
-            ? QPrinter::PdfFormat : QPrinter::PostScriptFormat );
+        printer.setOutputFormat( QPrinter::PdfFormat );
         printer.setResolution( resolution );
 
         QPainter painter( &printer );
         render( plot, &painter, documentRect );
+#endif
+    }
+    else if ( format == "ps" )
+    {
+#if QT_VERSION < 0x050000
+#ifndef QT_NO_PRINTER
+        QPrinter printer;
+        printer.setColorMode( QPrinter::Color );
+        printer.setFullPage( true );
+        printer.setPaperSize( sizeMM, QPrinter::Millimeter );
+        printer.setDocName( title );
+        printer.setOutputFileName( fileName );
+        printer.setOutputFormat( QPrinter::PostScriptFormat );
+        printer.setResolution( resolution );
+
+        QPainter painter( &printer );
+        render( plot, &painter, documentRect );
+#endif
+#endif
     }
 #ifndef QWT_NO_POLAR_SVG
@@ -300,5 +321,5 @@
 
     painter->save();
-    renderLegend( painter, layout->legendRect() );
+    renderLegend( plot, painter, layout->legendRect() );
     painter->restore();
 
@@ -340,82 +361,77 @@
   Render the legend into a given rectangle.
 
+  \param plot Plot widget
   \param painter Painter
   \param rect Bounding rectangle
 */
-
-void QwtPolarRenderer::renderLegend(
+void QwtPolarRenderer::renderLegend( const QwtPolarPlot *plot,
     QPainter *painter, const QRectF &rect ) const
 {
-    QwtLegend *legend = d_data->plot->legend();
-    if ( legend == NULL || legend->isEmpty() )
-        return;
-
-    const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>(
-        legend->contentsWidget()->layout() );
-    if ( legendLayout == NULL )
-        return;
-
-    uint numCols = legendLayout->columnsForWidth( rect.width() );
-    const QList<QRect> itemRects =
-        legendLayout->layoutItems( rect.toRect(), numCols );
-
-    int index = 0;
-
-    for ( int i = 0; i < legendLayout->count(); i++ )
-    {
-        QLayoutItem *item = legendLayout->itemAt( i );
-        QWidget *w = item->widget();
-        if ( w )
+    if ( plot->legend() )
+        plot->legend()->renderLegend( painter, rect, true );
+}
+
+/*!
+   \brief Execute a file dialog and render the plot to the selected file
+
+   The document will be rendered in 85 dpi for a size 30x30 cm
+
+   \param plot Plot widget
+   \param documentName Default document name
+   \param sizeMM Size for the document in millimeters.
+   \param resolution Resolution in dots per Inch (dpi)
+
+   \sa renderDocument()
+*/
+bool QwtPolarRenderer::exportTo( QwtPolarPlot *plot, 
+    const QString &documentName, const QSizeF &sizeMM, int resolution )
+{
+    if ( plot == NULL )
+        return false;
+
+    QString fileName = documentName;
+
+    // What about translation 
+
+#ifndef QT_NO_FILEDIALOG
+    const QList<QByteArray> imageFormats =
+        QImageWriter::supportedImageFormats();
+
+    QStringList filter;
+#ifndef QT_NO_PRINTER
+    filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)";
+#endif
+#ifndef QWT_NO_SVG
+    filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)";
+#endif
+#ifndef QT_NO_PRINTER
+    filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)";
+#endif
+
+    if ( imageFormats.size() > 0 )
+    {
+        QString imageFilter( tr( "Images" ) );
+        imageFilter += " (";
+        for ( int i = 0; i < imageFormats.size(); i++ )
         {
-            painter->save();
-
-            painter->setClipRect( itemRects[index] );
-            renderLegendItem( painter, w, itemRects[index] );
-
-            index++;
-            painter->restore();
+            if ( i > 0 )
+                imageFilter += " ";
+            imageFilter += "*.";
+            imageFilter += imageFormats[i];
         }
-    }
-
-}
-
-/*!
-  Print the legend item into a given rectangle.
-
-  \param painter Painter
-  \param widget Widget representing a legend item
-  \param rect Bounding rectangle
-
-  \note When widget is not derived from QwtLegendItem renderLegendItem
-        does nothing and needs to be overloaded
-*/
-void QwtPolarRenderer::renderLegendItem( QPainter *painter,
-    const QWidget *widget, const QRectF &rect ) const
-{
-    const QwtLegendItem *item = qobject_cast<const QwtLegendItem *>( widget );
-    if ( item )
-    {
-        const QSize sz = item->identifierSize();
-
-        const QRectF identifierRect( rect.x() + item->margin(),
-            rect.center().y() - 0.5 * sz.height(), sz.width(), sz.height() );
-
-        QwtLegendItemManager *itemManger = d_data->plot->legend()->find( item );
-        if ( itemManger )
-        {
-            painter->save();
-            painter->setClipRect( identifierRect, Qt::IntersectClip );
-            itemManger->drawLegendIdentifier( painter, identifierRect );
-            painter->restore();
-        }
-
-        // Label
-
-        QRectF titleRect = rect;
-        titleRect.setX( identifierRect.right() + 2 * item->spacing() );
-
-        painter->setFont( item->font() );
-        item->text().draw( painter, titleRect );
-    }
-}
-
+        imageFilter += ")";
+
+        filter += imageFilter;
+    }
+
+    fileName = QFileDialog::getSaveFileName(
+        NULL, tr( "Export File Name" ), fileName,
+        filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
+#endif
+    if ( fileName.isEmpty() )
+        return false;
+
+    renderDocument( plot, fileName, sizeMM, resolution );
+
+    return true;
+}
