27 #include "../../../color/ColorBar.h" 
   28 #include "../../../common/Globals.h" 
   29 #include "../../../common/STLUtils.h" 
   30 #include "../../../dataaccess/dataset/DataSet.h" 
   31 #include "../../../dataaccess/dataset/DataSetType.h" 
   32 #include "../../../dataaccess/utils/Utils.h" 
   33 #include "../../../geometry/GeometryProperty.h" 
   34 #include "../../../maptools/Enums.h" 
   35 #include "../../../maptools/Grouping.h" 
   36 #include "../../../maptools/GroupingAlgorithms.h" 
   37 #include "../../../maptools/GroupingItem.h" 
   38 #include "../../../maptools/Utils.h" 
   39 #include "../../../se/Utils.h" 
   40 #include "../colorbar/ColorBar.h" 
   41 #include "../se/SymbologyPreview.h" 
   43 #include "ui_GroupingWidgetForm.h" 
   49 #include <QtGui/QMessageBox> 
   51 #define MAX_SLICES 200 
   53 #define NO_TITLE "No Value" 
   58     m_ui(new Ui::GroupingWidgetForm)
 
   62   QGridLayout* l = 
new QGridLayout(
m_ui->m_colorBarWidget);
 
   63   l->setContentsMargins(0,0,0,0);
 
   95   std::string attr = m_ui->m_attrComboBox->currentText().toStdString();
 
   96   int attrIdx =  m_ui->m_attrComboBox->currentIndex();
 
   97   int attrType = m_ui->m_attrComboBox->itemData(attrIdx).toInt();
 
   99   int index = m_ui->m_typeComboBox->currentIndex();
 
  100   int type = m_ui->m_typeComboBox->itemData(index).toInt();
 
  104   group->setPropertyType(attrType);
 
  106   group->setNumSlices(m_ui->m_slicesSpinBox->value());
 
  108   group->setPrecision(m_ui->m_precSpinBox->value());
 
  110   group->setStdDeviation(m_ui->m_stdDevDoubleSpinBox->value());
 
  112   std::vector<te::map::GroupingItem*> groupingItems;
 
  113   for(std::size_t t = 0; t < m_legend.size(); ++t)
 
  117     groupingItems.push_back(gi);
 
  119   group->setGroupingItems(groupingItems);
 
  129   m_colorBar->setHeight(20);
 
  130   m_colorBar->setColorBar(m_cb);
 
  131   m_colorBar->setScaleVisible(
false);
 
  139   onTypeComboBoxActivated(0);
 
  142   m_ui->m_slicesSpinBox->setMinimum(1);
 
  143   m_ui->m_slicesSpinBox->setMaximum(
MAX_SLICES);
 
  144   m_ui->m_slicesSpinBox->setValue(5);
 
  145   m_ui->m_slicesSpinBox->setSingleStep(1);
 
  148   m_ui->m_stdDevDoubleSpinBox->setMinimum(0.25);
 
  149   m_ui->m_stdDevDoubleSpinBox->setMaximum(1.0);
 
  150   m_ui->m_stdDevDoubleSpinBox->setValue(0.5);
 
  151   m_ui->m_stdDevDoubleSpinBox->setSingleStep(0.25);
 
  154   m_ui->m_precSpinBox->setMinimum(1);
 
  155   m_ui->m_precSpinBox->setMaximum(
PRECISION);
 
  156   m_ui->m_precSpinBox->setValue(6);
 
  157   m_ui->m_precSpinBox->setSingleStep(1);
 
  160   m_ui->m_tableWidget->resizeColumnsToContents();
 
  161   m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
 
  168   disconnect(m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), 
this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
 
  170   m_ui->m_tableWidget->setRowCount(0);
 
  172   int index = m_ui->m_typeComboBox->currentIndex();
 
  173   int type = m_ui->m_typeComboBox->itemData(index).toInt();
 
  178     list.append(tr(
"Symbol"));
 
  179     list.append(tr(
"Title"));
 
  180     list.append(tr(
"Min"));
 
  181     list.append(tr(
"Max"));
 
  182     list.append(tr(
"Count"));
 
  184     m_ui->m_tableWidget->setColumnCount(5);
 
  185     m_ui->m_tableWidget->setHorizontalHeaderLabels(list);
 
  190     list.append(tr(
"Symbol"));
 
  191     list.append(tr(
"Title"));
 
  192     list.append(tr(
"Value"));
 
  193     list.append(tr(
"Count"));
 
  195     m_ui->m_tableWidget->setColumnCount(4);
 
  196     m_ui->m_tableWidget->setHorizontalHeaderLabels(list);
 
  199   for(std::size_t t = 0; t < m_legend.size(); ++t)
 
  203     int newrow = m_ui->m_tableWidget->rowCount();
 
  204     m_ui->m_tableWidget->insertRow(newrow);
 
  208       const std::vector<te::se::Symbolizer*>& ss = gi->
getSymbolizers();
 
  211       QTableWidgetItem* item = 
new QTableWidgetItem(icon, 
"");
 
  212       item->setFlags(Qt::ItemIsEnabled);
 
  213       m_ui->m_tableWidget->setItem(newrow, 0, item);
 
  218       QTableWidgetItem* item = 
new QTableWidgetItem(QString::fromStdString(gi->
getTitle()));
 
  219       item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
 
  220       m_ui->m_tableWidget->setItem(newrow, 1, item);
 
  230           QTableWidgetItem* item = 
new QTableWidgetItem(QString::fromStdString(gi->
getLowerLimit()));
 
  231           item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
 
  232           m_ui->m_tableWidget->setItem(newrow, 2, item);
 
  237           QTableWidgetItem* item = 
new QTableWidgetItem(QString::fromStdString(gi->
getUpperLimit()));
 
  238           item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
 
  239           m_ui->m_tableWidget->setItem(newrow, 3, item);
 
  244       QTableWidgetItem* item = 
new QTableWidgetItem(QString::number(gi->
getCount()));
 
  245       item->setFlags(Qt::ItemIsEnabled);
 
  246       m_ui->m_tableWidget->setItem(newrow, 4, item);
 
  254         QTableWidgetItem* item = 
new QTableWidgetItem(QString::fromStdString(gi->
getValue()));
 
  255         item->setFlags(Qt::ItemIsEnabled);
 
  256         m_ui->m_tableWidget->setItem(newrow, 2, item);
 
  260       QTableWidgetItem* item = 
new QTableWidgetItem(QString::number(gi->
getCount()));
 
  261       item->setFlags(Qt::ItemIsEnabled);
 
  262       m_ui->m_tableWidget->setItem(newrow, 3, item);
 
  267   m_ui->m_tableWidget->resizeColumnsToContents();
 
  268   m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
 
  270   connect(m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), 
this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
 
  288   for(
int i = 0; i < m_ui->m_typeComboBox->count(); ++i)
 
  290     if(type == m_ui->m_typeComboBox->itemData(i).toInt())
 
  292       m_ui->m_typeComboBox->setCurrentIndex(i);
 
  300   for(
int i = 0; i < m_ui->m_attrComboBox->count(); ++i)
 
  302     if(attrName == m_ui->m_attrComboBox->itemText(i).toStdString())
 
  304       m_ui->m_attrComboBox->setCurrentIndex(i);
 
  312   m_ui->m_precSpinBox->setValue((
int)prec);
 
  317   m_ui->m_slicesSpinBox->setValue((
int)slices);
 
  322   m_ui->m_stdDevDoubleSpinBox->setValue((
double)stdDev);
 
  332     m_legend.push_back(gi);
 
  342       int reply = QMessageBox::question(
this, tr(
"Classification"), tr(
"Manual changes will be lost. Continue?"), QMessageBox::Yes | QMessageBox::Cancel);
 
  344       if(reply != QMessageBox::Yes)
 
  348   int index = m_ui->m_typeComboBox->currentIndex();
 
  350   int type = m_ui->m_typeComboBox->itemData(index).toInt();
 
  351   int slices = m_ui->m_slicesSpinBox->value();
 
  352   int prec = m_ui->m_precSpinBox->value();
 
  353   double stdDev = m_ui->m_stdDevDoubleSpinBox->value();
 
  355   std::string attr = m_ui->m_attrComboBox->currentText().toStdString();
 
  356   int attrIdx =  m_ui->m_attrComboBox->currentIndex();
 
  357   int attrType = m_ui->m_attrComboBox->itemData(attrIdx).toInt();
 
  362   std::string mean = 
"";
 
  368     std::vector<double> vec;
 
  370     getDataAsDouble(vec, attr, attrType, nullValues);
 
  374     buildSymbolizer(mean);
 
  376     createDoubleNullGroupingItem(nullValues);
 
  380     std::vector<double> vec;
 
  382     getDataAsDouble(vec, attr, attrType, nullValues);
 
  386     buildSymbolizer(mean);
 
  388     createDoubleNullGroupingItem(nullValues);
 
  392     std::vector<double> vec;
 
  394     getDataAsDouble(vec, attr, attrType, nullValues);
 
  398     buildSymbolizer(mean);
 
  400     createDoubleNullGroupingItem(nullValues);
 
  404     std::vector<std::string> vec;
 
  406     getDataAsString(vec, attr, nullValues);
 
  410     buildSymbolizer(mean);
 
  412     createStringNullGroupingItem(nullValues);
 
  419   emit applyPushButtonClicked();
 
  424   int type = m_ui->m_typeComboBox->itemData(idx).toInt();
 
  428     m_ui->m_slicesSpinBox->setEnabled(
true);
 
  429     m_ui->m_precSpinBox->setEnabled(
true);
 
  430     m_ui->m_stdDevDoubleSpinBox->setEnabled(
false);
 
  434     m_ui->m_slicesSpinBox->setEnabled(
true);
 
  435     m_ui->m_precSpinBox->setEnabled(
true);
 
  436     m_ui->m_stdDevDoubleSpinBox->setEnabled(
false);
 
  440     m_ui->m_slicesSpinBox->setEnabled(
false);
 
  441     m_ui->m_precSpinBox->setEnabled(
true);
 
  442     m_ui->m_stdDevDoubleSpinBox->setEnabled(
true);
 
  446     m_ui->m_slicesSpinBox->setEnabled(
false);
 
  447     m_ui->m_precSpinBox->setEnabled(
true);
 
  448     m_ui->m_stdDevDoubleSpinBox->setEnabled(
false);
 
  472   int index = m_ui->m_typeComboBox->currentIndex();
 
  473   int type = m_ui->m_typeComboBox->itemData(index).toInt();
 
  475   int curRow = m_ui->m_tableWidget->currentRow();
 
  476   int curCol = m_ui->m_tableWidget->currentColumn();
 
  478   QString str = item->text();
 
  482     m_legend[curRow]->setTitle(str.toStdString());
 
  486   else if(curCol == 2 || curCol == 3) 
 
  497           item->setText(m_legend[curRow]->getLowerLimit().c_str());
 
  499           item->setText(m_legend[curRow]->getUpperLimit().c_str());
 
  504           m_legend[curRow]->setLowerLimit(item->text().toStdString());
 
  506           m_legend[curRow]->setUpperLimit(item->text().toStdString());
 
  516   assert(m_layer.get());
 
  518   std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
 
  522   for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
 
  524     if(dsType->getProperty(t)->getName() == attrName)
 
  531   std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
 
  533   ds->moveBeforeFirst();
 
  535   while(ds->moveNext())
 
  544       vec.push_back((
double)ds->getInt16(idx));
 
  546       vec.push_back((
double)ds->getInt32(idx));
 
  548       vec.push_back((
double)ds->getInt64(idx));
 
  550       vec.push_back((
double)ds->getFloat(idx));
 
  552       vec.push_back(ds->getDouble(idx));
 
  555       QString strNum = ds->getNumeric(idx).c_str();
 
  559       double value = strNum.toDouble(&ok);
 
  562         vec.push_back(value);
 
  569   assert(m_layer.get());
 
  571   std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
 
  575   for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
 
  577     if(dsType->getProperty(t)->getName() == attrName)
 
  584   std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
 
  586   ds->moveBeforeFirst();
 
  588   while(ds->moveNext())
 
  591       vec.push_back(ds->getAsString(idx));
 
  608   int geomType = getGeometryType();
 
  609   std::vector<te::se::Symbolizer*> symbVec;
 
  611   symbVec.push_back(s);
 
  614   m_legend.push_back(legendItem);
 
  627   int geomType = getGeometryType();
 
  628   std::vector<te::se::Symbolizer*> symbVec;
 
  630   symbVec.push_back(s);
 
  633   m_legend.push_back(legendItem);
 
  638   assert(m_layer.get());
 
  645   int legendSize = m_legend.size();
 
  647   std::vector<te::color::RGBAColor> colorVec;
 
  649   if(meanTitle.empty())
 
  651     colorVec = m_cb->getSlices(legendSize);
 
  659     for(
size_t t = 0; t < m_legend.size(); ++t)
 
  661       if(m_legend[t]->getTitle() != meanTitle)
 
  668         afterMean = m_legend.size() - t - 1;
 
  673     std::vector<te::color::RGBAColor> lowerColorVec = m_cb->getLowerMeanSlices(beforeMean);
 
  675     std::vector<te::color::RGBAColor> upperColorVec = m_cb->getUpperMeanSlices(afterMean);
 
  677     for(
size_t t = 0; t < lowerColorVec.size(); ++t)
 
  678       colorVec.push_back(lowerColorVec[t]);
 
  680     colorVec.push_back(meanColor);
 
  682     for(
size_t t = 0; t < upperColorVec.size(); ++t)
 
  683       colorVec.push_back(upperColorVec[t]);
 
  686   if(colorVec.size() != m_legend.size())
 
  689   int geomType = getGeometryType();
 
  691   for(
size_t t = 0; t < colorVec.size(); ++t)
 
  693     std::vector<te::se::Symbolizer*> symbVec;
 
  697     symbVec.push_back(s);
 
  699     m_legend[t]->setSymbolizers(symbVec);
 
  705   QString curValue = m_ui->m_attrComboBox->currentText();
 
  707   m_ui->m_attrComboBox->clear();
 
  709   std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
 
  712   int index = m_ui->m_typeComboBox->currentIndex();
 
  713   int type = m_ui->m_typeComboBox->itemData(index).toInt();
 
  717     for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
 
  731           m_ui->m_attrComboBox->addItem(p->
getName().c_str(), p->
getType());
 
  740     for(
size_t t = 0; t < dsType->getProperties().size(); ++t)
 
  755           m_ui->m_attrComboBox->addItem(p->
getName().c_str(), p->
getType());
 
  763   if(curValue.isEmpty() == 
false)
 
  765     int idx = m_ui->m_attrComboBox->findText(curValue);
 
  768       m_ui->m_attrComboBox->setCurrentIndex(idx);
 
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element. 
 
GroupingType
The grouping type associated to the layer. 
 
It models the concept of color bar. 
 
te::qt::widgets::colorbar::ColorBar * m_colorBar
Widget used to pick a color. 
 
This class contains the parameters needed for grouping the values of a Property. 
 
std::auto_ptr< te::map::Grouping > getGrouping()
 
const double getStdDeviation() const 
It gets the standard deviation used in the Standard Deviation grouping. 
 
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...
 
A Symbolizer describes how a feature is to appear on a map. 
 
~GroupingWidget()
Destructor. 
 
It QWidget implementation of color bar. 
 
void onTypeComboBoxActivated(int idx)
 
const std::string & getName() const 
It returns the property name. 
 
const std::string & getValue() const 
It gets the value of the legend item. 
 
std::size_t getCount() const 
It gets the number of objects whose values are between the lower and upper limits. 
 
void GroupingByQuantil(iterator begin, iterator end, int nSteps, std::vector< te::map::GroupingItem * > &legend, int precision=0, bool countElements=true)
It groups the values defined by a range of iterators using the quantil algorithm. ...
 
void setLowerLimit(const std::string &from)
It sets the lower limit value of the legend item. 
 
void updateUi()
Updates the widget form based on internal fill element. 
 
void onTableWidgetItemChanged(QTableWidgetItem *item)
 
