29 #include "../../../color/ColorBar.h" 30 #include "../../../common/Globals.h" 31 #include "../../../common/STLUtils.h" 32 #include "../../../core/translator/Translator.h" 33 #include "../../../dataaccess/dataset/DataSet.h" 34 #include "../../../dataaccess/datasource/DataSourceManager.h" 35 #include "../../../dataaccess/query_h.h" 36 #include "../../../dataaccess/utils/Utils.h" 37 #include "../../../maptools/GroupingAlgorithms.h" 38 #include "../../../maptools/Utils.h" 39 #include "../../../se.h" 40 #include "../../../se/SymbolizerColorFinder.h" 41 #include "../../../se/Utils.h" 42 #include "../../widgets/colorbar/ColorBar.h" 43 #include "../../widgets/colorbar/ColorCatalogWidget.h" 44 #include "../../widgets/se/LineSymbolizerWidget.h" 45 #include "../../widgets/se/PointSymbolizerWidget.h" 46 #include "../../widgets/se/PolygonSymbolizerWidget.h" 47 #include "../../widgets/se/SymbologyPreview.h" 48 #include "ui_TimeViewerEditLegendDialog.h" 51 #include <QDialogButtonBox> 52 #include <QFileDialog> 53 #include <QMessageBox> 57 #include <boost/algorithm/string.hpp> 58 #include <boost/filesystem.hpp> 59 #include <boost/lexical_cast.hpp> 60 #include <boost/property_tree/json_parser.hpp> 62 #define NO_TITLE "No Value" 73 m_ui->m_okPushButton->setEnabled(
false);
75 m_ui->m_tableWidget->resizeColumnsToContents();
77 QGridLayout* layout =
new QGridLayout(
m_ui->m_colorBarWidget);
78 layout->setContentsMargins(0, 0, 0, 0);
104 m_ui->m_layerNameLineEdit->setText(
m_layer->getTitle().c_str());
111 std::unique_ptr<te::map::LayerSchema> dsType(
m_layer->getSchema());
113 m_ui->m_attributeComboBox->clear();
115 for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
143 std::unique_ptr<te::map::LayerSchema> dsType(
m_layer->getSchema());
147 for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
149 if(dsType->getProperty(t)->getName() == attrName)
156 std::unique_ptr<te::da::DataSet>
ds(
m_layer->getData());
158 ds->moveBeforeFirst();
160 while(
ds->moveNext())
163 vec.push_back(
ds->getAsString(idx));
171 int prec =
m_ui->m_precisionSpinBox->value();
173 std::string attr =
m_ui->m_attributeComboBox->currentText().toUtf8().data();
174 int attrIdx =
m_ui->m_attributeComboBox->currentIndex();
175 int attrType =
m_ui->m_attributeComboBox->itemData(attrIdx).toInt();
186 std::vector<std::string> vec;
199 m_ui->m_okPushButton->setEnabled(
true);
211 m_ui->m_precisionSpinBox->setMinimum(1);
213 m_ui->m_precisionSpinBox->setValue(6);
214 m_ui->m_precisionSpinBox->setSingleStep(1);
217 #if(QT_VERSION >= 0x050000) 218 m_ui->m_tableWidget->horizontalHeader()->setSectionResizeMode(
219 QHeaderView::Stretch);
221 m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
235 std::vector<te::color::RGBAColor> colorVec;
237 if(meanTitle.empty())
246 for(
size_t t = 0; t <
m_legend.size(); ++t)
248 std::string ruleName = *
m_legend[t]->getName();
250 if(ruleName != meanTitle)
265 for(
size_t t = 0; t < lowerColorVec.size(); ++t)
266 colorVec.push_back(lowerColorVec[t]);
268 colorVec.push_back(meanColor);
270 for(
size_t t = 0; t < upperColorVec.size(); ++t)
271 colorVec.push_back(upperColorVec[t]);
274 if(colorVec.size() !=
m_legend.size())
279 for(
size_t t = 0; t < colorVec.size(); ++t)
281 std::vector<te::se::Symbolizer*> symbVec;
285 symbVec.push_back(s);
287 m_legend[t]->setSymbolizers(symbVec);
301 disconnect(
m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
303 m_ui->m_tableWidget->setRowCount(0);
306 list.append(tr(
"Symbol"));
307 list.append(tr(
"Title"));
308 list.append(tr(
"Value"));
310 m_ui->m_tableWidget->setColumnCount(3);
311 m_ui->m_tableWidget->setHorizontalHeaderLabels(list);
331 std::size_t count = 0;
333 for(std::size_t t = 0; t <
m_legend.size(); ++t)
342 int newrow =
m_ui->m_tableWidget->rowCount();
343 m_ui->m_tableWidget->insertRow(newrow);
347 const std::vector<te::se::Symbolizer*>& ss = ruleItem->
getSymbolizers();
350 QTableWidgetItem* item =
new QTableWidgetItem(icon,
"");
351 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
352 m_ui->m_tableWidget->setItem(newrow, 0, item);
357 QTableWidgetItem* item =
new QTableWidgetItem( QString::fromUtf8((*ruleItem->
getName()).c_str()));
358 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
359 m_ui->m_tableWidget->setItem(newrow, 1, item);
364 if(count != 0 && count !=
m_legend.size() - 1)
366 double pos = (1. / (
m_legend.size() - 1)) * count;
384 std::string ruleName = *ruleItem->
getName();
392 QTableWidgetItem* item =
new QTableWidgetItem(QString::fromUtf8(value.c_str()));
393 item->setFlags(Qt::ItemIsEnabled);
394 m_ui->m_tableWidget->setItem(newrow, 2, item);
408 #if(QT_VERSION >= 0x050000) 409 m_ui->m_tableWidget->horizontalHeader()->setSectionResizeMode(
410 QHeaderView::Stretch);
412 m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
415 connect(
m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
447 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"LEG (*.leg *.LEG);;"), 0,QFileDialog::DontConfirmOverwrite);
454 int rowCount =
m_ui->m_tableWidget->rowCount();
462 boost::property_tree::ptree pt;
463 boost::property_tree::ptree legend;
465 std::string attrName =
m_ui->m_attributeComboBox->currentText().toUtf8().data();
466 std::string precision =
m_ui->m_precisionSpinBox->text().toUtf8().data();
468 legend.add(
"Attribute", attrName);
469 legend.add(
"Precision", precision);
471 boost::property_tree::ptree items;
473 for(
int i = 0; i <
m_ui->m_tableWidget->rowCount(); ++i)
475 std::string className =
m_ui->m_tableWidget->item(i, 0)->text().toUtf8().data();
476 std::string r =
m_ui->m_tableWidget->item(i, 1)->text().toUtf8().data();
477 std::string g =
m_ui->m_tableWidget->item(i, 2)->text().toUtf8().data();
478 std::string
b =
m_ui->m_tableWidget->item(i, 3)->text().toUtf8().data();
480 boost::property_tree::ptree item;
481 item.add(
"ClassName", className);
483 item.add(
"Green", g);
486 items.add_child(
"Item", item);
489 legend.add_child(
"Items", items);
491 pt.add_child(
"Legend", legend);
493 boost::property_tree::write_json(path, pt);
498 int size =
m_ui->m_tableWidget->rowCount();
500 for(
int i = 0; i < size; ++i)
502 QTableWidgetItem* item =
m_ui->m_tableWidget->item(i, 5);
503 item->setCheckState(Qt::Checked);
509 int size =
m_ui->m_tableWidget->rowCount();
511 for(
int i = 0; i < size; ++i)
513 QTableWidgetItem* item =
m_ui->m_tableWidget->item(i, 5);
514 item->setCheckState(Qt::Unchecked);
520 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open..."), QString(), tr(
"LEG (*.leg *.LEG);;"), 0,
521 QFileDialog::DontConfirmOverwrite);
523 if(fileName.isEmpty())
526 m_ui->m_tableWidget->setRowCount(0);
528 boost::property_tree::ptree pt;
529 boost::property_tree::json_parser::read_json(fileName.toUtf8().data(), pt);
531 boost::property_tree::ptree legend = pt.get_child(
"Legend");
533 std::string attrName = legend.get<std::string>(
"Attribute");
534 std::string precision = legend.get<std::string>(
"Precision");
536 m_ui->m_attributeComboBox->setCurrentIndex(
m_ui->m_attributeComboBox->findText(attrName.c_str()));
537 m_ui->m_precisionSpinBox->setValue(boost::lexical_cast<double>(precision));
539 std::vector<std::vector<std::string> > items;
541 for(boost::property_tree::ptree::value_type& v : legend.get_child(
"Items"))
543 std::vector<std::string> item;
544 item.push_back(v.second.get<std::string>(
"ClassName"));
545 item.push_back(v.second.get<std::string>(
"Red"));
546 item.push_back(v.second.get<std::string>(
"Green"));
547 item.push_back(v.second.get<std::string>(
"Blue"));
549 items.push_back(item);
552 m_ui->m_tableWidget->setRowCount(items.size());
554 for(std::size_t i = 0; i < items.size(); ++i)
556 m_ui->m_tableWidget->setItem(i, 0,
new QTableWidgetItem(items[i][0].c_str()));
557 m_ui->m_tableWidget->setItem(i, 1,
new QTableWidgetItem(items[i][1].c_str()));
558 m_ui->m_tableWidget->setItem(i, 2,
new QTableWidgetItem(items[i][2].c_str()));
559 m_ui->m_tableWidget->setItem(i, 3,
new QTableWidgetItem(items[i][3].c_str()));
563 color.setRgb(boost::lexical_cast<int>(items[i][1]),
564 boost::lexical_cast<int>(items[i][2]),
565 boost::lexical_cast<int>(items[i][3]));
570 p.fillRect(0, 0, 12, 24, color);
571 p.fillRect(12, 0, 12, 24, color);
572 p.setBrush(Qt::transparent);
574 p.drawRect(0, 0, 23, 23);
578 QTableWidgetItem* item =
new QTableWidgetItem(icon,
"");
580 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
581 m_ui->m_tableWidget->setItem(i, 4, item);
584 QTableWidgetItem* item =
new QTableWidgetItem();
585 item->setCheckState(Qt::Checked);
586 m_ui->m_tableWidget->setItem(i, 5, item);
void onUnselectAllPushButtonClicked()
te::qt::widgets::ColorCatalogWidget * m_colorBar
Widget used to pick a color.
~TimeViewerEditLegendDialog()
Destructor.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void updateUi(bool loadColorBar=false)
te::color::ColorBar * m_cb
Terralib color bar objetc.
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
void saveLegend(const std::string &path)
void onCancelPushButtonClicked()
A Symbolizer describes how a feature is to appear on a map.
void getDataAsString(std::vector< std::string > &vec, const std::string &attrName, int &nullValues)
TEMAPEXPORT void GroupingByUniqueValues(std::string attrName, std::vector< std::string > &inputValues, int dataType, std::vector< te::se::Rule * > &rules, int precision)
It groups the values using the unique value algorithm.
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer.
const std::vector< te::color::RGBAColor > & getUpperMeanSlices(const int &n)
A dialog used to edit legend.
static te::dt::Date ds(2010, 01, 01)
const te::fe::Filter * getFilter() const
void onSelectAllPushButtonClicked()
It models a property definition.
void buildSymbolizer(std::string meanTitle="")
void onApplyPushButtonClicked()
const std::vector< te::color::RGBAColor > & getLowerMeanSlices(const int &n)
const std::vector< se::Rule * > & getRules() const
A filter is any valid predicate expression.
const te::color::RGBAColor & getMeanSlice()
A dialog used to edit legend.
A Symbology Enconding visitor that finds a color given a symbolizer element. If you want to use this ...
const std::vector< te::color::RGBAColor > & getSlices(const int &n)
It generates color bar.
const std::vector< Symbolizer * > & getSymbolizers() const
void onOkPushButtonClicked()
void onLoadPushButtonClicked()
int getType() const
It returns the property data type.
void find(const te::se::Symbolizer *symbolizer)
It find the color based on given symbolizer.
void addColor(const RGBAColor &color, const double &pos)
It adds a color in the color bar.
void okPushButtonClicked()
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
It models the concept of color bar.
void onSavePushButtonClicked()
std::unique_ptr< Ui::TimeViewerEditLegendDialog > m_ui
Dialog form.
TimeViewerEditLegendDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic fill dialog which is a child of parent, with widget flags set to f...
te::map::AbstractLayerPtr m_layer
TerraLib layer auto ptr.
te::color::RGBAColor getColor()
Get the color.
std::vector< te::se::Rule * > m_legend
Rule items.
void setLayers(te::map::AbstractLayerPtr layer)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
const std::string & getName() const
It returns the property name.
TEFEEXPORT void GetFilterUniqueValue(const te::fe::Filter *filter, std::string &value)
const std::string * getName() const