27 #include "../../../color/RGBAColor.h"
28 #include "../../../common/STLUtils.h"
29 #include "../../../maptools/Chart.h"
30 #include "../../../maptools/Enums.h"
31 #include "../utils/ColorPickerToolButton.h"
34 #include "ui_ChartLayerWidgetForm.h"
39 #include <QMessageBox>
40 #include <QPainterPath>
47 m_ui(new Ui::ChartLayerWidgetForm)
52 QGridLayout* layout =
new QGridLayout(
m_ui->m_contourColorWidget);
53 layout->setContentsMargins(0, 0, 0, 0);
63 connect(
m_ui->m_contourWidthSpinBox, SIGNAL(valueChanged(
int)),
this, SLOT(
updateUi()));
64 connect(
m_ui->m_tableWidget, SIGNAL(cellClicked(
int,
int)),
this, SLOT(
onItemClicked(
int,
int)));
84 if(m_chartMap.empty())
86 QMessageBox::warning(
this, tr(
"Warning"), tr(
"No attribute selected."));
91 int index = m_ui->m_typeComboBox->currentIndex();
92 int chartType = m_ui->m_typeComboBox->itemData(index).toInt();
95 std::vector<std::string> attrs;
96 std::vector<te::color::RGBAColor> colors;
98 std::map<std::string, QColor>::iterator it = m_chartMap.begin();
100 while(it != m_chartMap.end())
102 attrs.push_back(it->first);
110 chart->
setHeight((std::size_t)m_ui->m_sizeSpinBox->value());
111 chart->
setContourWidth((std::size_t)m_ui->m_contourWidthSpinBox->value());
118 double maxValue = 0.0;
119 std::size_t precision = 5;
122 const std::vector<std::string>& properties = chart->
getProperties();
125 std::auto_ptr<te::da::DataSet> dataset(m_layer->getData());
127 while(dataset->moveNext())
129 for(std::size_t i = 0; i < properties.size(); ++i)
131 QString qvalue(dataset->getAsString(properties[i], precision).c_str());
133 double value = qvalue.toDouble();
143 m_layer->setChart(chart);
152 int type = (int)chart->
getType();
154 for(
int i = 0; i < m_ui->m_typeComboBox->count(); ++i)
156 int t = m_ui->m_typeComboBox->itemData(i).toInt();
160 m_ui->m_typeComboBox->setCurrentIndex(i);
165 m_ui->m_sizeSpinBox->setValue((
int)chart->
getHeight());
170 for(std::size_t t = 0; t < chart->
getProperties().size(); ++t)
174 m_chartMap.insert(std::map<std::string, QColor>::value_type(value, c));
183 m_ui->m_typeComboBox->clear();
184 m_ui->m_typeComboBox->addItem(tr(
"Pie Chart"), QVariant(
te::map::Pie));
185 m_ui->m_typeComboBox->addItem(tr(
"Bar Chart"), QVariant(
te::map::Bar));
189 m_ui->m_addToolButton->setIcon(QIcon::fromTheme(
"list-add"));
190 m_ui->m_removeToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
195 m_ui->m_tableWidget->setRowCount(0);
197 std::map<std::string, QColor>::iterator it = m_chartMap.begin();
199 while(it != m_chartMap.end())
201 int newrow = m_ui->m_tableWidget->rowCount();
202 m_ui->m_tableWidget->insertRow(newrow);
206 QTableWidgetItem* item =
new QTableWidgetItem(icon,
"");
207 item->setFlags(Qt::ItemIsEnabled);
208 m_ui->m_tableWidget->setItem(newrow, 0, item);
211 QTableWidgetItem* itemAttr =
new QTableWidgetItem(it->first.c_str());
212 itemAttr->setFlags(Qt::ItemIsEnabled);
213 m_ui->m_tableWidget->setItem(newrow, 1, itemAttr);
221 std::string value = m_ui->m_attrComboBox->currentText().toStdString();
223 std::map<std::string, QColor>::iterator it = m_chartMap.find(value);
225 if(it != m_chartMap.end())
227 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Attribute already selected."));
231 QColor c(rand() % 255,rand() % 255,rand() % 255);
233 m_chartMap.insert(std::map<std::string, QColor>::value_type(value, c));
240 if(m_ui->m_tableWidget->currentRow() == -1)
243 std::string value = m_ui->m_tableWidget->item(m_ui->m_tableWidget->currentRow(), 1)->text().toStdString();
245 std::map<std::string, QColor>::iterator it = m_chartMap.find(value);
247 if(it != m_chartMap.end())
248 m_chartMap.erase(it);
258 std::string attr = m_ui->m_tableWidget->item(row, 1)->text().toStdString();
260 std::map<std::string, QColor>::iterator it = m_chartMap.find(attr);
262 if(it != m_chartMap.end())
264 QColor c = QColorDialog::getColor(it->second,
this);
274 m_ui->m_attrComboBox->clear();
276 std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
278 for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
292 m_ui->m_attrComboBox->addItem(p->
getName().c_str(), p->
getType());
ChartType
The chart types.
ChartType getType() const
const std::vector< std::string > & getProperties() const
void setContourColor(const te::color::RGBAColor &color)
void setHeight(std::size_t height)
It models a property definition.
void setAvoidConflicts(bool on)
const te::color::RGBAColor & getColor(std::size_t i) const
This class represents the informations needed to build map charts.
std::size_t getHeight() const
int getType() const
It returns the property data type.
std::size_t getContourWidth() const
const te::color::RGBAColor & getContourColor() const
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
bool getAvoidConflicts() const
void setMaxValue(double value)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void setContourWidth(std::size_t width)
const std::string & getName() const
It returns the property name.