- small comment fix in viewer
This commit is contained in:
parent
154fb73d84
commit
2e23eee24c
19 changed files with 203 additions and 184 deletions
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -35,6 +36,6 @@ info_dialog::info_dialog(QVector<QPair<QString,QString> > const& info, QWidget *
|
|||
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);
|
||||
ui.tableWidget->setItem(i,1,valueItem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -28,15 +29,15 @@ 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"));
|
||||
|
||||
|
||||
// Layer name
|
||||
ui.layerNameEdit->setText(QString(lay.name().c_str()));
|
||||
|
||||
// Named Styles : TODO!!!
|
||||
|
||||
|
||||
// Datasource
|
||||
mapnik::datasource_ptr ds = lay.datasource();
|
||||
if (ds)
|
||||
|
@ -57,10 +58,10 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
|||
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);
|
||||
ui.tableWidget->setItem(index,1,valueItem);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -37,7 +38,7 @@ void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||
else
|
||||
painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
|
||||
|
||||
|
||||
|
||||
painter->drawRoundRect(option.rect,4,4);
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -32,11 +33,11 @@ class QPainter;
|
|||
class LayerDelegate : public QAbstractItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
LayerDelegate(QObject *parent = 0);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index ) const;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -61,7 +62,7 @@ QVariant LayerListModel::data(QModelIndex const& index,int role) const
|
|||
{
|
||||
if (map_->layers().at(index.row()).isActive())
|
||||
return QVariant(Qt::Checked);
|
||||
else
|
||||
else
|
||||
return QVariant(Qt::Unchecked);
|
||||
}
|
||||
else
|
||||
|
@ -75,7 +76,7 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
|||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
|
||||
if (orientation == Qt::Horizontal)
|
||||
return QString("TODO Column %1").arg(section);
|
||||
else
|
||||
|
@ -86,22 +87,22 @@ bool LayerListModel::setData(const QModelIndex &index,
|
|||
const QVariant &value, int role)
|
||||
{
|
||||
if (!map_) return false;
|
||||
|
||||
|
||||
if (index.isValid() && role == Qt::CheckStateRole)
|
||||
{
|
||||
int status = value.toInt();
|
||||
int status = value.toInt();
|
||||
std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
|
||||
layers.at(index.row()).setActive(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;
|
||||
return flags;
|
||||
|
@ -121,4 +122,4 @@ boost::optional<mapnik::layer&> LayerListModel::map_layer(int i)
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -36,10 +37,10 @@ class LayerListModel : public QAbstractListModel
|
|||
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;
|
||||
int role = Qt::DisplayRole) const;
|
||||
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);
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -41,7 +42,7 @@ LayerTab::LayerTab(QWidget* parent)
|
|||
|
||||
void LayerTab::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QListView::paintEvent(e);
|
||||
QListView::paintEvent(e);
|
||||
}
|
||||
|
||||
void LayerTab::dataChanged(const QModelIndex &topLeft,
|
||||
|
@ -55,7 +56,7 @@ void LayerTab::dataChanged(const QModelIndex &topLeft,
|
|||
void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &)
|
||||
{
|
||||
QModelIndexList list = selected.indexes();
|
||||
if (list.size() != 0)
|
||||
if (list.size() != 0)
|
||||
{
|
||||
std::cout << "SELECTED LAYER ->" << list[0].row() << "\n";
|
||||
emit layerSelected(list[0].row());
|
||||
|
@ -69,7 +70,7 @@ void LayerTab::layerInfo()
|
|||
if (indexes.size() > 0)
|
||||
{
|
||||
qDebug("id = %d",indexes[0].row());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +82,7 @@ void LayerTab::layerInfo2(QModelIndex const& index)
|
|||
unsigned i = index.row();
|
||||
LayerListModel * model = static_cast<LayerListModel*>(this->model());
|
||||
boost::optional<mapnik::layer&> layer = model->map_layer(i);
|
||||
|
||||
|
||||
if (layer)
|
||||
{
|
||||
layer_info_dialog dlg(*layer,this);
|
||||
|
@ -91,7 +92,7 @@ void LayerTab::layerInfo2(QModelIndex const& index)
|
|||
|
||||
StyleTab::StyleTab(QWidget*)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void StyleTab::contextMenuEvent(QContextMenuEvent * event )
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -33,10 +34,10 @@ class LayerTab : public QListView
|
|||
void paintEvent(QPaintEvent *e);
|
||||
signals:
|
||||
void update_mapwidget();
|
||||
void layerSelected(int) const;
|
||||
void layerSelected(int) const;
|
||||
public slots:
|
||||
void layerInfo();
|
||||
void layerInfo2(QModelIndex const&);
|
||||
void layerInfo();
|
||||
void layerInfo2(QModelIndex const&);
|
||||
protected slots:
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
void selectionChanged(const QItemSelection & selected, const QItemSelection &);
|
||||
|
@ -51,4 +52,4 @@ protected:
|
|||
void contextMenuEvent(QContextMenuEvent * event );
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -34,13 +35,13 @@ int main( int argc, char **argv )
|
|||
{
|
||||
using mapnik::datasource_cache;
|
||||
using mapnik::freetype_engine;
|
||||
|
||||
|
||||
QCoreApplication::setOrganizationName("Mapnik");
|
||||
QCoreApplication::setOrganizationDomain("mapnik.org");
|
||||
QCoreApplication::setApplicationName("Viewer");
|
||||
|
||||
|
||||
QSettings settings("viewer.ini",QSettings::IniFormat);
|
||||
|
||||
|
||||
// register input plug-ins
|
||||
QString plugins_dir = settings.value("mapnik/plugins_dir",
|
||||
QVariant("/usr/local/lib/mapnik2/input/")).toString();
|
||||
|
@ -54,8 +55,8 @@ int main( int argc, char **argv )
|
|||
freetype_engine::register_fonts(font_dir.toStdString());
|
||||
}
|
||||
settings.endArray();
|
||||
|
||||
QApplication app( argc, argv );
|
||||
|
||||
QApplication app( argc, argv );
|
||||
MainWindow window;
|
||||
window.show();
|
||||
if (argc > 1) window.open(argv[1]);
|
||||
|
@ -82,5 +83,5 @@ int main( int argc, char **argv )
|
|||
double scaling_factor = QString(argv[3]).toDouble(&ok);
|
||||
if (ok) window.set_scaling_factor(scaling_factor);
|
||||
}
|
||||
return app.exec();
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -47,42 +48,42 @@
|
|||
MainWindow::MainWindow()
|
||||
: filename_(),
|
||||
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
|
||||
{
|
||||
{
|
||||
mapWidget_ = new MapWidget(this);
|
||||
QSplitter *splitter = new QSplitter(this);
|
||||
QSplitter *splitter = new QSplitter(this);
|
||||
QTabWidget *tabWidget=new QTabWidget;
|
||||
layerTab_ = new LayerTab;
|
||||
layerTab_->setFocusPolicy(Qt::NoFocus);
|
||||
layerTab_->setIconSize(QSize(16,16));
|
||||
|
||||
//LayerDelegate *delegate = new LayerDelegate(this);
|
||||
|
||||
//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"));
|
||||
|
||||
// Styles tab
|
||||
styleTab_ = new StyleTab;
|
||||
tabWidget->addTab(styleTab_,tr("Styles"));
|
||||
tabWidget->addTab(styleTab_,tr("Styles"));
|
||||
splitter->addWidget(tabWidget);
|
||||
splitter->addWidget(mapWidget_);
|
||||
QList<int> list;
|
||||
list.push_back(200);
|
||||
list.push_back(600);
|
||||
splitter->setSizes(list);
|
||||
|
||||
|
||||
mapWidget_->setFocusPolicy(Qt::StrongFocus);
|
||||
mapWidget_->setFocus();
|
||||
|
||||
|
||||
//setCentralWidget(mapWidget_);
|
||||
setCentralWidget(splitter);
|
||||
createActions();
|
||||
createMenus();
|
||||
createToolBars();
|
||||
createContextMenu();
|
||||
|
||||
|
||||
setWindowTitle(tr("Mapnik Viewer"));
|
||||
status=new QStatusBar(this);
|
||||
status->showMessage(tr(""));
|
||||
|
@ -91,11 +92,11 @@ MainWindow::MainWindow()
|
|||
|
||||
//connect mapview to layerlist
|
||||
connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update()));
|
||||
// slider
|
||||
// slider
|
||||
connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int)));
|
||||
//
|
||||
//
|
||||
connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap()));
|
||||
connect(layerTab_,SIGNAL(layerSelected(int)),
|
||||
connect(layerTab_,SIGNAL(layerSelected(int)),
|
||||
mapWidget_,SLOT(layerSelected(int)));
|
||||
}
|
||||
|
||||
|
@ -128,21 +129,21 @@ void MainWindow::open(QString const& path)
|
|||
{
|
||||
filename_ = 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);
|
||||
|
@ -157,7 +158,7 @@ void MainWindow::save()
|
|||
initialPath,
|
||||
tr("%1 Files (*.xml)")
|
||||
.arg(QString("Mapnik definition")));
|
||||
if (!filename.isEmpty())
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
std::cout<<"saving "<< filename.toStdString() << std::endl;
|
||||
mapnik::save_map(*mapWidget_->getMap(),filename.toStdString());
|
||||
|
@ -166,16 +167,16 @@ void MainWindow::save()
|
|||
|
||||
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();
|
||||
boost::shared_ptr<mapnik::Map> map(new mapnik::Map(width,height));
|
||||
boost::shared_ptr<mapnik::Map> map(new mapnik::Map(width,height));
|
||||
mapWidget_->setMap(map);
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
mapnik::load_map(*map,filename.toStdString());
|
||||
}
|
||||
catch (mapnik::config_error & ex)
|
||||
catch (mapnik::config_error & ex)
|
||||
{
|
||||
std::cout << ex.what() << "\n";
|
||||
}
|
||||
|
@ -195,7 +196,7 @@ void MainWindow::zoom_to_box()
|
|||
|
||||
void MainWindow::pan()
|
||||
{
|
||||
mapWidget_->setTool(MapWidget::Pan);
|
||||
mapWidget_->setTool(MapWidget::Pan);
|
||||
}
|
||||
|
||||
void MainWindow::info()
|
||||
|
@ -240,7 +241,7 @@ void MainWindow::export_as()
|
|||
tr("%1 Files (*.%2);;All Files (*)")
|
||||
.arg(QString(fileFormat.toUpper()))
|
||||
.arg(QString(fileFormat)));
|
||||
if (!fileName.isEmpty())
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
QPixmap const& pix = mapWidget_->pixmap();
|
||||
pix.save(fileName);
|
||||
|
@ -248,8 +249,8 @@ void MainWindow::export_as()
|
|||
}
|
||||
|
||||
void MainWindow::print()
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
//Q_ASSERT(mapWidget_->pixmap());
|
||||
//QPrintDialog dialog(&printer, this);
|
||||
//if (dialog.exec()) {
|
||||
|
@ -264,31 +265,31 @@ void MainWindow::print()
|
|||
}
|
||||
|
||||
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);
|
||||
connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all()));
|
||||
|
||||
|
||||
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->setCheckable(true);
|
||||
connect(panAct, SIGNAL(triggered()), this, SLOT(pan()));
|
||||
|
||||
|
||||
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->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);
|
||||
|
@ -302,27 +303,27 @@ void MainWindow::createActions()
|
|||
connect(panUpAct, SIGNAL(triggered()), this, SLOT(pan_up()));
|
||||
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);
|
||||
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&)));
|
||||
foreach (QByteArray format, QImageWriter::supportedImageFormats())
|
||||
foreach (QByteArray format, QImageWriter::supportedImageFormats())
|
||||
{
|
||||
QString text = tr("%1...").arg(QString(format).toUpper());
|
||||
|
||||
|
||||
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->setShortcut(tr("Ctrl+E"));
|
||||
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
||||
|
||||
|
||||
exitAct = new QAction(tr("E&xit"), this);
|
||||
exitAct->setShortcut(tr("Ctrl+Q"));
|
||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
@ -335,8 +336,8 @@ void MainWindow::createMenus()
|
|||
{
|
||||
exportMenu = new QMenu(tr("&Export As"), this);
|
||||
foreach (QAction *action, exportAsActs)
|
||||
exportMenu->addAction(action);
|
||||
|
||||
exportMenu->addAction(action);
|
||||
|
||||
fileMenu = new QMenu(tr("&File"),this);
|
||||
fileMenu->addAction(openAct);
|
||||
fileMenu->addAction(saveAct);
|
||||
|
@ -345,7 +346,7 @@ void MainWindow::createMenus()
|
|||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(exitAct);
|
||||
menuBar()->addMenu(fileMenu);
|
||||
|
||||
|
||||
helpMenu = new QMenu(tr("&Help"), this);
|
||||
helpMenu->addAction(aboutAct);
|
||||
menuBar()->addMenu(helpMenu);
|
||||
|
@ -377,10 +378,10 @@ void MainWindow::createToolBars()
|
|||
|
||||
void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<mapnik::Map> map_ptr = mapWidget_->getMap();
|
||||
if (map_ptr)
|
||||
if (map_ptr)
|
||||
{
|
||||
mapnik::projection prj(map_ptr->srs());
|
||||
prj.forward(x0,y0);
|
||||
|
@ -401,7 +402,7 @@ void MainWindow::set_scaling_factor(double scaling_factor)
|
|||
void MainWindow::zoom_all()
|
||||
{
|
||||
boost::shared_ptr<mapnik::Map> map_ptr = mapWidget_->getMap();
|
||||
if (map_ptr)
|
||||
if (map_ptr)
|
||||
{
|
||||
map_ptr->zoom_all();
|
||||
mapnik::box2d<double> const& ext = map_ptr->get_current_extent();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -67,7 +68,7 @@ private:
|
|||
void createToolBars();
|
||||
void createContextMenu();
|
||||
void load_map_file(QString const& filename);
|
||||
|
||||
|
||||
|
||||
QString currentPath;
|
||||
QString filename_;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -63,7 +64,7 @@ double scales [] = {279541132.014,
|
|||
1066.36479192,
|
||||
533.182395962};
|
||||
|
||||
MapWidget::MapWidget(QWidget *parent)
|
||||
MapWidget::MapWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
map_(),
|
||||
selected_(1),
|
||||
|
@ -90,9 +91,9 @@ void MapWidget::setTool(eTool tool)
|
|||
}
|
||||
|
||||
void MapWidget::paintEvent(QPaintEvent*)
|
||||
{
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
|
||||
if (drag_)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox)
|
||||
|
@ -119,7 +120,7 @@ void MapWidget::paintEvent(QPaintEvent*)
|
|||
}
|
||||
painter.end();
|
||||
}
|
||||
|
||||
|
||||
void MapWidget::resizeEvent(QResizeEvent * ev)
|
||||
{
|
||||
if (map_)
|
||||
|
@ -128,10 +129,10 @@ void MapWidget::resizeEvent(QResizeEvent * ev)
|
|||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MapWidget::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button()==Qt::LeftButton)
|
||||
if (e->button()==Qt::LeftButton)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
||||
{
|
||||
|
@ -142,17 +143,17 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
|||
else if (cur_tool_==Info)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
{
|
||||
QVector<QPair<QString,QString> > info;
|
||||
|
||||
|
||||
projection map_proj(map_->srs()); // map projection
|
||||
double scale_denom = scale_denominator(*map_,map_proj.is_geographic());
|
||||
CoordTransform t(map_->width(),map_->height(),map_->get_current_extent());
|
||||
|
||||
|
||||
for (unsigned index = 0; index < map_->layer_count();++index)
|
||||
{
|
||||
if (int(index) != selectedLayer_) continue;
|
||||
|
||||
|
||||
layer & layer = map_->layers()[index];
|
||||
if (!layer.isVisible(scale_denom)) continue;
|
||||
std::string name = layer.name();
|
||||
|
@ -163,11 +164,11 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
|||
mapnik::proj_transform prj_trans(map_proj,layer_proj);
|
||||
//std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
|
||||
mapnik::featureset_ptr fs = map_->query_map_point(index,x,y);
|
||||
|
||||
|
||||
if (fs)
|
||||
{
|
||||
feature_ptr feat = fs->next();
|
||||
if (feat)
|
||||
if (feat)
|
||||
{
|
||||
std::map<std::string,mapnik::value> const& props = feat->props();
|
||||
std::map<std::string,mapnik::value>::const_iterator itr=props.begin();
|
||||
|
@ -180,10 +181,10 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
|||
}
|
||||
}
|
||||
typedef mapnik::coord_transform2<mapnik::CoordTransform,mapnik::geometry_type> path_type;
|
||||
|
||||
|
||||
for (unsigned i=0; i<feat->num_geometries();++i)
|
||||
{
|
||||
mapnik::geometry_type & geom = feat->get_geometry(i);
|
||||
mapnik::geometry_type & geom = feat->get_geometry(i);
|
||||
path_type path(t,geom,prj_trans);
|
||||
if (geom.num_points() > 0)
|
||||
{
|
||||
|
@ -208,7 +209,7 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (info.size() > 0)
|
||||
{
|
||||
info_dialog info_dlg(info,this);
|
||||
|
@ -216,34 +217,34 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button()==Qt::LeftButton)
|
||||
if (e->button()==Qt::LeftButton)
|
||||
{
|
||||
end_x_ = e->x();
|
||||
end_y_ = e->y();
|
||||
|
@ -252,7 +253,7 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
|||
drag_=false;
|
||||
if (map_)
|
||||
{
|
||||
CoordTransform t(map_->width(),map_->height(),map_->get_current_extent());
|
||||
CoordTransform t(map_->width(),map_->height(),map_->get_current_extent());
|
||||
box2d<double> box = t.backward(box2d<double>(start_x_,start_y_,end_x_,end_y_));
|
||||
map_->zoom_to_box(box);
|
||||
updateMap();
|
||||
|
@ -267,7 +268,7 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
|||
int cy = int(0.5 * map_->height());
|
||||
int dx = end_x_ - start_x_;
|
||||
int dy = end_y_ - start_y_;
|
||||
map_->pan(cx - dx ,cy - dy);
|
||||
map_->pan(cx - dx ,cy - dy);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
@ -275,10 +276,10 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
|||
}
|
||||
|
||||
|
||||
void MapWidget::keyPressEvent(QKeyEvent *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;
|
||||
|
@ -294,10 +295,10 @@ void MapWidget::keyPressEvent(QKeyEvent *e)
|
|||
break;
|
||||
case Qt::Key_Down:
|
||||
panDown();
|
||||
break;
|
||||
break;
|
||||
case Qt::Key_Left:
|
||||
panLeft();
|
||||
break;
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
panRight();
|
||||
break;
|
||||
|
@ -309,7 +310,7 @@ void MapWidget::keyPressEvent(QKeyEvent *e)
|
|||
break;
|
||||
case 51:
|
||||
zoomToLevel(12);
|
||||
break;
|
||||
break;
|
||||
case 52:
|
||||
zoomToLevel(13);
|
||||
break;
|
||||
|
@ -318,7 +319,7 @@ void MapWidget::keyPressEvent(QKeyEvent *e)
|
|||
break;
|
||||
case 54:
|
||||
zoomToLevel(15);
|
||||
break;
|
||||
break;
|
||||
case 55:
|
||||
zoomToLevel(16);
|
||||
break;
|
||||
|
@ -327,12 +328,12 @@ void MapWidget::keyPressEvent(QKeyEvent *e)
|
|||
break;
|
||||
case 57:
|
||||
zoomToLevel(18);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
QWidget::keyPressEvent(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
||||
|
@ -344,7 +345,7 @@ void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
|||
}
|
||||
}
|
||||
|
||||
void MapWidget::defaultView()
|
||||
void MapWidget::defaultView()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
|
@ -354,7 +355,7 @@ void MapWidget::defaultView()
|
|||
}
|
||||
}
|
||||
|
||||
void MapWidget::zoomIn()
|
||||
void MapWidget::zoomIn()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
|
@ -363,7 +364,7 @@ void MapWidget::zoomIn()
|
|||
}
|
||||
}
|
||||
|
||||
void MapWidget::zoomOut()
|
||||
void MapWidget::zoomOut()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
|
@ -406,12 +407,12 @@ void MapWidget::panLeft()
|
|||
}
|
||||
|
||||
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));
|
||||
map_->pan(int(cx + cx * 0.25),int(cy));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
@ -425,11 +426,11 @@ void MapWidget::zoomToLevel(int level)
|
|||
std::cerr << "scale denominator = " << scale_denom << "\n";
|
||||
mapnik::box2d<double> ext = map_->get_current_extent();
|
||||
double width = static_cast<double>(map_->width());
|
||||
double height= static_cast<double>(map_->height());
|
||||
double height= static_cast<double>(map_->height());
|
||||
mapnik::coord2d pt = ext.center();
|
||||
|
||||
double res = scale_denom * 0.00028;
|
||||
|
||||
|
||||
mapnik::box2d<double> box(pt.x - 0.5 * width * res,
|
||||
pt.y - 0.5 * height*res,
|
||||
pt.x + 0.5 * width * res,
|
||||
|
@ -439,37 +440,37 @@ void MapWidget::zoomToLevel(int level)
|
|||
}
|
||||
}
|
||||
|
||||
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_32 image(width,height);
|
||||
//agg_renderer renderer(map,image);
|
||||
//renderer.apply();
|
||||
//image.saveToFile(filename,type);
|
||||
}
|
||||
|
||||
|
||||
void MapWidget::set_scaling_factor(double scaling_factor)
|
||||
{
|
||||
scaling_factor_ = scaling_factor;
|
||||
}
|
||||
|
||||
void MapWidget::updateMap()
|
||||
{
|
||||
void MapWidget::updateMap()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
unsigned width=map_->width();
|
||||
unsigned height=map_->height();
|
||||
|
||||
|
||||
image_32 buf(width,height);
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
mapnik::agg_renderer<image_32> ren(*map_,buf,scaling_factor_);
|
||||
ren.apply();
|
||||
|
||||
|
||||
QImage image((uchar*)buf.raw_data(),width,height,QImage::Format_ARGB32);
|
||||
pix_=QPixmap::fromImage(image.rgbSwapped());
|
||||
projection prj(map_->srs()); // map projection
|
||||
|
||||
|
||||
box2d<double> ext = map_->get_current_extent();
|
||||
double x0 = ext.minx();
|
||||
double y0 = ext.miny();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -32,19 +33,19 @@
|
|||
#include <boost/scoped_ptr.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
|
||||
class MapWidget : public QWidget
|
||||
class MapWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum eTool
|
||||
|
||||
public:
|
||||
enum eTool
|
||||
{
|
||||
ZoomToBox = 1,
|
||||
Pan,
|
||||
Info,
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
boost::shared_ptr<mapnik::Map> map_;
|
||||
int selected_;
|
||||
QPixmap pix_;
|
||||
|
@ -64,7 +65,7 @@ public:
|
|||
void setTool(eTool tool);
|
||||
boost::shared_ptr<mapnik::Map> getMap();
|
||||
inline QPixmap const& pixmap() const { return pix_;}
|
||||
void setMap(boost::shared_ptr<mapnik::Map> map);
|
||||
void setMap(boost::shared_ptr<mapnik::Map> map);
|
||||
void defaultView();
|
||||
void zoomToBox(mapnik::box2d<double> const& box);
|
||||
void zoomIn();
|
||||
|
@ -80,7 +81,7 @@ public slots:
|
|||
void layerSelected(int);
|
||||
signals:
|
||||
void mapViewChanged();
|
||||
protected:
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* ev);
|
||||
void resizeEvent(QResizeEvent* ev);
|
||||
void mousePressEvent(QMouseEvent* e);
|
||||
|
@ -89,8 +90,8 @@ protected:
|
|||
void keyPressEvent(QKeyEvent *e);
|
||||
void export_to_file(unsigned width,
|
||||
unsigned height,
|
||||
std::string const& filename,
|
||||
std::string const& type);
|
||||
std::string const& filename,
|
||||
std::string const& type);
|
||||
};
|
||||
|
||||
#endif // MAP_WIDGET_HPP
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -38,60 +39,60 @@ class node : private boost::noncopyable
|
|||
virtual QIcon icon() const=0;
|
||||
virtual ~node_base() {}
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct wrap : public node_base
|
||||
{
|
||||
wrap(T const& obj)
|
||||
: obj_(obj) {}
|
||||
|
||||
|
||||
~wrap() {}
|
||||
|
||||
|
||||
QString name () const
|
||||
{
|
||||
return obj_.name();
|
||||
}
|
||||
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return obj_.icon();
|
||||
}
|
||||
|
||||
|
||||
T obj_;
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
node ( T const& obj, node * parent=0)
|
||||
: impl_(new wrap<T>(obj)),
|
||||
parent_(parent)
|
||||
{}
|
||||
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return impl_->name();
|
||||
}
|
||||
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return impl_->icon();
|
||||
}
|
||||
|
||||
|
||||
unsigned num_children() const
|
||||
{
|
||||
return children_.count();
|
||||
}
|
||||
|
||||
|
||||
node * child(unsigned row) const
|
||||
{
|
||||
return children_.value(row);
|
||||
}
|
||||
|
||||
|
||||
node * parent() const
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
|
||||
node * add_child(node * child)
|
||||
{
|
||||
children_.push_back(child);
|
||||
|
@ -104,12 +105,12 @@ public:
|
|||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
~node()
|
||||
|
||||
~node()
|
||||
{
|
||||
qDeleteAll(children_);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
boost::scoped_ptr<node_base> impl_;
|
||||
QList<node*> children_;
|
||||
|
@ -124,7 +125,7 @@ struct symbolizer_info : public boost::static_visitor<QString>
|
|||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PointSymbolizer");
|
||||
}
|
||||
|
||||
|
||||
QString operator() (mapnik::line_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
|
@ -148,19 +149,19 @@ struct symbolizer_info : public boost::static_visitor<QString>
|
|||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PolygonSymbolizer");
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("ShieldSymbolizer");
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
QString operator() (T const& ) const
|
||||
{
|
||||
|
@ -200,14 +201,14 @@ struct symbolizer_icon : public boost::static_visitor<QIcon>
|
|||
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 = strk.get_color();
|
||||
QPen pen(QColor(col.red(),col.green(),col.blue(),col.alpha()));
|
||||
pen.setWidth(strk.get_width());
|
||||
painter.setPen(pen);
|
||||
painter.drawLine(0,7,47,7);
|
||||
//painter.drawLine(7,15,12,0);
|
||||
//painter.drawLine(12,0,8,15);
|
||||
//painter.drawLine(12,0,8,15);
|
||||
return QIcon(pix);
|
||||
}
|
||||
|
||||
|
@ -224,13 +225,13 @@ public:
|
|||
symbolizer_node(mapnik::symbolizer const & sym)
|
||||
: sym_(sym) {}
|
||||
~symbolizer_node(){}
|
||||
|
||||
QString name() const
|
||||
|
||||
QString name() const
|
||||
{
|
||||
//return QString("Symbolizer:fixme");
|
||||
return boost::apply_visitor(symbolizer_info(),sym_);
|
||||
}
|
||||
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return boost::apply_visitor(symbolizer_icon(),sym_);//QIcon(":/images/filter.png");
|
||||
|
@ -248,15 +249,15 @@ public:
|
|||
QString name() const
|
||||
{
|
||||
mapnik::expression_ptr filter = rule_.get_filter();
|
||||
|
||||
|
||||
return QString(mapnik::to_expression_string(*filter).c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/filter.png");
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
QString name_;
|
||||
mapnik::rule const& rule_;
|
||||
|
@ -268,19 +269,19 @@ public:
|
|||
style_node(QString name, mapnik::feature_type_style const& style)
|
||||
: name_(name),
|
||||
style_(style) {}
|
||||
|
||||
|
||||
~style_node() {}
|
||||
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/style.png");
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
QString name_;
|
||||
mapnik::feature_type_style const& style_;
|
||||
|
@ -292,26 +293,26 @@ public:
|
|||
explicit map_node(boost::shared_ptr<mapnik::Map> map)
|
||||
: map_(map) {}
|
||||
~map_node() {}
|
||||
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return QString("Map");
|
||||
}
|
||||
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/map.png");
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
boost::shared_ptr<mapnik::Map> map_;
|
||||
};
|
||||
|
||||
StyleModel::StyleModel(boost::shared_ptr<mapnik::Map> map, QObject * parent)
|
||||
: QAbstractItemModel(parent),
|
||||
root_(new node(map_node(map)))
|
||||
root_(new node(map_node(map)))
|
||||
{
|
||||
typedef std::map<std::string,mapnik::feature_type_style> style_type;
|
||||
typedef std::map<std::string,mapnik::feature_type_style> style_type;
|
||||
style_type const & styles = map->styles();
|
||||
style_type::const_iterator itr = styles.begin();
|
||||
style_type::const_iterator end = styles.end();
|
||||
|
@ -329,22 +330,22 @@ StyleModel::StyleModel(boost::shared_ptr<mapnik::Map> map, QObject * parent)
|
|||
rule_n->add_child(new node(symbolizer_node(*itr3),rule_n));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StyleModel::~StyleModel() {}
|
||||
|
||||
// interface
|
||||
// interface
|
||||
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;
|
||||
|
||||
|
||||
if (!parent.isValid())
|
||||
parent_node = root_.get();
|
||||
else
|
||||
parent_node = static_cast<node*>(parent.internalPointer());
|
||||
|
||||
|
||||
node * child_node = parent_node->child(row);
|
||||
if (child_node)
|
||||
return createIndex(row,col,child_node);
|
||||
|
@ -358,7 +359,7 @@ QModelIndex StyleModel::parent (QModelIndex const& index) const
|
|||
node * parent_node = child_node->parent();
|
||||
if (parent_node == root_.get())
|
||||
return QModelIndex();
|
||||
|
||||
|
||||
return createIndex(parent_node->row(),0,parent_node);
|
||||
}
|
||||
|
||||
|
@ -389,7 +390,7 @@ QVariant StyleModel::data(const QModelIndex & index, int role) const
|
|||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
|
||||
|
||||
return QVariant(cur_node->name());
|
||||
}
|
||||
else if ( role == Qt::DecorationRole)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* Mapnik is free software; you can redistribute it and/or
|
||||
|
@ -32,11 +33,11 @@ class StyleModel : public QAbstractItemModel
|
|||
public:
|
||||
StyleModel(boost::shared_ptr<mapnik::Map> map, QObject * parent=0);
|
||||
~StyleModel();
|
||||
// interface
|
||||
// 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;
|
||||
int columnCount( QModelIndex const& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
private:
|
||||
//boost::shared_ptr<mapnik::Map> map_;
|
||||
|
|
Loading…
Add table
Reference in a new issue