format dir demo
This commit is contained in:
parent
65035706fb
commit
4fbaa032f0
20 changed files with 888 additions and 996 deletions
|
@ -45,14 +45,16 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
using namespace mapnik;
|
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_lcc =
|
||||||
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";
|
"+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";
|
std::cout << " running demo ... \n";
|
||||||
datasource_cache::instance().register_datasources("plugins/input/");
|
datasource_cache::instance().register_datasources("plugins/input/");
|
||||||
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
|
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.fill = color(0, 0, 0);
|
||||||
placement_finder->defaults.format_defaults.halo_fill = color(255, 255, 200);
|
placement_finder->defaults.format_defaults.halo_fill = color(255, 255, 200);
|
||||||
placement_finder->defaults.format_defaults.halo_radius = 1.0;
|
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);
|
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
|
||||||
r.append(std::move(text_sym));
|
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
|
but instead let's build up a surface for more flexibility
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cairo_surface_ptr image_surface(
|
cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m.width(), m.height()),
|
||||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,m.width(),m.height()),
|
|
||||||
cairo_surface_closer());
|
cairo_surface_closer());
|
||||||
double scale_factor = 1.0;
|
double scale_factor = 1.0;
|
||||||
cairo_ptr image_context(create_context(image_surface));
|
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");
|
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
|
||||||
// but we can also benefit from quantization by converting
|
// but we can also benefit from quantization by converting
|
||||||
// to a mapnik image object and then saving that
|
// 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);
|
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);
|
cairo_surface_finish(&*image_surface);
|
||||||
|
@ -367,13 +370,11 @@ int main ( int, char** )
|
||||||
#endif
|
#endif
|
||||||
// save map definition (data + style)
|
// save map definition (data + style)
|
||||||
save_map(m, "map.xml");
|
save_map(m, "map.xml");
|
||||||
}
|
} catch (std::exception const& ex)
|
||||||
catch ( std::exception const& ex )
|
|
||||||
{
|
{
|
||||||
std::cerr << "### std::exception: " << ex.what() << std::endl;
|
std::cerr << "### std::exception: " << ex.what() << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
} catch (...)
|
||||||
catch ( ... )
|
|
||||||
{
|
{
|
||||||
std::cerr << "### Unknown exception." << std::endl;
|
std::cerr << "### Unknown exception." << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
@ -17,10 +17,8 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "about_dialog.hpp"
|
#include "about_dialog.hpp"
|
||||||
|
|
||||||
|
|
||||||
about_dialog::about_dialog(QWidget* parent)
|
about_dialog::about_dialog(QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined ABOUT_DIALOG_HPP
|
#if !defined ABOUT_DIALOG_HPP
|
||||||
#define ABOUT_DIALOG_HPP
|
#define ABOUT_DIALOG_HPP
|
||||||
|
|
||||||
|
@ -30,9 +28,9 @@ class about_dialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
about_dialog(QWidget* parent = 0);
|
about_dialog(QWidget* parent = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Dialog ui;
|
Ui::Dialog ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // ABOUT_DIALOG_HPP
|
#endif // ABOUT_DIALOG_HPP
|
||||||
|
|
|
@ -17,10 +17,8 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "info_dialog.hpp"
|
#include "info_dialog.hpp"
|
||||||
|
|
||||||
|
|
||||||
info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent)
|
info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef INFO_DIALOG_HPP
|
#ifndef INFO_DIALOG_HPP
|
||||||
#define INFO_DIALOG_HPP
|
#define INFO_DIALOG_HPP
|
||||||
|
|
||||||
|
@ -30,9 +28,9 @@ class info_dialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0);
|
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::InfoDialog ui;
|
Ui::InfoDialog ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // INFO_DIALOG_HPP
|
#endif // INFO_DIALOG_HPP
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "layer_info_dialog.hpp"
|
#include "layer_info_dialog.hpp"
|
||||||
|
|
||||||
// mapnik
|
// mapnik
|
||||||
|
@ -26,7 +25,6 @@
|
||||||
#include <mapnik/params_impl.hpp>
|
#include <mapnik/params_impl.hpp>
|
||||||
#include <mapnik/layer.hpp>
|
#include <mapnik/layer.hpp>
|
||||||
|
|
||||||
|
|
||||||
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
|
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,16 +17,13 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LAYER_INFO_DIALOG_HPP
|
#ifndef LAYER_INFO_DIALOG_HPP
|
||||||
#define LAYER_INFO_DIALOG_HPP
|
#define LAYER_INFO_DIALOG_HPP
|
||||||
|
|
||||||
#include "ui_layer_info.h"
|
#include "ui_layer_info.h"
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
class layer;
|
class layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +33,9 @@ class layer_info_dialog : public QDialog
|
||||||
public:
|
public:
|
||||||
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0);
|
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0);
|
||||||
Ui::LayerInfoDialog& getUI();
|
Ui::LayerInfoDialog& getUI();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::LayerInfoDialog ui;
|
Ui::LayerInfoDialog ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // LAYER_INFO_DIALOG_HPP
|
#endif // LAYER_INFO_DIALOG_HPP
|
||||||
|
|
|
@ -17,17 +17,14 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "layerdelegate.hpp"
|
#include "layerdelegate.hpp"
|
||||||
|
|
||||||
LayerDelegate::LayerDelegate(QObject* parent)
|
LayerDelegate::LayerDelegate(QObject* parent)
|
||||||
: QAbstractItemDelegate(parent)
|
: QAbstractItemDelegate(parent)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void LayerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
{
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
painter->setPen(QPen(QColor(255, 0, 0), 1));
|
painter->setPen(QPen(QColor(255, 0, 0), 1));
|
||||||
|
@ -37,18 +34,15 @@ void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
else
|
else
|
||||||
painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
|
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)
|
if (option.state & QStyle::State_Selected)
|
||||||
painter->setBrush(option.palette.highlightedText());
|
painter->setBrush(option.palette.highlightedText());
|
||||||
else
|
else
|
||||||
painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
|
painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
|
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const
|
||||||
const QModelIndex & /* index */) const
|
|
||||||
{
|
{
|
||||||
return QSize(120, 24);
|
return QSize(120, 24);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,8 @@ class LayerDelegate : public QAbstractItemDelegate
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LayerDelegate(QObject* parent = 0);
|
LayerDelegate(QObject* parent = 0);
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
const QModelIndex &index) const;
|
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
|
||||||
const QModelIndex &index ) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LAYER_DELEGATE_HPP
|
#endif // LAYER_DELEGATE_HPP
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "layerlistmodel.hpp"
|
#include "layerlistmodel.hpp"
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
|
@ -27,12 +25,14 @@
|
||||||
using mapnik::Map;
|
using mapnik::Map;
|
||||||
|
|
||||||
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent)
|
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent)
|
||||||
: QAbstractListModel(parent),
|
: QAbstractListModel(parent)
|
||||||
map_(map) {}
|
, map_(map)
|
||||||
|
{}
|
||||||
|
|
||||||
int LayerListModel::rowCount(QModelIndex const&) const
|
int LayerListModel::rowCount(QModelIndex const&) const
|
||||||
{
|
{
|
||||||
if (map_) return map_->layers().size();
|
if (map_)
|
||||||
|
return map_->layers().size();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +76,7 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
int role) const
|
|
||||||
{
|
{
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -88,10 +87,10 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
||||||
return QString("TODO Row %1").arg(section);
|
return QString("TODO Row %1").arg(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LayerListModel::setData(const QModelIndex &index,
|
bool LayerListModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
const QVariant &value, int role)
|
|
||||||
{
|
{
|
||||||
if (!map_) return false;
|
if (!map_)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (index.isValid() && role == Qt::CheckStateRole)
|
if (index.isValid() && role == Qt::CheckStateRole)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LAYER_LIST_MODEL_HPP
|
#ifndef LAYER_LIST_MODEL_HPP
|
||||||
#define 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);
|
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex& index, int role) const;
|
QVariant data(const QModelIndex& index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
int role = Qt::DisplayRole) const;
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
bool setData(const QModelIndex &index, const QVariant &value,
|
|
||||||
int role = Qt::EditRole);
|
|
||||||
Qt::ItemFlags flags(QModelIndex const& index) const;
|
Qt::ItemFlags flags(QModelIndex const& index) const;
|
||||||
boost::optional<mapnik::layer&> map_layer(int i);
|
boost::optional<mapnik::layer&> map_layer(int i);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "layerwidget.hpp"
|
#include "layerwidget.hpp"
|
||||||
#include <qabstractitemdelegate.h>
|
#include <qabstractitemdelegate.h>
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
|
@ -33,17 +32,15 @@
|
||||||
#include "layer_info_dialog.hpp"
|
#include "layer_info_dialog.hpp"
|
||||||
|
|
||||||
LayerTab::LayerTab(QWidget* parent)
|
LayerTab::LayerTab(QWidget* parent)
|
||||||
: QListView(parent) {}
|
: QListView(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
void LayerTab::paintEvent(QPaintEvent* e)
|
void LayerTab::paintEvent(QPaintEvent* e)
|
||||||
{
|
{
|
||||||
QListView::paintEvent(e);
|
QListView::paintEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerTab::dataChanged(const QModelIndex &topLeft,
|
void LayerTab::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
|
||||||
const QModelIndex &bottomRight,
|
|
||||||
const QVector<int> &roles)
|
|
||||||
{
|
{
|
||||||
emit update_mapwidget();
|
emit update_mapwidget();
|
||||||
QListView::dataChanged(topLeft, bottomRight, roles);
|
QListView::dataChanged(topLeft, bottomRight, roles);
|
||||||
|
@ -66,7 +63,6 @@ void LayerTab::layerInfo()
|
||||||
if (indexes.size() > 0)
|
if (indexes.size() > 0)
|
||||||
{
|
{
|
||||||
qDebug("id = %d", indexes[0].row());
|
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)
|
void StyleTab::contextMenuEvent(QContextMenuEvent* event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef LAYERWIDGET_HPP
|
#ifndef LAYERWIDGET_HPP
|
||||||
#define LAYERWIDGET_HPP
|
#define LAYERWIDGET_HPP
|
||||||
|
|
||||||
|
@ -47,6 +46,7 @@ class StyleTab : public QTreeView
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
StyleTab(QWidget* parent = 0);
|
StyleTab(QWidget* parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent* event);
|
void contextMenuEvent(QContextMenuEvent* event);
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// qt
|
// qt
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
@ -41,8 +40,7 @@ int main( int argc, char **argv )
|
||||||
QSettings settings("viewer.ini", QSettings::IniFormat);
|
QSettings settings("viewer.ini", QSettings::IniFormat);
|
||||||
|
|
||||||
// register input plug-ins
|
// register input plug-ins
|
||||||
QString plugins_dir = settings.value("mapnik/plugins_dir",
|
QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik/input/")).toString();
|
||||||
QVariant("/usr/local/lib/mapnik/input/")).toString();
|
|
||||||
datasource_cache::instance().register_datasources(plugins_dir.toStdString());
|
datasource_cache::instance().register_datasources(plugins_dir.toStdString());
|
||||||
// register fonts
|
// register fonts
|
||||||
int count = settings.beginReadArray("mapnik/fonts");
|
int count = settings.beginReadArray("mapnik/fonts");
|
||||||
|
@ -57,7 +55,8 @@ int main( int argc, char **argv )
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
MainWindow window;
|
MainWindow window;
|
||||||
window.show();
|
window.show();
|
||||||
if (argc > 1) window.open(argv[1]);
|
if (argc > 1)
|
||||||
|
window.open(argv[1]);
|
||||||
if (argc >= 3)
|
if (argc >= 3)
|
||||||
{
|
{
|
||||||
QStringList list = QString(argv[2]).split(",");
|
QStringList list = QString(argv[2]).split(",");
|
||||||
|
@ -68,23 +67,25 @@ int main( int argc, char **argv )
|
||||||
double y0 = list[1].toDouble(&ok);
|
double y0 = list[1].toDouble(&ok);
|
||||||
double x1 = list[2].toDouble(&ok);
|
double x1 = list[2].toDouble(&ok);
|
||||||
double y1 = list[3].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
|
else
|
||||||
{
|
{
|
||||||
std::shared_ptr<mapnik::Map> map = window.get_map();
|
std::shared_ptr<mapnik::Map> map = window.get_map();
|
||||||
if (map) map->zoom_all();
|
if (map)
|
||||||
|
map->zoom_all();
|
||||||
}
|
}
|
||||||
if (argc == 4)
|
if (argc == 4)
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
double scaling_factor = QString(argv[3]).toDouble(&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();
|
return app.exec();
|
||||||
}
|
} catch (std::exception const& ex)
|
||||||
catch (std::exception const& ex)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
|
std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -58,8 +57,8 @@
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
: filename_(),
|
: filename_()
|
||||||
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
|
, default_extent_(-20037508.3428, -20037508.3428, 20037508.3428, 20037508.3428)
|
||||||
{
|
{
|
||||||
mapWidget_ = new MapWidget(this);
|
mapWidget_ = new MapWidget(this);
|
||||||
QSplitter* splitter = new QSplitter(this);
|
QSplitter* splitter = new QSplitter(this);
|
||||||
|
@ -107,19 +106,18 @@ MainWindow::MainWindow()
|
||||||
// slider
|
// slider
|
||||||
connect(slider_, SIGNAL(valueChanged(int)), mapWidget_, SLOT(zoomToLevel(int)));
|
connect(slider_, SIGNAL(valueChanged(int)), mapWidget_, SLOT(zoomToLevel(int)));
|
||||||
// renderer selector
|
// renderer selector
|
||||||
connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)),
|
connect(renderer_selector_,
|
||||||
mapWidget_, SLOT(updateRenderer(QString const&)));
|
SIGNAL(currentIndexChanged(QString const&)),
|
||||||
|
mapWidget_,
|
||||||
|
SLOT(updateRenderer(QString const&)));
|
||||||
|
|
||||||
// scale factor
|
// scale factor
|
||||||
connect(scale_factor_,SIGNAL(valueChanged(double)),
|
connect(scale_factor_, SIGNAL(valueChanged(double)), mapWidget_, SLOT(updateScaleFactor(double)));
|
||||||
mapWidget_, SLOT(updateScaleFactor(double)));
|
|
||||||
//
|
//
|
||||||
connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap()));
|
connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap()));
|
||||||
connect(layerTab_,SIGNAL(layerSelected(int)),
|
connect(layerTab_, SIGNAL(layerSelected(int)), mapWidget_, SLOT(layerSelected(int)));
|
||||||
mapWidget_,SLOT(layerSelected(int)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete mapWidget_;
|
delete mapWidget_;
|
||||||
|
@ -141,8 +139,7 @@ void MainWindow::open(QString const& path)
|
||||||
{
|
{
|
||||||
if (path.isNull())
|
if (path.isNull())
|
||||||
{
|
{
|
||||||
filename_ = QFileDialog::getOpenFileName(this,tr("Open Mapnik file"),
|
filename_ = QFileDialog::getOpenFileName(this, tr("Open Mapnik file"), currentPath, "*.xml");
|
||||||
currentPath,"*.xml");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -151,18 +148,15 @@ void MainWindow::open(QString const& path)
|
||||||
|
|
||||||
if (!filename_.isEmpty())
|
if (!filename_.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
||||||
load_map_file(filename_);
|
load_map_file(filename_);
|
||||||
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
|
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::reload()
|
void MainWindow::reload()
|
||||||
{
|
{
|
||||||
if (!filename_.isEmpty())
|
if (!filename_.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
||||||
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
|
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
|
||||||
load_map_file(filename_);
|
load_map_file(filename_);
|
||||||
mapWidget_->zoomToBox(bbox);
|
mapWidget_->zoomToBox(bbox);
|
||||||
|
@ -173,10 +167,10 @@ void MainWindow::reload()
|
||||||
void MainWindow::save()
|
void MainWindow::save()
|
||||||
{
|
{
|
||||||
QString initialPath = QDir::currentPath() + "/untitled.xml";
|
QString initialPath = QDir::currentPath() + "/untitled.xml";
|
||||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save"),
|
QString filename = QFileDialog::getSaveFileName(this,
|
||||||
|
tr("Save"),
|
||||||
initialPath,
|
initialPath,
|
||||||
tr("%1 Files (*.xml)")
|
tr("%1 Files (*.xml)").arg(QString("Mapnik definition")));
|
||||||
.arg(QString("Mapnik definition")));
|
|
||||||
if (!filename.isEmpty())
|
if (!filename.isEmpty())
|
||||||
{
|
{
|
||||||
std::cout << "saving " << filename.toStdString() << std::endl;
|
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::auto_cpu_timer t(std::clog, "loading map took: ");
|
||||||
mapnik::load_map(*map, filename.toStdString());
|
mapnik::load_map(*map, filename.toStdString());
|
||||||
}
|
} catch (std::exception const& ex)
|
||||||
catch (std::exception const& ex)
|
|
||||||
{
|
{
|
||||||
std::cout << ex.what() << "\n";
|
std::cout << ex.what() << "\n";
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Exception caught in load_map\n";
|
std::cerr << "Exception caught in load_map\n";
|
||||||
}
|
}
|
||||||
|
@ -256,11 +248,11 @@ void MainWindow::export_as()
|
||||||
QByteArray fileFormat = action->data().toByteArray();
|
QByteArray fileFormat = action->data().toByteArray();
|
||||||
QString initialPath = QDir::currentPath() + "/map." + fileFormat;
|
QString initialPath = QDir::currentPath() + "/map." + fileFormat;
|
||||||
|
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"),
|
QString fileName = QFileDialog::getSaveFileName(
|
||||||
|
this,
|
||||||
|
tr("Export As"),
|
||||||
initialPath,
|
initialPath,
|
||||||
tr("%1 Files (*.%2);;All Files (*)")
|
tr("%1 Files (*.%2);;All Files (*)").arg(QString(fileFormat.toUpper())).arg(QString(fileFormat)));
|
||||||
.arg(QString(fileFormat.toUpper()))
|
|
||||||
.arg(QString(fileFormat)));
|
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
QPixmap const& pix = mapWidget_->pixmap();
|
QPixmap const& pix = mapWidget_->pixmap();
|
||||||
|
@ -270,7 +262,6 @@ void MainWindow::export_as()
|
||||||
|
|
||||||
void MainWindow::print()
|
void MainWindow::print()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Q_ASSERT(mapWidget_->pixmap());
|
// Q_ASSERT(mapWidget_->pixmap());
|
||||||
// QPrintDialog dialog(&printer, this);
|
// QPrintDialog dialog(&printer, this);
|
||||||
// if (dialog.exec()) {
|
// if (dialog.exec()) {
|
||||||
|
@ -411,8 +402,6 @@ void MainWindow::createToolBars()
|
||||||
fileToolBar->addAction(aboutAct);
|
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
|
try
|
||||||
|
@ -427,8 +416,8 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
||||||
mapWidget_->zoomToBox(default_extent_);
|
mapWidget_->zoomToBox(default_extent_);
|
||||||
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
|
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
|
||||||
}
|
}
|
||||||
}
|
} catch (...)
|
||||||
catch (...) {}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::set_scaling_factor(double scaling_factor)
|
void MainWindow::set_scaling_factor(double scaling_factor)
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAINWINDOW_HPP
|
#ifndef MAINWINDOW_HPP
|
||||||
#define MAINWINDOW_HPP
|
#define MAINWINDOW_HPP
|
||||||
|
|
||||||
|
@ -46,8 +45,10 @@ class MainWindow : public QMainWindow
|
||||||
virtual ~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);
|
void set_scaling_factor(double scaling_factor);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<mapnik::Map> get_map();
|
std::shared_ptr<mapnik::Map> get_map();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent* event);
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -65,6 +66,7 @@ public slots:
|
||||||
void pan_right();
|
void pan_right();
|
||||||
void pan_up();
|
void pan_up();
|
||||||
void pan_down();
|
void pan_down();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createActions();
|
void createActions();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
|
@ -112,5 +114,4 @@ private:
|
||||||
mapnik::box2d<double> default_extent_;
|
mapnik::box2d<double> default_extent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // MAINWINDOW_HPP
|
#endif // MAINWINDOW_HPP
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
@ -41,54 +40,38 @@
|
||||||
#include "mapwidget.hpp"
|
#include "mapwidget.hpp"
|
||||||
#include "info_dialog.hpp"
|
#include "info_dialog.hpp"
|
||||||
|
|
||||||
using mapnik::image_rgba8;
|
|
||||||
using mapnik::Map;
|
|
||||||
using mapnik::layer;
|
|
||||||
using mapnik::box2d;
|
using mapnik::box2d;
|
||||||
using mapnik::coord2d;
|
using mapnik::coord2d;
|
||||||
|
using mapnik::feature_kv_iterator;
|
||||||
using mapnik::feature_ptr;
|
using mapnik::feature_ptr;
|
||||||
using mapnik::view_transform;
|
using mapnik::image_rgba8;
|
||||||
|
using mapnik::layer;
|
||||||
|
using mapnik::Map;
|
||||||
using mapnik::projection;
|
using mapnik::projection;
|
||||||
using mapnik::scale_denominator;
|
using mapnik::scale_denominator;
|
||||||
using mapnik::feature_kv_iterator;
|
using mapnik::view_transform;
|
||||||
|
|
||||||
double scales [] = {279541132.014,
|
double scales[] = {279541132.014, 139770566.007, 69885283.0036, 34942641.5018, 17471320.7509,
|
||||||
139770566.007,
|
8735660.37545, 4367830.18772, 2183915.09386, 1091957.54693, 545978.773466,
|
||||||
69885283.0036,
|
272989.386733, 136494.693366, 68247.3466832, 34123.6733416, 17061.8366708,
|
||||||
34942641.5018,
|
8530.9183354, 4265.4591677, 2132.72958385, 1066.36479192, 533.182395962};
|
||||||
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)
|
MapWidget::MapWidget(QWidget* parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent)
|
||||||
map_(),
|
, map_()
|
||||||
selected_(1),
|
, selected_(1)
|
||||||
extent_(),
|
, extent_()
|
||||||
cur_tool_(ZoomToBox),
|
, cur_tool_(ZoomToBox)
|
||||||
start_x_(0),
|
, start_x_(0)
|
||||||
start_y_(0),
|
, start_y_(0)
|
||||||
end_x_(0),
|
, end_x_(0)
|
||||||
end_y_(0),
|
, end_y_(0)
|
||||||
drag_(false),
|
, drag_(false)
|
||||||
first_(true),
|
, first_(true)
|
||||||
pen_(QColor(0,0,255,96)),
|
, pen_(QColor(0, 0, 255, 96))
|
||||||
selectedLayer_(-1),
|
, selectedLayer_(-1)
|
||||||
scaling_factor_(1.0),
|
, scaling_factor_(1.0)
|
||||||
cur_renderer_(AGG)
|
, cur_renderer_(AGG)
|
||||||
{
|
{
|
||||||
pen_.setWidth(3);
|
pen_.setWidth(3);
|
||||||
pen_.setCapStyle(Qt::RoundCap);
|
pen_.setCapStyle(Qt::RoundCap);
|
||||||
|
@ -162,10 +145,12 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
||||||
|
|
||||||
for (unsigned index = 0; index < map_->layer_count(); ++index)
|
for (unsigned index = 0; index < map_->layer_count(); ++index)
|
||||||
{
|
{
|
||||||
if (int(index) != selectedLayer_) continue;
|
if (int(index) != selectedLayer_)
|
||||||
|
continue;
|
||||||
|
|
||||||
layer& layer = map_->layers()[index];
|
layer& layer = map_->layers()[index];
|
||||||
if (!layer.visible(scale_denom)) continue;
|
if (!layer.visible(scale_denom))
|
||||||
|
continue;
|
||||||
std::string name = layer.name();
|
std::string name = layer.name();
|
||||||
double x = e->x();
|
double x = e->x();
|
||||||
double y = e->y();
|
double y = e->y();
|
||||||
|
@ -231,10 +216,9 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove annotation layer
|
// remove annotation layer
|
||||||
map_->layers().erase(remove_if(map_->layers().begin(),
|
map_->layers().erase(
|
||||||
map_->layers().end(),
|
remove_if(map_->layers().begin(), map_->layers().end(), bind(&layer::name, _1) == "*annotations*"),
|
||||||
bind(&layer::name,_1) == "*annotations*")
|
map_->layers().end());
|
||||||
, map_->layers().end());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,7 +318,8 @@ void MapWidget::wheelEvent(QWheelEvent* e)
|
||||||
void MapWidget::keyPressEvent(QKeyEvent* e)
|
void MapWidget::keyPressEvent(QKeyEvent* e)
|
||||||
{
|
{
|
||||||
std::cout << "key pressed:" << e->key() << "\n";
|
std::cout << "key pressed:" << e->key() << "\n";
|
||||||
switch (e->key()) {
|
switch (e->key())
|
||||||
|
{
|
||||||
case Qt::Key_Minus:
|
case Qt::Key_Minus:
|
||||||
zoomOut();
|
zoomOut();
|
||||||
break;
|
break;
|
||||||
|
@ -387,8 +372,6 @@ void MapWidget::keyPressEvent(QKeyEvent *e)
|
||||||
default:
|
default:
|
||||||
QWidget::keyPressEvent(e);
|
QWidget::keyPressEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
||||||
|
@ -472,7 +455,6 @@ void MapWidget::panRight()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MapWidget::zoomToLevel(int level)
|
void MapWidget::zoomToLevel(int level)
|
||||||
{
|
{
|
||||||
if (map_ && level >= 0 && level < 19)
|
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)
|
catch (std::exception const& ex)
|
||||||
{
|
{
|
||||||
std::cerr << "exception: " << ex.what() << std::endl;
|
std::cerr << "exception: " << ex.what() << std::endl;
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown exception caught!\n";
|
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;
|
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
|
// FIXME
|
||||||
|
@ -567,9 +546,12 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||||
|
|
||||||
void MapWidget::updateRenderer(QString const& txt)
|
void MapWidget::updateRenderer(QString const& txt)
|
||||||
{
|
{
|
||||||
if (txt == "AGG") cur_renderer_ = AGG;
|
if (txt == "AGG")
|
||||||
else if (txt == "Cairo") cur_renderer_ = Cairo;
|
cur_renderer_ = AGG;
|
||||||
else if (txt == "Grid") cur_renderer_ = Grid;
|
else if (txt == "Cairo")
|
||||||
|
cur_renderer_ = Cairo;
|
||||||
|
else if (txt == "Grid")
|
||||||
|
cur_renderer_ = Grid;
|
||||||
std::cerr << "Update renderer called" << std::endl;
|
std::cerr << "Update renderer called" << std::endl;
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
|
@ -620,8 +602,7 @@ void MapWidget::updateMap()
|
||||||
update();
|
update();
|
||||||
// emit signal to interested widgets
|
// emit signal to interested widgets
|
||||||
emit mapViewChanged();
|
emit mapViewChanged();
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown exception caught!\n";
|
std::cerr << "Unknown exception caught!\n";
|
||||||
}
|
}
|
||||||
|
@ -638,7 +619,6 @@ void MapWidget::setMap(std::shared_ptr<Map> map)
|
||||||
map_ = map;
|
map_ = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MapWidget::layerSelected(int index)
|
void MapWidget::layerSelected(int index)
|
||||||
{
|
{
|
||||||
selectedLayer_ = index;
|
selectedLayer_ = index;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAP_WIDGET_HPP
|
#ifndef MAP_WIDGET_HPP
|
||||||
#define MAP_WIDGET_HPP
|
#define MAP_WIDGET_HPP
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
#ifndef Q_MOC_RUN
|
#ifndef Q_MOC_RUN
|
||||||
#include <mapnik/map.hpp>
|
#include <mapnik/map.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,19 +38,13 @@ class MapWidget : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum eTool
|
enum eTool {
|
||||||
{
|
|
||||||
ZoomToBox = 1,
|
ZoomToBox = 1,
|
||||||
Pan,
|
Pan,
|
||||||
Info,
|
Info,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eRenderer
|
enum eRenderer { AGG, Cairo, Grid };
|
||||||
{
|
|
||||||
AGG,
|
|
||||||
Cairo,
|
|
||||||
Grid
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<mapnik::Map> map_;
|
std::shared_ptr<mapnik::Map> map_;
|
||||||
|
@ -70,6 +62,7 @@ private:
|
||||||
int selectedLayer_;
|
int selectedLayer_;
|
||||||
double scaling_factor_;
|
double scaling_factor_;
|
||||||
eRenderer cur_renderer_;
|
eRenderer cur_renderer_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapWidget(QWidget* parent = 0);
|
MapWidget(QWidget* parent = 0);
|
||||||
void setTool(eTool tool);
|
void setTool(eTool tool);
|
||||||
|
@ -93,6 +86,7 @@ public slots:
|
||||||
void updateScaleFactor(double scale_factor);
|
void updateScaleFactor(double scale_factor);
|
||||||
signals:
|
signals:
|
||||||
void mapViewChanged();
|
void mapViewChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* ev);
|
void paintEvent(QPaintEvent* ev);
|
||||||
void resizeEvent(QResizeEvent* ev);
|
void resizeEvent(QResizeEvent* ev);
|
||||||
|
@ -101,10 +95,7 @@ protected:
|
||||||
void mouseReleaseEvent(QMouseEvent* e);
|
void mouseReleaseEvent(QMouseEvent* e);
|
||||||
void wheelEvent(QWheelEvent* e);
|
void wheelEvent(QWheelEvent* e);
|
||||||
void keyPressEvent(QKeyEvent* e);
|
void keyPressEvent(QKeyEvent* e);
|
||||||
void export_to_file(unsigned width,
|
void export_to_file(unsigned width, unsigned height, std::string const& filename, std::string const& type);
|
||||||
unsigned height,
|
|
||||||
std::string const& filename,
|
|
||||||
std::string const& type);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAP_WIDGET_HPP
|
#endif // MAP_WIDGET_HPP
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "styles_model.hpp"
|
#include "styles_model.hpp"
|
||||||
#include <mapnik/config.hpp>
|
#include <mapnik/config.hpp>
|
||||||
#include <mapnik/util/variant.hpp>
|
#include <mapnik/util/variant.hpp>
|
||||||
|
@ -48,19 +47,14 @@ class node : private mapnik::util::noncopyable
|
||||||
struct wrap : public node_base
|
struct wrap : public node_base
|
||||||
{
|
{
|
||||||
wrap(T const& obj)
|
wrap(T const& obj)
|
||||||
: obj_(obj) {}
|
: obj_(obj)
|
||||||
|
{}
|
||||||
|
|
||||||
~wrap() {}
|
~wrap() {}
|
||||||
|
|
||||||
QString name () const
|
QString name() const { return obj_.name(); }
|
||||||
{
|
|
||||||
return obj_.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return obj_.icon(); }
|
||||||
{
|
|
||||||
return obj_.icon();
|
|
||||||
}
|
|
||||||
|
|
||||||
T obj_;
|
T obj_;
|
||||||
};
|
};
|
||||||
|
@ -68,34 +62,19 @@ class node : private mapnik::util::noncopyable
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
node(T const& obj, node* parent = 0)
|
node(T const& obj, node* parent = 0)
|
||||||
: impl_(new wrap<T>(obj)),
|
: impl_(new wrap<T>(obj))
|
||||||
parent_(parent)
|
, parent_(parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QString name() const
|
QString name() const { return impl_->name(); }
|
||||||
{
|
|
||||||
return impl_->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return impl_->icon(); }
|
||||||
{
|
|
||||||
return impl_->icon();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned num_children() const
|
unsigned num_children() const { return children_.count(); }
|
||||||
{
|
|
||||||
return children_.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
node * child(unsigned row) const
|
node* child(unsigned row) const { return children_.value(row); }
|
||||||
{
|
|
||||||
return children_.value(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
node * parent() const
|
node* parent() const { return parent_; }
|
||||||
{
|
|
||||||
return parent_;
|
|
||||||
}
|
|
||||||
|
|
||||||
node* add_child(node* child)
|
node* add_child(node* child)
|
||||||
{
|
{
|
||||||
|
@ -110,10 +89,7 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~node()
|
~node() { qDeleteAll(children_); }
|
||||||
{
|
|
||||||
qDeleteAll(children_);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::unique_ptr<node_base> impl_;
|
const std::unique_ptr<node_base> impl_;
|
||||||
|
@ -121,7 +97,6 @@ private:
|
||||||
node* parent_;
|
node* parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct symbolizer_info
|
struct symbolizer_info
|
||||||
{
|
{
|
||||||
QString operator()(mapnik::point_symbolizer const& sym) const
|
QString operator()(mapnik::point_symbolizer const& sym) const
|
||||||
|
@ -239,7 +214,8 @@ class symbolizer_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
symbolizer_node(mapnik::symbolizer const& sym)
|
symbolizer_node(mapnik::symbolizer const& sym)
|
||||||
: sym_(sym) {}
|
: sym_(sym)
|
||||||
|
{}
|
||||||
~symbolizer_node() {}
|
~symbolizer_node() {}
|
||||||
|
|
||||||
QString name() const
|
QString name() const
|
||||||
|
@ -259,8 +235,9 @@ class rule_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
rule_node(QString name, mapnik::rule const& r)
|
rule_node(QString name, mapnik::rule const& r)
|
||||||
: name_(name),
|
: name_(name)
|
||||||
rule_(r) {}
|
, rule_(r)
|
||||||
|
{}
|
||||||
~rule_node() {}
|
~rule_node() {}
|
||||||
QString name() const
|
QString name() const
|
||||||
{
|
{
|
||||||
|
@ -268,10 +245,7 @@ public:
|
||||||
return QString(mapnik::to_expression_string(*filter).c_str());
|
return QString(mapnik::to_expression_string(*filter).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return QIcon(":/images/filter.png"); }
|
||||||
{
|
|
||||||
return QIcon(":/images/filter.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString name_;
|
QString name_;
|
||||||
|
@ -282,20 +256,15 @@ class style_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
style_node(QString name, mapnik::feature_type_style const& style)
|
style_node(QString name, mapnik::feature_type_style const& style)
|
||||||
: name_(name),
|
: name_(name)
|
||||||
style_(style) {}
|
, style_(style)
|
||||||
|
{}
|
||||||
|
|
||||||
~style_node() {}
|
~style_node() {}
|
||||||
|
|
||||||
QString name() const
|
QString name() const { return name_; }
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return QIcon(":/images/style.png"); }
|
||||||
{
|
|
||||||
return QIcon(":/images/style.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString name_;
|
QString name_;
|
||||||
|
@ -306,26 +275,21 @@ class map_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit map_node(std::shared_ptr<mapnik::Map> map)
|
explicit map_node(std::shared_ptr<mapnik::Map> map)
|
||||||
: map_(map) {}
|
: map_(map)
|
||||||
|
{}
|
||||||
~map_node() {}
|
~map_node() {}
|
||||||
|
|
||||||
QString name() const
|
QString name() const { return QString("Map"); }
|
||||||
{
|
|
||||||
return QString("Map");
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return QIcon(":/images/map.png"); }
|
||||||
{
|
|
||||||
return QIcon(":/images/map.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<mapnik::Map> map_;
|
std::shared_ptr<mapnik::Map> map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
|
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
|
||||||
: QAbstractItemModel(parent),
|
: QAbstractItemModel(parent)
|
||||||
root_(new node(map_node(map)))
|
, root_(new node(map_node(map)))
|
||||||
{
|
{
|
||||||
using style_type = std::map<std::string, mapnik::feature_type_style>;
|
using style_type = std::map<std::string, mapnik::feature_type_style>;
|
||||||
style_type const& styles = map->styles();
|
style_type const& styles = map->styles();
|
||||||
|
@ -382,7 +346,8 @@ int StyleModel::rowCount(QModelIndex const& parent) const
|
||||||
{
|
{
|
||||||
// qDebug("rowCount");
|
// qDebug("rowCount");
|
||||||
node* parent_node;
|
node* parent_node;
|
||||||
if (parent.column() > 0) return 0;
|
if (parent.column() > 0)
|
||||||
|
return 0;
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
parent_node = root_.get();
|
parent_node = root_.get();
|
||||||
else
|
else
|
||||||
|
@ -405,7 +370,6 @@ QVariant StyleModel::data(const QModelIndex & index, int role) const
|
||||||
{
|
{
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
{
|
{
|
||||||
|
|
||||||
return QVariant(cur_node->name());
|
return QVariant(cur_node->name());
|
||||||
}
|
}
|
||||||
else if (role == Qt::DecorationRole)
|
else if (role == Qt::DecorationRole)
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef STYLE_MODEL_HPP
|
#ifndef STYLE_MODEL_HPP
|
||||||
#define STYLE_MODEL_HPP
|
#define STYLE_MODEL_HPP
|
||||||
|
|
||||||
|
@ -27,8 +26,6 @@
|
||||||
#include <mapnik/map.hpp>
|
#include <mapnik/map.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class node;
|
class node;
|
||||||
class StyleModel : public QAbstractItemModel
|
class StyleModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
|
@ -42,6 +39,7 @@ class StyleModel : public QAbstractItemModel
|
||||||
int rowCount(QModelIndex const& parent = QModelIndex()) const;
|
int rowCount(QModelIndex const& parent = QModelIndex()) const;
|
||||||
int columnCount(QModelIndex const& parent = QModelIndex()) const;
|
int columnCount(QModelIndex const& parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// std::shared_ptr<mapnik::Map> map_;
|
// std::shared_ptr<mapnik::Map> map_;
|
||||||
const std::unique_ptr<node> root_;
|
const std::unique_ptr<node> root_;
|
||||||
|
|
Loading…
Reference in a new issue