diff --git a/demo/c++/rundemo.cpp b/demo/c++/rundemo.cpp index 1406ca4a8..dc4f8e823 100644 --- a/demo/c++/rundemo.cpp +++ b/demo/c++/rundemo.cpp @@ -45,19 +45,21 @@ #include - -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(); 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(parse_expression("[GEONAME]"))); + placement_finder->defaults.set_format_tree( + std::make_shared(parse_expression("[GEONAME]"))); put(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(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855)); + m.zoom_to_box(box2d(-8024477.28459, 5445190.38849, -7381388.20071, 5662941.44855)); - image_rgba8 buf(m.width(),m.height()); - agg_renderer ren(m,buf); + image_rgba8 buf(m.width(), m.height()); + agg_renderer 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,38 +345,36 @@ 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_closer()); + 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 png_render(m,image_context,scale_factor); + mapnik::cairo_renderer 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" - "- cairo-demo.png\n" - "- cairo-demo256.png\n" - "- cairo-demo.pdf\n" - "- cairo-demo.svg\n" - "Have a look!\n"; + "- cairo-demo.png\n" + "- cairo-demo256.png\n" + "- cairo-demo.pdf\n" + "- cairo-demo.svg\n" + "Have a look!\n"; #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; diff --git a/demo/viewer/about_dialog.cpp b/demo/viewer/about_dialog.cpp index ed63e3d7c..075e321cb 100644 --- a/demo/viewer/about_dialog.cpp +++ b/demo/viewer/about_dialog.cpp @@ -17,12 +17,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #include "about_dialog.hpp" - -about_dialog::about_dialog(QWidget *parent) - : QDialog(parent) +about_dialog::about_dialog(QWidget* parent) + : QDialog(parent) { - ui.setupUi(this); + ui.setupUi(this); } diff --git a/demo/viewer/about_dialog.hpp b/demo/viewer/about_dialog.hpp index 480631ed6..80d201d57 100644 --- a/demo/viewer/about_dialog.hpp +++ b/demo/viewer/about_dialog.hpp @@ -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 @@ -27,12 +25,12 @@ class about_dialog : public QDialog { - Q_OBJECT -public: - about_dialog(QWidget * parent = 0); -private: - Ui::Dialog ui; + Q_OBJECT + public: + about_dialog(QWidget* parent = 0); + + private: + Ui::Dialog ui; }; - -#endif //ABOUT_DIALOG_HPP +#endif // ABOUT_DIALOG_HPP diff --git a/demo/viewer/info_dialog.cpp b/demo/viewer/info_dialog.cpp index 85898d2c6..e2ad82392 100644 --- a/demo/viewer/info_dialog.cpp +++ b/demo/viewer/info_dialog.cpp @@ -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 > const& info, QWidget *parent) - : QDialog(parent) +info_dialog::info_dialog(QVector> const& info, QWidget* parent) + : QDialog(parent) { - ui.setupUi(this); - ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name")); - ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value")); + ui.setupUi(this); + 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;isetItem(i,0,keyItem); - ui.tableWidget->setItem(i,1,valueItem); - } + ui.tableWidget->setRowCount(info.size()); + ui.tableWidget->setColumnCount(2); + 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); + } } diff --git a/demo/viewer/info_dialog.hpp b/demo/viewer/info_dialog.hpp index 404de4a00..877be514e 100644 --- a/demo/viewer/info_dialog.hpp +++ b/demo/viewer/info_dialog.hpp @@ -17,8 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - - #ifndef INFO_DIALOG_HPP #define INFO_DIALOG_HPP @@ -27,12 +25,12 @@ class info_dialog : public QDialog { - Q_OBJECT + Q_OBJECT public: - info_dialog(QVector > const& info,QWidget * parent = 0); - private: - Ui::InfoDialog ui; + info_dialog(QVector> const& info, QWidget* parent = 0); + + private: + Ui::InfoDialog ui; }; - -#endif //INFO_DIALOG_HPP +#endif // INFO_DIALOG_HPP diff --git a/demo/viewer/layer_info_dialog.cpp b/demo/viewer/layer_info_dialog.cpp index 2b9947d57..c5c5bf4de 100644 --- a/demo/viewer/layer_info_dialog.cpp +++ b/demo/viewer/layer_info_dialog.cpp @@ -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 #include - -layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent) - : QDialog(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 result; - mapnik::util::apply_visitor(mapnik::value_extractor_visitor(result),pos->second); + mapnik::util::apply_visitor(mapnik::value_extractor_visitor(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; } } @@ -69,5 +67,5 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent) Ui::LayerInfoDialog& layer_info_dialog::getUI() { - return ui; + return ui; } diff --git a/demo/viewer/layer_info_dialog.hpp b/demo/viewer/layer_info_dialog.hpp index d3c46cefa..798fb7b1c 100644 --- a/demo/viewer/layer_info_dialog.hpp +++ b/demo/viewer/layer_info_dialog.hpp @@ -17,28 +17,25 @@ * 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 -namespace mapnik -{ +namespace mapnik { class layer; } class layer_info_dialog : public QDialog { - Q_OBJECT + 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; + + private: + Ui::LayerInfoDialog ui; }; - -#endif //LAYER_INFO_DIALOG_HPP +#endif // LAYER_INFO_DIALOG_HPP diff --git a/demo/viewer/layerdelegate.cpp b/demo/viewer/layerdelegate.cpp index d441e1e11..e4879ca2e 100644 --- a/demo/viewer/layerdelegate.cpp +++ b/demo/viewer/layerdelegate.cpp @@ -17,38 +17,32 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #include #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); } diff --git a/demo/viewer/layerdelegate.hpp b/demo/viewer/layerdelegate.hpp index 3dc1d28d3..37b031c71 100644 --- a/demo/viewer/layerdelegate.hpp +++ b/demo/viewer/layerdelegate.hpp @@ -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 diff --git a/demo/viewer/layerlistmodel.cpp b/demo/viewer/layerlistmodel.cpp index ec0eaac26..eb14bd681 100644 --- a/demo/viewer/layerlistmodel.cpp +++ b/demo/viewer/layerlistmodel.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - - #include "layerlistmodel.hpp" #include #include @@ -26,14 +24,16 @@ using mapnik::Map; -LayerListModel::LayerListModel(std::shared_ptr map, QObject *parent) - : QAbstractListModel(parent), - map_(map) {} +LayerListModel::LayerListModel(std::shared_ptr map, QObject* parent) + : QAbstractListModel(parent) + , map_(map) +{} int LayerListModel::rowCount(QModelIndex const&) const { - if (map_) return map_->layers().size(); - return 0; + if (map_) + return map_->layers().size(); + return 0; } QVariant LayerListModel::data(QModelIndex const& index, int role) const @@ -59,9 +59,9 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const else if (role == Qt::CheckStateRole) { if (map_->layers().at(index.row()).active()) - return QVariant(Qt::Checked); + return QVariant(Qt::Checked); else - return QVariant(Qt::Unchecked); + return QVariant(Qt::Unchecked); } else if (role == Qt::ForegroundRole) { @@ -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,37 +87,37 @@ 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 & layers = const_cast& >(map_->layers()); - layers.at(index.row()).set_active(status); - emit dataChanged(index, index); - return true; - } - return false; + if (index.isValid() && role == Qt::CheckStateRole) + { + int status = value.toInt(); + std::vector& layers = const_cast&>(map_->layers()); + layers.at(index.row()).set_active(status); + emit dataChanged(index, index); + return true; + } + return false; } Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const { Qt::ItemFlags flags = QAbstractItemModel::flags(index); if (index.isValid()) - flags |= Qt::ItemIsUserCheckable; + flags |= Qt::ItemIsUserCheckable; return flags; } boost::optional LayerListModel::map_layer(int i) { - if (map_) - { - std::vector & layers = const_cast& >(map_->layers()); - if (i < int(layers.size())) - return boost::optional(layers[i]); - } - return boost::optional(); + if (map_) + { + std::vector& layers = const_cast&>(map_->layers()); + if (i < int(layers.size())) + return boost::optional(layers[i]); + } + return boost::optional(); } diff --git a/demo/viewer/layerlistmodel.hpp b/demo/viewer/layerlistmodel.hpp index 9f29f051c..c0872cadd 100644 --- a/demo/viewer/layerlistmodel.hpp +++ b/demo/viewer/layerlistmodel.hpp @@ -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 @@ -32,20 +30,18 @@ class LayerListModel : public QAbstractListModel { - Q_OBJECT - public: - LayerListModel(std::shared_ptr 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 map_layer(int i); + Q_OBJECT + public: + LayerListModel(std::shared_ptr 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 map_layer(int i); - private: - std::shared_ptr map_; + private: + std::shared_ptr map_; }; -#endif //LAYER_LIST_MODEL_HPP +#endif // LAYER_LIST_MODEL_HPP diff --git a/demo/viewer/layerwidget.cpp b/demo/viewer/layerwidget.cpp index 5733f1e63..c23cc05fb 100644 --- a/demo/viewer/layerwidget.cpp +++ b/demo/viewer/layerwidget.cpp @@ -17,7 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #include "layerwidget.hpp" #include #include @@ -33,65 +32,59 @@ #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 &roles) +void LayerTab::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& 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()); - emit layerSelected(list[0].row()); - } + QModelIndexList list = selected.indexes(); + if (list.size() != 0) + { + qDebug("SELECTED LAYER -> %d", list[0].row()); + emit layerSelected(list[0].row()); + } } void LayerTab::layerInfo() { - qDebug("Layer info"); - QModelIndexList indexes = selectedIndexes(); - if (indexes.size() > 0) - { - qDebug("id = %d",indexes[0].row()); - - } + qDebug("Layer info"); + QModelIndexList indexes = selectedIndexes(); + if (indexes.size() > 0) + { + qDebug("id = %d", indexes[0].row()); + } } void LayerTab::layerInfo2(QModelIndex const& index) { - qDebug("LayerInfo id = %d",index.row()); - QVector > params; - QVector style_names; - unsigned i = index.row(); - LayerListModel * model = static_cast(this->model()); - boost::optional layer = model->map_layer(i); + qDebug("LayerInfo id = %d", index.row()); + QVector> params; + QVector style_names; + unsigned i = index.row(); + LayerListModel* model = static_cast(this->model()); + boost::optional layer = model->map_layer(i); - if (layer) - { - layer_info_dialog dlg(*layer,this); - dlg.exec(); - } + if (layer) + { + 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"); + qDebug("test"); } diff --git a/demo/viewer/layerwidget.hpp b/demo/viewer/layerwidget.hpp index 6761d79a4..854020443 100644 --- a/demo/viewer/layerwidget.hpp +++ b/demo/viewer/layerwidget.hpp @@ -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 &roles); - void selectionChanged(const QItemSelection & selected, const QItemSelection &); + protected slots: + void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& 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 diff --git a/demo/viewer/main.cpp b/demo/viewer/main.cpp index ef840cca6..09e90fac3 100644 --- a/demo/viewer/main.cpp +++ b/demo/viewer/main.cpp @@ -17,7 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - // qt #include #include @@ -26,27 +25,26 @@ #include #include "mainwindow.hpp" -int main( int argc, char **argv ) +int main(int argc, char** argv) { using mapnik::datasource_cache; using mapnik::freetype_engine; try { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); -#endif +#endif 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 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; diff --git a/demo/viewer/mainwindow.cpp b/demo/viewer/mainwindow.cpp index 338180f66..9253a25fa 100644 --- a/demo/viewer/mainwindow.cpp +++ b/demo/viewer/mainwindow.cpp @@ -17,7 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - // stl #include @@ -58,27 +57,27 @@ #include 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 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 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 map(new mapnik::Map(width,height)); + std::shared_ptr 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(sender()); + QAction* action = qobject_cast(sender()); QByteArray fileFormat = action->data().toByteArray(); QString initialPath = QDir::currentPath() + "/map." + fileFormat; - QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"), - initialPath, - tr("%1 Files (*.%2);;All Files (*)") - .arg(QString(fileFormat.toUpper())) - .arg(QString(fileFormat))); + QString fileName = QFileDialog::getSaveFileName( + this, + tr("Export As"), + initialPath, + tr("%1 Files (*.%2);;All Files (*)").arg(QString(fileFormat.toUpper())).arg(QString(fileFormat))); if (!fileName.isEmpty()) { QPixmap const& pix = mapWidget_->pixmap(); @@ -270,77 +262,76 @@ void MainWindow::export_as() void MainWindow::print() { - - //Q_ASSERT(mapWidget_->pixmap()); - //QPrintDialog dialog(&printer, this); - //if (dialog.exec()) { - // QPainter painter(&printer); - // QRect rect = painter.viewport(); - // QSize size = mapWidget_->pixmap()->size(); - // size.scale(rect.size(), Qt::KeepAspectRatio); - // painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); - // painter.setWindow(mapWidget_->pixmap()->rect()); - // painter.drawPixmap(0, 0, *mapWidget_->pixmap()); - //} + // Q_ASSERT(mapWidget_->pixmap()); + // QPrintDialog dialog(&printer, this); + // if (dialog.exec()) { + // QPainter painter(&printer); + // QRect rect = painter.viewport(); + // QSize size = mapWidget_->pixmap()->size(); + // size.scale(rect.size(), Qt::KeepAspectRatio); + // painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); + // painter.setWindow(mapWidget_->pixmap()->rect()); + // painter.drawPixmap(0, 0, *mapWidget_->pixmap()); + // } } 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(x0, y0, x1, y1); + default_extent_ = mapnik::box2d(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) diff --git a/demo/viewer/mainwindow.hpp b/demo/viewer/mainwindow.hpp index 4926d5ff0..62e17994a 100644 --- a/demo/viewer/mainwindow.hpp +++ b/demo/viewer/mainwindow.hpp @@ -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; @@ -41,22 +40,24 @@ class QDoubleSpinBox; class MainWindow : public QMainWindow { Q_OBJECT - public: + 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 get_map(); -protected: + + protected: void closeEvent(QCloseEvent* event); -public slots: + public slots: void zoom_all(); void zoom_to_box(); void pan(); void info(); void export_as(); - void open(QString const& path = QString()); + void open(QString const& path = QString()); void reload(); void save(); void print(); @@ -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 exportAsActs; - QActionGroup *toolsGroup; + QAbstractItemModel* model; + LayerTab* layerTab_; + StyleTab* styleTab_; + MapWidget* mapWidget_; + // actions + QList 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 default_extent_; }; - -#endif //MAINWINDOW_HPP +#endif // MAINWINDOW_HPP diff --git a/demo/viewer/mapwidget.cpp b/demo/viewer/mapwidget.cpp index 81579e373..ba3e1c000 100644 --- a/demo/viewer/mapwidget.cpp +++ b/demo/viewer/mapwidget.cpp @@ -17,7 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #include #include @@ -41,153 +40,139 @@ #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); - pen_.setJoinStyle(Qt::RoundJoin); + pen_.setWidth(3); + pen_.setCapStyle(Qt::RoundCap); + pen_.setJoinStyle(Qt::RoundJoin); } void MapWidget::setTool(eTool tool) { - cur_tool_=tool; + cur_tool_ = tool; } void MapWidget::paintEvent(QPaintEvent*) { - QPainter painter(this); + QPainter painter(this); - if (drag_) - { - if (cur_tool_ == ZoomToBox) - { - 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); - } - 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_); - } - } - else - { - painter.drawPixmap(QPoint(0, 0),pix_); - } - painter.end(); + if (drag_) + { + if (cur_tool_ == ZoomToBox) + { + 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); + } + 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_); + } + } + else + { + 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()); - updateMap(); - } + if (map_) + { + map_->resize(ev->size().width(), ev->size().height()); + updateMap(); + } } void MapWidget::mousePressEvent(QMouseEvent* e) { - if (e->button()==Qt::LeftButton) - { - if (cur_tool_ == ZoomToBox || cur_tool_==Pan) - { - start_x_ = e->x(); - start_y_ = e->y(); - drag_=true; - } - else if (cur_tool_==Info) - { - if (map_) - { - QVector > 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()); - - for (unsigned index = 0; index < map_->layer_count();++index) + if (e->button() == Qt::LeftButton) + { + if (cur_tool_ == ZoomToBox || cur_tool_ == Pan) + { + start_x_ = e->x(); + start_y_ = e->y(); + drag_ = true; + } + else if (cur_tool_ == Info) + { + if (map_) { - if (int(index) != selectedLayer_) continue; + QVector> info; - 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 data(new mapnik::memory_datasource); - mapnik::featureset_ptr fs = map_->query_map_point(index,x,y); + 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()); - if (fs) - { - feature_ptr feat = fs->next(); - if (feat) - { - feature_kv_iterator itr(*feat,true); - feature_kv_iterator end(*feat); + for (unsigned index = 0; index < map_->layer_count(); ++index) + { + if (int(index) != selectedLayer_) + continue; - for ( ;itr!=end; ++itr) - { - info.push_back(QPair(QString(std::get<0>(*itr).c_str()), - std::get<1>(*itr).to_string().c_str())); - } + 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 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 end(*feat); + + for (; itr != end; ++itr) + { + info.push_back(QPair(QString(std::get<0>(*itr).c_str()), + std::get<1>(*itr).to_string().c_str())); + } #if 0 // using path_type = mapnik::transform_path_adapter; @@ -219,288 +204,285 @@ void MapWidget::mousePressEvent(QMouseEvent* e) } } #endif - } - } + } + } - if (info.size() > 0) - { - info_dialog info_dlg(info,this); - info_dlg.exec(); - break; - } + if (info.size() > 0) + { + 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()); } - - // remove annotation layer - 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) - { - //updateMap(); - } + } + } + else if (e->button() == Qt::RightButton) + { + // updateMap(); + } } void MapWidget::mouseMoveEvent(QMouseEvent* e) { - if (cur_tool_ == ZoomToBox || cur_tool_==Pan) - { - end_x_ = e->x(); - end_y_ = e->y(); - update(); - } + if (cur_tool_ == ZoomToBox || cur_tool_ == Pan) + { + end_x_ = e->x(); + end_y_ = e->y(); + update(); + } } void MapWidget::mouseReleaseEvent(QMouseEvent* e) { - if (e->button()==Qt::LeftButton) - { - end_x_ = e->x(); - end_y_ = e->y(); - if (cur_tool_ == ZoomToBox) - { - drag_=false; - if (map_) - { - view_transform t(map_->width(),map_->height(),map_->get_current_extent()); - box2d box = t.backward(box2d(start_x_,start_y_,end_x_,end_y_)); - map_->zoom_to_box(box); - updateMap(); - } - } - else if (cur_tool_==Pan) - { - 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); - updateMap(); - } - } - } + if (e->button() == Qt::LeftButton) + { + end_x_ = e->x(); + end_y_ = e->y(); + if (cur_tool_ == ZoomToBox) + { + drag_ = false; + if (map_) + { + view_transform t(map_->width(), map_->height(), map_->get_current_extent()); + box2d box = t.backward(box2d(start_x_, start_y_, end_x_, end_y_)); + map_->zoom_to_box(box); + updateMap(); + } + } + else if (cur_tool_ == Pan) + { + 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); + updateMap(); + } + } + } } void MapWidget::wheelEvent(QWheelEvent* e) { - if (!map_) - { - return; - } -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - QPointF corner(map_->width(), map_->height()); - QPointF zoomCoords; - double zoom; - if (e->angleDelta().y() > 0) - { - zoom = 0.5; - QPointF center = corner / 2; - QPointF delta = e->position() - center; - zoomCoords = zoom * delta + center; - } - else - { - zoom = 2.0; - zoomCoords = corner - e->position(); - } + if (!map_) + { + return; + } +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QPointF corner(map_->width(), map_->height()); + QPointF zoomCoords; + double zoom; + if (e->angleDelta().y() > 0) + { + zoom = 0.5; + QPointF center = corner / 2; + QPointF delta = e->position() - center; + zoomCoords = zoom * delta + center; + } + else + { + zoom = 2.0; + zoomCoords = corner - e->position(); + } #else - QPoint corner(map_->width(), map_->height()); - QPoint zoomCoords; - double zoom; - if (e->delta() > 0) - { - zoom = 0.5; - QPoint center = corner / 2; - QPoint delta = e->pos() - center; - zoomCoords = zoom * delta + center; - } - else - { - zoom = 2.0; - zoomCoords = corner - e->pos(); - } + QPoint corner(map_->width(), map_->height()); + QPoint zoomCoords; + double zoom; + if (e->delta() > 0) + { + zoom = 0.5; + QPoint center = corner / 2; + QPoint delta = e->pos() - center; + zoomCoords = zoom * delta + center; + } + else + { + zoom = 2.0; + zoomCoords = corner - e->pos(); + } #endif - map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom); - updateMap(); + map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom); + updateMap(); } -void MapWidget::keyPressEvent(QKeyEvent *e) +void MapWidget::keyPressEvent(QKeyEvent* e) { - std::cout << "key pressed:"<< e->key()<<"\n"; - switch (e->key()) { - case Qt::Key_Minus: - zoomOut(); - break; - case Qt::Key_Plus: - case 61: - zoomIn(); - break; - case 65: - defaultView(); - break; - case Qt::Key_Up: - panUp(); - break; - case Qt::Key_Down: - panDown(); - break; - case Qt::Key_Left: - panLeft(); - break; - case Qt::Key_Right: - panRight(); - break; - case 49: - zoomToLevel(10); - break; - case 50: - zoomToLevel(11); - break; - case 51: - zoomToLevel(12); - break; - case 52: - zoomToLevel(13); - break; - case 53: - zoomToLevel(14); - break; - case 54: - zoomToLevel(15); - break; - case 55: - zoomToLevel(16); - break; - case 56: - zoomToLevel(17); - break; - case 57: - zoomToLevel(18); - break; - default: - QWidget::keyPressEvent(e); - } - - + std::cout << "key pressed:" << e->key() << "\n"; + switch (e->key()) + { + case Qt::Key_Minus: + zoomOut(); + break; + case Qt::Key_Plus: + case 61: + zoomIn(); + break; + case 65: + defaultView(); + break; + case Qt::Key_Up: + panUp(); + break; + case Qt::Key_Down: + panDown(); + break; + case Qt::Key_Left: + panLeft(); + break; + case Qt::Key_Right: + panRight(); + break; + case 49: + zoomToLevel(10); + break; + case 50: + zoomToLevel(11); + break; + case 51: + zoomToLevel(12); + break; + case 52: + zoomToLevel(13); + break; + case 53: + zoomToLevel(14); + break; + case 54: + zoomToLevel(15); + break; + case 55: + zoomToLevel(16); + break; + case 56: + zoomToLevel(17); + break; + case 57: + zoomToLevel(18); + break; + default: + QWidget::keyPressEvent(e); + } } void MapWidget::zoomToBox(mapnik::box2d const& bbox) { - if (map_) - { - map_->zoom_to_box(bbox); - updateMap(); - } + if (map_) + { + map_->zoom_to_box(bbox); + updateMap(); + } } void MapWidget::defaultView() { - if (map_) - { - map_->resize(width(),height()); - map_->zoom_all(); - updateMap(); - } + if (map_) + { + map_->resize(width(), height()); + map_->zoom_all(); + updateMap(); + } } void MapWidget::zoomIn() { - if (map_) - { - map_->zoom(0.5); - updateMap(); - } + if (map_) + { + map_->zoom(0.5); + updateMap(); + } } void MapWidget::zoomOut() { - if (map_) - { - map_->zoom(2.0); - updateMap(); - } + if (map_) + { + map_->zoom(2.0); + updateMap(); + } } 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)); - updateMap(); - } + if (map_) + { + double cx = 0.5 * map_->width(); + double cy = 0.5 * map_->height(); + map_->pan(int(cx), int(cy - cy * 0.25)); + updateMap(); + } } 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)); - updateMap(); - } + if (map_) + { + double cx = 0.5 * map_->width(); + double cy = 0.5 * map_->height(); + map_->pan(int(cx), int(cy + cy * 0.25)); + updateMap(); + } } 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)); - updateMap(); - } + if (map_) + { + double cx = 0.5 * map_->width(); + double cy = 0.5 * map_->height(); + map_->pan(int(cx - cx * 0.25), int(cy)); + updateMap(); + } } 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)); - updateMap(); - } + if (map_) + { + 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 ) - { - double scale_denom = scales[level]; - std::cerr << "scale denominator = " << scale_denom << "\n"; - mapnik::box2d ext = map_->get_current_extent(); - double width = static_cast(map_->width()); - double height= static_cast(map_->height()); - mapnik::coord2d pt = ext.center(); + if (map_ && level >= 0 && level < 19) + { + double scale_denom = scales[level]; + std::cerr << "scale denominator = " << scale_denom << "\n"; + mapnik::box2d ext = map_->get_current_extent(); + double width = static_cast(map_->width()); + double height = static_cast(map_->height()); + mapnik::coord2d pt = ext.center(); - double res = scale_denom * 0.00028; + double res = scale_denom * 0.00028; - mapnik::box2d box(pt.x - 0.5 * width * res, - pt.y - 0.5 * height*res, - pt.x + 0.5 * width * res, - pt.y + 0.5 * height*res); - map_->zoom_to_box(box); - updateMap(); - } + mapnik::box2d box(pt.x - 0.5 * width * res, + pt.y - 0.5 * height * res, + pt.x + 0.5 * width * 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 ren(map,buf,scaling_factor); + image_rgba8 buf(width, height); + mapnik::agg_renderer 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; - //} + // 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(); } @@ -582,50 +564,49 @@ void MapWidget::updateScaleFactor(double scale_factor) void MapWidget::updateMap() { - if (map_) - { - if (cur_renderer_== AGG) - { - render_agg(*map_, scaling_factor_, pix_); - } - else if (cur_renderer_ == Cairo) - { - render_cairo(*map_, scaling_factor_, pix_); - } - else if (cur_renderer_ == Grid) - { - render_grid(*map_, scaling_factor_, pix_); - } - else - { - std::cerr << "Unknown renderer..." << std::endl; - } + if (map_) + { + if (cur_renderer_ == AGG) + { + render_agg(*map_, scaling_factor_, pix_); + } + else if (cur_renderer_ == Cairo) + { + render_cairo(*map_, scaling_factor_, pix_); + } + else if (cur_renderer_ == Grid) + { + render_grid(*map_, scaling_factor_, pix_); + } + else + { + std::cerr << "Unknown renderer..." << std::endl; + } - try - { - projection prj(map_->srs(), true); // map projection - box2d ext = map_->get_current_extent(); - double x0 = ext.minx(); - double y0 = ext.miny(); - double x1 = ext.maxx(); - double y1 = ext.maxy(); - double z = 0; - std::string dest_srs = {"epsg:4326"}; - mapnik::proj_transform proj_tr(map_->srs(), dest_srs); + try + { + projection prj(map_->srs(), true); // map projection + box2d ext = map_->get_current_extent(); + double x0 = ext.minx(); + double y0 = ext.miny(); + double x1 = ext.maxx(); + double y1 = ext.maxy(); + double z = 0; + std::string dest_srs = {"epsg:4326"}; + mapnik::proj_transform proj_tr(map_->srs(), dest_srs); - proj_tr.forward(x0, y0, z); - proj_tr.forward(x1, y1, z); - std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl; - std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n"; - update(); - // emit signal to interested widgets - emit mapViewChanged(); - } - catch (...) - { - std::cerr << "Unknown exception caught!\n"; - } - } + proj_tr.forward(x0, y0, z); + proj_tr.forward(x1, y1, z); + std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl; + std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n"; + update(); + // emit signal to interested widgets + emit mapViewChanged(); + } catch (...) + { + std::cerr << "Unknown exception caught!\n"; + } + } } std::shared_ptr MapWidget::getMap() @@ -638,7 +619,6 @@ void MapWidget::setMap(std::shared_ptr map) map_ = map; } - void MapWidget::layerSelected(int index) { selectedLayer_ = index; diff --git a/demo/viewer/mapwidget.hpp b/demo/viewer/mapwidget.hpp index db192a8ee..4f6748f71 100644 --- a/demo/viewer/mapwidget.hpp +++ b/demo/viewer/mapwidget.hpp @@ -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 #include - #ifndef Q_MOC_RUN #include #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 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 getMap(); - inline QPixmap const& pixmap() const { return pix_;} + inline QPixmap const& pixmap() const { return pix_; } void setMap(std::shared_ptr map); void defaultView(); void zoomToBox(mapnik::box2d 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 diff --git a/demo/viewer/styles_model.cpp b/demo/viewer/styles_model.cpp index 5eef82032..101152682 100644 --- a/demo/viewer/styles_model.cpp +++ b/demo/viewer/styles_model.cpp @@ -17,7 +17,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #include "styles_model.hpp" #include #include @@ -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 + template struct wrap : public node_base { - wrap(T const& obj) - : obj_(obj) {} + wrap(T const& obj) + : obj_(obj) + {} - ~wrap() {} + ~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_; + T obj_; }; -public: - template - node ( T const& obj, node * parent=0) - : impl_(new wrap(obj)), - parent_(parent) + public: + template + node(T const& obj, node* parent = 0) + : impl_(new wrap(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(this)); @@ -110,94 +89,90 @@ public: return 0; } - ~node() - { - qDeleteAll(children_); - } + ~node() { qDeleteAll(children_); } -private: + private: const std::unique_ptr impl_; QList 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 - QString operator() (T const& ) const + template + 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(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(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(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 - QIcon operator() (T const& ) const + template + 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 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 map_; }; -StyleModel::StyleModel(std::shared_ptr map, QObject * parent) - : QAbstractItemModel(parent), - root_(new node(map_node(map))) +StyleModel::StyleModel(std::shared_ptr map, QObject* parent) + : QAbstractItemModel(parent) + , root_(new node(map_node(map))) { - using style_type = std::map; - style_type const & styles = map->styles(); + using style_type = std::map; + 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 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(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(index.internalPointer()); - node * parent_node = child_node->parent(); + node* child_node = static_cast(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(index.internalPointer()); + node* cur_node = static_cast(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(); } diff --git a/demo/viewer/styles_model.hpp b/demo/viewer/styles_model.hpp index 13a86d3e1..c22435071 100644 --- a/demo/viewer/styles_model.hpp +++ b/demo/viewer/styles_model.hpp @@ -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,24 +26,23 @@ #include #endif - - class node; class StyleModel : public QAbstractItemModel { - Q_OBJECT + Q_OBJECT public: - StyleModel(std::shared_ptr 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; - private: - //std::shared_ptr map_; - const std::unique_ptr root_; + StyleModel(std::shared_ptr 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; + + private: + // std::shared_ptr map_; + const std::unique_ptr root_; }; #endif // STYLE_MODEL_HPP