2007-08-07 17:09:41 +02:00
|
|
|
/* This file is part of Mapnik (c++ mapping toolkit)
|
2011-10-23 16:09:12 +02:00
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2007-08-07 17:09:41 +02:00
|
|
|
*
|
|
|
|
* Mapnik is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// qt
|
|
|
|
#include <QtGui>
|
|
|
|
#include <QSplitter>
|
|
|
|
#include <QTreeView>
|
|
|
|
#include <QListView>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QList>
|
|
|
|
#include <QItemDelegate>
|
|
|
|
#include <QSlider>
|
2012-05-03 16:21:17 +02:00
|
|
|
#include <QComboBox>
|
2012-07-10 17:58:43 +02:00
|
|
|
#include <QDoubleSpinBox>
|
2013-05-16 17:24:18 +02:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QToolBar>
|
2007-08-07 17:09:41 +02:00
|
|
|
// mapnik
|
2012-04-18 13:15:50 +02:00
|
|
|
|
|
|
|
#ifndef Q_MOC_RUN // QT moc chokes on BOOST_JOIN
|
2007-10-05 13:27:00 +02:00
|
|
|
#include <mapnik/config_error.hpp>
|
2007-08-07 17:09:41 +02:00
|
|
|
#include <mapnik/load_map.hpp>
|
2010-02-10 16:16:44 +01:00
|
|
|
#include <mapnik/save_map.hpp>
|
2012-08-16 11:41:48 +02:00
|
|
|
#include <mapnik/projection.hpp>
|
2012-04-18 13:15:50 +02:00
|
|
|
#endif
|
2007-08-07 17:09:41 +02:00
|
|
|
|
2010-02-10 16:16:44 +01:00
|
|
|
// qt
|
2007-08-07 17:09:41 +02:00
|
|
|
#include "mainwindow.hpp"
|
|
|
|
#include "layerlistmodel.hpp"
|
|
|
|
#include "styles_model.hpp"
|
|
|
|
#include "layerwidget.hpp"
|
|
|
|
#include "layerdelegate.hpp"
|
|
|
|
#include "about_dialog.hpp"
|
|
|
|
|
2013-11-28 07:50:15 +01:00
|
|
|
// boost
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
MainWindow::MainWindow()
|
2010-06-15 14:27:34 +02:00
|
|
|
: filename_(),
|
|
|
|
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_ = new MapWidget(this);
|
2011-10-23 16:09:12 +02:00
|
|
|
QSplitter *splitter = new QSplitter(this);
|
2010-06-15 14:27:34 +02:00
|
|
|
QTabWidget *tabWidget=new QTabWidget;
|
|
|
|
layerTab_ = new LayerTab;
|
|
|
|
layerTab_->setFocusPolicy(Qt::NoFocus);
|
|
|
|
layerTab_->setIconSize(QSize(16,16));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
|
|
|
//LayerDelegate *delegate = new LayerDelegate(this);
|
2010-06-15 14:27:34 +02:00
|
|
|
//layerTab_->setItemDelegate(delegate);
|
|
|
|
//layerTab_->setItemDelegate(new QItemDelegate(this));
|
|
|
|
//layerTab_->setViewMode(QListView::IconMode);
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
layerTab_->setFlow(QListView::TopToBottom);
|
|
|
|
tabWidget->addTab(layerTab_,tr("Layers"));
|
|
|
|
|
|
|
|
// Styles tab
|
|
|
|
styleTab_ = new StyleTab;
|
2011-10-23 16:09:12 +02:00
|
|
|
tabWidget->addTab(styleTab_,tr("Styles"));
|
2010-06-15 14:27:34 +02:00
|
|
|
splitter->addWidget(tabWidget);
|
|
|
|
splitter->addWidget(mapWidget_);
|
|
|
|
QList<int> list;
|
|
|
|
list.push_back(200);
|
|
|
|
list.push_back(600);
|
|
|
|
splitter->setSizes(list);
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
mapWidget_->setFocus();
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
//setCentralWidget(mapWidget_);
|
|
|
|
setCentralWidget(splitter);
|
|
|
|
createActions();
|
|
|
|
createMenus();
|
|
|
|
createToolBars();
|
|
|
|
createContextMenu();
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
setWindowTitle(tr("Mapnik Viewer"));
|
|
|
|
status=new QStatusBar(this);
|
|
|
|
status->showMessage(tr(""));
|
|
|
|
setStatusBar(status);
|
|
|
|
resize(800,600);
|
|
|
|
|
|
|
|
//connect mapview to layerlist
|
|
|
|
connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update()));
|
2011-10-23 16:09:12 +02:00
|
|
|
// slider
|
2012-07-10 17:58:43 +02:00
|
|
|
connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int)));
|
2012-05-03 16:21:17 +02:00
|
|
|
// renderer selector
|
2012-07-10 17:58:43 +02:00
|
|
|
connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)),
|
2012-05-03 16:21:17 +02:00
|
|
|
mapWidget_, SLOT(updateRenderer(QString const&)));
|
2012-07-10 17:58:43 +02:00
|
|
|
|
|
|
|
// scale factor
|
|
|
|
connect(scale_factor_,SIGNAL(valueChanged(double)),
|
|
|
|
mapWidget_, SLOT(updateScaleFactor(double)));
|
|
|
|
//
|
2010-06-15 14:27:34 +02:00
|
|
|
connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap()));
|
2011-10-23 16:09:12 +02:00
|
|
|
connect(layerTab_,SIGNAL(layerSelected(int)),
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_,SLOT(layerSelected(int)));
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
delete mapWidget_;
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
event->accept();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::createContextMenu()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
layerTab_->setContextMenuPolicy(Qt::ActionsContextMenu);
|
|
|
|
layerTab_->addAction(openAct);
|
|
|
|
layerTab_->addAction(layerInfo);
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::open(QString const& path)
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
if (path.isNull())
|
|
|
|
{
|
|
|
|
filename_ = QFileDialog::getOpenFileName(this,tr("Open Mapnik file"),
|
|
|
|
currentPath,"*.xml");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename_ = path;
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
if (!filename_.isEmpty())
|
|
|
|
{
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
load_map_file(filename_);
|
|
|
|
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
void MainWindow::reload()
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
2010-03-10 18:08:28 +01:00
|
|
|
if (!filename_.isEmpty())
|
|
|
|
{
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
|
2010-06-15 14:27:34 +02:00
|
|
|
load_map_file(filename_);
|
|
|
|
mapWidget_->zoomToBox(bbox);
|
|
|
|
setWindowTitle(tr("%1 - *Reloaded*").arg(filename_));
|
2010-03-10 18:08:28 +01:00
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::save()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
QString initialPath = QDir::currentPath() + "/untitled.xml";
|
|
|
|
QString filename = QFileDialog::getSaveFileName(this, tr("Save"),
|
|
|
|
initialPath,
|
|
|
|
tr("%1 Files (*.xml)")
|
|
|
|
.arg(QString("Mapnik definition")));
|
2011-10-23 16:09:12 +02:00
|
|
|
if (!filename.isEmpty())
|
2010-06-15 14:27:34 +02:00
|
|
|
{
|
|
|
|
std::cout<<"saving "<< filename.toStdString() << std::endl;
|
|
|
|
mapnik::save_map(*mapWidget_->getMap(),filename.toStdString());
|
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::load_map_file(QString const& filename)
|
|
|
|
{
|
2013-12-02 10:52:08 +01:00
|
|
|
std::cout << "loading "<< filename.toStdString() << std::endl;
|
2010-06-15 14:27:34 +02:00
|
|
|
unsigned width = mapWidget_->width();
|
|
|
|
unsigned height = mapWidget_->height();
|
2013-09-20 15:00:11 +02:00
|
|
|
std::shared_ptr<mapnik::Map> map(new mapnik::Map(width,height));
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->setMap(map);
|
2011-10-23 16:09:12 +02:00
|
|
|
try
|
|
|
|
{
|
2013-12-02 10:52:08 +01:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
|
2010-06-15 14:27:34 +02:00
|
|
|
mapnik::load_map(*map,filename.toStdString());
|
2013-12-02 10:52:08 +01:00
|
|
|
std::chrono::duration<double,std::milli> elapsed = std::chrono::system_clock::now() - start;
|
|
|
|
std::clog << "loading map took: " << std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count() << " milliseconds" << std::endl;
|
2010-06-15 14:27:34 +02:00
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
catch (mapnik::config_error & ex)
|
2010-06-15 14:27:34 +02:00
|
|
|
{
|
|
|
|
std::cout << ex.what() << "\n";
|
|
|
|
}
|
2010-06-18 12:53:49 +02:00
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cerr << "Exception caught in load_map\n";
|
|
|
|
}
|
2010-06-15 14:27:34 +02:00
|
|
|
layerTab_->setModel(new LayerListModel(map,this));
|
|
|
|
styleTab_->setModel(new StyleModel(map,this));
|
2010-07-16 01:08:22 +02:00
|
|
|
zoom_all();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::zoom_to_box()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->setTool(MapWidget::ZoomToBox);
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::pan()
|
|
|
|
{
|
2011-10-23 16:09:12 +02:00
|
|
|
mapWidget_->setTool(MapWidget::Pan);
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::info()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->setTool(MapWidget::Info);
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::pan_left()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->panLeft();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::pan_right()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->panRight();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::pan_up()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->panUp();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::pan_down()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
mapWidget_->panDown();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::about()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
about_dialog dlg;
|
|
|
|
dlg.exec();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::export_as()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
QAction *action = qobject_cast<QAction *>(sender());
|
|
|
|
QByteArray fileFormat = action->data().toByteArray();
|
|
|
|
QString initialPath = QDir::currentPath() + "/map." + fileFormat;
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"),
|
|
|
|
initialPath,
|
|
|
|
tr("%1 Files (*.%2);;All Files (*)")
|
|
|
|
.arg(QString(fileFormat.toUpper()))
|
|
|
|
.arg(QString(fileFormat)));
|
2011-10-23 16:09:12 +02:00
|
|
|
if (!fileName.isEmpty())
|
2010-06-15 14:27:34 +02:00
|
|
|
{
|
|
|
|
QPixmap const& pix = mapWidget_->pixmap();
|
|
|
|
pix.save(fileName);
|
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::print()
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
//Q_ASSERT(mapWidget_->pixmap());
|
|
|
|
//QPrintDialog dialog(&printer, this);
|
|
|
|
//if (dialog.exec()) {
|
|
|
|
// QPainter painter(&printer);
|
|
|
|
// QRect rect = painter.viewport();
|
|
|
|
// QSize size = mapWidget_->pixmap()->size();
|
|
|
|
// size.scale(rect.size(), Qt::KeepAspectRatio);
|
|
|
|
// painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
|
|
|
// painter.setWindow(mapWidget_->pixmap()->rect());
|
|
|
|
// painter.drawPixmap(0, 0, *mapWidget_->pixmap());
|
|
|
|
//}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::createActions()
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
//exportAct = new QAction(tr("&Export as ..."),this);
|
|
|
|
//exportAct->setShortcut(tr("Ctrl+E"));
|
|
|
|
//connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as()));
|
|
|
|
zoomAllAct = new QAction(QIcon(":/images/home.png"),tr("Zoom All"),this);
|
|
|
|
connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all()));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"),tr("Zoom To Box"),this);
|
|
|
|
zoomBoxAct->setCheckable(true);
|
|
|
|
connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box()));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
panAct = new QAction(QIcon(":/images/pan.png"),tr("Pan"),this);
|
|
|
|
panAct->setCheckable(true);
|
|
|
|
connect(panAct, SIGNAL(triggered()), this, SLOT(pan()));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
infoAct = new QAction(QIcon(":/images/info.png"),tr("Info"),this);
|
|
|
|
infoAct->setCheckable(true);
|
|
|
|
connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
toolsGroup=new QActionGroup(this);
|
|
|
|
toolsGroup->addAction(zoomBoxAct);
|
|
|
|
toolsGroup->addAction(panAct);
|
|
|
|
toolsGroup->addAction(infoAct);
|
|
|
|
zoomBoxAct->setChecked(true);
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
openAct=new QAction(tr("Open Map definition"),this);
|
|
|
|
connect(openAct,SIGNAL(triggered()),this,SLOT(open()));
|
|
|
|
saveAct=new QAction(tr("Save Map definition"),this);
|
|
|
|
connect(saveAct,SIGNAL(triggered()),this,SLOT(save()));
|
|
|
|
|
|
|
|
panLeftAct = new QAction(QIcon(":/images/left.png"),tr("&Pan Left"),this);
|
|
|
|
connect(panLeftAct, SIGNAL(triggered()), this, SLOT(pan_left()));
|
|
|
|
panRightAct = new QAction(QIcon(":/images/right.png"),tr("&Pan Right"),this);
|
|
|
|
connect(panRightAct, SIGNAL(triggered()), this, SLOT(pan_right()));
|
|
|
|
panUpAct = new QAction(QIcon(":/images/up.png"),tr("&Pan Up"),this);
|
|
|
|
connect(panUpAct, SIGNAL(triggered()), this, SLOT(pan_up()));
|
|
|
|
panDownAct = new QAction(QIcon(":/images/down.png"),tr("&Pan Down"),this);
|
|
|
|
connect(panDownAct, SIGNAL(triggered()), this, SLOT(pan_down()));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
reloadAct = new QAction(QIcon(":/images/reload.png"),tr("Reload"),this);
|
|
|
|
connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
layerInfo = new QAction(QIcon(":/images/info.png"),tr("&Layer info"),layerTab_);
|
|
|
|
connect(layerInfo, SIGNAL(triggered()), layerTab_,SLOT(layerInfo()));
|
|
|
|
connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_,SLOT(layerInfo2(QModelIndex const&)));
|
2011-10-23 16:09:12 +02:00
|
|
|
foreach (QByteArray format, QImageWriter::supportedImageFormats())
|
2010-06-15 14:27:34 +02:00
|
|
|
{
|
|
|
|
QString text = tr("%1...").arg(QString(format).toUpper());
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
QAction *action = new QAction(text, this);
|
|
|
|
action->setData(format);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(export_as()));
|
|
|
|
exportAsActs.append(action);
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
|
|
|
printAct->setShortcut(tr("Ctrl+E"));
|
|
|
|
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
exitAct = new QAction(tr("E&xit"), this);
|
|
|
|
exitAct->setShortcut(tr("Ctrl+Q"));
|
|
|
|
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
2007-08-07 17:09:41 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
aboutAct = new QAction(QIcon(":/images/about.png"),tr("&About"), this);
|
|
|
|
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::createMenus()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
exportMenu = new QMenu(tr("&Export As"), this);
|
|
|
|
foreach (QAction *action, exportAsActs)
|
2011-10-23 16:09:12 +02:00
|
|
|
exportMenu->addAction(action);
|
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
fileMenu = new QMenu(tr("&File"),this);
|
|
|
|
fileMenu->addAction(openAct);
|
|
|
|
fileMenu->addAction(saveAct);
|
|
|
|
fileMenu->addMenu(exportMenu);
|
|
|
|
fileMenu->addAction(printAct);
|
|
|
|
fileMenu->addSeparator();
|
|
|
|
fileMenu->addAction(exitAct);
|
|
|
|
menuBar()->addMenu(fileMenu);
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-15 14:27:34 +02:00
|
|
|
helpMenu = new QMenu(tr("&Help"), this);
|
|
|
|
helpMenu->addAction(aboutAct);
|
|
|
|
menuBar()->addMenu(helpMenu);
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::createToolBars()
|
|
|
|
{
|
2010-06-15 14:27:34 +02:00
|
|
|
fileToolBar = addToolBar(tr("Actions"));
|
|
|
|
fileToolBar->addAction(zoomAllAct);
|
|
|
|
fileToolBar->addAction(zoomBoxAct);
|
|
|
|
fileToolBar->addAction(panAct);
|
|
|
|
fileToolBar->addAction(panLeftAct);
|
|
|
|
fileToolBar->addAction(panRightAct);
|
|
|
|
fileToolBar->addAction(panUpAct);
|
|
|
|
fileToolBar->addAction(panDownAct);
|
|
|
|
fileToolBar->addAction(infoAct);
|
|
|
|
fileToolBar->addAction(reloadAct);
|
|
|
|
fileToolBar->addAction(printAct);
|
2012-07-10 17:58:43 +02:00
|
|
|
|
2012-05-03 16:21:17 +02:00
|
|
|
renderer_selector_ = new QComboBox(fileToolBar);
|
|
|
|
renderer_selector_->setFocusPolicy(Qt::NoFocus);
|
|
|
|
renderer_selector_->addItem("AGG");
|
|
|
|
#ifdef HAVE_CAIRO
|
|
|
|
renderer_selector_->addItem("Cairo");
|
|
|
|
#endif
|
2012-07-10 17:58:43 +02:00
|
|
|
renderer_selector_->addItem("Grid");
|
2012-05-03 16:21:17 +02:00
|
|
|
fileToolBar->addWidget(renderer_selector_);
|
|
|
|
|
2012-07-10 17:58:43 +02:00
|
|
|
scale_factor_ = new QDoubleSpinBox(fileToolBar);
|
|
|
|
scale_factor_->setMinimum(0.1);
|
|
|
|
scale_factor_->setMaximum(5.0);
|
|
|
|
scale_factor_->setSingleStep(0.1);
|
|
|
|
scale_factor_->setValue(1.0);
|
|
|
|
|
|
|
|
fileToolBar->addWidget(scale_factor_);
|
2010-06-15 14:27:34 +02:00
|
|
|
slider_ = new QSlider(Qt::Horizontal,fileToolBar);
|
|
|
|
slider_->setRange(1,18);
|
|
|
|
slider_->setTickPosition(QSlider::TicksBelow);
|
|
|
|
slider_->setTickInterval(1);
|
|
|
|
slider_->setTracking(false);
|
|
|
|
fileToolBar->addWidget(slider_);
|
|
|
|
fileToolBar->addAction(aboutAct);
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
2007-10-05 13:27:00 +02:00
|
|
|
|
|
|
|
|
2008-01-03 12:41:39 +01:00
|
|
|
|
|
|
|
void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
|
|
|
{
|
2011-10-23 16:09:12 +02:00
|
|
|
try
|
2008-01-03 12:41:39 +01:00
|
|
|
{
|
2013-09-20 15:00:11 +02:00
|
|
|
std::shared_ptr<mapnik::Map> map_ptr = mapWidget_->getMap();
|
2011-10-23 16:09:12 +02:00
|
|
|
if (map_ptr)
|
2010-06-15 14:27:34 +02:00
|
|
|
{
|
|
|
|
mapnik::projection prj(map_ptr->srs());
|
|
|
|
prj.forward(x0,y0);
|
|
|
|
prj.forward(x1,y1);
|
|
|
|
default_extent_=mapnik::box2d<double>(x0,y0,x1,y1);
|
|
|
|
mapWidget_->zoomToBox(default_extent_);
|
|
|
|
std::cout << "SET DEFAULT EXT\n";
|
|
|
|
}
|
2008-01-03 12:41:39 +01:00
|
|
|
}
|
|
|
|
catch (...) {}
|
2010-06-15 14:28:30 +02:00
|
|
|
}
|
|
|
|
|
2010-06-17 10:26:08 +02:00
|
|
|
void MainWindow::set_scaling_factor(double scaling_factor)
|
|
|
|
{
|
|
|
|
mapWidget_->set_scaling_factor(scaling_factor);
|
|
|
|
}
|
|
|
|
|
2010-06-15 14:28:30 +02:00
|
|
|
void MainWindow::zoom_all()
|
|
|
|
{
|
2013-09-20 15:00:11 +02:00
|
|
|
std::shared_ptr<mapnik::Map> map_ptr = mapWidget_->getMap();
|
2011-10-23 16:09:12 +02:00
|
|
|
if (map_ptr)
|
2010-06-15 14:28:30 +02:00
|
|
|
{
|
|
|
|
map_ptr->zoom_all();
|
2010-06-25 17:23:35 +02:00
|
|
|
mapnik::box2d<double> const& ext = map_ptr->get_current_extent();
|
2010-06-15 14:28:30 +02:00
|
|
|
mapWidget_->zoomToBox(ext);
|
|
|
|
}
|
2008-01-03 12:41:39 +01:00
|
|
|
}
|
2013-11-28 07:50:15 +01:00
|
|
|
|
|
|
|
std::shared_ptr<mapnik::Map> MainWindow::get_map()
|
|
|
|
{
|
|
|
|
return mapWidget_->getMap();
|
|
|
|
}
|