void GroupingByEqualSteps(iterator begin, iterator end, int nSteps, std::vector< te::map::GroupingItem * > &legend, int precision=0, bool countElements=true)
It groups the values defined by a range of iterators using the equal steps algorithm. 
 
void setUpperLimit(const std::string &to)
It sets the upper limit value of the legend item. 
 
const size_t getNumSlices() const 
It gets the number of slices used in the Equal Steps and Quantil groupings. 
 
std::string getPropertyName() const 
It gets the property name whose values will be grouped. 
 
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. 
 
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type. 
 
std::auto_ptr< Ui::GroupingWidgetForm > m_ui
Widget form. 
 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code. 
 
void setCount(std::size_t count)
It It sets the number of objects whose values are between the lower and upper limits. 
 
void setTitle(const std::string &title)
It sets the title of the legend item. 
 
GroupingWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic fill widget which is a child of parent, with widget flags set to f...
 
void onApplyPushButtonClicked()
 
const size_t getPrecision() const 
It gets the precision used for the property values. 
 
void createDoubleNullGroupingItem(int count)
 
const std::string & getLowerLimit() const 
It gets the lower limit value of the legend item. 
 
void setSymbolizers(const std::vector< te::se::Symbolizer * > &symbolizers)
It sets the symbolizers of the legend item. 
 
TEMAPEXPORT void GroupingByUniqueValues(std::vector< std::string > &inputValues, int dataType, std::vector< te::map::GroupingItem * > &legend, int precision)
It groups the values using the unique value algorithm. 
 
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque. 
 
void GroupingByStdDeviation(iterator begin, iterator end, double nDevs, std::vector< te::map::GroupingItem * > &legend, std::string &meanTitle, int precision=0, bool countElements=true)
It groups the values defined by a range of iterators using the standard deviation algorithm...
 
void setValue(const std::string &value)
It sets value of the legend item. 
 
void getDataAsDouble(std::vector< double > &vec, const std::string &attrName, const int &dataType, int &nullValues)
 
const std::vector< te::se::Symbolizer * > & getSymbolizers() const 
It gets the symbolizer of the legend item. 
 
It models a property definition. 
 
void initialize()
Internal method to initialize the widget (e.g.: color, combos, icons, etc.) 
 
int getType() const 
It returns the property data type. 
 
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
 
A widget used to build a grouping. 
 
std::string getTitle()
It gets the title of the legend item. 
 
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer. 
 
void createStringNullGroupingItem(int count)
 
static const std::string sm_nanStr
Not a number string value. 
 
void buildSymbolizer(std::string meanTitle="")
 
const std::string & getUpperLimit() const 
It gets the upper limit value of the legend item. 
 
const std::vector< te::map::GroupingItem * > & getGroupingItems() const 
It gets the vector of grouping items. 
 
void onAttrComboBoxActivated(int idx)
 
void getDataAsString(std::vector< std::string > &vec, const std::string &attrName, int &nullValues)
 
void setLayer(te::map::AbstractLayerPtr layer)
 
const GroupingType getType() const 
It gets the grouping type. 
 
A GroupingItem contains information about a grouping item associated to a layer.