+ export as mapnik SVG
This commit is contained in:
parent
a2691d57ca
commit
179631560d
4 changed files with 84 additions and 16 deletions
|
@ -267,7 +267,7 @@ void MainWindow::export_as()
|
||||||
void MainWindow::export_as_skia_pdf()
|
void MainWindow::export_as_skia_pdf()
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
QByteArray fileFormat("pdf");
|
QByteArray fileFormat = action->data().toByteArray();
|
||||||
QString initialPath = QDir::currentPath() + "/map-skia." + fileFormat;
|
QString initialPath = QDir::currentPath() + "/map-skia." + fileFormat;
|
||||||
|
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Skia PDF"),
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Skia PDF"),
|
||||||
|
@ -287,9 +287,8 @@ void MainWindow::export_as_skia_pdf()
|
||||||
#ifdef HAVE_CAIRO
|
#ifdef HAVE_CAIRO
|
||||||
void MainWindow::export_as_cairo_pdf()
|
void MainWindow::export_as_cairo_pdf()
|
||||||
{
|
{
|
||||||
|
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
QByteArray fileFormat("pdf");
|
QByteArray fileFormat = action->data().toByteArray();
|
||||||
QString initialPath = QDir::currentPath() + "/map-cairo." + fileFormat;
|
QString initialPath = QDir::currentPath() + "/map-cairo." + fileFormat;
|
||||||
|
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Cairo PDF"),
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Cairo PDF"),
|
||||||
|
@ -306,6 +305,29 @@ void MainWindow::export_as_cairo_pdf()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SVG_RENDERER
|
||||||
|
|
||||||
|
void MainWindow::export_as_mapnik_svg()
|
||||||
|
{
|
||||||
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
|
QByteArray fileFormat = action->data().toByteArray();
|
||||||
|
QString initialPath = QDir::currentPath() + "/map-mapnik." + fileFormat;
|
||||||
|
|
||||||
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As Mapnik SVG"),
|
||||||
|
initialPath,
|
||||||
|
tr("%1 Files (*.%2);;All Files (*)")
|
||||||
|
.arg(QString(fileFormat.toUpper()))
|
||||||
|
.arg(QString(fileFormat)));
|
||||||
|
if (!fileName.isEmpty())
|
||||||
|
{
|
||||||
|
std::cerr << "Mapnik SVG" << std::endl;
|
||||||
|
mapWidget_->export_mapnik_svg(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void MainWindow::print()
|
void MainWindow::print()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -378,13 +400,21 @@ void MainWindow::createActions()
|
||||||
exportAsActs.append(action);
|
exportAsActs.append(action);
|
||||||
}
|
}
|
||||||
#ifdef SKIA_RENDERER
|
#ifdef SKIA_RENDERER
|
||||||
exportSkiaPdf = new QAction("Skia",this);
|
exportSkiaPDF = new QAction("Skia",this);
|
||||||
connect(exportSkiaPdf, SIGNAL(triggered()), this, SLOT(export_as_skia_pdf()));
|
exportSkiaPDF->setData(QByteArray("pdf"));
|
||||||
|
connect(exportSkiaPDF, SIGNAL(triggered()), this, SLOT(export_as_skia_pdf()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CAIRO
|
#ifdef HAVE_CAIRO
|
||||||
exportCairoPdf = new QAction("Cairo",this);
|
exportCairoPDF = new QAction("Cairo",this);
|
||||||
connect(exportCairoPdf, SIGNAL(triggered()), this, SLOT(export_as_cairo_pdf()));
|
exportCairoPDF->setData(QByteArray("pdf"));
|
||||||
|
connect(exportCairoPDF, SIGNAL(triggered()), this, SLOT(export_as_cairo_pdf()));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SVG_RENDERER
|
||||||
|
exportMapnikSVG = new QAction("Mapnik",this);
|
||||||
|
exportMapnikSVG->setData(QByteArray("svg"));
|
||||||
|
connect(exportMapnikSVG, SIGNAL(triggered()), this, SLOT(export_as_mapnik_svg()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
||||||
|
@ -405,15 +435,19 @@ void MainWindow::createMenus()
|
||||||
foreach (QAction *action, exportAsActs)
|
foreach (QAction *action, exportAsActs)
|
||||||
exportMenu->addAction(action);
|
exportMenu->addAction(action);
|
||||||
|
|
||||||
exportPdfMenu = new QMenu(tr("&Export As PDF"), this);
|
exportPDFMenu = new QMenu(tr("&Export As PDF"), this);
|
||||||
exportPdfMenu->addAction(exportSkiaPdf);
|
exportPDFMenu->addAction(exportSkiaPDF);
|
||||||
exportPdfMenu->addAction(exportCairoPdf);
|
exportPDFMenu->addAction(exportCairoPDF);
|
||||||
|
|
||||||
|
exportSVGMenu = new QMenu(tr("&Export As SVG"), this);
|
||||||
|
exportSVGMenu->addAction(exportMapnikSVG);
|
||||||
|
|
||||||
fileMenu = new QMenu(tr("&File"),this);
|
fileMenu = new QMenu(tr("&File"),this);
|
||||||
fileMenu->addAction(openAct);
|
fileMenu->addAction(openAct);
|
||||||
fileMenu->addAction(saveAct);
|
fileMenu->addAction(saveAct);
|
||||||
fileMenu->addMenu(exportMenu);
|
fileMenu->addMenu(exportMenu);
|
||||||
fileMenu->addMenu(exportPdfMenu);
|
fileMenu->addMenu(exportPDFMenu);
|
||||||
|
fileMenu->addMenu(exportSVGMenu);
|
||||||
fileMenu->addAction(printAct);
|
fileMenu->addAction(printAct);
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
fileMenu->addAction(exitAct);
|
fileMenu->addAction(exitAct);
|
||||||
|
|
|
@ -56,6 +56,7 @@ public slots:
|
||||||
void export_as();
|
void export_as();
|
||||||
void export_as_skia_pdf();
|
void export_as_skia_pdf();
|
||||||
void export_as_cairo_pdf();
|
void export_as_cairo_pdf();
|
||||||
|
void export_as_mapnik_svg();
|
||||||
void open(QString const& path = QString());
|
void open(QString const& path = QString());
|
||||||
void reload();
|
void reload();
|
||||||
void save();
|
void save();
|
||||||
|
@ -98,14 +99,16 @@ private:
|
||||||
QAction *panDownAct;
|
QAction *panDownAct;
|
||||||
QAction *reloadAct;
|
QAction *reloadAct;
|
||||||
QAction *layerInfo;
|
QAction *layerInfo;
|
||||||
QAction *exportSkiaPdf;
|
QAction *exportSkiaPDF;
|
||||||
QAction *exportCairoPdf;
|
QAction *exportCairoPDF;
|
||||||
|
QAction *exportMapnikSVG;
|
||||||
//toolbars
|
//toolbars
|
||||||
QToolBar *fileToolBar;
|
QToolBar *fileToolBar;
|
||||||
QToolBar *editToolBar;
|
QToolBar *editToolBar;
|
||||||
//menus
|
//menus
|
||||||
QMenu *exportMenu;
|
QMenu *exportMenu;
|
||||||
QMenu *exportPdfMenu;
|
QMenu *exportPDFMenu;
|
||||||
|
QMenu *exportSVGMenu;
|
||||||
QMenu *fileMenu;
|
QMenu *fileMenu;
|
||||||
QMenu *helpMenu;
|
QMenu *helpMenu;
|
||||||
//status bar
|
//status bar
|
||||||
|
|
|
@ -35,6 +35,10 @@
|
||||||
#include <mapnik/config_error.hpp>
|
#include <mapnik/config_error.hpp>
|
||||||
#include <mapnik/image_util.hpp>
|
#include <mapnik/image_util.hpp>
|
||||||
|
|
||||||
|
#ifdef SVG_RENDERER
|
||||||
|
#include <mapnik/svg/output/svg_renderer.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CAIRO
|
#ifdef HAVE_CAIRO
|
||||||
// cairo
|
// cairo
|
||||||
#include <mapnik/cairo_renderer.hpp>
|
#include <mapnik/cairo_renderer.hpp>
|
||||||
|
@ -664,8 +668,6 @@ void MapWidget::export_skia_pdf(QString const& filename)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||||
{
|
{
|
||||||
std::cerr << "Not supported" << std::endl;
|
std::cerr << "Not supported" << std::endl;
|
||||||
|
@ -675,6 +677,7 @@ void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||||
void MapWidget::export_cairo_pdf(QString const& filename)
|
void MapWidget::export_cairo_pdf(QString const& filename)
|
||||||
{
|
{
|
||||||
save_to_cairo_file(*map_,filename.toStdString(),scaling_factor_);
|
save_to_cairo_file(*map_,filename.toStdString(),scaling_factor_);
|
||||||
|
std::cerr << "Done" << std::endl;
|
||||||
}
|
}
|
||||||
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||||
{
|
{
|
||||||
|
@ -690,6 +693,30 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SVG_RENDERER
|
||||||
|
void MapWidget::export_mapnik_svg(QString const& filename)
|
||||||
|
{
|
||||||
|
boost::timer::auto_cpu_timer t;
|
||||||
|
std::ofstream output_stream(filename.toStdString().c_str());
|
||||||
|
if (output_stream)
|
||||||
|
{
|
||||||
|
std::ostream_iterator<char> output_itr(output_stream);
|
||||||
|
mapnik::svg_renderer<std::ostream_iterator<char> > ren(*map_, output_itr, scaling_factor_);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ren.apply();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "Exception caught." << std::endl;
|
||||||
|
}
|
||||||
|
output_stream.close();
|
||||||
|
}
|
||||||
|
std::cerr << "Done" << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void MapWidget::updateRenderer(QString const& txt)
|
void MapWidget::updateRenderer(QString const& txt)
|
||||||
{
|
{
|
||||||
bool auto_swap = true;
|
bool auto_swap = true;
|
||||||
|
|
|
@ -98,6 +98,10 @@ public:
|
||||||
void export_cairo_pdf(QString const& filename);
|
void export_cairo_pdf(QString const& filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SVG_RENDERER
|
||||||
|
void export_mapnik_svg(QString const& filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void zoomToLevel(int level);
|
void zoomToLevel(int level);
|
||||||
void updateMap();
|
void updateMap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue