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" 
   37 #include <QtCore/QString> 
   38 #include <QtGui/QColor> 
   39 #include <QtGui/QMessageBox> 
   40 #include <QtGui/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());
 
  117     double maxValue = 0.0;
 
  118     std::size_t precision = 5;
 
  121     const std::vector<std::string>& properties = chart->
getProperties();
 
  124     std::auto_ptr<te::da::DataSet> dataset(m_layer->getData());
 
  126     while(dataset->moveNext())
 
  128       for(std::size_t i = 0; i < properties.size(); ++i)
 
  130         QString qvalue(dataset->getAsString(properties[i], precision).c_str());
 
  132         double value = qvalue.toDouble();
 
  142   m_layer->setChart(chart);
 
  151   int type = (int)chart->
getType();
 
  153   for(
int i = 0; i < m_ui->m_typeComboBox->count(); ++i)
 
  155     int t = m_ui->m_typeComboBox->itemData(i).toInt();
 
  159       m_ui->m_typeComboBox->setCurrentIndex(i);
 
  164   m_ui->m_sizeSpinBox->setValue((
int)chart->
getHeight());
 
  168   for(std::size_t t = 0; t < chart->
getProperties().size(); ++t)
 
  172     m_chartMap.insert(std::map<std::string, QColor>::value_type(value, c));
 
  181   m_ui->m_typeComboBox->clear();
 
  182   m_ui->m_typeComboBox->addItem(tr(
"Pie Chart"), QVariant(
te::map::Pie));
 
  183   m_ui->m_typeComboBox->addItem(tr(
"Bar Chart"), QVariant(
te::map::Bar));
 
  187   m_ui->m_addToolButton->setIcon(QIcon::fromTheme(
"list-add"));
 
  188   m_ui->m_removeToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
 
  193   m_ui->m_tableWidget->setRowCount(0);
 
  195   std::map<std::string, QColor>::iterator it = m_chartMap.begin();
 
  197   while(it != m_chartMap.end())
 
  199     int newrow = m_ui->m_tableWidget->rowCount();
 
  200     m_ui->m_tableWidget->insertRow(newrow);
 
  204     QTableWidgetItem* item = 
new QTableWidgetItem(icon, 
"");
 
  205     item->setFlags(Qt::ItemIsEnabled);
 
  206     m_ui->m_tableWidget->setItem(newrow, 0, item);
 
  209     QTableWidgetItem* itemAttr = 
new QTableWidgetItem(it->first.c_str());
 
  210     itemAttr->setFlags(Qt::ItemIsEnabled);
 
  211     m_ui->m_tableWidget->setItem(newrow, 1, itemAttr);
 
  219   std::string value = m_ui->m_attrComboBox->currentText().toStdString();
 
  221   std::map<std::string, QColor>::iterator it = m_chartMap.find(value);
 
  223   if(it != m_chartMap.end())
 
  225     QMessageBox::warning(
this, tr(
"Warning"), tr(
"Attribute already selected."));
 
  229   QColor c(rand() % 255,rand() % 255,rand() % 255);
 
  231   m_chartMap.insert(std::map<std::string, QColor>::value_type(value, c));
 
  238   if(m_ui->m_tableWidget->currentRow() == -1)
 
  241   std::string value = m_ui->m_tableWidget->item(m_ui->m_tableWidget->currentRow(), 1)->text().toStdString();
 
  243   std::map<std::string, QColor>::iterator it = m_chartMap.find(value);
 
  245   if(it != m_chartMap.end())
 
  246     m_chartMap.erase(it);
 
  256   std::string attr = m_ui->m_tableWidget->item(row, 1)->text().toStdString();
 
  258   std::map<std::string, QColor>::iterator it = m_chartMap.find(attr);
 
  260   if(it != m_chartMap.end())
 
  262     QColor c = QColorDialog::getColor(it->second, 
this);
 
  272   m_ui->m_attrComboBox->clear();
 
  274   std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
 
  276   for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
 
  290         m_ui->m_attrComboBox->addItem(p->
getName().c_str(), p->
getType());
 
TEQTWIDGETSEXPORT te::color::RGBAColor Convert2TerraLib(const QColor &color)
It converts a Qt Color to TerraLib Color. 
void onAddToolButtonClicked()
Function used when the user clicked over the add tool button. 
const te::color::RGBAColor & getContourColor() const 
bool buildChart()
Creates the te::map::Chart object using the interface parameters. 
std::size_t getContourWidth() const 
ChartType getType() const 
const std::string & getName() const 
It returns the property name. 
void initialize()
Internal method to initialize the widget (e.g.: color, combos, icons, etc.) 
void onItemClicked(int row, int column)
Function used when the user clicked over the table (color column). 
~ChartLayerWidget()
Destructor. 
TEQTWIDGETSEXPORT QPixmap CreatePixmapIcon(const int &size, const QColor &penColor, const QColor &brushColor, const int &contourSize)
It creates a pixmap to use as icon (to be used as legend icon). 
void setMaxValue(double value)
const std::vector< std::string > & getProperties() const 
void setHeight(std::size_t height)
void onRemoveToolButtonClicked()
Function used when the user clicked over the remove tool button. 
ChartType
The chart types. 
ColorPickerToolButton * m_colorPicker
The color picker used to customise the color of several chart parameters. 
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. 
void updateUi()
Updates the widget form based on internal fill element. 
ChartLayerWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic fill widget which is a child of parent, with widget flags set to f...
A widget used to build a chart. 
void setContourColor(const te::color::RGBAColor &color)
const te::color::RGBAColor & getColor(std::size_t i) const 
TEQTWIDGETSEXPORT QColor Convert2Qt(const te::color::RGBAColor &color)
It converts a TerraLib Color to Qt Color. 
It models a property definition. 
This class represents the informations needed to build map charts. 
void setLayer(te::map::AbstractLayerPtr layer)
Set a layer. 
Custom tool button used to pick a color. 
void setChart(te::map::Chart *chart)
Update the interface with the chart properties. 
int getType() const 
It returns the property data type. 
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::auto_ptr< Ui::ChartLayerWidgetForm > m_ui
Widget form. 
std::size_t getHeight() const 
void setContourWidth(std::size_t width)
void listAttributes()
List the layer attributes (from layer schema)