+ move layer info logic into dialog ctor

This commit is contained in:
Artem Pavlenko 2010-03-10 17:08:37 +00:00
parent 556df8a751
commit 8661d60f43
4 changed files with 89 additions and 81 deletions

View file

@ -1,60 +1,69 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>Artem Pavlenko</author>
<class>LayerInfoDialog</class>
<widget class="QDialog" name="LayerInfoDialog" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<widget class="QDialog" name="LayerInfoDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>446</width>
<height>344</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Layer Info</string>
</property>
<property name="sizeGripEnabled" >
<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" >
<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" >
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="layerNameEdit" />
<widget class="QLineEdit" name="layerNameEdit"/>
</item>
</layout>
</item>
<item row="1" column="0" >
<layout class="QHBoxLayout" >
<item row="1" column="0">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="stylesLabel" >
<property name="text" >
<widget class="QLabel" name="stylesLabel">
<property name="text">
<string>Styles:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox" />
<widget class="QComboBox" name="comboBox"/>
</item>
</layout>
</item>
<item row="2" column="0" >
<widget class="QTableWidget" name="tableWidget" />
<item row="2" column="0">
<widget class="QTableWidget" name="tableWidget"/>
</item>
<item row="3" column="0" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<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 name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
@ -62,7 +71,6 @@
</item>
</layout>
</widget>
<includes/>
<resources/>
<connections>
<connection>
@ -71,11 +79,11 @@
<receiver>LayerInfoDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
@ -87,11 +95,11 @@
<receiver>LayerInfoDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>

View file

@ -20,22 +20,48 @@
#include "layer_info_dialog.hpp"
layer_info_dialog::layer_info_dialog(QVector<QPair<QString,QString> > const& info, QWidget *parent)
// mapnik
#include <mapnik/layer.hpp>
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
//ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
//ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
ui.tableWidget->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.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)
{
mapnik::parameters ps = ds->params();
ui.tableWidget->setRowCount(ps.size());
ui.tableWidget->setColumnCount(2);
mapnik::parameters::const_iterator pos;
int index=0;
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)
{
QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str()));
ui.tableWidget->setItem(index,0,keyItem);
ui.tableWidget->setItem(index,1,valueItem);
++index;
}
}
}
}
Ui::LayerInfoDialog& layer_info_dialog::getUI()

View file

@ -25,12 +25,17 @@
#include "ui_layer_info.h"
#include <QDialog>
namespace mapnik
{
struct layer;
}
class layer_info_dialog : public QDialog
{
Q_OBJECT
public:
layer_info_dialog(QVector<QPair<QString,QString> > const& params,QWidget * parent = 0);
Ui::LayerInfoDialog& getUI();
layer_info_dialog(mapnik::layer& l, QWidget * parent = 0);
Ui::LayerInfoDialog& getUI();
private:
Ui::LayerInfoDialog ui;
};

View file

@ -77,46 +77,15 @@ void LayerTab::layerInfo2(QModelIndex const& index)
{
qDebug("LayerInfo id = %d",index.row());
QVector<QPair<QString,QString> > params;
QVector<QString> style_names;
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();
layer_info_dialog dlg(*layer,this);
dlg.exec();
}
}