Merge branch 'master' of github.com:mapnik/mapnik

This commit is contained in:
Dane Springmeyer 2012-07-10 09:36:28 -07:00
commit 5a968959b5
4 changed files with 46 additions and 25 deletions

View file

@ -32,6 +32,7 @@
#include <QItemDelegate>
#include <QSlider>
#include <QComboBox>
#include <QDoubleSpinBox>
// mapnik
@ -97,12 +98,15 @@ MainWindow::MainWindow()
//connect mapview to layerlist
connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update()));
// slider
connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int)));
connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int)));
// renderer selector
connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)),
connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)),
mapWidget_, SLOT(updateRenderer(QString const&)));
//
// scale factor
connect(scale_factor_,SIGNAL(valueChanged(double)),
mapWidget_, SLOT(updateScaleFactor(double)));
//
connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap()));
connect(layerTab_,SIGNAL(layerSelected(int)),
mapWidget_,SLOT(layerSelected(int)));
@ -373,16 +377,23 @@ void MainWindow::createToolBars()
fileToolBar->addAction(infoAct);
fileToolBar->addAction(reloadAct);
fileToolBar->addAction(printAct);
renderer_selector_ = new QComboBox(fileToolBar);
renderer_selector_->setFocusPolicy(Qt::NoFocus);
renderer_selector_->addItem("AGG");
#ifdef HAVE_CAIRO
renderer_selector_->addItem("Cairo");
#endif
renderer_selector_->addItem("Grid");
renderer_selector_->addItem("Grid");
fileToolBar->addWidget(renderer_selector_);
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_);
slider_ = new QSlider(Qt::Horizontal,fileToolBar);
slider_->setRange(1,18);
slider_->setTickPosition(QSlider::TicksBelow);

View file

@ -28,6 +28,7 @@
#include <QActionGroup>
#include <QStatusBar>
#include <QAbstractItemModel>
#include <QDoubleSpinBox>
#include "mapwidget.hpp"
@ -37,6 +38,7 @@ class LayerTab;
class StyleTab;
class QSlider;
class QComboBox;
class QDoubleSpinBox;
class MainWindow : public QMainWindow
{
@ -108,6 +110,7 @@ private:
QStatusBar *status;
QSlider * slider_;
QComboBox * renderer_selector_;
QDoubleSpinBox * scale_factor_;
mapnik::box2d<double> default_extent_;
};

View file

@ -184,16 +184,16 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
feature_ptr feat = fs->next();
if (feat)
{
feature_kv_iterator itr(*feat,true);
feature_kv_iterator end(*feat);
for ( ;itr!=end; ++itr)
{
info.push_back(QPair<QString,QString>(QString(boost::get<0>(*itr).c_str()),
boost::get<1>(*itr).to_string().c_str()));
}
typedef mapnik::coord_transform<mapnik::CoordTransform,mapnik::geometry_type> path_type;
for (unsigned i=0; i<feat->num_geometries();++i)
@ -498,12 +498,12 @@ void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{
unsigned width=map.width();
unsigned height=map.height();
image_32 buf(width,height);
mapnik::agg_renderer<image_32> ren(map,buf,scaling_factor);
try
{
{
ren.apply();
QImage image((uchar*)buf.raw_data(),width,height,QImage::Format_ARGB32);
pix = QPixmap::fromImage(image.rgbSwapped());
@ -527,23 +527,23 @@ void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{
unsigned width=map.width();
unsigned height=map.height();
mapnik::grid buf(width,height,"F_CODE", 1);
mapnik::grid_renderer<mapnik::grid> ren(map,buf,scaling_factor);
try
{
{
ren.apply();
int * imdata = static_cast<int*>(buf.raw_data());
QImage image(width,height,QImage::Format_RGB32);
for (unsigned i = 0 ; i < height ; ++i)
{
{
for (unsigned j = 0 ; j < width ; ++j)
{
image.setPixel(j,i,qRgb((uint8_t)(imdata[i*width+j]>>8),
(uint8_t)(imdata[i*width+j+1]>>8),
(uint8_t)(imdata[i*width+j+2]>>8)));
(uint8_t)(imdata[i*width+j+2]>>8)));
}
}
pix = QPixmap::fromImage(image);
@ -567,12 +567,12 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{
#ifdef HAVE_CAIRO
Cairo::RefPtr<Cairo::ImageSurface> image_surface =
Cairo::RefPtr<Cairo::ImageSurface> image_surface =
Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, map.width(),map.height());
mapnik::cairo_renderer<Cairo::Surface> png_render(map, image_surface, scaling_factor);
png_render.apply();
image_32 buf(image_surface);
QImage image((uchar*)buf.raw_data(),buf.width(),buf.height(),QImage::Format_ARGB32);
pix = QPixmap::fromImage(image.rgbSwapped());
@ -588,6 +588,12 @@ void MapWidget::updateRenderer(QString const& txt)
updateMap();
}
void MapWidget::updateScaleFactor(double scale_factor)
{
set_scaling_factor(scale_factor);
updateMap();
}
void MapWidget::updateMap()
{
if (map_)
@ -611,7 +617,7 @@ void MapWidget::updateMap()
try
{
projection prj(map_->srs()); // map projection
projection prj(map_->srs()); // map projection
box2d<double> ext = map_->get_current_extent();
double x0 = ext.minx();
double y0 = ext.miny();
@ -623,7 +629,7 @@ void MapWidget::updateMap()
update();
// emit signal to interested widgets
emit mapViewChanged();
}
}
catch (...)
{
std::cerr << "Unknown exception caught!\n";

View file

@ -53,8 +53,8 @@ public:
AGG,
Cairo,
Grid
};
};
private:
boost::shared_ptr<mapnik::Map> map_;
int selected_;
@ -91,6 +91,7 @@ public slots:
void updateMap();
void layerSelected(int);
void updateRenderer(QString const& txt);
void updateScaleFactor(double scale_factor);
signals:
void mapViewChanged();
protected: