format dir demo
This commit is contained in:
parent
65035706fb
commit
4fbaa032f0
20 changed files with 888 additions and 996 deletions
|
@ -45,19 +45,21 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int main ( int, char** )
|
||||
int main(int, char**)
|
||||
{
|
||||
using namespace mapnik;
|
||||
const std::string srs_lcc="+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs";
|
||||
const std::string srs_merc="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over";
|
||||
const std::string srs_lcc =
|
||||
"+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs";
|
||||
const std::string srs_merc = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 "
|
||||
"+units=m +nadgrids=@null +wktext +no_defs +over";
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
std::cout << " running demo ... \n";
|
||||
datasource_cache::instance().register_datasources("plugins/input/");
|
||||
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
|
||||
|
||||
Map m(800,600);
|
||||
Map m(800, 600);
|
||||
m.set_background(parse_color("white"));
|
||||
m.set_srs(srs_merc);
|
||||
// create styles
|
||||
|
@ -93,13 +95,13 @@ int main ( int, char** )
|
|||
rule r;
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(0,0,0));
|
||||
put(line_sym,keys::stroke_width,1.0);
|
||||
put(line_sym, keys::stroke, color(0, 0, 0));
|
||||
put(line_sym, keys::stroke_width, 1.0);
|
||||
dash_array dash;
|
||||
dash.emplace_back(8,4);
|
||||
dash.emplace_back(2,2);
|
||||
dash.emplace_back(2,2);
|
||||
put(line_sym,keys::stroke_dasharray,dash);
|
||||
dash.emplace_back(8, 4);
|
||||
dash.emplace_back(2, 2);
|
||||
dash.emplace_back(2, 2);
|
||||
put(line_sym, keys::stroke_dasharray, dash);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
provlines_style.add_rule(std::move(r));
|
||||
|
@ -127,10 +129,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(171,158,137));
|
||||
put(line_sym,keys::stroke_width,2.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(171, 158, 137));
|
||||
put(line_sym, keys::stroke_width, 2.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads34_style.add_rule(std::move(r));
|
||||
|
@ -144,10 +146,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(171,158,137));
|
||||
put(line_sym,keys::stroke_width,4.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(171, 158, 137));
|
||||
put(line_sym, keys::stroke_width, 4.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads2_style_1.add_rule(std::move(r));
|
||||
|
@ -160,10 +162,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(255,250,115));
|
||||
put(line_sym,keys::stroke_width,2.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(255, 250, 115));
|
||||
put(line_sym, keys::stroke_width, 2.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads2_style_2.add_rule(std::move(r));
|
||||
|
@ -177,10 +179,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(188,149,28));
|
||||
put(line_sym,keys::stroke_width,7.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(188, 149, 28));
|
||||
put(line_sym, keys::stroke_width, 7.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads1_style_1.add_rule(std::move(r));
|
||||
|
@ -193,10 +195,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(242,191,36));
|
||||
put(line_sym,keys::stroke_width,5.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(242, 191, 36));
|
||||
put(line_sym, keys::stroke_width, 5.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads1_style_2.add_rule(std::move(r));
|
||||
|
@ -212,10 +214,11 @@ int main ( int, char** )
|
|||
text_placements_ptr placement_finder = std::make_shared<text_placements_dummy>();
|
||||
placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book";
|
||||
placement_finder->defaults.format_defaults.text_size = 10.0;
|
||||
placement_finder->defaults.format_defaults.fill = color(0,0,0);
|
||||
placement_finder->defaults.format_defaults.halo_fill = color(255,255,200);
|
||||
placement_finder->defaults.format_defaults.fill = color(0, 0, 0);
|
||||
placement_finder->defaults.format_defaults.halo_fill = color(255, 255, 200);
|
||||
placement_finder->defaults.format_defaults.halo_radius = 1.0;
|
||||
placement_finder->defaults.set_format_tree(std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]")));
|
||||
placement_finder->defaults.set_format_tree(
|
||||
std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]")));
|
||||
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
|
||||
r.append(std::move(text_sym));
|
||||
}
|
||||
|
@ -228,9 +231,9 @@ int main ( int, char** )
|
|||
// Provincial polygons
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/boundaries";
|
||||
p["encoding"]="utf8";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/boundaries";
|
||||
p["encoding"] = "utf8";
|
||||
|
||||
layer lyr("Provinces");
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
|
@ -242,8 +245,8 @@ int main ( int, char** )
|
|||
// Drainage
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/qcdrainage";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/qcdrainage";
|
||||
layer lyr("Quebec Hydrography");
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
lyr.set_srs(srs_lcc);
|
||||
|
@ -253,8 +256,8 @@ int main ( int, char** )
|
|||
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/ontdrainage";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/ontdrainage";
|
||||
layer lyr("Ontario Hydrography");
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
lyr.set_srs(srs_lcc);
|
||||
|
@ -265,8 +268,8 @@ int main ( int, char** )
|
|||
// Provincial boundaries
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/boundaries_l";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/boundaries_l";
|
||||
layer lyr("Provincial borders");
|
||||
lyr.set_srs(srs_lcc);
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
|
@ -277,8 +280,8 @@ int main ( int, char** )
|
|||
// Roads
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/roads";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/roads";
|
||||
layer lyr("Roads");
|
||||
lyr.set_srs(srs_lcc);
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
|
@ -293,8 +296,8 @@ int main ( int, char** )
|
|||
// popplaces
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/popplaces";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/popplaces";
|
||||
p["encoding"] = "utf8";
|
||||
layer lyr("Populated Places");
|
||||
lyr.set_srs(srs_lcc);
|
||||
|
@ -303,28 +306,28 @@ int main ( int, char** )
|
|||
m.add_layer(lyr);
|
||||
}
|
||||
|
||||
m.zoom_to_box(box2d<double>(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855));
|
||||
m.zoom_to_box(box2d<double>(-8024477.28459, 5445190.38849, -7381388.20071, 5662941.44855));
|
||||
|
||||
image_rgba8 buf(m.width(),m.height());
|
||||
agg_renderer<image_rgba8> ren(m,buf);
|
||||
image_rgba8 buf(m.width(), m.height());
|
||||
agg_renderer<image_rgba8> ren(m, buf);
|
||||
ren.apply();
|
||||
std::string msg("These maps have been rendered using AGG in the current directory:\n");
|
||||
#ifdef HAVE_JPEG
|
||||
save_to_file(buf,"demo.jpg","jpeg");
|
||||
save_to_file(buf, "demo.jpg", "jpeg");
|
||||
msg += "- demo.jpg\n";
|
||||
#endif
|
||||
#ifdef HAVE_PNG
|
||||
save_to_file(buf,"demo.png","png");
|
||||
save_to_file(buf,"demo256.png","png8");
|
||||
save_to_file(buf, "demo.png", "png");
|
||||
save_to_file(buf, "demo256.png", "png8");
|
||||
msg += "- demo.png\n";
|
||||
msg += "- demo256.png\n";
|
||||
#endif
|
||||
#ifdef HAVE_TIFF
|
||||
save_to_file(buf,"demo.tif","tiff");
|
||||
save_to_file(buf, "demo.tif", "tiff");
|
||||
msg += "- demo.tif\n";
|
||||
#endif
|
||||
#ifdef HAVE_WEBP
|
||||
save_to_file(buf,"demo.webp","webp");
|
||||
save_to_file(buf, "demo.webp", "webp");
|
||||
msg += "- demo.webp\n";
|
||||
#endif
|
||||
msg += "Have a look!\n";
|
||||
|
@ -332,8 +335,8 @@ int main ( int, char** )
|
|||
|
||||
#if defined(HAVE_CAIRO)
|
||||
// save to pdf/svg files
|
||||
save_to_cairo_file(m,"cairo-demo.pdf");
|
||||
save_to_cairo_file(m,"cairo-demo.svg");
|
||||
save_to_cairo_file(m, "cairo-demo.pdf");
|
||||
save_to_cairo_file(m, "cairo-demo.svg");
|
||||
|
||||
/* we could also do:
|
||||
|
||||
|
@ -342,20 +345,20 @@ int main ( int, char** )
|
|||
but instead let's build up a surface for more flexibility
|
||||
*/
|
||||
|
||||
cairo_surface_ptr image_surface(
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,m.width(),m.height()),
|
||||
cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m.width(), m.height()),
|
||||
cairo_surface_closer());
|
||||
double scale_factor = 1.0;
|
||||
cairo_ptr image_context(create_context(image_surface));
|
||||
mapnik::cairo_renderer<cairo_ptr> png_render(m,image_context,scale_factor);
|
||||
mapnik::cairo_renderer<cairo_ptr> png_render(m, image_context, scale_factor);
|
||||
png_render.apply();
|
||||
// we can now write to png with cairo functionality
|
||||
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
|
||||
// but we can also benefit from quantization by converting
|
||||
// to a mapnik image object and then saving that
|
||||
mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface));
|
||||
mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface),
|
||||
cairo_image_surface_get_height(&*image_surface));
|
||||
cairo_image_to_rgba8(im_data, image_surface);
|
||||
save_to_file(im_data, "cairo-demo256.png","png8");
|
||||
save_to_file(im_data, "cairo-demo256.png", "png8");
|
||||
cairo_surface_finish(&*image_surface);
|
||||
|
||||
std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
|
||||
|
@ -367,13 +370,11 @@ int main ( int, char** )
|
|||
#endif
|
||||
// save map definition (data + style)
|
||||
save_map(m, "map.xml");
|
||||
}
|
||||
catch ( std::exception const& ex )
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::cerr << "### std::exception: " << ex.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch ( ... )
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "### Unknown exception." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -17,11 +17,9 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "about_dialog.hpp"
|
||||
|
||||
|
||||
about_dialog::about_dialog(QWidget *parent)
|
||||
about_dialog::about_dialog(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if !defined ABOUT_DIALOG_HPP
|
||||
#define ABOUT_DIALOG_HPP
|
||||
|
||||
|
@ -28,11 +26,11 @@
|
|||
class about_dialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
about_dialog(QWidget * parent = 0);
|
||||
private:
|
||||
public:
|
||||
about_dialog(QWidget* parent = 0);
|
||||
|
||||
private:
|
||||
Ui::Dialog ui;
|
||||
};
|
||||
|
||||
|
||||
#endif //ABOUT_DIALOG_HPP
|
||||
#endif // ABOUT_DIALOG_HPP
|
||||
|
|
|
@ -17,24 +17,22 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "info_dialog.hpp"
|
||||
|
||||
|
||||
info_dialog::info_dialog(QVector<QPair<QString,QString> > const& info, QWidget *parent)
|
||||
info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||
|
||||
ui.tableWidget->setRowCount(info.size());
|
||||
ui.tableWidget->setColumnCount(2);
|
||||
for (int i=0;i<info.size();++i)
|
||||
for (int i = 0; i < info.size(); ++i)
|
||||
{
|
||||
QTableWidgetItem *keyItem = new QTableWidgetItem(info[i].first);
|
||||
QTableWidgetItem *valueItem = new QTableWidgetItem(info[i].second);
|
||||
ui.tableWidget->setItem(i,0,keyItem);
|
||||
ui.tableWidget->setItem(i,1,valueItem);
|
||||
QTableWidgetItem* keyItem = new QTableWidgetItem(info[i].first);
|
||||
QTableWidgetItem* valueItem = new QTableWidgetItem(info[i].second);
|
||||
ui.tableWidget->setItem(i, 0, keyItem);
|
||||
ui.tableWidget->setItem(i, 1, valueItem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef INFO_DIALOG_HPP
|
||||
#define INFO_DIALOG_HPP
|
||||
|
||||
|
@ -29,10 +27,10 @@ class info_dialog : public QDialog
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
info_dialog(QVector<QPair<QString,QString> > const& info,QWidget * parent = 0);
|
||||
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0);
|
||||
|
||||
private:
|
||||
Ui::InfoDialog ui;
|
||||
};
|
||||
|
||||
|
||||
#endif //INFO_DIALOG_HPP
|
||||
#endif // INFO_DIALOG_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "layer_info_dialog.hpp"
|
||||
|
||||
// mapnik
|
||||
|
@ -26,14 +25,13 @@
|
|||
#include <mapnik/params_impl.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
|
||||
|
||||
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
||||
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||
|
||||
// Layer name
|
||||
ui.layerNameEdit->setText(QString(lay.name().c_str()));
|
||||
|
@ -50,17 +48,17 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
|||
ui.tableWidget->setColumnCount(2);
|
||||
|
||||
mapnik::parameters::const_iterator pos;
|
||||
int index=0;
|
||||
for (pos = ps.begin();pos != ps.end();++pos)
|
||||
int index = 0;
|
||||
for (pos = ps.begin(); pos != ps.end(); ++pos)
|
||||
{
|
||||
boost::optional<std::string> result;
|
||||
mapnik::util::apply_visitor(mapnik::value_extractor_visitor<std::string>(result),pos->second);
|
||||
mapnik::util::apply_visitor(mapnik::value_extractor_visitor<std::string>(result), pos->second);
|
||||
if (result)
|
||||
{
|
||||
QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
|
||||
QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str()));
|
||||
ui.tableWidget->setItem(index,0,keyItem);
|
||||
ui.tableWidget->setItem(index,1,valueItem);
|
||||
QTableWidgetItem* keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
|
||||
QTableWidgetItem* valueItem = new QTableWidgetItem(QString((*result).c_str()));
|
||||
ui.tableWidget->setItem(index, 0, keyItem);
|
||||
ui.tableWidget->setItem(index, 1, valueItem);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,16 +17,13 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef LAYER_INFO_DIALOG_HPP
|
||||
#define LAYER_INFO_DIALOG_HPP
|
||||
|
||||
#include "ui_layer_info.h"
|
||||
#include <QDialog>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
class layer;
|
||||
}
|
||||
|
||||
|
@ -34,11 +31,11 @@ class layer_info_dialog : public QDialog
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
layer_info_dialog(mapnik::layer& l, QWidget * parent = 0);
|
||||
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0);
|
||||
Ui::LayerInfoDialog& getUI();
|
||||
|
||||
private:
|
||||
Ui::LayerInfoDialog ui;
|
||||
};
|
||||
|
||||
|
||||
#endif //LAYER_INFO_DIALOG_HPP
|
||||
#endif // LAYER_INFO_DIALOG_HPP
|
||||
|
|
|
@ -17,38 +17,32 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui>
|
||||
#include "layerdelegate.hpp"
|
||||
|
||||
LayerDelegate::LayerDelegate(QObject *parent)
|
||||
LayerDelegate::LayerDelegate(QObject* parent)
|
||||
: QAbstractItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
void LayerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setPen(QPen(QColor(255,0,0),1));
|
||||
painter->setPen(QPen(QColor(255, 0, 0), 1));
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
painter->setBrush(QBrush(QColor(0, 0, 255, 64)));
|
||||
else
|
||||
painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
|
||||
|
||||
|
||||
painter->drawRoundedRect(option.rect,4,4);
|
||||
painter->drawRoundedRect(option.rect, 4, 4);
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
painter->setBrush(option.palette.highlightedText());
|
||||
else
|
||||
painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
|
||||
|
||||
}
|
||||
|
||||
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
|
||||
const QModelIndex & /* index */) const
|
||||
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const
|
||||
{
|
||||
return QSize(120,24);
|
||||
return QSize(120, 24);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,10 @@ class LayerDelegate : public QAbstractItemDelegate
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LayerDelegate(QObject *parent = 0);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index ) const;
|
||||
public:
|
||||
LayerDelegate(QObject* parent = 0);
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
#endif //LAYER_DELEGATE_HPP
|
||||
#endif // LAYER_DELEGATE_HPP
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "layerlistmodel.hpp"
|
||||
#include <QIcon>
|
||||
#include <QBrush>
|
||||
|
@ -26,13 +24,15 @@
|
|||
|
||||
using mapnik::Map;
|
||||
|
||||
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
map_(map) {}
|
||||
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent)
|
||||
: QAbstractListModel(parent)
|
||||
, map_(map)
|
||||
{}
|
||||
|
||||
int LayerListModel::rowCount(QModelIndex const&) const
|
||||
{
|
||||
if (map_) return map_->layers().size();
|
||||
if (map_)
|
||||
return map_->layers().size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -76,8 +76,7 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const
|
|||
}
|
||||
}
|
||||
|
||||
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
@ -88,15 +87,15 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
|||
return QString("TODO Row %1").arg(section);
|
||||
}
|
||||
|
||||
bool LayerListModel::setData(const QModelIndex &index,
|
||||
const QVariant &value, int role)
|
||||
bool LayerListModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
if (!map_) return false;
|
||||
if (!map_)
|
||||
return false;
|
||||
|
||||
if (index.isValid() && role == Qt::CheckStateRole)
|
||||
{
|
||||
int status = value.toInt();
|
||||
std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
|
||||
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers());
|
||||
layers.at(index.row()).set_active(status);
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
|
@ -116,7 +115,7 @@ boost::optional<mapnik::layer&> LayerListModel::map_layer(int i)
|
|||
{
|
||||
if (map_)
|
||||
{
|
||||
std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
|
||||
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers());
|
||||
if (i < int(layers.size()))
|
||||
return boost::optional<mapnik::layer&>(layers[i]);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef LAYER_LIST_MODEL_HPP
|
||||
#define LAYER_LIST_MODEL_HPP
|
||||
|
||||
|
@ -34,13 +32,11 @@ class LayerListModel : public QAbstractListModel
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject * parent = 0);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole);
|
||||
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex& index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
Qt::ItemFlags flags(QModelIndex const& index) const;
|
||||
boost::optional<mapnik::layer&> map_layer(int i);
|
||||
|
||||
|
@ -48,4 +44,4 @@ class LayerListModel : public QAbstractListModel
|
|||
std::shared_ptr<mapnik::Map> map_;
|
||||
};
|
||||
|
||||
#endif //LAYER_LIST_MODEL_HPP
|
||||
#endif // LAYER_LIST_MODEL_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "layerwidget.hpp"
|
||||
#include <qabstractitemdelegate.h>
|
||||
#include <qapplication.h>
|
||||
|
@ -33,28 +32,26 @@
|
|||
#include "layer_info_dialog.hpp"
|
||||
|
||||
LayerTab::LayerTab(QWidget* parent)
|
||||
: QListView(parent) {}
|
||||
: QListView(parent)
|
||||
{}
|
||||
|
||||
|
||||
void LayerTab::paintEvent(QPaintEvent *e)
|
||||
void LayerTab::paintEvent(QPaintEvent* e)
|
||||
{
|
||||
QListView::paintEvent(e);
|
||||
}
|
||||
|
||||
void LayerTab::dataChanged(const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles)
|
||||
void LayerTab::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
|
||||
{
|
||||
emit update_mapwidget();
|
||||
QListView::dataChanged(topLeft, bottomRight, roles);
|
||||
}
|
||||
|
||||
void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &)
|
||||
void LayerTab::selectionChanged(const QItemSelection& selected, const QItemSelection&)
|
||||
{
|
||||
QModelIndexList list = selected.indexes();
|
||||
if (list.size() != 0)
|
||||
{
|
||||
qDebug("SELECTED LAYER -> %d",list[0].row());
|
||||
qDebug("SELECTED LAYER -> %d", list[0].row());
|
||||
emit layerSelected(list[0].row());
|
||||
}
|
||||
}
|
||||
|
@ -65,33 +62,29 @@ void LayerTab::layerInfo()
|
|||
QModelIndexList indexes = selectedIndexes();
|
||||
if (indexes.size() > 0)
|
||||
{
|
||||
qDebug("id = %d",indexes[0].row());
|
||||
|
||||
qDebug("id = %d", indexes[0].row());
|
||||
}
|
||||
}
|
||||
|
||||
void LayerTab::layerInfo2(QModelIndex const& index)
|
||||
{
|
||||
qDebug("LayerInfo id = %d",index.row());
|
||||
QVector<QPair<QString,QString> > params;
|
||||
qDebug("LayerInfo id = %d", index.row());
|
||||
QVector<QPair<QString, QString>> params;
|
||||
QVector<QString> style_names;
|
||||
unsigned i = index.row();
|
||||
LayerListModel * model = static_cast<LayerListModel*>(this->model());
|
||||
LayerListModel* model = static_cast<LayerListModel*>(this->model());
|
||||
boost::optional<mapnik::layer&> layer = model->map_layer(i);
|
||||
|
||||
if (layer)
|
||||
{
|
||||
layer_info_dialog dlg(*layer,this);
|
||||
layer_info_dialog dlg(*layer, this);
|
||||
dlg.exec();
|
||||
}
|
||||
}
|
||||
|
||||
StyleTab::StyleTab(QWidget*)
|
||||
{
|
||||
StyleTab::StyleTab(QWidget*) {}
|
||||
|
||||
}
|
||||
|
||||
void StyleTab::contextMenuEvent(QContextMenuEvent * event )
|
||||
void StyleTab::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
qDebug("test");
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LAYERWIDGET_HPP
|
||||
#define LAYERWIDGET_HPP
|
||||
|
||||
|
@ -28,27 +27,28 @@
|
|||
class LayerTab : public QListView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LayerTab(QWidget* parent=0);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
signals:
|
||||
public:
|
||||
LayerTab(QWidget* parent = 0);
|
||||
void paintEvent(QPaintEvent* e);
|
||||
signals:
|
||||
void update_mapwidget();
|
||||
void layerSelected(int) const;
|
||||
public slots:
|
||||
public slots:
|
||||
void layerInfo();
|
||||
void layerInfo2(QModelIndex const&);
|
||||
protected slots:
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||
void selectionChanged(const QItemSelection & selected, const QItemSelection &);
|
||||
protected slots:
|
||||
void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
|
||||
void selectionChanged(const QItemSelection& selected, const QItemSelection&);
|
||||
};
|
||||
|
||||
class StyleTab : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StyleTab(QWidget* parent=0);
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent * event );
|
||||
public:
|
||||
StyleTab(QWidget* parent = 0);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
// qt
|
||||
#include <QApplication>
|
||||
#include <QStringList>
|
||||
|
@ -26,7 +25,7 @@
|
|||
#include <mapnik/font_engine_freetype.hpp>
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
int main( int argc, char **argv )
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using mapnik::datasource_cache;
|
||||
using mapnik::freetype_engine;
|
||||
|
@ -38,15 +37,14 @@ int main( int argc, char **argv )
|
|||
QCoreApplication::setOrganizationName("Mapnik");
|
||||
QCoreApplication::setOrganizationDomain("mapnik.org");
|
||||
QCoreApplication::setApplicationName("Viewer");
|
||||
QSettings settings("viewer.ini",QSettings::IniFormat);
|
||||
QSettings settings("viewer.ini", QSettings::IniFormat);
|
||||
|
||||
// register input plug-ins
|
||||
QString plugins_dir = settings.value("mapnik/plugins_dir",
|
||||
QVariant("/usr/local/lib/mapnik/input/")).toString();
|
||||
QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik/input/")).toString();
|
||||
datasource_cache::instance().register_datasources(plugins_dir.toStdString());
|
||||
// register fonts
|
||||
int count = settings.beginReadArray("mapnik/fonts");
|
||||
for (int index=0; index < count; ++index)
|
||||
for (int index = 0; index < count; ++index)
|
||||
{
|
||||
settings.setArrayIndex(index);
|
||||
QString font_dir = settings.value("dir").toString();
|
||||
|
@ -54,37 +52,40 @@ int main( int argc, char **argv )
|
|||
}
|
||||
settings.endArray();
|
||||
|
||||
QApplication app( argc, argv );
|
||||
QApplication app(argc, argv);
|
||||
MainWindow window;
|
||||
window.show();
|
||||
if (argc > 1) window.open(argv[1]);
|
||||
if (argc > 1)
|
||||
window.open(argv[1]);
|
||||
if (argc >= 3)
|
||||
{
|
||||
QStringList list = QString(argv[2]).split(",");
|
||||
if (list.size()==4)
|
||||
if (list.size() == 4)
|
||||
{
|
||||
bool ok;
|
||||
double x0 = list[0].toDouble(&ok);
|
||||
double y0 = list[1].toDouble(&ok);
|
||||
double x1 = list[2].toDouble(&ok);
|
||||
double y1 = list[3].toDouble(&ok);
|
||||
if (ok) window.set_default_extent(x0,y0,x1,y1);
|
||||
if (ok)
|
||||
window.set_default_extent(x0, y0, x1, y1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<mapnik::Map> map = window.get_map();
|
||||
if (map) map->zoom_all();
|
||||
if (map)
|
||||
map->zoom_all();
|
||||
}
|
||||
if (argc == 4)
|
||||
{
|
||||
bool ok;
|
||||
double scaling_factor = QString(argv[3]).toDouble(&ok);
|
||||
if (ok) window.set_scaling_factor(scaling_factor);
|
||||
if (ok)
|
||||
window.set_scaling_factor(scaling_factor);
|
||||
}
|
||||
return app.exec();
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
|
||||
return 1;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
// stl
|
||||
#include <iostream>
|
||||
|
||||
|
@ -58,27 +57,27 @@
|
|||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: filename_(),
|
||||
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
|
||||
: filename_()
|
||||
, default_extent_(-20037508.3428, -20037508.3428, 20037508.3428, 20037508.3428)
|
||||
{
|
||||
mapWidget_ = new MapWidget(this);
|
||||
QSplitter *splitter = new QSplitter(this);
|
||||
QTabWidget *tabWidget=new QTabWidget;
|
||||
QSplitter* splitter = new QSplitter(this);
|
||||
QTabWidget* tabWidget = new QTabWidget;
|
||||
layerTab_ = new LayerTab;
|
||||
layerTab_->setFocusPolicy(Qt::NoFocus);
|
||||
layerTab_->setIconSize(QSize(16,16));
|
||||
layerTab_->setIconSize(QSize(16, 16));
|
||||
|
||||
//LayerDelegate *delegate = new LayerDelegate(this);
|
||||
//layerTab_->setItemDelegate(delegate);
|
||||
//layerTab_->setItemDelegate(new QItemDelegate(this));
|
||||
//layerTab_->setViewMode(QListView::IconMode);
|
||||
// LayerDelegate *delegate = new LayerDelegate(this);
|
||||
// layerTab_->setItemDelegate(delegate);
|
||||
// layerTab_->setItemDelegate(new QItemDelegate(this));
|
||||
// layerTab_->setViewMode(QListView::IconMode);
|
||||
|
||||
layerTab_->setFlow(QListView::TopToBottom);
|
||||
tabWidget->addTab(layerTab_,tr("Layers"));
|
||||
tabWidget->addTab(layerTab_, tr("Layers"));
|
||||
|
||||
// Styles tab
|
||||
styleTab_ = new StyleTab;
|
||||
tabWidget->addTab(styleTab_,tr("Styles"));
|
||||
tabWidget->addTab(styleTab_, tr("Styles"));
|
||||
splitter->addWidget(tabWidget);
|
||||
splitter->addWidget(mapWidget_);
|
||||
QList<int> list;
|
||||
|
@ -89,7 +88,7 @@ MainWindow::MainWindow()
|
|||
mapWidget_->setFocusPolicy(Qt::StrongFocus);
|
||||
mapWidget_->setFocus();
|
||||
|
||||
//setCentralWidget(mapWidget_);
|
||||
// setCentralWidget(mapWidget_);
|
||||
setCentralWidget(splitter);
|
||||
createActions();
|
||||
createMenus();
|
||||
|
@ -97,29 +96,28 @@ MainWindow::MainWindow()
|
|||
createContextMenu();
|
||||
|
||||
setWindowTitle(tr("Mapnik Viewer"));
|
||||
status=new QStatusBar(this);
|
||||
status = new QStatusBar(this);
|
||||
status->showMessage(tr(""));
|
||||
setStatusBar(status);
|
||||
resize(800,600);
|
||||
resize(800, 600);
|
||||
|
||||
//connect mapview to layerlist
|
||||
connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update()));
|
||||
// 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&)),
|
||||
mapWidget_, SLOT(updateRenderer(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(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)));
|
||||
connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap()));
|
||||
connect(layerTab_, SIGNAL(layerSelected(int)), mapWidget_, SLOT(layerSelected(int)));
|
||||
}
|
||||
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete mapWidget_;
|
||||
|
@ -141,8 +139,7 @@ void MainWindow::open(QString const& path)
|
|||
{
|
||||
if (path.isNull())
|
||||
{
|
||||
filename_ = QFileDialog::getOpenFileName(this,tr("Open Mapnik file"),
|
||||
currentPath,"*.xml");
|
||||
filename_ = QFileDialog::getOpenFileName(this, tr("Open Mapnik file"), currentPath, "*.xml");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -151,18 +148,15 @@ void MainWindow::open(QString const& path)
|
|||
|
||||
if (!filename_.isEmpty())
|
||||
{
|
||||
|
||||
load_map_file(filename_);
|
||||
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::reload()
|
||||
{
|
||||
if (!filename_.isEmpty())
|
||||
{
|
||||
|
||||
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
|
||||
load_map_file(filename_);
|
||||
mapWidget_->zoomToBox(bbox);
|
||||
|
@ -173,39 +167,37 @@ void MainWindow::reload()
|
|||
void MainWindow::save()
|
||||
{
|
||||
QString initialPath = QDir::currentPath() + "/untitled.xml";
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save"),
|
||||
QString filename = QFileDialog::getSaveFileName(this,
|
||||
tr("Save"),
|
||||
initialPath,
|
||||
tr("%1 Files (*.xml)")
|
||||
.arg(QString("Mapnik definition")));
|
||||
tr("%1 Files (*.xml)").arg(QString("Mapnik definition")));
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
std::cout<<"saving "<< filename.toStdString() << std::endl;
|
||||
mapnik::save_map(*mapWidget_->getMap(),filename.toStdString());
|
||||
std::cout << "saving " << filename.toStdString() << std::endl;
|
||||
mapnik::save_map(*mapWidget_->getMap(), filename.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::load_map_file(QString const& filename)
|
||||
{
|
||||
std::cout << "loading "<< filename.toStdString() << std::endl;
|
||||
std::cout << "loading " << filename.toStdString() << std::endl;
|
||||
unsigned width = mapWidget_->width();
|
||||
unsigned height = mapWidget_->height();
|
||||
std::shared_ptr<mapnik::Map> map(new mapnik::Map(width,height));
|
||||
std::shared_ptr<mapnik::Map> map(new mapnik::Map(width, height));
|
||||
mapWidget_->setMap(map);
|
||||
try
|
||||
{
|
||||
mapnik::auto_cpu_timer t(std::clog, "loading map took: ");
|
||||
mapnik::load_map(*map,filename.toStdString());
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
mapnik::load_map(*map, filename.toStdString());
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::cout << ex.what() << "\n";
|
||||
}
|
||||
catch (...)
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught in load_map\n";
|
||||
}
|
||||
layerTab_->setModel(new LayerListModel(map,this));
|
||||
styleTab_->setModel(new StyleModel(map,this));
|
||||
layerTab_->setModel(new LayerListModel(map, this));
|
||||
styleTab_->setModel(new StyleModel(map, this));
|
||||
zoom_all();
|
||||
}
|
||||
|
||||
|
@ -252,15 +244,15 @@ void MainWindow::about()
|
|||
|
||||
void MainWindow::export_as()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
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"),
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr("Export As"),
|
||||
initialPath,
|
||||
tr("%1 Files (*.%2);;All Files (*)")
|
||||
.arg(QString(fileFormat.toUpper()))
|
||||
.arg(QString(fileFormat)));
|
||||
tr("%1 Files (*.%2);;All Files (*)").arg(QString(fileFormat.toUpper())).arg(QString(fileFormat)));
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
QPixmap const& pix = mapWidget_->pixmap();
|
||||
|
@ -270,10 +262,9 @@ void MainWindow::export_as()
|
|||
|
||||
void MainWindow::print()
|
||||
{
|
||||
|
||||
//Q_ASSERT(mapWidget_->pixmap());
|
||||
//QPrintDialog dialog(&printer, this);
|
||||
//if (dialog.exec()) {
|
||||
// Q_ASSERT(mapWidget_->pixmap());
|
||||
// QPrintDialog dialog(&printer, this);
|
||||
// if (dialog.exec()) {
|
||||
// QPainter painter(&printer);
|
||||
// QRect rect = painter.viewport();
|
||||
// QSize size = mapWidget_->pixmap()->size();
|
||||
|
@ -281,66 +272,66 @@ void MainWindow::print()
|
|||
// painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||
// painter.setWindow(mapWidget_->pixmap()->rect());
|
||||
// painter.drawPixmap(0, 0, *mapWidget_->pixmap());
|
||||
//}
|
||||
// }
|
||||
}
|
||||
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
//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);
|
||||
// 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()));
|
||||
|
||||
zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"),tr("Zoom To Box"),this);
|
||||
zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"), tr("Zoom To Box"), this);
|
||||
zoomBoxAct->setCheckable(true);
|
||||
connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box()));
|
||||
|
||||
panAct = new QAction(QIcon(":/images/pan.png"),tr("Pan"),this);
|
||||
panAct = new QAction(QIcon(":/images/pan.png"), tr("Pan"), this);
|
||||
panAct->setCheckable(true);
|
||||
connect(panAct, SIGNAL(triggered()), this, SLOT(pan()));
|
||||
|
||||
infoAct = new QAction(QIcon(":/images/info.png"),tr("Info"),this);
|
||||
infoAct = new QAction(QIcon(":/images/info.png"), tr("Info"), this);
|
||||
infoAct->setCheckable(true);
|
||||
connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
|
||||
|
||||
toolsGroup=new QActionGroup(this);
|
||||
toolsGroup = new QActionGroup(this);
|
||||
toolsGroup->addAction(zoomBoxAct);
|
||||
toolsGroup->addAction(panAct);
|
||||
toolsGroup->addAction(infoAct);
|
||||
zoomBoxAct->setChecked(true);
|
||||
|
||||
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()));
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
panDownAct = new QAction(QIcon(":/images/down.png"), tr("&Pan Down"), this);
|
||||
connect(panDownAct, SIGNAL(triggered()), this, SLOT(pan_down()));
|
||||
|
||||
reloadAct = new QAction(QIcon(":/images/reload.png"),tr("Reload"),this);
|
||||
reloadAct = new QAction(QIcon(":/images/reload.png"), tr("Reload"), this);
|
||||
connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
|
||||
|
||||
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&)));
|
||||
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&)));
|
||||
foreach (QByteArray format, QImageWriter::supportedImageFormats())
|
||||
{
|
||||
QString text = tr("%1...").arg(QString(format).toUpper());
|
||||
|
||||
QAction *action = new QAction(text, this);
|
||||
QAction* action = new QAction(text, this);
|
||||
action->setData(format);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(export_as()));
|
||||
exportAsActs.append(action);
|
||||
}
|
||||
|
||||
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
||||
printAct = new QAction(QIcon(":/images/print.png"), tr("&Print ..."), this);
|
||||
printAct->setShortcut(tr("Ctrl+E"));
|
||||
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
||||
|
||||
|
@ -348,17 +339,17 @@ void MainWindow::createActions()
|
|||
exitAct->setShortcut(tr("Ctrl+Q"));
|
||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
aboutAct = new QAction(QIcon(":/images/about.png"),tr("&About"), this);
|
||||
aboutAct = new QAction(QIcon(":/images/about.png"), tr("&About"), this);
|
||||
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
{
|
||||
exportMenu = new QMenu(tr("&Export As"), this);
|
||||
foreach (QAction *action, exportAsActs)
|
||||
foreach (QAction* action, exportAsActs)
|
||||
exportMenu->addAction(action);
|
||||
|
||||
fileMenu = new QMenu(tr("&File"),this);
|
||||
fileMenu = new QMenu(tr("&File"), this);
|
||||
fileMenu->addAction(openAct);
|
||||
fileMenu->addAction(saveAct);
|
||||
fileMenu->addMenu(exportMenu);
|
||||
|
@ -402,8 +393,8 @@ void MainWindow::createToolBars()
|
|||
scale_factor_->setValue(1.0);
|
||||
|
||||
fileToolBar->addWidget(scale_factor_);
|
||||
slider_ = new QSlider(Qt::Horizontal,fileToolBar);
|
||||
slider_->setRange(1,18);
|
||||
slider_ = new QSlider(Qt::Horizontal, fileToolBar);
|
||||
slider_->setRange(1, 18);
|
||||
slider_->setTickPosition(QSlider::TicksBelow);
|
||||
slider_->setTickInterval(1);
|
||||
slider_->setTracking(false);
|
||||
|
@ -411,9 +402,7 @@ void MainWindow::createToolBars()
|
|||
fileToolBar->addAction(aboutAct);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
||||
void MainWindow::set_default_extent(double x0, double y0, double x1, double y1)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -423,12 +412,12 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
|||
mapnik::projection prj(map_ptr->srs());
|
||||
prj.forward(x0, y0);
|
||||
prj.forward(x1, y1);
|
||||
default_extent_=mapnik::box2d<double>(x0, y0, x1, y1);
|
||||
default_extent_ = mapnik::box2d<double>(x0, y0, x1, y1);
|
||||
mapWidget_->zoomToBox(default_extent_);
|
||||
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
} catch (...)
|
||||
{}
|
||||
}
|
||||
|
||||
void MainWindow::set_scaling_factor(double scaling_factor)
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MAINWINDOW_HPP
|
||||
#define MAINWINDOW_HPP
|
||||
|
||||
|
@ -30,7 +29,7 @@
|
|||
|
||||
#include "mapwidget.hpp"
|
||||
|
||||
//using namespace mapnik;
|
||||
// using namespace mapnik;
|
||||
|
||||
class LayerTab;
|
||||
class StyleTab;
|
||||
|
@ -44,13 +43,15 @@ class MainWindow : public QMainWindow
|
|||
public:
|
||||
MainWindow();
|
||||
virtual ~MainWindow();
|
||||
void set_default_extent(double x0,double y0,double x1, double y1);
|
||||
void set_default_extent(double x0, double y0, double x1, double y1);
|
||||
void set_scaling_factor(double scaling_factor);
|
||||
public :
|
||||
|
||||
public:
|
||||
std::shared_ptr<mapnik::Map> get_map();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
public slots:
|
||||
public slots:
|
||||
void zoom_all();
|
||||
void zoom_to_box();
|
||||
void pan();
|
||||
|
@ -65,7 +66,8 @@ public slots:
|
|||
void pan_right();
|
||||
void pan_up();
|
||||
void pan_down();
|
||||
private:
|
||||
|
||||
private:
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void createToolBars();
|
||||
|
@ -74,43 +76,42 @@ private:
|
|||
|
||||
QString currentPath;
|
||||
QString filename_;
|
||||
QAbstractItemModel *model;
|
||||
LayerTab *layerTab_;
|
||||
StyleTab * styleTab_;
|
||||
MapWidget * mapWidget_;
|
||||
//actions
|
||||
QList<QAction *> exportAsActs;
|
||||
QActionGroup *toolsGroup;
|
||||
QAbstractItemModel* model;
|
||||
LayerTab* layerTab_;
|
||||
StyleTab* styleTab_;
|
||||
MapWidget* mapWidget_;
|
||||
// actions
|
||||
QList<QAction*> exportAsActs;
|
||||
QActionGroup* toolsGroup;
|
||||
|
||||
QAction *zoomAllAct;
|
||||
QAction *zoomBoxAct;
|
||||
QAction *panAct;
|
||||
QAction *infoAct;
|
||||
QAction *openAct;
|
||||
QAction *saveAct;
|
||||
QAction *printAct;
|
||||
QAction *exitAct;
|
||||
QAction *aboutAct;
|
||||
QAction *panLeftAct;
|
||||
QAction *panRightAct;
|
||||
QAction *panUpAct;
|
||||
QAction *panDownAct;
|
||||
QAction *reloadAct;
|
||||
QAction *layerInfo;
|
||||
//toolbars
|
||||
QToolBar *fileToolBar;
|
||||
QToolBar *editToolBar;
|
||||
//menus
|
||||
QMenu *exportMenu;
|
||||
QMenu *fileMenu;
|
||||
QMenu *helpMenu;
|
||||
//status bar
|
||||
QStatusBar *status;
|
||||
QSlider * slider_;
|
||||
QComboBox * renderer_selector_;
|
||||
QDoubleSpinBox * scale_factor_;
|
||||
QAction* zoomAllAct;
|
||||
QAction* zoomBoxAct;
|
||||
QAction* panAct;
|
||||
QAction* infoAct;
|
||||
QAction* openAct;
|
||||
QAction* saveAct;
|
||||
QAction* printAct;
|
||||
QAction* exitAct;
|
||||
QAction* aboutAct;
|
||||
QAction* panLeftAct;
|
||||
QAction* panRightAct;
|
||||
QAction* panUpAct;
|
||||
QAction* panDownAct;
|
||||
QAction* reloadAct;
|
||||
QAction* layerInfo;
|
||||
// toolbars
|
||||
QToolBar* fileToolBar;
|
||||
QToolBar* editToolBar;
|
||||
// menus
|
||||
QMenu* exportMenu;
|
||||
QMenu* fileMenu;
|
||||
QMenu* helpMenu;
|
||||
// status bar
|
||||
QStatusBar* status;
|
||||
QSlider* slider_;
|
||||
QComboBox* renderer_selector_;
|
||||
QDoubleSpinBox* scale_factor_;
|
||||
mapnik::box2d<double> default_extent_;
|
||||
};
|
||||
|
||||
|
||||
#endif //MAINWINDOW_HPP
|
||||
#endif // MAINWINDOW_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -41,54 +40,38 @@
|
|||
#include "mapwidget.hpp"
|
||||
#include "info_dialog.hpp"
|
||||
|
||||
using mapnik::image_rgba8;
|
||||
using mapnik::Map;
|
||||
using mapnik::layer;
|
||||
using mapnik::box2d;
|
||||
using mapnik::coord2d;
|
||||
using mapnik::feature_kv_iterator;
|
||||
using mapnik::feature_ptr;
|
||||
using mapnik::view_transform;
|
||||
using mapnik::image_rgba8;
|
||||
using mapnik::layer;
|
||||
using mapnik::Map;
|
||||
using mapnik::projection;
|
||||
using mapnik::scale_denominator;
|
||||
using mapnik::feature_kv_iterator;
|
||||
using mapnik::view_transform;
|
||||
|
||||
double scales [] = {279541132.014,
|
||||
139770566.007,
|
||||
69885283.0036,
|
||||
34942641.5018,
|
||||
17471320.7509,
|
||||
8735660.37545,
|
||||
4367830.18772,
|
||||
2183915.09386,
|
||||
1091957.54693,
|
||||
545978.773466,
|
||||
272989.386733,
|
||||
136494.693366,
|
||||
68247.3466832,
|
||||
34123.6733416,
|
||||
17061.8366708,
|
||||
8530.9183354,
|
||||
4265.4591677,
|
||||
2132.72958385,
|
||||
1066.36479192,
|
||||
533.182395962};
|
||||
double scales[] = {279541132.014, 139770566.007, 69885283.0036, 34942641.5018, 17471320.7509,
|
||||
8735660.37545, 4367830.18772, 2183915.09386, 1091957.54693, 545978.773466,
|
||||
272989.386733, 136494.693366, 68247.3466832, 34123.6733416, 17061.8366708,
|
||||
8530.9183354, 4265.4591677, 2132.72958385, 1066.36479192, 533.182395962};
|
||||
|
||||
MapWidget::MapWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
map_(),
|
||||
selected_(1),
|
||||
extent_(),
|
||||
cur_tool_(ZoomToBox),
|
||||
start_x_(0),
|
||||
start_y_(0),
|
||||
end_x_(0),
|
||||
end_y_(0),
|
||||
drag_(false),
|
||||
first_(true),
|
||||
pen_(QColor(0,0,255,96)),
|
||||
selectedLayer_(-1),
|
||||
scaling_factor_(1.0),
|
||||
cur_renderer_(AGG)
|
||||
MapWidget::MapWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, map_()
|
||||
, selected_(1)
|
||||
, extent_()
|
||||
, cur_tool_(ZoomToBox)
|
||||
, start_x_(0)
|
||||
, start_y_(0)
|
||||
, end_x_(0)
|
||||
, end_y_(0)
|
||||
, drag_(false)
|
||||
, first_(true)
|
||||
, pen_(QColor(0, 0, 255, 96))
|
||||
, selectedLayer_(-1)
|
||||
, scaling_factor_(1.0)
|
||||
, cur_renderer_(AGG)
|
||||
{
|
||||
pen_.setWidth(3);
|
||||
pen_.setCapStyle(Qt::RoundCap);
|
||||
|
@ -97,7 +80,7 @@ MapWidget::MapWidget(QWidget *parent)
|
|||
|
||||
void MapWidget::setTool(eTool tool)
|
||||
{
|
||||
cur_tool_=tool;
|
||||
cur_tool_ = tool;
|
||||
}
|
||||
|
||||
void MapWidget::paintEvent(QPaintEvent*)
|
||||
|
@ -108,84 +91,86 @@ void MapWidget::paintEvent(QPaintEvent*)
|
|||
{
|
||||
if (cur_tool_ == ZoomToBox)
|
||||
{
|
||||
unsigned width = end_x_-start_x_;
|
||||
unsigned height = end_y_-start_y_;
|
||||
painter.drawPixmap(QPoint(0, 0),pix_);
|
||||
unsigned width = end_x_ - start_x_;
|
||||
unsigned height = end_y_ - start_y_;
|
||||
painter.drawPixmap(QPoint(0, 0), pix_);
|
||||
painter.setPen(pen_);
|
||||
painter.setBrush(QColor(200,200,255,128));
|
||||
painter.drawRect(start_x_,start_y_,width,height);
|
||||
painter.setBrush(QColor(200, 200, 255, 128));
|
||||
painter.drawRect(start_x_, start_y_, width, height);
|
||||
}
|
||||
else if (cur_tool_ == Pan)
|
||||
{
|
||||
int dx = end_x_-start_x_;
|
||||
int dy = end_y_-start_y_;
|
||||
painter.setBrush(QColor(200,200,200,128));
|
||||
painter.drawRect(0,0,width(),height());
|
||||
painter.drawPixmap(QPoint(dx,dy),pix_);
|
||||
int dx = end_x_ - start_x_;
|
||||
int dy = end_y_ - start_y_;
|
||||
painter.setBrush(QColor(200, 200, 200, 128));
|
||||
painter.drawRect(0, 0, width(), height());
|
||||
painter.drawPixmap(QPoint(dx, dy), pix_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.drawPixmap(QPoint(0, 0),pix_);
|
||||
painter.drawPixmap(QPoint(0, 0), pix_);
|
||||
}
|
||||
painter.end();
|
||||
}
|
||||
|
||||
void MapWidget::resizeEvent(QResizeEvent * ev)
|
||||
void MapWidget::resizeEvent(QResizeEvent* ev)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
map_->resize(ev->size().width(),ev->size().height());
|
||||
map_->resize(ev->size().width(), ev->size().height());
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button()==Qt::LeftButton)
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan)
|
||||
{
|
||||
start_x_ = e->x();
|
||||
start_y_ = e->y();
|
||||
drag_=true;
|
||||
drag_ = true;
|
||||
}
|
||||
else if (cur_tool_==Info)
|
||||
else if (cur_tool_ == Info)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
QVector<QPair<QString,QString> > info;
|
||||
QVector<QPair<QString, QString>> info;
|
||||
|
||||
projection map_proj(map_->srs(), true); // map projection
|
||||
double scale_denom = scale_denominator(map_->scale(),map_proj.is_geographic());
|
||||
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
|
||||
double scale_denom = scale_denominator(map_->scale(), map_proj.is_geographic());
|
||||
view_transform t(map_->width(), map_->height(), map_->get_current_extent());
|
||||
|
||||
for (unsigned index = 0; index < map_->layer_count();++index)
|
||||
for (unsigned index = 0; index < map_->layer_count(); ++index)
|
||||
{
|
||||
if (int(index) != selectedLayer_) continue;
|
||||
if (int(index) != selectedLayer_)
|
||||
continue;
|
||||
|
||||
layer & layer = map_->layers()[index];
|
||||
if (!layer.visible(scale_denom)) continue;
|
||||
layer& layer = map_->layers()[index];
|
||||
if (!layer.visible(scale_denom))
|
||||
continue;
|
||||
std::string name = layer.name();
|
||||
double x = e->x();
|
||||
double y = e->y();
|
||||
std::cout << "query at " << x << "," << y << "\n";
|
||||
projection layer_proj(layer.srs(), true);
|
||||
mapnik::proj_transform prj_trans(map_proj,layer_proj);
|
||||
//std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
|
||||
mapnik::featureset_ptr fs = map_->query_map_point(index,x,y);
|
||||
mapnik::proj_transform prj_trans(map_proj, layer_proj);
|
||||
// std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
|
||||
mapnik::featureset_ptr fs = map_->query_map_point(index, x, y);
|
||||
|
||||
if (fs)
|
||||
{
|
||||
feature_ptr feat = fs->next();
|
||||
if (feat)
|
||||
{
|
||||
feature_kv_iterator itr(*feat,true);
|
||||
feature_kv_iterator itr(*feat, true);
|
||||
feature_kv_iterator end(*feat);
|
||||
|
||||
for ( ;itr!=end; ++itr)
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
|
||||
info.push_back(QPair<QString, QString>(QString(std::get<0>(*itr).c_str()),
|
||||
std::get<1>(*itr).to_string().c_str()));
|
||||
}
|
||||
|
||||
|
@ -224,29 +209,28 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
|||
|
||||
if (info.size() > 0)
|
||||
{
|
||||
info_dialog info_dlg(info,this);
|
||||
info_dialog info_dlg(info, this);
|
||||
info_dlg.exec();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// remove annotation layer
|
||||
map_->layers().erase(remove_if(map_->layers().begin(),
|
||||
map_->layers().end(),
|
||||
bind(&layer::name,_1) == "*annotations*")
|
||||
, map_->layers().end());
|
||||
map_->layers().erase(
|
||||
remove_if(map_->layers().begin(), map_->layers().end(), bind(&layer::name, _1) == "*annotations*"),
|
||||
map_->layers().end());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e->button()==Qt::RightButton)
|
||||
else if (e->button() == Qt::RightButton)
|
||||
{
|
||||
//updateMap();
|
||||
// updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan)
|
||||
{
|
||||
end_x_ = e->x();
|
||||
end_y_ = e->y();
|
||||
|
@ -256,31 +240,31 @@ void MapWidget::mouseMoveEvent(QMouseEvent* e)
|
|||
|
||||
void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button()==Qt::LeftButton)
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
end_x_ = e->x();
|
||||
end_y_ = e->y();
|
||||
if (cur_tool_ == ZoomToBox)
|
||||
{
|
||||
drag_=false;
|
||||
drag_ = false;
|
||||
if (map_)
|
||||
{
|
||||
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
|
||||
box2d<double> box = t.backward(box2d<double>(start_x_,start_y_,end_x_,end_y_));
|
||||
view_transform t(map_->width(), map_->height(), map_->get_current_extent());
|
||||
box2d<double> box = t.backward(box2d<double>(start_x_, start_y_, end_x_, end_y_));
|
||||
map_->zoom_to_box(box);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
else if (cur_tool_==Pan)
|
||||
else if (cur_tool_ == Pan)
|
||||
{
|
||||
drag_=false;
|
||||
drag_ = false;
|
||||
if (map_)
|
||||
{
|
||||
int cx = int(0.5 * map_->width());
|
||||
int cy = int(0.5 * map_->height());
|
||||
int dx = end_x_ - start_x_;
|
||||
int dy = end_y_ - start_y_;
|
||||
map_->pan(cx - dx ,cy - dy);
|
||||
map_->pan(cx - dx, cy - dy);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
@ -331,10 +315,11 @@ void MapWidget::wheelEvent(QWheelEvent* e)
|
|||
updateMap();
|
||||
}
|
||||
|
||||
void MapWidget::keyPressEvent(QKeyEvent *e)
|
||||
void MapWidget::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
std::cout << "key pressed:"<< e->key()<<"\n";
|
||||
switch (e->key()) {
|
||||
std::cout << "key pressed:" << e->key() << "\n";
|
||||
switch (e->key())
|
||||
{
|
||||
case Qt::Key_Minus:
|
||||
zoomOut();
|
||||
break;
|
||||
|
@ -387,8 +372,6 @@ void MapWidget::keyPressEvent(QKeyEvent *e)
|
|||
default:
|
||||
QWidget::keyPressEvent(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
||||
|
@ -404,7 +387,7 @@ void MapWidget::defaultView()
|
|||
{
|
||||
if (map_)
|
||||
{
|
||||
map_->resize(width(),height());
|
||||
map_->resize(width(), height());
|
||||
map_->zoom_all();
|
||||
updateMap();
|
||||
}
|
||||
|
@ -432,9 +415,9 @@ void MapWidget::panUp()
|
|||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx),int(cy - cy*0.25));
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx), int(cy - cy * 0.25));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
@ -443,9 +426,9 @@ void MapWidget::panDown()
|
|||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx),int(cy + cy*0.25));
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx), int(cy + cy * 0.25));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
@ -454,9 +437,9 @@ void MapWidget::panLeft()
|
|||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx - cx * 0.25),int(cy));
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx - cx * 0.25), int(cy));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
@ -465,42 +448,41 @@ void MapWidget::panRight()
|
|||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx + cx * 0.25),int(cy));
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx + cx * 0.25), int(cy));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MapWidget::zoomToLevel(int level)
|
||||
{
|
||||
if ( map_ && level >= 0 && level < 19 )
|
||||
if (map_ && level >= 0 && level < 19)
|
||||
{
|
||||
double scale_denom = scales[level];
|
||||
std::cerr << "scale denominator = " << scale_denom << "\n";
|
||||
mapnik::box2d<double> ext = map_->get_current_extent();
|
||||
double width = static_cast<double>(map_->width());
|
||||
double height= static_cast<double>(map_->height());
|
||||
double height = static_cast<double>(map_->height());
|
||||
mapnik::coord2d pt = ext.center();
|
||||
|
||||
double res = scale_denom * 0.00028;
|
||||
|
||||
mapnik::box2d<double> box(pt.x - 0.5 * width * res,
|
||||
pt.y - 0.5 * height*res,
|
||||
pt.y - 0.5 * height * res,
|
||||
pt.x + 0.5 * width * res,
|
||||
pt.y + 0.5 * height*res);
|
||||
pt.y + 0.5 * height * res);
|
||||
map_->zoom_to_box(box);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&)
|
||||
void MapWidget::export_to_file(unsigned, unsigned, std::string const&, std::string const&)
|
||||
{
|
||||
//image_rgba8 image(width,height);
|
||||
//agg_renderer renderer(map,image);
|
||||
//renderer.apply();
|
||||
//image.saveToFile(filename,type);
|
||||
// image_rgba8 image(width,height);
|
||||
// agg_renderer renderer(map,image);
|
||||
// renderer.apply();
|
||||
// image.saveToFile(filename,type);
|
||||
std::cout << "Export to file .." << std::endl;
|
||||
}
|
||||
|
||||
|
@ -509,47 +491,44 @@ void MapWidget::set_scaling_factor(double scaling_factor)
|
|||
scaling_factor_ = scaling_factor;
|
||||
}
|
||||
|
||||
void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||
void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
|
||||
{
|
||||
unsigned width=map.width();
|
||||
unsigned height=map.height();
|
||||
unsigned width = map.width();
|
||||
unsigned height = map.height();
|
||||
|
||||
image_rgba8 buf(width,height);
|
||||
mapnik::agg_renderer<image_rgba8> ren(map,buf,scaling_factor);
|
||||
image_rgba8 buf(width, height);
|
||||
mapnik::agg_renderer<image_rgba8> ren(map, buf, scaling_factor);
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
|
||||
ren.apply();
|
||||
QImage image((uchar*)buf.data(),width,height,QImage::Format_ARGB32);
|
||||
QImage image((uchar*)buf.data(), width, height, QImage::Format_ARGB32);
|
||||
pix = QPixmap::fromImage(image.rgbSwapped());
|
||||
}
|
||||
//catch (mapnik::config_error & ex)
|
||||
// catch (mapnik::config_error & ex)
|
||||
//{
|
||||
// std::cerr << ex.what() << std::endl;
|
||||
//}
|
||||
// }
|
||||
catch (std::exception const& ex)
|
||||
{
|
||||
std::cerr << "exception: " << ex.what() << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "Unknown exception caught!\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
|
||||
{
|
||||
// FIXME
|
||||
#ifdef HAVE_CAIRO
|
||||
mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,map.width(),map.height()),
|
||||
mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, map.width(), map.height()),
|
||||
mapnik::cairo_surface_closer());
|
||||
mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);
|
||||
if (cairo)
|
||||
|
@ -560,16 +539,19 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|||
}
|
||||
mapnik::image_rgba8 data(map.width(), map.height());
|
||||
mapnik::cairo_image_to_rgba8(data, image_surface);
|
||||
QImage image((uchar*)data.bytes(),data.width(),data.height(),QImage::Format_ARGB32);
|
||||
QImage image((uchar*)data.bytes(), data.width(), data.height(), QImage::Format_ARGB32);
|
||||
pix = QPixmap::fromImage(image.rgbSwapped());
|
||||
#endif
|
||||
}
|
||||
|
||||
void MapWidget::updateRenderer(QString const& txt)
|
||||
{
|
||||
if (txt == "AGG") cur_renderer_ = AGG;
|
||||
else if (txt == "Cairo") cur_renderer_ = Cairo;
|
||||
else if (txt == "Grid") cur_renderer_ = Grid;
|
||||
if (txt == "AGG")
|
||||
cur_renderer_ = AGG;
|
||||
else if (txt == "Cairo")
|
||||
cur_renderer_ = Cairo;
|
||||
else if (txt == "Grid")
|
||||
cur_renderer_ = Grid;
|
||||
std::cerr << "Update renderer called" << std::endl;
|
||||
updateMap();
|
||||
}
|
||||
|
@ -584,7 +566,7 @@ void MapWidget::updateMap()
|
|||
{
|
||||
if (map_)
|
||||
{
|
||||
if (cur_renderer_== AGG)
|
||||
if (cur_renderer_ == AGG)
|
||||
{
|
||||
render_agg(*map_, scaling_factor_, pix_);
|
||||
}
|
||||
|
@ -620,8 +602,7 @@ void MapWidget::updateMap()
|
|||
update();
|
||||
// emit signal to interested widgets
|
||||
emit mapViewChanged();
|
||||
}
|
||||
catch (...)
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "Unknown exception caught!\n";
|
||||
}
|
||||
|
@ -638,7 +619,6 @@ void MapWidget::setMap(std::shared_ptr<Map> map)
|
|||
map_ = map;
|
||||
}
|
||||
|
||||
|
||||
void MapWidget::layerSelected(int index)
|
||||
{
|
||||
selectedLayer_ = index;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MAP_WIDGET_HPP
|
||||
#define MAP_WIDGET_HPP
|
||||
|
||||
|
@ -30,7 +29,6 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <mapnik/map.hpp>
|
||||
#endif
|
||||
|
@ -39,22 +37,16 @@ class MapWidget : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum eTool
|
||||
{
|
||||
public:
|
||||
enum eTool {
|
||||
ZoomToBox = 1,
|
||||
Pan,
|
||||
Info,
|
||||
};
|
||||
|
||||
enum eRenderer
|
||||
{
|
||||
AGG,
|
||||
Cairo,
|
||||
Grid
|
||||
};
|
||||
enum eRenderer { AGG, Cairo, Grid };
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<mapnik::Map> map_;
|
||||
int selected_;
|
||||
QPixmap pix_;
|
||||
|
@ -70,11 +62,12 @@ private:
|
|||
int selectedLayer_;
|
||||
double scaling_factor_;
|
||||
eRenderer cur_renderer_;
|
||||
public:
|
||||
MapWidget(QWidget *parent=0);
|
||||
|
||||
public:
|
||||
MapWidget(QWidget* parent = 0);
|
||||
void setTool(eTool tool);
|
||||
std::shared_ptr<mapnik::Map> getMap();
|
||||
inline QPixmap const& pixmap() const { return pix_;}
|
||||
inline QPixmap const& pixmap() const { return pix_; }
|
||||
void setMap(std::shared_ptr<mapnik::Map> map);
|
||||
void defaultView();
|
||||
void zoomToBox(mapnik::box2d<double> const& box);
|
||||
|
@ -85,26 +78,24 @@ public:
|
|||
void panUp();
|
||||
void panDown();
|
||||
void set_scaling_factor(double);
|
||||
public slots:
|
||||
public slots:
|
||||
void zoomToLevel(int level);
|
||||
void updateMap();
|
||||
void layerSelected(int);
|
||||
void updateRenderer(QString const& txt);
|
||||
void updateScaleFactor(double scale_factor);
|
||||
signals:
|
||||
signals:
|
||||
void mapViewChanged();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* ev);
|
||||
void resizeEvent(QResizeEvent* ev);
|
||||
void mousePressEvent(QMouseEvent* e);
|
||||
void mouseMoveEvent(QMouseEvent* e);
|
||||
void mouseReleaseEvent(QMouseEvent* e);
|
||||
void wheelEvent(QWheelEvent* e);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void export_to_file(unsigned width,
|
||||
unsigned height,
|
||||
std::string const& filename,
|
||||
std::string const& type);
|
||||
void keyPressEvent(QKeyEvent* e);
|
||||
void export_to_file(unsigned width, unsigned height, std::string const& filename, std::string const& type);
|
||||
};
|
||||
|
||||
#endif // MAP_WIDGET_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "styles_model.hpp"
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
|
@ -39,70 +38,50 @@ class node : private mapnik::util::noncopyable
|
|||
{
|
||||
struct node_base
|
||||
{
|
||||
virtual QString name() const=0;
|
||||
virtual QIcon icon() const=0;
|
||||
virtual QString name() const = 0;
|
||||
virtual QIcon icon() const = 0;
|
||||
virtual ~node_base() {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct wrap : public node_base
|
||||
{
|
||||
wrap(T const& obj)
|
||||
: obj_(obj) {}
|
||||
: obj_(obj)
|
||||
{}
|
||||
|
||||
~wrap() {}
|
||||
|
||||
QString name () const
|
||||
{
|
||||
return obj_.name();
|
||||
}
|
||||
QString name() const { return obj_.name(); }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return obj_.icon();
|
||||
}
|
||||
QIcon icon() const { return obj_.icon(); }
|
||||
|
||||
T obj_;
|
||||
};
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
node ( T const& obj, node * parent=0)
|
||||
: impl_(new wrap<T>(obj)),
|
||||
parent_(parent)
|
||||
public:
|
||||
template<typename T>
|
||||
node(T const& obj, node* parent = 0)
|
||||
: impl_(new wrap<T>(obj))
|
||||
, parent_(parent)
|
||||
{}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return impl_->name();
|
||||
}
|
||||
QString name() const { return impl_->name(); }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return impl_->icon();
|
||||
}
|
||||
QIcon icon() const { return impl_->icon(); }
|
||||
|
||||
unsigned num_children() const
|
||||
{
|
||||
return children_.count();
|
||||
}
|
||||
unsigned num_children() const { return children_.count(); }
|
||||
|
||||
node * child(unsigned row) const
|
||||
{
|
||||
return children_.value(row);
|
||||
}
|
||||
node* child(unsigned row) const { return children_.value(row); }
|
||||
|
||||
node * parent() const
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
node* parent() const { return parent_; }
|
||||
|
||||
node * add_child(node * child)
|
||||
node* add_child(node* child)
|
||||
{
|
||||
children_.push_back(child);
|
||||
return child;
|
||||
}
|
||||
int row () const
|
||||
int row() const
|
||||
{
|
||||
if (parent_)
|
||||
return parent_->children_.indexOf(const_cast<node*>(this));
|
||||
|
@ -110,94 +89,90 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
~node()
|
||||
{
|
||||
qDeleteAll(children_);
|
||||
}
|
||||
~node() { qDeleteAll(children_); }
|
||||
|
||||
private:
|
||||
private:
|
||||
const std::unique_ptr<node_base> impl_;
|
||||
QList<node*> children_;
|
||||
node * parent_;
|
||||
node* parent_;
|
||||
};
|
||||
|
||||
|
||||
struct symbolizer_info
|
||||
{
|
||||
QString operator() (mapnik::point_symbolizer const& sym) const
|
||||
QString operator()(mapnik::point_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PointSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::line_symbolizer const& sym) const
|
||||
QString operator()(mapnik::line_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("LineSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::line_pattern_symbolizer const& sym) const
|
||||
QString operator()(mapnik::line_pattern_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("LinePatternSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::polygon_symbolizer const& sym) const
|
||||
QString operator()(mapnik::polygon_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PolygonSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::polygon_pattern_symbolizer const& sym) const
|
||||
QString operator()(mapnik::polygon_pattern_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PolygonSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::text_symbolizer const& sym) const
|
||||
QString operator()(mapnik::text_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("TextSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::shield_symbolizer const& sym) const
|
||||
QString operator()(mapnik::shield_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("ShieldSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::markers_symbolizer const& sym) const
|
||||
QString operator()(mapnik::markers_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("MarkersSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::building_symbolizer const& sym) const
|
||||
QString operator()(mapnik::building_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("BuildingSymbolizer");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QString operator() (T const& ) const
|
||||
template<typename T>
|
||||
QString operator()(T const&) const
|
||||
{
|
||||
return QString ("FIXME");
|
||||
return QString("FIXME");
|
||||
}
|
||||
};
|
||||
|
||||
struct symbolizer_icon
|
||||
{
|
||||
QIcon operator() (mapnik::polygon_symbolizer const& sym) const
|
||||
QIcon operator()(mapnik::polygon_symbolizer const& sym) const
|
||||
{
|
||||
QPixmap pix(16,16);
|
||||
QPixmap pix(16, 16);
|
||||
QPainter painter(&pix);
|
||||
mapnik::color const& fill = mapnik::get<mapnik::color>(sym, mapnik::keys::fill);
|
||||
QBrush brush(QColor(fill.red(),fill.green(),fill.blue(),fill.alpha()));
|
||||
QBrush brush(QColor(fill.red(), fill.green(), fill.blue(), fill.alpha()));
|
||||
painter.fillRect(0, 0, 16, 16, brush);
|
||||
return QIcon(pix);
|
||||
}
|
||||
|
||||
QIcon operator() (mapnik::point_symbolizer const& sym) const
|
||||
QIcon operator()(mapnik::point_symbolizer const& sym) const
|
||||
{
|
||||
// FIXME!
|
||||
/*
|
||||
|
@ -212,55 +187,57 @@ struct symbolizer_icon
|
|||
*/
|
||||
return QIcon();
|
||||
}
|
||||
QIcon operator() (mapnik::line_symbolizer const& sym) const
|
||||
QIcon operator()(mapnik::line_symbolizer const& sym) const
|
||||
{
|
||||
QPixmap pix(48,16);
|
||||
QPixmap pix(48, 16);
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
//mapnik::stroke const& strk = sym.get_stroke();
|
||||
// mapnik::stroke const& strk = sym.get_stroke();
|
||||
mapnik::color const& col = mapnik::get<mapnik::color>(sym, mapnik::keys::stroke);
|
||||
QPen pen(QColor(col.red(),col.green(),col.blue(),col.alpha()));
|
||||
QPen pen(QColor(col.red(), col.green(), col.blue(), col.alpha()));
|
||||
pen.setWidth(mapnik::get<double>(sym, mapnik::keys::width));
|
||||
painter.setPen(pen);
|
||||
painter.drawLine(0,7,47,7);
|
||||
//painter.drawLine(7,15,12,0);
|
||||
//painter.drawLine(12,0,8,15);
|
||||
painter.drawLine(0, 7, 47, 7);
|
||||
// painter.drawLine(7,15,12,0);
|
||||
// painter.drawLine(12,0,8,15);
|
||||
return QIcon(pix);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QIcon operator() (T const& ) const
|
||||
template<typename T>
|
||||
QIcon operator()(T const&) const
|
||||
{
|
||||
return QIcon (":/images/filter.png");
|
||||
return QIcon(":/images/filter.png");
|
||||
}
|
||||
};
|
||||
|
||||
class symbolizer_node
|
||||
{
|
||||
public:
|
||||
symbolizer_node(mapnik::symbolizer const & sym)
|
||||
: sym_(sym) {}
|
||||
~symbolizer_node(){}
|
||||
public:
|
||||
symbolizer_node(mapnik::symbolizer const& sym)
|
||||
: sym_(sym)
|
||||
{}
|
||||
~symbolizer_node() {}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
//return QString("Symbolizer:fixme");
|
||||
return mapnik::util::apply_visitor(symbolizer_info(),sym_);
|
||||
// return QString("Symbolizer:fixme");
|
||||
return mapnik::util::apply_visitor(symbolizer_info(), sym_);
|
||||
}
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return mapnik::util::apply_visitor(symbolizer_icon(),sym_);//QIcon(":/images/filter.png");
|
||||
return mapnik::util::apply_visitor(symbolizer_icon(), sym_); // QIcon(":/images/filter.png");
|
||||
}
|
||||
mapnik::symbolizer const& sym_;
|
||||
};
|
||||
|
||||
class rule_node
|
||||
{
|
||||
public:
|
||||
rule_node(QString name,mapnik::rule const & r)
|
||||
: name_(name),
|
||||
rule_(r) {}
|
||||
public:
|
||||
rule_node(QString name, mapnik::rule const& r)
|
||||
: name_(name)
|
||||
, rule_(r)
|
||||
{}
|
||||
~rule_node() {}
|
||||
QString name() const
|
||||
{
|
||||
|
@ -268,81 +245,68 @@ public:
|
|||
return QString(mapnik::to_expression_string(*filter).c_str());
|
||||
}
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/filter.png");
|
||||
}
|
||||
QIcon icon() const { return QIcon(":/images/filter.png"); }
|
||||
|
||||
private:
|
||||
private:
|
||||
QString name_;
|
||||
mapnik::rule const& rule_;
|
||||
};
|
||||
|
||||
class style_node
|
||||
{
|
||||
public:
|
||||
public:
|
||||
style_node(QString name, mapnik::feature_type_style const& style)
|
||||
: name_(name),
|
||||
style_(style) {}
|
||||
: name_(name)
|
||||
, style_(style)
|
||||
{}
|
||||
|
||||
~style_node() {}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
QString name() const { return name_; }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/style.png");
|
||||
}
|
||||
QIcon icon() const { return QIcon(":/images/style.png"); }
|
||||
|
||||
private:
|
||||
private:
|
||||
QString name_;
|
||||
mapnik::feature_type_style const& style_;
|
||||
};
|
||||
|
||||
class map_node
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit map_node(std::shared_ptr<mapnik::Map> map)
|
||||
: map_(map) {}
|
||||
: map_(map)
|
||||
{}
|
||||
~map_node() {}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return QString("Map");
|
||||
}
|
||||
QString name() const { return QString("Map"); }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/map.png");
|
||||
}
|
||||
QIcon icon() const { return QIcon(":/images/map.png"); }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<mapnik::Map> map_;
|
||||
};
|
||||
|
||||
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent)
|
||||
: QAbstractItemModel(parent),
|
||||
root_(new node(map_node(map)))
|
||||
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, root_(new node(map_node(map)))
|
||||
{
|
||||
using style_type = std::map<std::string,mapnik::feature_type_style>;
|
||||
style_type const & styles = map->styles();
|
||||
using style_type = std::map<std::string, mapnik::feature_type_style>;
|
||||
style_type const& styles = map->styles();
|
||||
style_type::const_iterator itr = styles.begin();
|
||||
style_type::const_iterator end = styles.end();
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
node * style_n = root_->add_child(new node(style_node(QString(itr->first.c_str()),itr->second),root_.get()));
|
||||
node* style_n = root_->add_child(new node(style_node(QString(itr->first.c_str()), itr->second), root_.get()));
|
||||
mapnik::rules const& rules = itr->second.get_rules();
|
||||
mapnik::rules::const_iterator itr2 = rules.begin();
|
||||
for ( ; itr2 != rules.end();++itr2)
|
||||
for (; itr2 != rules.end(); ++itr2)
|
||||
{
|
||||
node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"),*itr2),style_n));
|
||||
node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"), *itr2), style_n));
|
||||
mapnik::rule::symbolizers::const_iterator itr3 = (*itr2).begin();
|
||||
for ( ; itr3 !=itr2->end();++itr3)
|
||||
for (; itr3 != itr2->end(); ++itr3)
|
||||
{
|
||||
rule_n->add_child(new node(symbolizer_node(*itr3),rule_n));
|
||||
rule_n->add_child(new node(symbolizer_node(*itr3), rule_n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,38 +315,39 @@ StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent)
|
|||
StyleModel::~StyleModel() {}
|
||||
|
||||
// interface
|
||||
QModelIndex StyleModel::index (int row, int col, QModelIndex const& parent) const
|
||||
QModelIndex StyleModel::index(int row, int col, QModelIndex const& parent) const
|
||||
{
|
||||
// qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId());
|
||||
node * parent_node;
|
||||
// qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId());
|
||||
node* parent_node;
|
||||
|
||||
if (!parent.isValid())
|
||||
parent_node = root_.get();
|
||||
else
|
||||
parent_node = static_cast<node*>(parent.internalPointer());
|
||||
|
||||
node * child_node = parent_node->child(row);
|
||||
node* child_node = parent_node->child(row);
|
||||
if (child_node)
|
||||
return createIndex(row,col,child_node);
|
||||
return createIndex(row, col, child_node);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex StyleModel::parent (QModelIndex const& index) const
|
||||
QModelIndex StyleModel::parent(QModelIndex const& index) const
|
||||
{
|
||||
node * child_node = static_cast<node*>(index.internalPointer());
|
||||
node * parent_node = child_node->parent();
|
||||
node* child_node = static_cast<node*>(index.internalPointer());
|
||||
node* parent_node = child_node->parent();
|
||||
if (parent_node == root_.get())
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parent_node->row(),0,parent_node);
|
||||
return createIndex(parent_node->row(), 0, parent_node);
|
||||
}
|
||||
|
||||
int StyleModel::rowCount(QModelIndex const& parent) const
|
||||
{
|
||||
//qDebug("rowCount");
|
||||
node * parent_node;
|
||||
if (parent.column() > 0) return 0;
|
||||
// qDebug("rowCount");
|
||||
node* parent_node;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
if (!parent.isValid())
|
||||
parent_node = root_.get();
|
||||
else
|
||||
|
@ -390,25 +355,24 @@ int StyleModel::rowCount(QModelIndex const& parent) const
|
|||
return parent_node->num_children();
|
||||
}
|
||||
|
||||
int StyleModel::columnCount( QModelIndex const&) const
|
||||
int StyleModel::columnCount(QModelIndex const&) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant StyleModel::data(const QModelIndex & index, int role) const
|
||||
QVariant StyleModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
//qDebug("data index::internalId() = %lld", index.internalId());
|
||||
// qDebug("data index::internalId() = %lld", index.internalId());
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
node * cur_node = static_cast<node*>(index.internalPointer());
|
||||
node* cur_node = static_cast<node*>(index.internalPointer());
|
||||
if (cur_node)
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
|
||||
return QVariant(cur_node->name());
|
||||
}
|
||||
else if ( role == Qt::DecorationRole)
|
||||
else if (role == Qt::DecorationRole)
|
||||
{
|
||||
return cur_node->icon();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef STYLE_MODEL_HPP
|
||||
#define STYLE_MODEL_HPP
|
||||
|
||||
|
@ -27,23 +26,22 @@
|
|||
#include <mapnik/map.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class node;
|
||||
class StyleModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent=0);
|
||||
StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
|
||||
~StyleModel();
|
||||
// interface
|
||||
QModelIndex index (int row, int col, QModelIndex const& parent = QModelIndex()) const;
|
||||
QModelIndex parent (QModelIndex const& child) const;
|
||||
int rowCount( QModelIndex const& parent = QModelIndex()) const;
|
||||
int columnCount( QModelIndex const& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int col, QModelIndex const& parent = QModelIndex()) const;
|
||||
QModelIndex parent(QModelIndex const& child) const;
|
||||
int rowCount(QModelIndex const& parent = QModelIndex()) const;
|
||||
int columnCount(QModelIndex const& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
|
||||
private:
|
||||
//std::shared_ptr<mapnik::Map> map_;
|
||||
// std::shared_ptr<mapnik::Map> map_;
|
||||
const std::unique_ptr<node> root_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue