format dir demo

This commit is contained in:
Mathis Logemann 2022-01-26 23:34:08 +01:00
parent 65035706fb
commit 4fbaa032f0
20 changed files with 888 additions and 996 deletions

View file

@ -45,14 +45,16 @@
#include <iostream>
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");
@ -215,7 +217,8 @@ int main ( int, char** )
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));
}
@ -342,8 +345,7 @@ 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));
@ -353,7 +355,8 @@ int main ( int, char** )
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");
cairo_surface_finish(&*image_surface);
@ -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;

View file

@ -17,10 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "about_dialog.hpp"
about_dialog::about_dialog(QWidget* parent)
: QDialog(parent)
{

View file

@ -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
@ -30,9 +28,9 @@ class about_dialog : public QDialog
Q_OBJECT
public:
about_dialog(QWidget* parent = 0);
private:
Ui::Dialog ui;
};
#endif // ABOUT_DIALOG_HPP

View file

@ -17,10 +17,8 @@
* 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)
: QDialog(parent)
{

View file

@ -17,8 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef INFO_DIALOG_HPP
#define INFO_DIALOG_HPP
@ -30,9 +28,9 @@ class info_dialog : public QDialog
Q_OBJECT
public:
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0);
private:
Ui::InfoDialog ui;
};
#endif // INFO_DIALOG_HPP

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "layer_info_dialog.hpp"
// mapnik
@ -26,7 +25,6 @@
#include <mapnik/params_impl.hpp>
#include <mapnik/layer.hpp>
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
: QDialog(parent)
{

View file

@ -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;
}
@ -36,9 +33,9 @@ class layer_info_dialog : public QDialog
public:
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0);
Ui::LayerInfoDialog& getUI();
private:
Ui::LayerInfoDialog ui;
};
#endif // LAYER_INFO_DIALOG_HPP

View file

@ -17,17 +17,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QtGui>
#include "layerdelegate.hpp"
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));
@ -37,18 +34,15 @@ void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
else
painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
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);
}

View file

@ -35,10 +35,8 @@ class LayerDelegate : public QAbstractItemDelegate
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;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
};
#endif // LAYER_DELEGATE_HPP

View file

@ -17,8 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "layerlistmodel.hpp"
#include <QIcon>
#include <QBrush>
@ -27,12 +25,14 @@
using mapnik::Map;
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent)
: QAbstractListModel(parent),
map_(map) {}
: 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,10 +87,10 @@ 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)
{

View file

@ -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
@ -37,10 +35,8 @@ class LayerListModel : public QAbstractListModel
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);
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);

View file

@ -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,17 +32,15 @@
#include "layer_info_dialog.hpp"
LayerTab::LayerTab(QWidget* parent)
: QListView(parent) {}
: QListView(parent)
{}
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);
@ -66,7 +63,6 @@ void LayerTab::layerInfo()
if (indexes.size() > 0)
{
qDebug("id = %d", indexes[0].row());
}
}
@ -86,10 +82,7 @@ void LayerTab::layerInfo2(QModelIndex const& index)
}
}
StyleTab::StyleTab(QWidget*)
{
}
StyleTab::StyleTab(QWidget*) {}
void StyleTab::contextMenuEvent(QContextMenuEvent* event)
{

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef LAYERWIDGET_HPP
#define LAYERWIDGET_HPP
@ -47,6 +46,7 @@ class StyleTab : public QTreeView
Q_OBJECT
public:
StyleTab(QWidget* parent = 0);
protected:
void contextMenuEvent(QContextMenuEvent* event);
};

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// qt
#include <QApplication>
#include <QStringList>
@ -41,8 +40,7 @@ int main( int argc, char **argv )
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");
@ -57,7 +55,8 @@ int main( int argc, char **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(",");
@ -68,23 +67,25 @@ int main( int argc, char **argv )
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;

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// stl
#include <iostream>
@ -58,8 +57,8 @@
#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);
@ -107,19 +106,18 @@ MainWindow::MainWindow()
// slider
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(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,10 +167,10 @@ 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;
@ -195,12 +189,10 @@ void MainWindow::load_map_file(QString const& filename)
{
mapnik::auto_cpu_timer t(std::clog, "loading map took: ");
mapnik::load_map(*map, filename.toStdString());
}
catch (std::exception const& ex)
} catch (std::exception const& ex)
{
std::cout << ex.what() << "\n";
}
catch (...)
} catch (...)
{
std::cerr << "Exception caught in load_map\n";
}
@ -256,11 +248,11 @@ void MainWindow::export_as()
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,7 +262,6 @@ void MainWindow::export_as()
void MainWindow::print()
{
// Q_ASSERT(mapWidget_->pixmap());
// QPrintDialog dialog(&printer, this);
// if (dialog.exec()) {
@ -411,8 +402,6 @@ void MainWindow::createToolBars()
fileToolBar->addAction(aboutAct);
}
void MainWindow::set_default_extent(double x0, double y0, double x1, double y1)
{
try
@ -427,8 +416,8 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
mapWidget_->zoomToBox(default_extent_);
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
}
}
catch (...) {}
} catch (...)
{}
}
void MainWindow::set_scaling_factor(double scaling_factor)

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
@ -46,8 +45,10 @@ class MainWindow : public QMainWindow
virtual ~MainWindow();
void set_default_extent(double x0, double y0, double x1, double y1);
void set_scaling_factor(double scaling_factor);
public:
std::shared_ptr<mapnik::Map> get_map();
protected:
void closeEvent(QCloseEvent* event);
public slots:
@ -65,6 +66,7 @@ public slots:
void pan_right();
void pan_up();
void pan_down();
private:
void createActions();
void createMenus();
@ -112,5 +114,4 @@ private:
mapnik::box2d<double> default_extent_;
};
#endif // MAINWINDOW_HPP

View file

@ -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)
: 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);
@ -162,10 +145,12 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
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;
if (!layer.visible(scale_denom))
continue;
std::string name = layer.name();
double x = e->x();
double y = e->y();
@ -231,10 +216,9 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
}
// 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());
}
}
}
@ -334,7 +318,8 @@ void MapWidget::wheelEvent(QWheelEvent* e)
void MapWidget::keyPressEvent(QKeyEvent* e)
{
std::cout << "key pressed:" << e->key() << "\n";
switch (e->key()) {
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)
@ -472,7 +455,6 @@ void MapWidget::panRight()
}
}
void MapWidget::zoomToLevel(int level)
{
if (map_ && level >= 0 && level < 19)
@ -531,20 +513,17 @@ void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
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)
{
std::cerr << "Not supported" << std::endl;
}
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
{
// FIXME
@ -567,9 +546,12 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
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();
}
@ -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;

View file

@ -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
@ -40,19 +38,13 @@ class MapWidget : public QWidget
Q_OBJECT
public:
enum eTool
{
enum eTool {
ZoomToBox = 1,
Pan,
Info,
};
enum eRenderer
{
AGG,
Cairo,
Grid
};
enum eRenderer { AGG, Cairo, Grid };
private:
std::shared_ptr<mapnik::Map> map_;
@ -70,6 +62,7 @@ private:
int selectedLayer_;
double scaling_factor_;
eRenderer cur_renderer_;
public:
MapWidget(QWidget* parent = 0);
void setTool(eTool tool);
@ -93,6 +86,7 @@ public slots:
void updateScaleFactor(double scale_factor);
signals:
void mapViewChanged();
protected:
void paintEvent(QPaintEvent* ev);
void resizeEvent(QResizeEvent* ev);
@ -101,10 +95,7 @@ protected:
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 export_to_file(unsigned width, unsigned height, std::string const& filename, std::string const& type);
};
#endif // MAP_WIDGET_HPP

View file

@ -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>
@ -48,19 +47,14 @@ class node : private mapnik::util::noncopyable
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_;
};
@ -68,34 +62,19 @@ class node : private mapnik::util::noncopyable
public:
template<typename T>
node(T const& obj, node* parent = 0)
: impl_(new wrap<T>(obj)),
parent_(parent)
: 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)
{
@ -110,10 +89,7 @@ public:
return 0;
}
~node()
{
qDeleteAll(children_);
}
~node() { qDeleteAll(children_); }
private:
const std::unique_ptr<node_base> impl_;
@ -121,7 +97,6 @@ private:
node* parent_;
};
struct symbolizer_info
{
QString operator()(mapnik::point_symbolizer const& sym) const
@ -239,7 +214,8 @@ class symbolizer_node
{
public:
symbolizer_node(mapnik::symbolizer const& sym)
: sym_(sym) {}
: sym_(sym)
{}
~symbolizer_node() {}
QString name() const
@ -259,8 +235,9 @@ class rule_node
{
public:
rule_node(QString name, mapnik::rule const& r)
: name_(name),
rule_(r) {}
: name_(name)
, rule_(r)
{}
~rule_node() {}
QString name() const
{
@ -268,10 +245,7 @@ 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:
QString name_;
@ -282,20 +256,15 @@ class style_node
{
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:
QString name_;
@ -306,26 +275,21 @@ class map_node
{
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:
std::shared_ptr<mapnik::Map> map_;
};
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
: QAbstractItemModel(parent),
root_(new node(map_node(map)))
: 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();
@ -382,7 +346,8 @@ int StyleModel::rowCount(QModelIndex const& parent) const
{
// qDebug("rowCount");
node* parent_node;
if (parent.column() > 0) return 0;
if (parent.column() > 0)
return 0;
if (!parent.isValid())
parent_node = root_.get();
else
@ -405,7 +370,6 @@ QVariant StyleModel::data(const QModelIndex & index, int role) const
{
if (role == Qt::DisplayRole)
{
return QVariant(cur_node->name());
}
else if (role == Qt::DecorationRole)

View file

@ -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,8 +26,6 @@
#include <mapnik/map.hpp>
#endif
class node;
class StyleModel : public QAbstractItemModel
{
@ -42,6 +39,7 @@ class StyleModel : public QAbstractItemModel
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_;
const std::unique_ptr<node> root_;