added layer_info dialog

improved style_model
This commit is contained in:
Artem Pavlenko 2007-08-13 09:13:58 +00:00
parent 59977745a0
commit b36a802107
11 changed files with 309 additions and 7 deletions

View file

@ -0,0 +1,101 @@
<ui version="4.0" >
<author>Artem Pavlenko</author>
<class>LayerInfoDialog</class>
<widget class="QDialog" name="LayerInfoDialog" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" >
<string>Layer Info</string>
</property>
<property name="sizeGripEnabled" >
<bool>false</bool>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="nameLabel" >
<property name="text" >
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="layerNameEdit" />
</item>
</layout>
</item>
<item row="1" column="0" >
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="stylesLabel" >
<property name="text" >
<string>Styles:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox" />
</item>
</layout>
</item>
<item row="2" column="0" >
<widget class="QTableWidget" name="tableWidget" />
</item>
<item row="3" column="0" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<includes/>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LayerInfoDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LayerInfoDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -0,0 +1,45 @@
/* This file is part of Mapnik (c++ mapping toolkit)
* Copyright (C) 2007 Artem Pavlenko
*
* Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//$Id$
#include "layer_info_dialog.hpp"
layer_info_dialog::layer_info_dialog(QVector<QPair<QString,QString> > const& info, QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
//ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
//ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
ui.tableWidget->setRowCount(info.size());
ui.tableWidget->setColumnCount(2);
for (int i=0;i<info.size();++i)
{
QTableWidgetItem *keyItem = new QTableWidgetItem(info[i].first);
QTableWidgetItem *valueItem = new QTableWidgetItem(info[i].second);
ui.tableWidget->setItem(i,0,keyItem);
ui.tableWidget->setItem(i,1,valueItem);
}
}
Ui::LayerInfoDialog& layer_info_dialog::getUI()
{
return ui;
}

View file

@ -0,0 +1,39 @@
/* This file is part of Mapnik (c++ mapping toolkit)
* Copyright (C) 2007 Artem Pavlenko
*
* Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//$Id$
#ifndef LAYER_INFO_DIALOG_HPP
#define LAYER_INFO_DIALOG_HPP
#include "ui_layer_info.h"
#include <QDialog>
class layer_info_dialog : public QDialog
{
Q_OBJECT
public:
layer_info_dialog(QVector<QPair<QString,QString> > const& params,QWidget * parent = 0);
Ui::LayerInfoDialog& getUI();
private:
Ui::LayerInfoDialog ui;
};
#endif //LAYER_INFO_DIALOG_HPP

View file

@ -107,6 +107,17 @@ Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const
return flags;
}
boost::optional<mapnik::Layer&> LayerListModel::map_layer(int i)
{
if (map_)
{
std::vector<mapnik::Layer> & layers = const_cast<std::vector<mapnik::Layer>& >(map_->layers());
if (i < layers.size())
return boost::optional<mapnik::Layer&>(layers[i]);
}
return boost::optional<mapnik::Layer&>();
}

View file

@ -26,8 +26,7 @@
#include <QModelIndex>
#include <QVariant>
#include <mapnik/map.hpp>
//using namespace mapnik;
#include <boost/optional/optional.hpp>
class LayerListModel : public QAbstractListModel
{
@ -41,6 +40,7 @@ class LayerListModel : public QAbstractListModel
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);
private:
boost::shared_ptr<mapnik::Map> map_;

View file

@ -30,6 +30,8 @@
#include <qrubberband.h>
#include <qdebug.h>
#include <iostream>
#include "layerlistmodel.hpp"
#include "layer_info_dialog.hpp"
using namespace std;
@ -50,6 +52,64 @@ void LayerTab::dataChanged(const QModelIndex &topLeft,
emit update_mapwidget();
}
void LayerTab::layerInfo()
{
qDebug("Layer info");
QModelIndexList indexes = selectedIndexes();
if (indexes.size() > 0)
{
qDebug("id = %d",indexes[0].row());
}
}
void LayerTab::layerInfo2(QModelIndex const& index)
{
qDebug("LayerInfo id = %d",index.row());
QVector<QPair<QString,QString> > params;
unsigned i = index.row();
LayerListModel * model = static_cast<LayerListModel*>(this->model());
boost::optional<mapnik::Layer&> layer = model->map_layer(i);
if (layer)
{
mapnik::datasource_ptr ds = (*layer).datasource();
if (ds)
{
mapnik::parameters ps = ds->params();
//mapnik::parameters::extract_iterator_type itr = ps.extract_begin();
//mapnik::parameters::extract_iterator_type end = ps.extract_end();
//for (;itr != end;++itr)
//{
//if (itr->second)
// {
/// params.push_back(QPair<QString,QString>(itr->first.c_str(),itr->first.c_str()));
// }
//}
mapnik::parameters::const_iterator pos;
for (pos = ps.begin();pos != ps.end();++pos)
{
boost::optional<std::string> result;
boost::apply_visitor(mapnik::value_extractor_visitor<std::string>(result),pos->second);
if (result)
{
params.push_back(QPair<QString,QString>(pos->first.c_str(),(*result).c_str()));
}
}
}
layer_info_dialog dlg(params,this);
dlg.getUI().layerNameEdit->setText(QString((*layer).name().c_str()));
dlg.exec();
}
}
StyleTab::StyleTab(QWidget*)
{

View file

@ -32,7 +32,10 @@ class LayerTab : public QListView
LayerTab(QWidget* parent=0);
void paintEvent(QPaintEvent *e);
signals:
void update_mapwidget();
void update_mapwidget();
public slots:
void layerInfo();
void layerInfo2(QModelIndex const&);
protected slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
};

View file

@ -109,6 +109,7 @@ void MainWindow::createContextMenu()
{
layerTab_->setContextMenuPolicy(Qt::ActionsContextMenu);
layerTab_->addAction(openAct);
layerTab_->addAction(layerInfo);
}
void MainWindow::open(QString const& path)
@ -299,6 +300,9 @@ void MainWindow::createActions()
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())
{
QString text = tr("%1...").arg(QString(format).toUpper());

View file

@ -97,6 +97,7 @@ public slots:
QAction *panUpAct;
QAction *panDownAct;
QAction *reloadAct;
QAction *layerInfo;
//toolbars
QToolBar *fileToolBar;
QToolBar *editToolBar;

View file

@ -23,6 +23,8 @@
#include <boost/utility.hpp>
#include <QList>
#include <QIcon>
#include <QPainter>
#include <QPixmap>
class node : private boost::noncopyable
{
@ -110,6 +112,7 @@ class node : private boost::noncopyable
node * parent_;
};
struct symbolizer_info : public boost::static_visitor<QString>
{
QString operator() (mapnik::point_symbolizer const& sym) const
@ -154,6 +157,37 @@ struct symbolizer_info : public boost::static_visitor<QString>
}
};
struct symbolizer_icon : public boost::static_visitor<QIcon>
{
QIcon operator() (mapnik::polygon_symbolizer const& sym) const
{
QPixmap pix(16,16);
QPainter painter(&pix);
mapnik::Color fill = sym.get_fill();
QBrush brush(QColor(fill.red(),fill.green(),fill.blue(),fill.alpha()));
painter.fillRect(0, 0, 16, 16, brush);
return QIcon(pix);
}
QIcon operator() (mapnik::point_symbolizer const& sym) const
{
boost::shared_ptr<mapnik::ImageData32> symbol = sym.get_data();
if (symbol)
{
QImage image(symbol->getBytes(),symbol->width(),symbol->height(),QImage::Format_ARGB32);
QPixmap pix = QPixmap::fromImage(image.rgbSwapped());
return QIcon(pix);
}
return QIcon();
}
template <typename T>
QIcon operator() (T const& ) const
{
return QIcon (":/images/filter.png");
}
};
class symbolizer_node
{
public:
@ -169,7 +203,7 @@ class symbolizer_node
QIcon icon() const
{
return QIcon(":/images/filter.png");
return boost::apply_visitor(symbolizer_icon(),sym_);//QIcon(":/images/filter.png");
}
mapnik::symbolizer const& sym_;
};

View file

@ -16,7 +16,9 @@ unix:LIBS = -L/usr/local/lib -lmapnik -lfreetype
# Input
CONFIG += qt debug_and_release
FORMS += forms/about.ui forms/info.ui
FORMS += forms/about.ui \
forms/info.ui \
forms/layer_info.ui
HEADERS += mainwindow.hpp \
mapwidget.hpp \
@ -26,7 +28,8 @@ HEADERS += mainwindow.hpp \
styles_model.hpp
HEADERS += about_dialog.hpp \
info_dialog.hpp
info_dialog.hpp \
layer_info_dialog.hpp
SOURCES += main.cpp \
mainwindow.cpp \
@ -37,6 +40,7 @@ SOURCES += main.cpp \
styles_model.cpp
SOURCES += about_dialog.cpp \
info_dialog.cpp
info_dialog.cpp \
layer_info_dialog.cpp
RESOURCES += mapnik_viewer.qrc