DataSetTableView.cpp
Go to the documentation of this file.
1 #include "AddColumnDialog.h"
2 #include "DataSetTableModel.h"
5 #include "DataSetTableView.h"
6 #include "HighlightDelegate.h"
7 #include "Promoter.h"
8 #include "RenameColumnDialog.h"
9 #include "RetypeColumnDialog.h"
10 #include "AlterDataDialog.h"
11 
12 // TerraLib include files
13 #include "../charts/HistogramDataWidget.h"
14 #include "../charts/Utils.h"
15 #include "../utils/ScopedCursor.h"
16 #include "../Config.h"
17 #include "../Exception.h"
18 #include "../../../common/Exception.h"
19 #include "../../../dataaccess/dataset/DataSet.h"
20 #include "../../../dataaccess/dataset/ObjectId.h"
21 #include "../../../dataaccess/dataset/ObjectIdSet.h"
22 #include "../../../dataaccess/dataset/DataSetTypeCapabilities.h"
23 #include "../../../dataaccess/datasource/DataSourceManager.h"
24 #include "../../../dataaccess/datasource/DataSourceTransactor.h"
25 #include "../../../dataaccess/query/DataSetName.h"
26 #include "../../../dataaccess/query/Field.h"
27 #include "../../../dataaccess/query/From.h"
28 #include "../../../dataaccess/query/In.h"
29 #include "../../../dataaccess/query/Literal.h"
30 #include "../../../dataaccess/query/Or.h"
31 #include "../../../dataaccess/query/OrderBy.h"
32 #include "../../../dataaccess/query/OrderByItem.h"
33 #include "../../../dataaccess/query/Select.h"
34 #include "../../../dataaccess/utils/Utils.h"
35 #include "../../../geometry/Geometry.h"
36 #include "../../../maptools/DataSetLayer.h"
37 #include "../../../maptools/DataSetAdapterLayer.h"
38 #include "../../../maptools/QueryLayer.h"
39 #include "../../../statistics/qt/StatisticsDialog.h"
40 #include "../../../st/maptools/ObservationDataSetLayer.h"
41 #include "../../../st/maptools/TimeSeriesDataSetLayer.h"
42 #include "../../../st/maptools/TrajectoryDataSetLayer.h"
43 
44 // Qt
45 #include <QBoxLayout>
46 #include <QContextMenuEvent>
47 #include <QCursor>
48 #include <QDialogButtonBox>
49 #include <QHeaderView>
50 #include <QLabel>
51 #include <QMenu>
52 #include <QMessageBox>
53 #include <QPainter>
54 #include <QSpinBox>
55 
56 
57 // STL
58 #include <vector>
59 #include <memory>
60 
61 bool IsGeometryColumn(te::da::DataSet* dset, const size_t& col)
62 {
63  return dset->getPropertyDataType(col) == te::dt::GEOMETRY_TYPE;
64 }
65 
66 void GetGeometryColumnsPositions(te::da::DataSet* dset, std::vector<int>& cols)
67 {
68  size_t nProps = dset->getNumProperties();
69 
70  cols.clear();
71 
72  for(size_t i=0; i<nProps; i++)
73  if(IsGeometryColumn(dset, i))
74  cols.push_back((int)i);
75 }
76 
77 std::vector<int> GetHiddenSections(QHeaderView* hView, te::da::DataSet* dset)
78 {
79  std::vector<int> res;
80 
81  int sz = dset->getNumProperties();
82 
83  if(sz > 0)
84  {
85  for (int i=0; i<sz; i++)
86  if(hView->isSectionHidden(i) && !IsGeometryColumn(dset, i))
87  res.push_back(i);
88  }
89 
90  return res;
91 }
92 
93 QMenu* GetHiddenColumnsMenu(QHeaderView* hView, te::da::DataSet* dset, QMenu* hMnu)
94 {
95  std::vector<int> hSecs = GetHiddenSections(hView, dset);
96  std::vector<int>::iterator it;
97 
98  QMenu* mnu = new QMenu(hMnu);
99  mnu->setTitle(QObject::tr("Show hidden column"));
100 
101  if(hSecs.empty())
102  mnu->setEnabled(false);
103  else
104  for(it=hSecs.begin(); it!=hSecs.end(); ++it)
105  {
106  QString cName = hView->model()->headerData(*it, Qt::Horizontal, Qt::DisplayRole).toString();
107  QAction* act = new QAction(mnu);
108 
109  act->setText(cName);
110  act->setData(QVariant(*it));
111 
112  QString tt = QObject::tr("Turns column \"%1\" visible.").arg(cName);
113 
114  act->setToolTip(tt);
115 
116  mnu->addAction(act);
117  }
118 
119  return mnu;
120 }
121 
122 QAction* GetShowAllMenu(QHeaderView* hView, te::da::DataSet* dset, QMenu* hMnu)
123 {
124  QAction* act = new QAction(hMnu);
125  act->setText(QObject::tr("Show all columns"));
126  act->setEnabled(!GetHiddenSections(hView, dset).empty());
127 
128  return act;
129 }
130 
132 {
133  // Getting data source, if it is available
135 
136  if(layer->getType() == "DATASETLAYER")
137  {
138  const te::map::DataSetLayer* l = dynamic_cast<const te::map::DataSetLayer*>(layer);
139 
140  if(l != 0)
142  }
143  else if(layer->getType() == "DATASETADAPTERLAYER")
144  {
145  const te::map::DataSetAdapterLayer* l = dynamic_cast<const te::map::DataSetAdapterLayer*>(layer);
146 
147  if(l != 0)
149  }
150  else if(layer->getType() == "QUERYLAYER")
151  {
152  const te::map::QueryLayer* l = dynamic_cast<const te::map::QueryLayer*>(layer);
153 
154  if(l != 0)
156  }
157  else if(layer->getType() == "OBSERVATIONDATASETLAYER")
158  {
159  const te::st::ObservationDataSetLayer* l = dynamic_cast<const te::st::ObservationDataSetLayer*>(layer);
160 
161  if(l != 0)
163  }
164  else if(layer->getType() == "TIMESERIESDATASETLAYER")
165  {
166  const te::st::TimeSeriesDataSetLayer* l = dynamic_cast<const te::st::TimeSeriesDataSetLayer*>(layer);
167 
168  if(l != 0)
170  }
171  else if(layer->getType() == "TRAJECTORYDATASETLAYER")
172  {
173  const te::st::TrajectoryDataSetLayer* l = dynamic_cast<const te::st::TrajectoryDataSetLayer*>(layer);
174 
175  if(l != 0)
177  }
178  return ds;
179 }
180 
182 {
183  // Getting data source capabilities, if it is available
185 
186  if(ds.get() != 0)
187  {
188  const te::map::DataSetLayer* dl = dynamic_cast<const te::map::DataSetLayer*>(layer);
189 
190  if(dl != 0)
191  return ds->getCapabilities(dl->getDataSetName()).release();
192  }
193 
194  return 0;
195 }
196 
197 std::auto_ptr<te::da::Select> GetSelectExpression(const std::string& datasetName, const std::vector<std::string>& colsNames, const bool& asc)
198 {
199  te::da::Fields fields;
200 
201  fields.push_back(std::auto_ptr<te::da::Field>(new te::da::Field("*")));
202 
203  te::da::From from;
204 
205  from.push_back(std::auto_ptr<te::da::DataSetName>(new te::da::DataSetName(datasetName)));
206 
207  te::da::OrderBy order_by;
208 
209  for(size_t i=0; i<colsNames.size(); i++)
210  order_by.push_back(std::auto_ptr<te::da::OrderByItem>(new te::da::OrderByItem(colsNames[i], (asc) ? te::da::ASC : te::da::DESC)));
211 
212  return std::auto_ptr<te::da::Select>(new te::da::Select(fields, from, order_by));
213 }
214 
215 std::auto_ptr<te::da::Select> GetSelectExpression(const std::string& tableName, const te::da::DataSet* set, const std::vector<int>& cols, const bool& asc)
216 {
217  std::vector<std::string> colsNames;
218 
219  for(size_t i = 0; i < cols.size(); ++i)
220  colsNames.push_back(set->getPropertyName((size_t)cols[i]));
221 
222  return GetSelectExpression(tableName, colsNames, asc);
223 }
224 
225 std::auto_ptr<te::da::DataSet> GetDataSet(const te::map::AbstractLayer* layer, const te::da::DataSet* set, const std::vector<int>& cols, const bool& asc)
226 {
227  std::auto_ptr<te::da::Select> query = GetSelectExpression(layer->getSchema()->getName(), set, cols, asc);
228 
229  try
230  {
231  if(query.get() == 0)
232  throw std::string("Fail to generate query.");
233 
235 
236  if(dsc.get() == 0)
237  throw std::string("Fail to get data source.");
238 
239  return dsc->getTransactor()->query(query.get(), te::common::RANDOM);
240  }
241  catch(...)
242  {
243  return std::auto_ptr<te::da::DataSet>();
244  }
245 }
246 
247 std::auto_ptr<te::da::DataSet> GetDataSet(const te::map::AbstractLayer* layer, const std::vector<std::string>& colsNames, const bool& asc)
248 {
249  std::auto_ptr<te::da::Select> query;
250 
251  if(layer->getType() == "DATASETLAYER")
252  {
253  const te::map::DataSetLayer* l = dynamic_cast<const te::map::DataSetLayer*>(layer);
254 
255  if(l != 0)
256  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
257  }
258  else if(layer->getType() == "DATASETADAPTERLAYER")
259  {
260  const te::map::DataSetAdapterLayer* l = dynamic_cast<const te::map::DataSetAdapterLayer*>(layer);
261 
262  if(l != 0)
263  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
264  }
265  else if(layer->getType() == "QUERYLAYER")
266  {
267  const te::map::QueryLayer* l = dynamic_cast<const te::map::QueryLayer*>(layer);
268 
269  if (l != 0)
270  {
271  query.reset(new te::da::Select(l->getQuery()));
272  te::da::OrderBy* order_by = new te::da::OrderBy();
273 
274  for (size_t i = 0; i<colsNames.size(); i++)
275  order_by->push_back(std::auto_ptr<te::da::OrderByItem>(new te::da::OrderByItem(colsNames[i], (asc) ? te::da::ASC : te::da::DESC)));
276 
277  query->setOrderBy(order_by);
278  }
279  }
280  else if(layer->getType() == "OBSERVATIONDATASETLAYER")
281  {
282  const te::st::ObservationDataSetLayer* l = dynamic_cast<const te::st::ObservationDataSetLayer*>(layer);
283 
284  if(l != 0)
285  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
286  }
287  else if(layer->getType() == "TIMESERIESDATASETLAYER")
288  {
289  const te::st::TimeSeriesDataSetLayer* l = dynamic_cast<const te::st::TimeSeriesDataSetLayer*>(layer);
290 
291  if(l != 0)
292  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
293  }
294  else if(layer->getType() == "TRAJECTORYDATASETLAYER")
295  {
296  const te::st::TrajectoryDataSetLayer* l = dynamic_cast<const te::st::TrajectoryDataSetLayer*>(layer);
297 
298  if(l != 0)
299  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
300  }
301 
302  try
303  {
304  if(query.get() == 0)
305  throw std::string("Fail to generate query.");
306 
308 
309  if(dsc.get() == 0)
310  throw std::string("Fail to get data source.");
311 
312  return dsc->getTransactor()->query(query.get(), te::common::RANDOM);
313  }
314  catch(...)
315  {
316  return std::auto_ptr<te::da::DataSet>();
317  }
318 }
319 
320 std::vector<QString> GetColumnsNames(te::da::DataSet* dset)
321 {
322  std::vector<QString> res;
323 
324  if(dset != 0)
325  {
326  size_t n = dset->getNumProperties();
327 
328  for(size_t i=0; i<n; i++)
329  if(!IsGeometryColumn(dset, i))
330  res.push_back(dset->getPropertyName(i).c_str());
331  }
332 
333  return res;
334 }
335 
336 std::auto_ptr<te::gm::Envelope> GetExtent(te::da::DataSet* dset, te::qt::widgets::Promoter* p, const int& rowPosition)
337 {
338  // Getting last select object bounding rectangle
339  std::vector<int> geoCols;
340 
341  GetGeometryColumnsPositions(dset, geoCols);
342 
343  if(!geoCols.empty())
344  {
345  int rpos = p->getLogicalRow(rowPosition);
346 
347  dset->move(rpos);
348 
349  size_t pos = (size_t)geoCols[0];
350 
351  std::auto_ptr<te::gm::Geometry> g = dset->getGeometry(pos);
352 
353  return std::auto_ptr<te::gm::Envelope> (new te::gm::Envelope(*g->getMBR()));
354  }
355 
356  return std::auto_ptr<te::gm::Envelope>();
357 }
358 
360 {
361  te::qt::widgets::HighlightDelegate* d = dynamic_cast<te::qt::widgets::HighlightDelegate*>(view->itemDelegate());
362 
363  if(d == 0)
364  return false;
365 
366  const te::da::ObjectIdSet* objs = d->getSelected();
367 
368  if(objs == 0)
369  return false;
370 
371  std::vector<size_t> cols = objs->getPropertyPos();
372  std::vector<size_t>::iterator it;
373 
374  for(it = cols.begin(); it != cols.end(); ++it)
375  if((size_t)col == *it)
376  return true;
377 
378  return false;
379 }
380 
382 {
383  if(dset != 0)
384  {
385  std::vector<int> geoCols;
386  std::vector<int>::iterator it;
387  GetGeometryColumnsPositions(dset, geoCols);
388 
389  for(it = geoCols.begin(); it != geoCols.end(); ++it)
390  view->hideColumn(*it);
391  }
392 }
393 
395 {
396  if(dset != 0)
397  {
398  size_t nProps = dset->getNumProperties();
399 
400  for(std::size_t i = 0; i < nProps; ++i)
401  if(dset->getPropertyName(i) == "tsvector")
402  view->hideColumn(i);
403  }
404 }
405 
406 /*!
407  \class Filter for popup menus
408 */
409 class TablePopupFilter : public QObject
410 {
411  Q_OBJECT
412 
413  public:
414 
415  /*!
416  \brief Contructor.
417  */
419  QObject(view),
420  m_view(view),
421  m_hMenu(0),
422  m_vMenu(0),
423  m_vportMenu(0),
424  m_dset(0),
425  m_showOidsColumns(false),
426  m_enabled(true),
427  m_autoScrollEnabled(false),
428  m_promotionEnabled(false),
429  m_isOGR(false)
430  {
431  m_view->horizontalHeader()->installEventFilter(this);
432  m_view->verticalHeader()->installEventFilter(this);
433  m_view->viewport()->installEventFilter(this);
434 
435  m_view->connect(this, SIGNAL(createHistogram(const int&)), SLOT(createHistogram(const int&)));
436  m_view->connect(this, SIGNAL(createNormalDistribution(const int&)), SLOT(createNormalDistribution(const int&)));
437  m_view->connect(this, SIGNAL(hideColumn(const int&)), SLOT(hideColumn(const int&)));
438  m_view->connect(this, SIGNAL(showColumn(const int&)), SLOT(showColumn(const int&)));
439  m_view->connect(this, SIGNAL(removeColumn(const int&)), SLOT(removeColumn(const int&)));
440  m_view->connect(this, SIGNAL(enableAutoScroll(const bool&)), SLOT(setAutoScrollEnabled(const bool&)));
441  m_view->connect(this, SIGNAL(sortData(const bool&)), SLOT(sortByColumns(const bool&)));
442  m_view->connect(this, SIGNAL(renameColumn(const int&)), SLOT(renameColumn(const int&)));
443  m_view->connect(this, SIGNAL(retypeColumn(const int&)), SLOT(retypeColumn(const int&)));
444  m_view->connect(this, SIGNAL(changeColumnData(const int&)), SLOT(changeColumnData(const int&)));
445  m_view->connect(this, SIGNAL(enablePromotion(const bool&)), SLOT(setPromotionEnabled(const bool&)));
446  m_view->connect(this, SIGNAL(saveEditions()), SLOT(saveEditions()));
447  }
448 
449  /*!
450  \brief Destructor.
451  */
453  {
454  delete m_hMenu;
455  delete m_vMenu;
456  delete m_vportMenu;
457  }
458 
459  bool eventFilter(QObject* watched, QEvent* event)
460  {
461  if(!m_enabled)
462  return QObject::eventFilter(watched, event);
463 
464  QWidget* vport = m_view->viewport();
465  QHeaderView* hHdr = m_view->horizontalHeader();
466  QHeaderView* vHdr = m_view->verticalHeader();
467 
468  switch(event->type())
469  {
470  case QEvent::ContextMenu:
471  {
472  if(watched == hHdr)
473  {
474  delete m_hMenu;
475  m_hMenu = 0;
476 
477  QContextMenuEvent* evt = static_cast<QContextMenuEvent*>(event);
478  QPoint pos = evt->globalPos();
479 
480  m_columnPressed = hHdr->logicalIndex(hHdr->visualIndexAt(evt->pos().x()));
481  bool isPKey = IsPrimaryKey(m_columnPressed, m_view);
482 
483  if(m_columnPressed > 0 && !isPKey)
484  {
485  m_hMenu = new QMenu;
486 
487  QAction* act = new QAction(m_hMenu);
488  act->setText(tr("Hide column"));
489  act->setToolTip(tr("Hides the selected column."));
490 
491  m_hMenu->addAction(act);
492 
493  QMenu* hMnu = GetHiddenColumnsMenu(hHdr, m_dset, m_hMenu);
494 
495  if(m_columnPressed == -1)
496  act->setEnabled(false);
497 
498  m_hMenu->addAction(hMnu->menuAction());
499 
500  QAction* act2 = GetShowAllMenu(hHdr, m_dset, m_hMenu);
501  m_hMenu->addAction(act2);
502 
503  QAction* act3 = new QAction(m_hMenu);
504  act3->setText(tr("Reset columns order"));
505  act3->setToolTip(tr("Put all columns in the original order."));
506  m_hMenu->addAction(act3);
507 
508  m_hMenu->addSeparator();
509 
510  QAction* act5 = new QAction(m_hMenu);
511  act5->setText(tr("Sort data ASC"));
512  act5->setToolTip(tr("Sort data in ascendent order using selected columns."));
513  m_hMenu->addAction(act5);
514 
515  QAction* act9 = new QAction(m_hMenu);
516  act9->setText(tr("Sort data DESC"));
517  act9->setToolTip(tr("Sort data in descendent order using selected columns."));
518  m_hMenu->addAction(act9);
519 
520  m_hMenu->addSeparator();
521 
522  QAction* act4 = new QAction(m_hMenu);
523  act4->setText(tr("Histogram"));
524  act4->setToolTip(tr("Creates a new histogram based on the data of the selected colunm."));
525  m_hMenu->addAction(act4);
526 
527  QAction* act10 = new QAction(m_hMenu);
528  act10->setText(tr("Normal Probability"));
529  act10->setToolTip(tr("Show a chart that displays the normal probability curve."));
530  m_hMenu->addAction(act10);
531 
532  QAction* act6 = new QAction(m_hMenu);
533  act6->setText(tr("Statistics"));
534  act6->setToolTip(tr("Show the statistics summary of the selected colunm."));
535  m_hMenu->addAction(act6);
536 
537  m_hMenu->addSeparator();
538 
539  // Signal / Slot connections
540  connect(act, SIGNAL(triggered()), SLOT(hideColumn()));
541  connect(hMnu, SIGNAL(triggered(QAction*)), SLOT(showColumn(QAction*)));
542 
543  connect(act4, SIGNAL(triggered()), SLOT(createHistogram()));
544 
545  m_view->connect(act2, SIGNAL(triggered()), SLOT(showAllColumns()));
546  m_view->connect(act3, SIGNAL(triggered()), SLOT(resetColumnsOrder()));
547 
548 
549  connect(act6, SIGNAL(triggered()), SLOT(showStatistics()));
550  connect(act5, SIGNAL(triggered()), SLOT(sortDataAsc()));
551  connect(act9, SIGNAL(triggered()), SLOT(sortDataDesc()));
552  connect(act10, SIGNAL(triggered()), SLOT(createNormalDistribution()));
553 
554  if(m_caps.get())
555  {
556  QAction* act7 = new QAction(m_hMenu);
557  act7->setText(tr("Add column"));
558  act7->setToolTip(tr("Adds a column to the table."));
559  m_hMenu->addAction(act7);
560  act7->setEnabled(m_caps->supportsAddColumn());
561 
562  QAction* act8 = new QAction(m_hMenu);
563  act8->setText(tr("Remove column"));
564  act8->setToolTip(tr("Removes a column from the table."));
565  m_hMenu->addAction(act8);
566  act8->setEnabled(m_caps->supportsRemoveColumn());
567 
568  QAction* act10 = new QAction(m_hMenu);
569  act10->setText(tr("Rename column"));
570  act10->setToolTip(tr("Renames a column of the table."));
571  m_hMenu->addAction(act10);
572 
573  QAction* act11 = new QAction(m_hMenu);
574  act11->setText(tr("Change column type"));
575  act11->setToolTip(tr("Changes the type of a column of the table."));
576  act11->setEnabled(!m_isOGR);
577  m_hMenu->addAction(act11);
578 
579  QAction* act12 = new QAction(m_hMenu);
580  act12->setText(tr("Change column data"));
581  act12->setToolTip(tr("Changes the data of a column of the table."));
582  act12->setEnabled(!m_isOGR);
583  m_hMenu->addAction(act12);
584 
585  QAction* act13 = new QAction(m_hMenu);
586  act13->setText(tr("Save editions"));
587  act13->setToolTip(tr("Save pendent editions to layer."));
588  act13->setEnabled(m_view->hasEditions());
589  m_hMenu->addAction(act13);
590 
591  m_view->connect(act7, SIGNAL(triggered()), SLOT(addColumn()));
592 
593  connect(act8, SIGNAL(triggered()), SLOT(removeColumn()));
594  connect (act10, SIGNAL(triggered()), SLOT(renameColumn()));
595  connect (act11, SIGNAL(triggered()), SLOT(retypeColumn()));
596  connect (act12, SIGNAL(triggered()), SLOT(changeColumnData()));
597  connect (act13, SIGNAL(triggered()), SIGNAL(saveEditions()));
598  }
599 
600  m_hMenu->popup(pos);
601  }
602  }
603  else if(watched == vport)
604  {
605  }
606  else if(watched == vHdr)
607  {
608  delete m_vMenu;
609 
610  QContextMenuEvent* evt = static_cast<QContextMenuEvent*>(event);
611  QPoint pos = evt->globalPos();
612 
613  m_vMenu = new QMenu;
614  QAction* act = new QAction(m_vMenu);
615  act->setText(tr("Enable auto scroll"));
616  act->setToolTip(tr("Goes to the selected row."));
617 
618  act->setCheckable(true);
619  act->setChecked(m_autoScrollEnabled);
620 
621  m_vMenu->addAction(act);
622 
623  connect(act, SIGNAL(triggered()), SLOT(setAutoScrollEnabled()));
624 
625  act = new QAction(m_vMenu);
626  act->setText(tr("Enable promotion"));
627  act->setToolTip(tr("Enables promotion of selected rows."));
628 
629  act->setCheckable(true);
630  act->setChecked(m_promotionEnabled);
631 
632  m_vMenu->addSeparator();
633 
634  m_vMenu->addAction(act);
635 
636  connect(act, SIGNAL(triggered()), SLOT(enablePromotion()));
637 
638  m_vMenu->popup(pos);
639  }
640  }
641  break;
642 
643  default:
644  break;
645  }
646 
647  return QObject::eventFilter(watched, event);
648  }
649 
651  {
652  m_dset = dset;
653  }
654 
655  std::vector<int> getHiddenColumns()
656  {
657  return GetHiddenSections(m_view->horizontalHeader(), m_dset);
658  }
659 
660  void setEnabled(const bool& enabled)
661  {
662  m_enabled = enabled;
663  }
664 
666  {
667  m_caps.reset(caps);
668  }
669 
670  void setPromotionEnabled(const bool& enabled)
671  {
672  m_promotionEnabled = enabled;
673  }
674 
675  void setIsOGR(const bool& isOGR)
676  {
677  m_isOGR = isOGR;
678  }
679 
680  protected slots:
681 
683  {
685  }
686 
688  {
690  }
691 
692  void hideColumn()
693  {
695  }
696 
697  void showColumn(QAction* act)
698  {
699  int column = act->data().toInt();
700 
701  emit showColumn(column);
702  }
703 
705  {
706  te::stat::StatisticsDialog statisticDialog;
707  std::string prop = m_dset->getPropertyName(m_columnPressed);
708  statisticDialog.setStatistics(m_dset, prop);
709  statisticDialog.exec();
710  }
711 
713  {
715  }
716 
718  {
720 
722  }
723 
724  void sortDataAsc()
725  {
726  emit sortData(true);
727  }
728 
730  {
731  emit sortData(false);
732  }
733 
735  {
737  }
738 
740  {
742  }
743 
745  {
747  }
748 
750  {
752 
754  }
755 
756  signals:
757 
758  void createHistogram(const int&);
759 
760  void createNormalDistribution(const int&);
761 
762  void hideColumn(const int&);
763 
764  void showColumn(const int&);
765 
766  void renameColumn(const int&);
767 
768  void retypeColumn(const int&);
769 
770  void changeColumnData(const int&);
771 
772  void selectObject(const int&, const bool&);
773 
774  void selectObjects(const int&, const int&);
775 
776  void enablePromotion(const bool&);
777 
778  void removeColumn(const int&);
779 
780  void enableAutoScroll(const bool&);
781 
782  void sortData(const bool&);
783 
784  void saveEditions();
785 
786  protected:
787 
789  QMenu* m_hMenu;
790  QMenu* m_vMenu;
791  QMenu* m_vportMenu;
793  std::auto_ptr<te::da::DataSetTypeCapabilities> m_caps;
795  bool m_enabled;
799  bool m_isOGR;
800 };
801 
803  QTableView(parent),
804  m_layer(0),
805  m_autoScrollEnabled(false),
806  m_doScroll(true),
807  m_promotionEnabled(false),
808  m_dset(0),
809  m_orderAsc(true)
810 {
811  m_model = new DataSetTableModel(this);
812 
813  setModel(m_model);
814 
815  setVerticalHeader(new DataSetTableVerticalHeader(this));
816  setHorizontalHeader(new DataSetTableHorizontalHeader(this));
817 
818 #if QT_VERSION >= 0x050000
819  horizontalHeader()->setSectionsMovable(true);
820 #else
821  horizontalHeader()->setMovable(true);
822 #endif
823 
824  setSelectionMode(QAbstractItemView::MultiSelection);
825  setSelectionBehavior(QAbstractItemView::SelectColumns);
826 
827  m_popupFilter = new TablePopupFilter(this);
828 
829  m_delegate = new HighlightDelegate(this);
830 
832 
833  m_delegate->setColor(Qt::green);
834 
835  setItemDelegate(m_delegate);
836 
837  connect(verticalHeader(), SIGNAL(selectedRow(const int&, const bool&)), SLOT(highlightRow(const int&, const bool&)));
838  connect(verticalHeader(), SIGNAL(selectedRows(const int&, const int&)), SLOT(highlightRows(const int&, const int&)));
839 }
840 
842 {
843  if (m_model->hasEditions())
844  {
845  QMessageBox msgBox(this);
846  msgBox.setText("There are unsaved changes on table.");
847  msgBox.setInformativeText("Do you want to save your changes?");
848  msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
849  msgBox.setDefaultButton(QMessageBox::Save);
850 
851  int ret = msgBox.exec();
852 
853  if(ret == QMessageBox::Save)
854  saveEditions();
855  }
856 }
857 
859 {
860  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
861  hheader->setDragDrop(true);
862 }
863 
865 {
866  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
867  return hheader->getDragDrop();
868 }
869 
871 {
872  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
873  hheader->setAcceptDrop(true);
874 }
875 
877 {
878  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
879  return hheader->getAcceptDrop();
880 }
881 
883 {
884  ScopedCursor cursor(Qt::WaitCursor);
885 
886  m_layer = layer;
887  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
888  hheader->setLayer(m_layer);
889 
890  std::auto_ptr<te::map::LayerSchema> sch = m_layer->getSchema();
891 
892  if (m_orderby.empty())
893  {
894  std::vector<te::dt::Property*> psps;
895 
896  if(sch->getPrimaryKey())
897  psps = sch->getPrimaryKey()->getProperties();
898  else
899  psps = sch->getProperties();
900 
901  std::vector<te::dt::Property*>::iterator it;
902 
903  for(it = psps.begin(); it != psps.end(); ++it)
904  m_orderby.push_back((*it)->getName());
905  }
906 
907  te::da::DataSourcePtr dsc = GetDataSource(m_layer);
908 
909  setDataSet(GetDataSet(m_layer, m_orderby, m_orderAsc).release(), dsc->getEncoding(), clearEditor);
910 
911  setLayerSchema(sch.get());
912 
914 
915  m_popupFilter->setDataSetTypeCapabilities(caps);
916 
917  if(caps)
918  m_model->setEditable(caps->supportsDataEdition());
919 
920  if(dsc.get() != 0)
921  {
922  bool isOGR = (dsc->getType().compare("OGR") == 0);
923  setSelectionMode(isOGR ? SingleSelection : MultiSelection);
924  setSelectionBehavior(isOGR ? QAbstractItemView::SelectColumns : QAbstractItemView::SelectItems);
925  m_popupFilter->setIsOGR(isOGR);
926  }
927 
928  highlightOIds(m_layer->getSelected());
929 }
930 
932 {
933  reset();
934 
935  m_encoding = enc;
936 
937  m_model->setDataSet(dset, enc, clearEditor);
938  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
939  hheader->setDataSet(dset);
940 
941  HideGeometryColumns(dset, this);
942  HideTsVectorColumn(dset, this);
943 
944  m_popupFilter->setDataSet(dset);
945  m_delegate->setDataSet(dset);
946  m_dset = dset;
947 }
948 
950 {
951  te::da::ObjectIdSet* objs = 0;
952 
953  te::da::GetEmptyOIDSet(schema, objs);
954 
955  std::auto_ptr<te::da::ObjectIdSet> objs_ptr(objs);
956 
957  m_delegate->setObjectIdSet(objs_ptr.get());
958 
959  m_model->setPkeysColumns(objs_ptr->getPropertyPos());
960 
961 // m_model->getPromoter()->preProcessKeys(m_dset, objs_ptr->getPropertyPos());
962 }
963 
965 {
966  if(oids == 0)
967  return;
968 
969  m_delegate->setObjectIdSet(oids);
970 
971  if(m_autoScrollEnabled && oids != 0 && oids->size() > 0)
972  {
973  size_t row = m_model->getPromoter()->map2Row(*oids->begin());
974 
975  scrollTo(m_model->index((int)row, 0));
976  }
977 
978  if(m_promotionEnabled)
979  promote(m_doScroll);
980 
981  viewport()->repaint();
982 }
983 
985 {
986  m_delegate->setColor(color);
987 
988  repaint();
989 }
990 
992 {
993  return m_model->hasEditions();
994 }
995 
997 {
998  QDialog* dialog = new QDialog(this);
999  dialog->setFixedSize(160, 75);
1000 
1001  const te::map::LayerSchema* schema = m_layer->getSchema().release();
1002 
1003  te::da::DataSet* dataset = m_layer->getData().release();
1004  te::da::DataSetType* dataType = (te::da::DataSetType*) schema;
1005 
1006  // Histogram data Widget
1007  te::qt::widgets::HistogramDataWidget* histogramWidget = new te::qt::widgets::HistogramDataWidget(dataset, dataType, dialog);
1008  histogramWidget->setHistogramProperty(column);
1009 
1010  // Adjusting...
1011  QGridLayout* layout = new QGridLayout(dialog);
1012  layout->addWidget(histogramWidget);
1013 
1014  QDialogButtonBox* bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
1015  connect(bbox, SIGNAL(accepted()), dialog, SLOT(accept()));
1016  connect(bbox, SIGNAL(rejected()), dialog, SLOT(reject()));
1017 
1018  layout->addWidget(bbox);
1019  layout->setSizeConstraint(QLayout::SetFixedSize);
1020 
1021  int res = dialog->exec();
1022  if (res == QDialog::Accepted)
1023  emit createChartDisplay(te::qt::widgets::createHistogramDisplay(dataset, dataType, column, histogramWidget->getSummaryFunction(), histogramWidget->getHistogram()));
1024 
1025  delete dialog;
1026 }
1027 
1029 {
1030  int propType = m_layer->getData()->getPropertyDataType(column);
1031  if(propType >= te::dt::INT16_TYPE && propType <= te::dt::NUMERIC_TYPE)
1032  {
1033  emit createChartDisplay(te::qt::widgets::createNormalDistribution(m_layer->getData().get(), column));
1034  }
1035  else
1036  {
1037  QString msgErr(tr("This operation is not available for this type of data"));
1038  QString msgTitle(tr("TNormal Probability"));
1039  QMessageBox::warning(this, msgTitle, msgErr);
1040  }
1041 }
1042 
1044 {
1045  horizontalHeader()->hideSection(column);
1046 }
1047 
1049 {
1050  horizontalHeader()->showSection(column);
1051 }
1052 
1054 {
1055  RenameColumnDialog dlg(parentWidget());
1056 
1057  dlg.setOldColumnName(QString::fromStdString(m_dset->getPropertyName(column)));
1058 
1059  if(dlg.exec() == QDialog::Accepted)
1060  {
1061  std::string oldName = dlg.getOldName().toStdString();
1062  std::string newName = dlg.getNewName().toStdString();
1063  te::da::DataSourcePtr dsrc = GetDataSource(m_layer);
1064 
1065  if(dsrc.get() == 0)
1066  throw Exception(tr("Fail to get data source.").toStdString());
1067 
1068  if(!dsrc->isPropertyNameValid(newName))
1069  {
1070  QMessageBox::warning(this, tr("TerraView"), tr("Invalid column name. Choose another."));
1071  return;
1072  }
1073 
1074  try
1075  {
1076  dsrc->renameProperty(m_layer->getSchema()->getName(), oldName, newName);
1077  }
1078  catch (const te::common::Exception& e)
1079  {
1080  QMessageBox::information(this, tr("Rename Column"), tr("The column could not be renamed: ") + e.what());
1081  }
1082 
1083  m_layer->setOutOfDate();
1084 
1085  setLayer(m_layer);
1086  }
1087 }
1088 
1090 {
1091  RetypeColumnDialog dlg(parentWidget());
1092 
1093  std::auto_ptr<te::da::DataSetType> schema = m_layer->getSchema();
1094  te::dt::Property* prp;
1095  std::string dsetName = schema->getName();
1096  std::string columnName;
1097 
1098  prp = schema->getProperty(column);
1099 
1100  if(prp == 0)
1101  throw Exception(tr("Fail to get property of the dataset.").toStdString());
1102 
1103  columnName = prp->getName();
1104 
1105  dlg.setTableName(dsetName.c_str());
1106  dlg.setColumnName(columnName.c_str());
1107  dlg.setType(prp->getType());
1108 
1109  if(dlg.exec() == QDialog::Accepted)
1110  {
1111  te::da::DataSourcePtr dsrc = GetDataSource(m_layer);
1112 
1113  if(dsrc.get() == 0)
1114  throw Exception(tr("Fail to get data source.").toStdString());
1115 
1116  setDataSet(0, te::common::LATIN1);
1117 
1118  dsrc->changePropertyDefinition(dsetName, columnName, dlg.getProperty().release());
1119 
1120  m_layer->setOutOfDate();
1121 
1122  setLayer(m_layer);
1123  }
1124 }
1125 
1127 {
1128  if(m_dset == 0 || m_layer == 0)
1129  return;
1130 
1131  std::auto_ptr<te::da::DataSetType> schema = m_layer->getSchema();
1132  te::da::PrimaryKey* pk = schema->getPrimaryKey();
1133  std::string dsetName = schema->getName();
1134  te::dt::Property* prop = schema->getProperty(column);
1135  std::string columnName = prop->getName();
1136  std::vector<QString> cols = GetColumnsNames(m_dset);
1137 
1138  std::map<std::string, int> pkColumnsType;
1139 
1140  std::vector<te::dt::Property*> pkProps = pk->getProperties();
1141 
1142  for (size_t i = 0; i < pkProps.size(); i++)
1143  {
1144  pkColumnsType[pkProps[i]->getName()] = pkProps[i]->getType();
1145  }
1146 
1147  AlterDataDialog dlg(parentWidget());
1148  dlg.setSelectedColumn(columnName.c_str());
1149  dlg.setDataColumns(cols);
1150  if (prop->getType() == te::dt::STRING_TYPE)
1151  dlg.setHelpLabelText(tr("This is a string column, use single quotes"));
1152 
1153  if(dlg.exec() == QDialog::Accepted)
1154  {
1155  te::da::DataSourcePtr dsrc = GetDataSource(m_layer);
1156 
1157  if(dsrc.get() == 0)
1158  throw Exception(tr("Fail to get data source.").toStdString());
1159 
1160  std::string sql = "UPDATE " + dsetName + " SET " + columnName + " = " + dlg.getExpression().toStdString();
1161 
1162  try
1163  {
1164  //TODO: create class Update at dataaccess/query to do this operations
1165  //Obs: not working when the dataset primary key has more than two properties
1166  if (!dlg.alterAllData())
1167  {
1168  const te::da::ObjectIdSet* objSet = m_layer->getSelected();
1169 
1170  std::vector<std::string> pkCols = objSet->getPropertyNames();
1171 
1173 
1174  te::da::In* inExp = dynamic_cast<te::da::In*>(exp);
1175  te::da::Or* orExp = dynamic_cast<te::da::Or*>(exp);
1176 
1177  te::da::In* orFirstInExp = 0;
1178  te::da::In* orSecondInExp = 0;
1179 
1180  std::string orFirstInExpStr = " IN (";
1181  std::string orSecondInExpStr = " IN (";
1182 
1183  if (orExp) // more than one properties at primary key
1184  {
1185  orFirstInExp = dynamic_cast<te::da::In*>(orExp->getFirst());
1186  orSecondInExp = dynamic_cast<te::da::In*>(orExp->getSecond());
1187 
1188  for (std::size_t i = 0; i < orFirstInExp->getNumArgs(); ++i)
1189  {
1190  te::da::Expression* a1 = orFirstInExp->getArg(i);
1191 
1192  te::da::Literal* l1 = dynamic_cast<te::da::Literal*>(a1);
1193 
1194  std::string inStr = l1->getValue()->toString();
1195 
1196  if (pkColumnsType[objSet->getPropertyNames()[0]] == te::dt::STRING_TYPE)
1197  inStr = "'" + inStr + "'";
1198 
1199  if (i == orFirstInExp->getNumArgs() - 1)
1200  orFirstInExpStr += inStr + ")";
1201  else
1202  orFirstInExpStr += inStr + ",";
1203  }
1204 
1205  for (std::size_t i = 0; i < orSecondInExp->getNumArgs(); ++i)
1206  {
1207  te::da::Expression* a1 = orSecondInExp->getArg(i);
1208 
1209  te::da::Literal* l1 = dynamic_cast<te::da::Literal*>(a1);
1210 
1211  std::string inStr = l1->getValue()->toString();
1212 
1213  if (pkColumnsType[objSet->getPropertyNames()[1]] == te::dt::STRING_TYPE)
1214  inStr = "'" + inStr + "'";
1215 
1216  if (i == orSecondInExp->getNumArgs() - 1)
1217  orSecondInExpStr += inStr + ")";
1218  else
1219  orSecondInExpStr += inStr + ",";
1220  }
1221 
1222  sql += " WHERE " + objSet->getPropertyNames()[0] + orFirstInExpStr + " AND " + objSet->getPropertyNames()[1] + orSecondInExpStr;
1223 
1224  }
1225  else if (inExp)
1226  {
1227 
1228  std::string inExpStr = " IN (";
1229 
1230  for (std::size_t i = 0; i < inExp->getNumArgs(); ++i)
1231  {
1232  te::da::Expression* a1 = inExp->getArg(i);
1233 
1234  te::da::Literal* l1 = dynamic_cast<te::da::Literal*>(a1);
1235 
1236  std::string inStr = l1->getValue()->toString();
1237 
1238  if (pkColumnsType[objSet->getPropertyNames()[0]] == te::dt::STRING_TYPE)
1239  inStr = "'" + inStr + "'";
1240 
1241  if (i == inExp->getNumArgs() - 1)
1242  {
1243  inExpStr += inStr + ")";
1244  }
1245  else
1246  {
1247  inExpStr += inStr + ",";
1248  }
1249  }
1250 
1251  sql += " WHERE " + objSet->getPropertyNames()[0] + inExpStr;
1252  }
1253 
1254  }
1255 
1256  // Ignore \n
1257  std::replace(sql.begin(), sql.end(), '\n', ' ');
1258 
1259  dsrc->execute(sql);
1260 
1261  m_layer->setOutOfDate();
1262 
1263  setLayer(m_layer);
1264  }
1265  catch(te::common::Exception& e)
1266  {
1267  QMessageBox::information(this, tr("Updating data failure"), e.what());
1268  }
1269  catch(...)
1270  {
1271  QMessageBox::information(this, tr("Updating data failure"), tr("Data source operation fail for unknown reason."));
1272  }
1273  }
1274 }
1275 
1277 {
1278  std::vector<int> hCols = m_popupFilter->getHiddenColumns();
1279  std::vector<int>::iterator it;
1280 
1281  for (it=hCols.begin(); it!=hCols.end(); ++it)
1282  horizontalHeader()->showSection(*it);
1283 }
1284 
1286 {
1287  QHeaderView* hdr = horizontalHeader();
1288 
1289  int nCols = hdr->count();
1290 
1291  for(int i=0; i<nCols; i++)
1292  {
1293  int visCol = hdr->visualIndex(i);
1294 
1295  if(visCol != i)
1296  hdr->moveSection(visCol, i);
1297  }
1298 }
1299 
1300 void te::qt::widgets::DataSetTableView::highlightRow(const int& row, const bool& add)
1301 {
1302  te::da::ObjectIdSet* oids = m_model->getObjectIdSet(row, row);
1303 
1304  if(add)
1305  {
1306  te::da::ObjectId* oid = *oids->begin();
1307 
1308  if(m_delegate->getSelected()->contains(oid))
1309  {
1310  emit deselectOIds(oids);
1311 
1312  delete oids;
1313 
1314  m_delegate->setObjectIdSet(m_layer->getSelected());
1315 
1316  if(m_promotionEnabled)
1317  promote();
1318 
1319  viewport()->repaint();
1320 
1321  return;
1322  }
1323  }
1324 
1325  m_doScroll = false;
1326 
1327  emit selectOIds(oids, add, GetExtent(m_dset, m_model->getPromoter(), row).get());
1328 
1329  if(m_promotionEnabled)
1330  promote();
1331 
1332  viewport()->repaint();
1333 
1334  m_doScroll = true;
1335 }
1336 
1337 void te::qt::widgets::DataSetTableView::highlightRows(const int& initRow, const int& finalRow)
1338 {
1339  int ini,
1340  final;
1341 
1342  if(initRow < finalRow)
1343  {
1344  ini = initRow;
1345  final = finalRow;
1346  }
1347  else
1348  {
1349  ini = finalRow;
1350  final = initRow;
1351  }
1352 
1353  te::da::ObjectIdSet* oids = m_model->getObjectIdSet(ini, final);
1354 
1355  m_doScroll = false;
1356 
1357  emit selectOIds(oids, true, GetExtent(m_dset, m_model->getPromoter(), final).get());
1358 
1359  if(m_promotionEnabled)
1360  promote();
1361 
1362  viewport()->repaint();
1363 
1364  m_doScroll = false;
1365 }
1366 
1368 {
1369  ScopedCursor cursor(Qt::WaitCursor);
1370 
1371  setEnabled(false);
1372  m_model->setEnabled(false);
1373  m_popupFilter->setEnabled(false);
1374 
1375  const te::da::ObjectIdSet* oids = m_delegate->getSelected();
1376  m_model->promote(oids);
1377 
1378  m_popupFilter->setEnabled(true);
1379  m_model->setEnabled(true);
1380  setEnabled(true);
1381 
1382  viewport()->repaint();
1383 
1384  if(scroll)
1385  scrollToTop();
1386 }
1387 
1389 {
1390  //*********************
1391  // Sort by query
1392  //*********************
1393  try
1394  {
1395  ScopedCursor cursor(Qt::WaitCursor);
1396 
1397  std::vector<int> selCols;
1398 
1399  m_orderby.clear();
1400 
1401  int nCols = model()->columnCount();
1402 
1403  for(int i=0; i<nCols; i++)
1404  {
1405  int logRow = horizontalHeader()->logicalIndex(i);
1406  if(selectionModel()->isColumnSelected(logRow, QModelIndex()))
1407  {
1408  m_orderby.push_back(m_dset->getPropertyName((size_t)logRow));
1409  selCols.push_back(logRow);
1410  }
1411  }
1412 
1413  if(selCols.empty())
1414  return;
1415 
1416  std::auto_ptr<te::da::DataSet> dset = GetDataSet(m_layer, m_orderby, asc);
1417 
1418  if(dset.get() == 0)
1419  throw te::common::Exception(tr("Sort operation not supported by the source of data.").toStdString());
1420 
1421  setDataSet(dset.release(), m_encoding);
1422 
1423  viewport()->repaint();
1424 
1425  setUpdatesEnabled(false);
1426 
1427  m_model->getPromoter()->preProcessKeys(m_dset, m_delegate->getSelected()->getPropertyPos());
1428 
1429  setUpdatesEnabled(true);
1430 
1431  if(m_promotionEnabled)
1432  promote();
1433  }
1434  catch(te::common::Exception& e)
1435  {
1436  QMessageBox::information(this, tr("Sorting columns failure"), tr("Could not sort data: ") + e.what());
1437  }
1438 }
1439 
1441 {
1442  m_model->showOIdsVisible(visible);
1443 
1444  horizontalHeader()->viewport()->repaint();
1445 }
1446 
1448 {
1449  if(m_layer == 0)
1450  return;
1451 
1452  try
1453  {
1454  AddColumnDialog dlg(parentWidget());
1455 
1456  std::auto_ptr<te::da::DataSetType> ds_t = m_layer->getSchema();
1457 
1458  std::string dsName = ds_t->getName();
1459  size_t n_prop = ds_t->getProperties().size();
1460  dlg.setTableName(dsName);
1461 
1462  if(dlg.exec() == QDialog::Accepted)
1463  {
1464  te::da::DataSourcePtr ds = GetDataSource(m_layer);
1465 
1466  if(ds.get() == 0)
1467  throw te::common::Exception(tr("Fail to get data source of the layer.").toStdString());
1468 
1469  std::auto_ptr<te::dt::Property> p(dlg.getNewProperty());
1470 
1471  if(p->getName().empty())
1472  throw te::common::Exception(tr("Name must not be empty.").toStdString());
1473 
1474  if(!ds->isPropertyNameValid(p->getName()))
1475  throw te::common::Exception(tr("The property name is invalid.").toStdString());
1476 
1477  if(ds->propertyExists(dsName, p->getName()))
1478  throw te::common::Exception(tr("There already exists a property with this name.").toStdString());
1479 
1480  ds->addProperty(dsName, p.get());
1481 
1482  if(ds->getType().compare("OGR") == 0)
1483  m_model->insertColumns(((int)n_prop-1), 0);
1484 
1485  m_layer->setOutOfDate();
1486 
1487  setLayer(m_layer, false);
1488  }
1489  }
1490  catch(te::common::Exception& e)
1491  {
1492  QMessageBox::information(this, tr("Creating column failure"), tr("The column could not be created: ") + e.what());
1493  }
1494 }
1495 
1497 {
1498  try
1499  {
1500  if(QMessageBox::question(this, tr("Remove column"), tr("Are you sure you want to remove this column?"), QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
1501  {
1502  te::da::DataSourcePtr ds = GetDataSource(m_layer);
1503 
1504  if(ds.get() == 0)
1505  throw te::common::Exception(tr("Fail to get data source of the layer.").toStdString());
1506 
1507  std::auto_ptr<te::da::DataSetType> ds_t = m_layer->getSchema();
1508  std::string dsName = ds_t->getName();
1509 
1510  std::string pName = ds_t->getProperty(column)->getName();
1511 
1512  ds->dropProperty(dsName, pName);
1513 
1514  m_model->removeColumns(column, 0);
1515 
1516  m_layer->setOutOfDate();
1517 
1518  setLayer(m_layer, false);
1519  }
1520  }
1521  catch(te::common::Exception& e)
1522  {
1523  QMessageBox::information(this, tr("Removing column failure"), tr("The column could not be removed: ") + e.what());
1524  }
1525 }
1526 
1528 {
1529  m_autoScrollEnabled = enable;
1530 
1531  m_model->getPromoter()->preProcessKeys(m_dset, m_delegate->getSelected()->getPropertyPos());
1532 }
1533 
1535 {
1536  m_promotionEnabled = enable;
1537 
1538  m_model->getPromoter()->preProcessKeys(m_dset, m_delegate->getSelected()->getPropertyPos());
1539 
1540  if(m_promotionEnabled)
1541  promote();
1542 
1543  m_popupFilter->setPromotionEnabled(m_promotionEnabled);
1544 }
1545 
1546 void te::qt::widgets::DataSetTableView::removeSelection(const int& initRow, const int& finalRow)
1547 {
1548  QItemSelection toRemove;
1549 
1550  for(int i=initRow; i<=finalRow; i++)
1551  {
1552  QModelIndexList idx = selectionModel()->selectedColumns(i);
1553 
1554  if(!idx.empty())
1555  toRemove.select(idx.first(), idx.last());
1556  }
1557 
1558  selectionModel()->select(toRemove, QItemSelectionModel::Deselect);
1559 }
1560 
1562 {
1563  try
1564  {
1565  ScopedCursor c(Qt::WaitCursor);
1566 
1567  std::vector< std::set<int> > ed;
1568 
1569  std::auto_ptr<te::map::LayerSchema> sch = m_layer->getSchema();
1570 
1571  std::auto_ptr<te::da::DataSet> md = m_model->getEditions(sch.get(), ed);
1572 
1573  te::da::DataSourcePtr ds = GetDataSource(m_layer);
1574 
1575  if(ds.get() == 0)
1576  throw te::common::Exception(tr("Fail to get data source from layer").toStdString());
1577 
1578  te::da::ObjectIdSet* objs = 0;
1579 
1580  te::da::GetEmptyOIDSet(sch.get(), objs);
1581 
1582  std::auto_ptr<te::da::ObjectIdSet> objs1(objs);
1583 
1584  ds->update(sch->getName(), md.get(), ed, objs1->getPropertyPos());
1585 
1586  setLayer(m_layer);
1587  }
1588  catch(te::common::Exception& e)
1589  {
1590  QMessageBox::warning(this, tr("Save edition failure"), e.what());
1591  }
1592 }
1593 
1594 #include "DataSetTableView.moc"
1595 
TEQTWIDGETSEXPORT ChartDisplayWidget * createNormalDistribution(te::da::DataSet *dataset, int propId)
Definition: Utils.cpp:1122
Expression * getArg(std::size_t i) const
It returns the i-th function argument.
Definition: Function.cpp:67
virtual const std::string & getType() const =0
It returns the layer type.
A widget used to adjust a histogram's input data.
void sortByColumns(const bool &asc)
Sort by the selected columns.
A Qt dialog for reset data of a column in the table.
std::auto_ptr< te::dt::Property > getProperty()
An specialization of QItemDelegate to be used with te::map::AbstractTable objects.
bool IsGeometryColumn(te::da::DataSet *dset, const size_t &col)
void enableAutoScroll(const bool &)
Expression * getFirst() const
It returns the first function argument.
std::vector< QString > GetColumnsNames(te::da::DataSet *dset)
void highlightRow(const int &row, const bool &add)
Used to highlight the data when the mouse is clicked over a row in the table.
const std::string & getDataSetName() const
const std::string & getDataSourceId() const
A class that informs what kind of constraint and index is supported by a given data source...
te::da::DataSetTypeCapabilities * GetCapabilities(const te::map::AbstractLayer *layer)
virtual void setColor(const QColor &c)
Update the color group.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
Definition: Field.h:50
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it.
Definition: Utils.cpp:286
A layer with reference to a dataset that contains trajectories.
std::vector< int > GetHiddenSections(QHeaderView *hView, te::da::DataSet *dset)
void setPromoter(Promoter *promoter)
Sets the promoter being used.
A Qt dialog for renaming columns into a table.
A model based on te::da::DataSet.
Defines a vertical header for a dataset table view.
CharEncoding
Supported charsets (character encoding).
A layer with reference to a dataset that contains observations.
This is the base class for layers.
Definition: AbstractLayer.h:76
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
te::qt::widgets::Histogram * getHistogram()
Returns a pointer to the widget's form.
void setLayer(te::map::AbstractLayer *layer, const bool &clearEditor=true)
Sets the layer to be presented.
void promote(const bool &scroll=false)
Promotes the highlighted rows.
void changeColumnData(const int &column)
Shows the change column data dialog.
A class that models the description of a dataset.
Definition: DataSetType.h:72
void setDataSet(te::da::DataSet *dset)
void setStatistics(te::da::DataSet *dataSet, const std::string prop)
virtual const char * what() const
It outputs the exception message.
Definition: Exception.cpp:58
Defines an mechanism for logical ordering of rows.
virtual void setLayerSchema(const te::da::DataSetType *schema)
Sets the schema of the data set. It is used to define the primary keys and create the ObjectIdSet...
void retypeColumn(const int &column)
Changes teh type of a column in the table.
~TablePopupFilter()
Destructor.
void selectObject(const int &, const bool &)
void setEnabled(const bool &enabled)
void setTableName(const std::string &name)
boost::ptr_vector< OrderByItem > OrderBy
A class that can be used to model an ORDER BY clause.
Definition: OrderBy.h:37
virtual std::string toString() const =0
It returns the data value in a string notation.
void setDragDrop(bool b)
Sets the drag drop on the horizontal header. When the drag drop is enabled, you lose the ability to s...
A layer resulting from a query.
Definition: QueryLayer.h:50
void setHistogramProperty(int propId)
Sets the property to be used in order to generate the histogram.
void renameColumn(const int &column)
Rename a column of the table.
void setIsOGR(const bool &isOGR)
te::da::DataSet * m_dset
std::auto_ptr< te::da::DataSetTypeCapabilities > m_caps
void setHelpLabelText(const QString &text)
It models a property definition.
Definition: Property.h:59
void setOldColumnName(const QString &name)
void setTableName(const QString &name)
This is an abstract class that models a query expression.
Definition: Expression.h:47
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
void HideGeometryColumns(te::da::DataSet *dset, te::qt::widgets::DataSetTableView *view)
bool eventFilter(QObject *watched, QEvent *event)
te::da::DataSourcePtr GetDataSource(const te::map::AbstractLayer *layer)
std::auto_ptr< te::da::DataSet > GetDataSet(const te::map::AbstractLayer *layer, const te::da::DataSet *set, const std::vector< int > &cols, const bool &asc)
void createNormalDistribution(const int &column)
Creates a new chart that displays the normal distribution based on the data at position column...
A layer with reference to a DataSetTypeConverter.
void setLayer(const te::map::AbstractLayer *layer)
Sets the layer to get drag and drop information.
DataSetTableModel * m_model
The model to be used.
void addColumn()
Add column to the table.
A table view for a dataset.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
te::dt::Property * getNewProperty() const
void hideColumn(const int &column)
Hides the column at position column.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
bool getDragDrop()
Gets the drag drop flag.
const std::string & getDataSourceId() const
void showAllColumns()
Shows all hidden columns.
This class models a literal value.
Definition: Literal.h:53
Definition: Or.h:46
DataSetTableView(QWidget *parent=0)
Constructor.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
A Qt dialog for inserting columns into a table.
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
std::size_t size() const
It returns the object id set size.
void GetGeometryColumnsPositions(te::da::DataSet *dset, std::vector< int > &cols)
std::string getSummaryFunction()
Returns the name of the chosen summary function. Default is None.
const std::string & getDataSourceId() const
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:205
virtual ~DataSetTableView()
Virtual destructor.
void setColumnName(const QString &name)
TEQTWIDGETSEXPORT ChartDisplayWidget * createHistogramDisplay(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices=10, int stat=-1)
Histogram Creator.
Definition: Utils.cpp:1007
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
const std::string & getDataSourceId() const
void highlightOIds(const te::da::ObjectIdSet *oids)
Highlights the objects identified by oids.
bool IsPrimaryKey(const int &col, te::qt::widgets::DataSetTableView *view)
const std::string & getDataSourceId() const
Definition: QueryLayer.cpp:376
TablePopupFilter * m_popupFilter
The menus popup filter.
void showColumn(QAction *act)
void setAcceptDrop(bool b)
Sets the drop on the horizontal header.
te::da::Select * getQuery() const
Definition: QueryLayer.cpp:342
bool hasEditions() const
Returns true if there are unsaved editions e false if there is not.
A class used for logical ordering of rows.
Definition: Promoter.h:69
QAction * GetShowAllMenu(QHeaderView *hView, te::da::DataSet *dset, QMenu *hMnu)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
bool getAcceptDrop()
Gets accept drop flag.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
const std::string & getDataSourceId() const
void createHistogram(const int &column)
Creates a new histogram based on the data at position column.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
te::qt::widgets::DataSetTableView * m_view
void selectObjects(const int &, const int &)
void setSelectedColumn(const QString &colName)
HighlightDelegate * m_delegate
Delegate used for rendering selected rows.
void removeSelection(const int &initRow, const int &finalRow)
int getType() const
It returns the property data type.
Definition: Property.h:161
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
void setDataSetTypeCapabilities(te::da::DataSetTypeCapabilities *caps)
void highlightRows(const int &initRow, const int &finalRow)
Select all rows from initRow to finalRow.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void HideTsVectorColumn(te::da::DataSet *dset, te::qt::widgets::DataSetTableView *view)
std::auto_ptr< te::gm::Envelope > GetExtent(te::da::DataSet *dset, te::qt::widgets::Promoter *p, const int &rowPosition)
void setDataSet(te::da::DataSet *dset, te::common::CharEncoding enc, const bool &clearEditor=true)
Updates the data set being visualized.
Promoter * getPromoter()
Returns the pointer to the promoter being used.
void setOIdsColumnsVisible(const bool &visible)
Shows or hides the icon sinalizing the columns that identify each row.
A layer with reference to a dataset that contains trajectories.
void setDataColumns(const std::vector< QString > &cols)
A customized table view for te::map::AbstractLayer objects. Uses a te::qt::widgets::DataSetModel as i...
std::auto_ptr< te::da::Select > GetSelectExpression(const std::string &datasetName, const std::vector< std::string > &colsNames, const bool &asc)
A delegate for highlight the selected object ids.
const std::vector< std::string > & getPropertyNames() const
It returns the property names used to generated the oids.
size_t getLogicalRow(const size_t &visualRow)
Returns the logical position of the row visualRow.
Definition: Promoter.cpp:187
Expression * getExpressionByInClause(const std::string source="") const
A class that represents the IN operator.
Definition: In.h:52
const std::vector< std::size_t > & getPropertyPos() const
It returns the property positions used to generated the oids.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
void sortData(const bool &)
A table model representing a te::da::DataSet.
void setDataSet(te::da::DataSet *dset)
Sets the data set to get drag and drop information.
QMenu * GetHiddenColumnsMenu(QHeaderView *hView, te::da::DataSet *dset, QMenu *hMnu)
virtual const std::string & getName() const
It returns the constraint name.
Definition: Constraint.h:119
A class that can be used in an ORDER BY clause to sort the items of a resulting query.
Definition: OrderByItem.h:53
virtual const te::da::ObjectIdSet * getSelected() const
Returns the identifiers of the rows highlighted.
TablePopupFilter(te::qt::widgets::DataSetTableView *view)
Contructor.
Expression * getSecond() const
It returns the second function argument.
void setHighlightColor(const QColor &color)
Update the color to be used.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
std::vector< int > getHiddenColumns()
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator begin() const
Returns an iterator for the object ids in container.
te::dt::AbstractData * getValue() const
It returns the value associated to the literal.
Definition: Literal.cpp:65
void showColumn(const int &column)
Shows the hidden column.
void saveEditions()
Saves all editions to the dataset.
std::size_t getNumArgs() const
It returns the number of arguments informed to the function.
Definition: Function.cpp:62
void removeColumn(const int &column)
void setAutoScrollEnabled(const bool &enable)
Enable / disable auto-scroll.
void resetColumnsOrder()
Shows columns in the original order.
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
void setPromotionEnabled(const bool &enable)
Enable / disable promotion.
virtual std::auto_ptr< LayerSchema > getSchema() const =0
It returns the layer schema.
A vertical header used for selecting rows at a table view.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
void setPromotionEnabled(const bool &enabled)