All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/OrderBy.h"
29 #include "../../../dataaccess/query/OrderByItem.h"
30 #include "../../../dataaccess/query/Select.h"
31 #include "../../../dataaccess/utils/Utils.h"
32 #include "../../../geometry/Geometry.h"
33 #include "../../../maptools/DataSetLayer.h"
34 #include "../../../maptools/DataSetAdapterLayer.h"
35 #include "../../../maptools/QueryLayer.h"
36 #include "../../../statistics/qt/StatisticsDialog.h"
37 #include "../../../st/maptools/ObservationDataSetLayer.h"
38 #include "../../../st/maptools/TimeSeriesDataSetLayer.h"
39 #include "../../../st/maptools/TrajectoryDataSetLayer.h"
40 
41 // Qt
42 #include <QBoxLayout>
43 #include <QContextMenuEvent>
44 #include <QCursor>
45 #include <QDialogButtonBox>
46 #include <QHeaderView>
47 #include <QLabel>
48 #include <QMenu>
49 #include <QMessageBox>
50 #include <QPainter>
51 #include <QSpinBox>
52 
53 
54 // STL
55 #include <vector>
56 #include <memory>
57 
58 bool IsGeometryColumn(te::da::DataSet* dset, const size_t& col)
59 {
60  return dset->getPropertyDataType(col) == te::dt::GEOMETRY_TYPE;
61 }
62 
63 void GetGeometryColumnsPositions(te::da::DataSet* dset, std::vector<int>& cols)
64 {
65  size_t nProps = dset->getNumProperties();
66 
67  cols.clear();
68 
69  for(size_t i=0; i<nProps; i++)
70  if(IsGeometryColumn(dset, i))
71  cols.push_back((int)i);
72 }
73 
74 std::vector<int> GetHiddenSections(QHeaderView* hView, te::da::DataSet* dset)
75 {
76  std::vector<int> res;
77 
78  int sz = dset->getNumProperties();
79 
80  if(sz > 0)
81  {
82  for (int i=0; i<sz; i++)
83  if(hView->isSectionHidden(i) && !IsGeometryColumn(dset, i))
84  res.push_back(i);
85  }
86 
87  return res;
88 }
89 
90 QMenu* GetHiddenColumnsMenu(QHeaderView* hView, te::da::DataSet* dset, QMenu* hMnu)
91 {
92  std::vector<int> hSecs = GetHiddenSections(hView, dset);
93  std::vector<int>::iterator it;
94 
95  QMenu* mnu = new QMenu(hMnu);
96  mnu->setTitle(QObject::tr("Show hidden column"));
97 
98  if(hSecs.empty())
99  mnu->setEnabled(false);
100  else
101  for(it=hSecs.begin(); it!=hSecs.end(); ++it)
102  {
103  QString cName = hView->model()->headerData(*it, Qt::Horizontal, Qt::DisplayRole).toString();
104  QAction* act = new QAction(mnu);
105 
106  act->setText(cName);
107  act->setData(QVariant(*it));
108 
109  QString tt = QObject::tr("Turns column \"%1\" visible.").arg(cName);
110 
111  act->setToolTip(tt);
112 
113  mnu->addAction(act);
114  }
115 
116  return mnu;
117 }
118 
119 QAction* GetShowAllMenu(QHeaderView* hView, te::da::DataSet* dset, QMenu* hMnu)
120 {
121  QAction* act = new QAction(hMnu);
122  act->setText(QObject::tr("Show all columns"));
123  act->setEnabled(!GetHiddenSections(hView, dset).empty());
124 
125  return act;
126 }
127 
129 {
130  // Getting data source, if it is available
132 
133  if(layer->getType() == "DATASETLAYER")
134  {
135  const te::map::DataSetLayer* l = dynamic_cast<const te::map::DataSetLayer*>(layer);
136 
137  if(l != 0)
139  }
140  else if(layer->getType() == "DATASETADAPTERLAYER")
141  {
142  const te::map::DataSetAdapterLayer* l = dynamic_cast<const te::map::DataSetAdapterLayer*>(layer);
143 
144  if(l != 0)
146  }
147  else if(layer->getType() == "QUERYLAYER")
148  {
149  const te::map::QueryLayer* l = dynamic_cast<const te::map::QueryLayer*>(layer);
150 
151  if(l != 0)
153  }
154  else if(layer->getType() == "OBSERVATIONDATASETLAYER")
155  {
156  const te::st::ObservationDataSetLayer* l = dynamic_cast<const te::st::ObservationDataSetLayer*>(layer);
157 
158  if(l != 0)
160  }
161  else if(layer->getType() == "TIMESERIESDATASETLAYER")
162  {
163  const te::st::TimeSeriesDataSetLayer* l = dynamic_cast<const te::st::TimeSeriesDataSetLayer*>(layer);
164 
165  if(l != 0)
167  }
168  else if(layer->getType() == "TRAJECTORYDATASETLAYER")
169  {
170  const te::st::TrajectoryDataSetLayer* l = dynamic_cast<const te::st::TrajectoryDataSetLayer*>(layer);
171 
172  if(l != 0)
174  }
175  return ds;
176 }
177 
179 {
180  // Getting data source capabilities, if it is available
182 
183  if(ds.get() != 0)
184  {
185  const te::map::DataSetLayer* dl = dynamic_cast<const te::map::DataSetLayer*>(layer);
186 
187  if(dl != 0)
188  return ds->getCapabilities(dl->getDataSetName()).release();
189  }
190 
191  return 0;
192 }
193 
194 std::auto_ptr<te::da::Select> GetSelectExpression(const std::string& datasetName, const std::vector<std::string>& colsNames, const bool& asc)
195 {
196  te::da::Fields fields;
197 
198  fields.push_back(std::auto_ptr<te::da::Field>(new te::da::Field("*")));
199 
200  te::da::From from;
201 
202  from.push_back(std::auto_ptr<te::da::DataSetName>(new te::da::DataSetName(datasetName)));
203 
204  te::da::OrderBy order_by;
205 
206  for(size_t i=0; i<colsNames.size(); i++)
207  order_by.push_back(std::auto_ptr<te::da::OrderByItem>(new te::da::OrderByItem(colsNames[i], (asc) ? te::da::ASC : te::da::DESC)));
208 
209  return std::auto_ptr<te::da::Select>(new te::da::Select(fields, from, order_by));
210 }
211 
212 std::auto_ptr<te::da::Select> GetSelectExpression(const std::string& tableName, const te::da::DataSet* set, const std::vector<int>& cols, const bool& asc)
213 {
214  std::vector<std::string> colsNames;
215 
216  for(size_t i = 0; i < cols.size(); ++i)
217  colsNames.push_back(set->getPropertyName((size_t)cols[i]));
218 
219  return GetSelectExpression(tableName, colsNames, asc);
220 }
221 
222 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)
223 {
224  std::auto_ptr<te::da::Select> query = GetSelectExpression(layer->getSchema()->getName(), set, cols, asc);
225 
226  try
227  {
228  if(query.get() == 0)
229  throw std::string("Fail to generate query.");
230 
232 
233  if(dsc.get() == 0)
234  throw std::string("Fail to get data source.");
235 
236  return dsc->getTransactor()->query(query.get(), te::common::RANDOM);
237  }
238  catch(...)
239  {
240  return std::auto_ptr<te::da::DataSet>();
241  }
242 }
243 
244 std::auto_ptr<te::da::DataSet> GetDataSet(const te::map::AbstractLayer* layer, const std::vector<std::string>& colsNames, const bool& asc)
245 {
246  std::auto_ptr<te::da::Select> query;
247 
248  if(layer->getType() == "DATASETLAYER")
249  {
250  const te::map::DataSetLayer* l = dynamic_cast<const te::map::DataSetLayer*>(layer);
251 
252  if(l != 0)
253  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
254  }
255  else if(layer->getType() == "DATASETADAPTERLAYER")
256  {
257  const te::map::DataSetAdapterLayer* l = dynamic_cast<const te::map::DataSetAdapterLayer*>(layer);
258 
259  if(l != 0)
260  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
261  }
262  else if(layer->getType() == "QUERYLAYER")
263  {
264  const te::map::QueryLayer* l = dynamic_cast<const te::map::QueryLayer*>(layer);
265 
266  if(l != 0)
267  query.reset(new te::da::Select(l->getQuery()));
268  }
269  else if(layer->getType() == "OBSERVATIONDATASETLAYER")
270  {
271  const te::st::ObservationDataSetLayer* l = dynamic_cast<const te::st::ObservationDataSetLayer*>(layer);
272 
273  if(l != 0)
274  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
275  }
276  else if(layer->getType() == "TIMESERIESDATASETLAYER")
277  {
278  const te::st::TimeSeriesDataSetLayer* l = dynamic_cast<const te::st::TimeSeriesDataSetLayer*>(layer);
279 
280  if(l != 0)
281  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
282  }
283  else if(layer->getType() == "TRAJECTORYDATASETLAYER")
284  {
285  const te::st::TrajectoryDataSetLayer* l = dynamic_cast<const te::st::TrajectoryDataSetLayer*>(layer);
286 
287  if(l != 0)
288  query = GetSelectExpression(layer->getSchema()->getName(), colsNames, asc);
289  }
290 
291  try
292  {
293  if(query.get() == 0)
294  throw std::string("Fail to generate query.");
295 
297 
298  if(dsc.get() == 0)
299  throw std::string("Fail to get data source.");
300 
301  return dsc->getTransactor()->query(query.get(), te::common::RANDOM);
302  }
303  catch(...)
304  {
305  return std::auto_ptr<te::da::DataSet>();
306  }
307 }
308 
309 std::vector<QString> GetColumnsNames(te::da::DataSet* dset)
310 {
311  std::vector<QString> res;
312 
313  if(dset != 0)
314  {
315  size_t n = dset->getNumProperties();
316 
317  for(size_t i=0; i<n; i++)
318  if(!IsGeometryColumn(dset, i))
319  res.push_back(dset->getPropertyName(i).c_str());
320  }
321 
322  return res;
323 }
324 
325 std::auto_ptr<te::gm::Envelope> GetExtent(te::da::DataSet* dset, te::qt::widgets::Promoter* p, const int& rowPosition)
326 {
327  // Getting last select object bounding rectangle
328  std::vector<int> geoCols;
329 
330  GetGeometryColumnsPositions(dset, geoCols);
331 
332  if(!geoCols.empty())
333  {
334  int rpos = p->getLogicalRow(rowPosition);
335 
336  dset->move(rpos);
337 
338  size_t pos = (size_t)geoCols[0];
339 
340  std::auto_ptr<te::gm::Geometry> g = dset->getGeometry(pos);
341 
342  return std::auto_ptr<te::gm::Envelope> (new te::gm::Envelope(*g->getMBR()));
343  }
344 
345  return std::auto_ptr<te::gm::Envelope>();
346 }
347 
349 {
350  te::qt::widgets::HighlightDelegate* d = dynamic_cast<te::qt::widgets::HighlightDelegate*>(view->itemDelegate());
351 
352  if(d == 0)
353  return false;
354 
355  const te::da::ObjectIdSet* objs = d->getSelected();
356 
357  if(objs == 0)
358  return false;
359 
360  std::vector<size_t> cols = objs->getPropertyPos();
361  std::vector<size_t>::iterator it;
362 
363  for(it = cols.begin(); it != cols.end(); ++it)
364  if((size_t)col == *it)
365  return true;
366 
367  return false;
368 }
369 
371 {
372  if(dset != 0)
373  {
374  std::vector<int> geoCols;
375  std::vector<int>::iterator it;
376  GetGeometryColumnsPositions(dset, geoCols);
377 
378  for(it = geoCols.begin(); it != geoCols.end(); ++it)
379  view->hideColumn(*it);
380  }
381 }
382 
384 {
385  if(dset != 0)
386  {
387  size_t nProps = dset->getNumProperties();
388 
389  for(std::size_t i = 0; i < nProps; ++i)
390  if(dset->getPropertyName(i) == "tsvector")
391  view->hideColumn(i);
392  }
393 }
394 
395 /*!
396  \class Filter for popup menus
397 */
398 class TablePopupFilter : public QObject
399 {
400  Q_OBJECT
401 
402  public:
403 
404  /*!
405  \brief Contructor.
406  */
408  QObject(view),
409  m_view(view),
410  m_hMenu(0),
411  m_vMenu(0),
412  m_vportMenu(0),
413  m_dset(0),
414  m_showOidsColumns(false),
415  m_enabled(true),
416  m_autoScrollEnabled(false),
417  m_promotionEnabled(false)
418  {
419  m_view->horizontalHeader()->installEventFilter(this);
420  m_view->verticalHeader()->installEventFilter(this);
421  m_view->viewport()->installEventFilter(this);
422 
423  m_view->connect(this, SIGNAL(createHistogram(const int&)), SLOT(createHistogram(const int&)));
424  m_view->connect(this, SIGNAL(createNormalDistribution(const int&)), SLOT(createNormalDistribution(const int&)));
425  m_view->connect(this, SIGNAL(hideColumn(const int&)), SLOT(hideColumn(const int&)));
426  m_view->connect(this, SIGNAL(showColumn(const int&)), SLOT(showColumn(const int&)));
427  m_view->connect(this, SIGNAL(removeColumn(const int&)), SLOT(removeColumn(const int&)));
428  m_view->connect(this, SIGNAL(enableAutoScroll(const bool&)), SLOT(setAutoScrollEnabled(const bool&)));
429  m_view->connect(this, SIGNAL(sortData(const bool&)), SLOT(sortByColumns(const bool&)));
430  m_view->connect(this, SIGNAL(renameColumn(const int&)), SLOT(renameColumn(const int&)));
431  m_view->connect(this, SIGNAL(retypeColumn(const int&)), SLOT(retypeColumn(const int&)));
432  m_view->connect(this, SIGNAL(changeColumnData(const int&)), SLOT(changeColumnData(const int&)));
433  m_view->connect(this, SIGNAL(enablePromotion(const bool&)), SLOT(setPromotionEnabled(const bool&)));
434  m_view->connect(this, SIGNAL(saveEditions()), SLOT(saveEditions()));
435  }
436 
437  /*!
438  \brief Destructor.
439  */
441  {
442  delete m_hMenu;
443  delete m_vMenu;
444  delete m_vportMenu;
445  }
446 
447  bool eventFilter(QObject* watched, QEvent* event)
448  {
449  if(!m_enabled)
450  return QObject::eventFilter(watched, event);
451 
452  QWidget* vport = m_view->viewport();
453  QHeaderView* hHdr = m_view->horizontalHeader();
454  QHeaderView* vHdr = m_view->verticalHeader();
455 
456  switch(event->type())
457  {
458  case QEvent::ContextMenu:
459  {
460  if(watched == hHdr)
461  {
462  delete m_hMenu;
463  m_hMenu = 0;
464 
465  QContextMenuEvent* evt = static_cast<QContextMenuEvent*>(event);
466  QPoint pos = evt->globalPos();
467 
468  m_columnPressed = hHdr->logicalIndex(hHdr->visualIndexAt(evt->pos().x()));
469  bool isPKey = IsPrimaryKey(m_columnPressed, m_view);
470 
471  if(m_columnPressed > 0 && !isPKey)
472  {
473  m_hMenu = new QMenu;
474 
475  QAction* act = new QAction(m_hMenu);
476  act->setText(tr("Hide column"));
477  act->setToolTip(tr("Hides the selected column."));
478 
479  m_hMenu->addAction(act);
480 
481  QMenu* hMnu = GetHiddenColumnsMenu(hHdr, m_dset, m_hMenu);
482 
483  if(m_columnPressed == -1)
484  act->setEnabled(false);
485 
486  m_hMenu->addAction(hMnu->menuAction());
487 
488  QAction* act2 = GetShowAllMenu(hHdr, m_dset, m_hMenu);
489  m_hMenu->addAction(act2);
490 
491  QAction* act3 = new QAction(m_hMenu);
492  act3->setText(tr("Reset columns order"));
493  act3->setToolTip(tr("Put all columns in the original order."));
494  m_hMenu->addAction(act3);
495 
496  m_hMenu->addSeparator();
497 
498  QAction* act5 = new QAction(m_hMenu);
499  act5->setText(tr("Sort data ASC"));
500  act5->setToolTip(tr("Sort data in ascendent order using selected columns."));
501  m_hMenu->addAction(act5);
502 
503  QAction* act9 = new QAction(m_hMenu);
504  act9->setText(tr("Sort data DESC"));
505  act9->setToolTip(tr("Sort data in descendent order using selected columns."));
506  m_hMenu->addAction(act9);
507 
508  m_hMenu->addSeparator();
509 
510  QAction* act4 = new QAction(m_hMenu);
511  act4->setText(tr("Histogram"));
512  act4->setToolTip(tr("Creates a new histogram based on the data of the selected colunm."));
513  m_hMenu->addAction(act4);
514 
515  QAction* act10 = new QAction(m_hMenu);
516  act10->setText(tr("Normal Probability"));
517  act10->setToolTip(tr("Show a chart that displays the normal probability curve."));
518  m_hMenu->addAction(act10);
519 
520  QAction* act6 = new QAction(m_hMenu);
521  act6->setText(tr("Statistics"));
522  act6->setToolTip(tr("Show the statistics summary of the selected colunm."));
523  m_hMenu->addAction(act6);
524 
525  m_hMenu->addSeparator();
526 
527  // Signal / Slot connections
528  connect(act, SIGNAL(triggered()), SLOT(hideColumn()));
529  connect(hMnu, SIGNAL(triggered(QAction*)), SLOT(showColumn(QAction*)));
530 
531  connect(act4, SIGNAL(triggered()), SLOT(createHistogram()));
532 
533  m_view->connect(act2, SIGNAL(triggered()), SLOT(showAllColumns()));
534  m_view->connect(act3, SIGNAL(triggered()), SLOT(resetColumnsOrder()));
535 
536 
537  connect(act6, SIGNAL(triggered()), SLOT(showStatistics()));
538  connect(act5, SIGNAL(triggered()), SLOT(sortDataAsc()));
539  connect(act9, SIGNAL(triggered()), SLOT(sortDataDesc()));
540  connect(act10, SIGNAL(triggered()), SLOT(createNormalDistribution()));
541 
542  if(m_caps.get())
543  {
544  QAction* act7 = new QAction(m_hMenu);
545  act7->setText(tr("Add column"));
546  act7->setToolTip(tr("Adds a column to the table."));
547  m_hMenu->addAction(act7);
548  act7->setEnabled(m_caps->supportsAddColumn());
549 
550  QAction* act8 = new QAction(m_hMenu);
551  act8->setText(tr("Remove column"));
552  act8->setToolTip(tr("Removes a column from the table."));
553  m_hMenu->addAction(act8);
554  act8->setEnabled(m_caps->supportsRemoveColumn());
555 
556  QAction* act10 = new QAction(m_hMenu);
557  act10->setText(tr("Rename column"));
558  act10->setToolTip(tr("Renames a column of the table."));
559  m_hMenu->addAction(act10);
560 
561  QAction* act11 = new QAction(m_hMenu);
562  act11->setText(tr("Change column type"));
563  act11->setToolTip(tr("Changes the type of a column of the table."));
564  m_hMenu->addAction(act11);
565 
566  QAction* act12 = new QAction(m_hMenu);
567  act12->setText(tr("Change column data"));
568  act12->setToolTip(tr("Changes the data of a column of the table."));
569  m_hMenu->addAction(act12);
570 
571  QAction* act13 = new QAction(m_hMenu);
572  act13->setText(tr("Save editions"));
573  act13->setToolTip(tr("Save pendent editions to layer."));
574  act13->setEnabled(m_view->hasEditions());
575  m_hMenu->addAction(act13);
576 
577  m_view->connect(act7, SIGNAL(triggered()), SLOT(addColumn()));
578 
579  connect(act8, SIGNAL(triggered()), SLOT(removeColumn()));
580  connect (act10, SIGNAL(triggered()), SLOT(renameColumn()));
581  connect (act11, SIGNAL(triggered()), SLOT(retypeColumn()));
582  connect (act12, SIGNAL(triggered()), SLOT(changeColumnData()));
583  connect (act13, SIGNAL(triggered()), SIGNAL(saveEditions()));
584  }
585 
586  m_hMenu->popup(pos);
587  }
588  }
589  else if(watched == vport)
590  {
591  }
592  else if(watched == vHdr)
593  {
594  delete m_vMenu;
595 
596  QContextMenuEvent* evt = static_cast<QContextMenuEvent*>(event);
597  QPoint pos = evt->globalPos();
598 
599  m_vMenu = new QMenu;
600  QAction* act = new QAction(m_vMenu);
601  act->setText(tr("Enable auto scroll"));
602  act->setToolTip(tr("Goes to the selected row."));
603 
604  act->setCheckable(true);
605  act->setChecked(m_autoScrollEnabled);
606 
607  m_vMenu->addAction(act);
608 
609  connect(act, SIGNAL(triggered()), SLOT(setAutoScrollEnabled()));
610 
611  act = new QAction(m_vMenu);
612  act->setText(tr("Enable promotion"));
613  act->setToolTip(tr("Enables promotion of selected rows."));
614 
615  act->setCheckable(true);
616  act->setChecked(m_promotionEnabled);
617 
618  m_vMenu->addSeparator();
619 
620  m_vMenu->addAction(act);
621 
622  connect(act, SIGNAL(triggered()), SLOT(enablePromotion()));
623 
624  m_vMenu->popup(pos);
625  }
626  }
627  break;
628 
629  default:
630  break;
631  }
632 
633  return QObject::eventFilter(watched, event);
634  }
635 
637  {
638  m_dset = dset;
639  }
640 
641  std::vector<int> getHiddenColumns()
642  {
643  return GetHiddenSections(m_view->horizontalHeader(), m_dset);
644  }
645 
646  void setEnabled(const bool& enabled)
647  {
648  m_enabled = enabled;
649  }
650 
652  {
653  m_caps.reset(caps);
654  }
655 
656  void setPromotionEnabled(const bool& enabled)
657  {
658  m_promotionEnabled = enabled;
659  }
660 
661  protected slots:
662 
664  {
666  }
667 
669  {
671  }
672 
673  void hideColumn()
674  {
676  }
677 
678  void showColumn(QAction* act)
679  {
680  int column = act->data().toInt();
681 
682  emit showColumn(column);
683  }
684 
686  {
687  te::stat::StatisticsDialog statisticDialog;
688  std::string prop = m_dset->getPropertyName(m_columnPressed);
689  statisticDialog.setStatistics(m_dset, prop);
690  statisticDialog.exec();
691  }
692 
694  {
696  }
697 
699  {
701 
703  }
704 
705  void sortDataAsc()
706  {
707  emit sortData(true);
708  }
709 
711  {
712  emit sortData(false);
713  }
714 
716  {
718  }
719 
721  {
723  }
724 
726  {
728  }
729 
731  {
733 
735  }
736 
737  signals:
738 
739  void createHistogram(const int&);
740 
741  void createNormalDistribution(const int&);
742 
743  void hideColumn(const int&);
744 
745  void showColumn(const int&);
746 
747  void renameColumn(const int&);
748 
749  void retypeColumn(const int&);
750 
751  void changeColumnData(const int&);
752 
753  void selectObject(const int&, const bool&);
754 
755  void selectObjects(const int&, const int&);
756 
757  void enablePromotion(const bool&);
758 
759  void removeColumn(const int&);
760 
761  void enableAutoScroll(const bool&);
762 
763  void sortData(const bool&);
764 
765  void saveEditions();
766 
767  protected:
768 
770  QMenu* m_hMenu;
771  QMenu* m_vMenu;
772  QMenu* m_vportMenu;
774  std::auto_ptr<te::da::DataSetTypeCapabilities> m_caps;
776  bool m_enabled;
780 };
781 
783  QTableView(parent),
784  m_layer(0),
785  m_autoScrollEnabled(false),
786  m_doScroll(true),
787  m_promotionEnabled(false),
788  m_dset(0),
789  m_orderAsc(true)
790 {
791  m_model = new DataSetTableModel(this);
792 
793  setModel(m_model);
794 
795  setVerticalHeader(new DataSetTableVerticalHeader(this));
796  setHorizontalHeader(new DataSetTableHorizontalHeader(this));
797 
798 #if QT_VERSION >= 0x050000
799  horizontalHeader()->setSectionsMovable(true);
800 #else
801  horizontalHeader()->setMovable(true);
802 #endif
803 
804  setSelectionMode(QAbstractItemView::MultiSelection);
805  setSelectionBehavior(QAbstractItemView::SelectColumns);
806 
807  m_popupFilter = new TablePopupFilter(this);
808 
809  m_delegate = new HighlightDelegate(this);
810 
812 
813  m_delegate->setColor(Qt::green);
814 
815  setItemDelegate(m_delegate);
816 
817  connect(verticalHeader(), SIGNAL(selectedRow(const int&, const bool&)), SLOT(highlightRow(const int&, const bool&)));
818  connect(verticalHeader(), SIGNAL(selectedRows(const int&, const int&)), SLOT(highlightRows(const int&, const int&)));
819 }
820 
822 {
823  if (m_model->hasEditions())
824  {
825  QMessageBox msgBox(this);
826  msgBox.setText("There are unsaved changes on table.");
827  msgBox.setInformativeText("Do you want to save your changes?");
828  msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
829  msgBox.setDefaultButton(QMessageBox::Save);
830 
831  int ret = msgBox.exec();
832 
833  if(ret == QMessageBox::Save)
834  saveEditions();
835  }
836 }
837 
839 {
840  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
841  hheader->setDragDrop(true);
842 }
843 
845 {
846  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
847  return hheader->getDragDrop();
848 }
849 
851 {
852  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
853  hheader->setAcceptDrop(true);
854 }
855 
857 {
858  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
859  return hheader->getAcceptDrop();
860 }
861 
863 {
864  ScopedCursor cursor(Qt::WaitCursor);
865 
866  m_layer = layer;
867  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
868  hheader->setLayer(m_layer);
869 
870  std::auto_ptr<te::map::LayerSchema> sch = m_layer->getSchema();
871 
872  if (m_orderby.empty())
873  {
874  std::vector<te::dt::Property*> psps;
875 
876  if(sch->getPrimaryKey())
877  psps = sch->getPrimaryKey()->getProperties();
878  else
879  psps = sch->getProperties();
880 
881  std::vector<te::dt::Property*>::iterator it;
882 
883  for(it = psps.begin(); it != psps.end(); ++it)
884  m_orderby.push_back((*it)->getName());
885  }
886 
887  te::da::DataSourcePtr dsc = GetDataSource(m_layer);
888 
889  setDataSet(GetDataSet(m_layer, m_orderby, m_orderAsc).release(), dsc->getEncoding(), clearEditor);
890  setLayerSchema(sch.get());
891 
893 
894  m_popupFilter->setDataSetTypeCapabilities(caps);
895 
896  if(caps)
897  m_model->setEditable(caps->supportsDataEdition());
898 
899  if(dsc.get() != 0)
900  {
901  setSelectionMode((dsc->getType().compare("OGR") == 0) ? SingleSelection : MultiSelection);
902  setSelectionBehavior((dsc->getType().compare("OGR") == 0) ? QAbstractItemView::SelectColumns : QAbstractItemView::SelectItems);
903  }
904 
905  highlightOIds(m_layer->getSelected());
906 }
907 
909 {
910  reset();
911 
912  m_encoding = enc;
913 
914  m_model->setDataSet(dset, enc, clearEditor);
915  DataSetTableHorizontalHeader* hheader = static_cast<DataSetTableHorizontalHeader*>(horizontalHeader());
916  hheader->setDataSet(dset);
917 
918  HideGeometryColumns(dset, this);
919  HideTsVectorColumn(dset, this);
920 
921  m_popupFilter->setDataSet(dset);
922  m_delegate->setDataSet(dset);
923  m_dset = dset;
924 }
925 
927 {
928  te::da::ObjectIdSet* objs = 0;
929 
930  te::da::GetEmptyOIDSet(schema, objs);
931 
932  std::auto_ptr<te::da::ObjectIdSet> objs_ptr(objs);
933 
934  m_delegate->setObjectIdSet(objs_ptr.get());
935 
936  m_model->setPkeysColumns(objs_ptr->getPropertyPos());
937 
938  m_model->getPromoter()->preProcessKeys(m_dset, objs_ptr->getPropertyPos());
939 }
940 
942 {
943  if(oids == 0)
944  return;
945 
946  m_delegate->setObjectIdSet(oids);
947 
948  if(m_autoScrollEnabled && oids != 0 && oids->size() > 0)
949  {
950  size_t row = m_model->getPromoter()->map2Row(*oids->begin());
951 
952  scrollTo(m_model->index((int)row, 0));
953  }
954 
955  if(m_promotionEnabled)
956  promote(m_doScroll);
957 
958  viewport()->repaint();
959 }
960 
962 {
963  m_delegate->setColor(color);
964 
965  repaint();
966 }
967 
969 {
970  return m_model->hasEditions();
971 }
972 
974 {
975  QDialog* dialog = new QDialog(this);
976  dialog->setFixedSize(160, 75);
977 
978  const te::map::LayerSchema* schema = m_layer->getSchema().release();
979 
980  te::da::DataSet* dataset = m_layer->getData().release();
981  te::da::DataSetType* dataType = (te::da::DataSetType*) schema;
982 
983  // Histogram data Widget
984  te::qt::widgets::HistogramDataWidget* histogramWidget = new te::qt::widgets::HistogramDataWidget(dataset, dataType, dialog);
985  histogramWidget->setHistogramProperty(column);
986 
987  // Adjusting...
988  QGridLayout* layout = new QGridLayout(dialog);
989  layout->addWidget(histogramWidget);
990 
991  QDialogButtonBox* bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
992  connect(bbox, SIGNAL(accepted()), dialog, SLOT(accept()));
993  connect(bbox, SIGNAL(rejected()), dialog, SLOT(reject()));
994 
995  layout->addWidget(bbox);
996  layout->setSizeConstraint(QLayout::SetFixedSize);
997 
998  int res = dialog->exec();
999  if (res == QDialog::Accepted)
1000  emit createChartDisplay(te::qt::widgets::createHistogramDisplay(dataset,dataType, column, histogramWidget->getHistogram()));
1001 
1002  delete dialog;
1003 }
1004 
1006 {
1007  int propType = m_layer->getData()->getPropertyDataType(column);
1008  if(propType >= te::dt::INT16_TYPE && propType <= te::dt::NUMERIC_TYPE)
1009  {
1010  emit createChartDisplay(te::qt::widgets::createNormalDistribution(m_layer->getData().get(), column));
1011  }
1012  else
1013  {
1014  QString msgErr(tr("This operation is not available for this type of data"));
1015  QString msgTitle(tr("TNormal Probability"));
1016  QMessageBox::warning(this, msgTitle, msgErr);
1017  }
1018 }
1019 
1021 {
1022  horizontalHeader()->hideSection(column);
1023 }
1024 
1026 {
1027  horizontalHeader()->showSection(column);
1028 }
1029 
1031 {
1032  RenameColumnDialog dlg(parentWidget());
1033 
1034  dlg.setOldColumnName(QString::fromStdString(m_dset->getPropertyName(column)));
1035 
1036  if(dlg.exec() == QDialog::Accepted)
1037  {
1038  std::string oldName = dlg.getOldName().toStdString();
1039  std::string newName = dlg.getNewName().toStdString();
1040  te::da::DataSourcePtr dsrc = GetDataSource(m_layer);
1041 
1042  if(dsrc.get() == 0)
1043  throw Exception(tr("Fail to get data source.").toStdString());
1044 
1045  if(!dsrc->isPropertyNameValid(newName))
1046  {
1047  QMessageBox::warning(this, tr("TerraView"), tr("Invalid column name. Choose another."));
1048  return;
1049  }
1050 
1051  try
1052  {
1053  dsrc->renameProperty(m_layer->getSchema()->getName(), oldName, newName);
1054  }
1055  catch (const te::common::Exception& e)
1056  {
1057  QMessageBox::information(this, tr("Rename Column"), tr("The column could not be renamed: ") + e.what());
1058  }
1059 
1060  m_layer->setOutOfDate();
1061 
1062  setLayer(m_layer);
1063  }
1064 }
1065 
1067 {
1068  RetypeColumnDialog dlg(parentWidget());
1069 
1070  std::auto_ptr<te::da::DataSetType> schema = m_layer->getSchema();
1071  te::dt::Property* prp;
1072  std::string dsetName = schema->getName();
1073  std::string columnName;
1074 
1075  prp = schema->getProperty(column);
1076 
1077  if(prp == 0)
1078  throw Exception(tr("Fail to get property of the dataset.").toStdString());
1079 
1080  columnName = prp->getName();
1081 
1082  dlg.setTableName(dsetName.c_str());
1083  dlg.setColumnName(columnName.c_str());
1084  dlg.setType(prp->getType());
1085 
1086  if(dlg.exec() == QDialog::Accepted)
1087  {
1088  te::da::DataSourcePtr dsrc = GetDataSource(m_layer);
1089 
1090  if(dsrc.get() == 0)
1091  throw Exception(tr("Fail to get data source.").toStdString());
1092 
1093  setDataSet(0, te::common::LATIN1);
1094 
1095  dsrc->changePropertyDefinition(dsetName, columnName, dlg.getProperty().release());
1096 
1097  m_layer->setOutOfDate();
1098 
1099  setLayer(m_layer);
1100  }
1101 }
1102 
1104 {
1105  if(m_dset == 0 || m_layer == 0)
1106  return;
1107 
1108  std::auto_ptr<te::da::DataSetType> schema = m_layer->getSchema();
1109  std::string dsetName = schema->getName();
1110  std::string columnName = schema->getProperty(column)->getName();
1111  std::vector<QString> cols = GetColumnsNames(m_dset);
1112 
1113  AlterDataDialog dlg(parentWidget());
1114  dlg.setSelectedColumn(columnName.c_str());
1115  dlg.setDataColumns(cols);
1116 
1117  if(dlg.exec() == QDialog::Accepted)
1118  {
1119  te::da::DataSourcePtr dsrc = GetDataSource(m_layer);
1120 
1121  if(dsrc.get() == 0)
1122  throw Exception(tr("Fail to get data source.").toStdString());
1123 
1124  std::string sql;
1125 
1126  if(dlg.alterAllData())
1127  sql = "UPDATE " + dsetName + " SET " + columnName + " = " + dlg.getExpression().toStdString();
1128 
1129  try
1130  {
1131  dsrc->execute(sql);
1132 
1133  m_layer->setOutOfDate();
1134 
1135  setLayer(m_layer);
1136  }
1137  catch(te::common::Exception& e)
1138  {
1139  QMessageBox::information(this, tr("Updating data failure"), e.what());
1140  }
1141  catch(...)
1142  {
1143  QMessageBox::information(this, tr("Updating data failure"), tr("Data source operation fail for unknown reason."));
1144  }
1145  }
1146 }
1147 
1149 {
1150  std::vector<int> hCols = m_popupFilter->getHiddenColumns();
1151  std::vector<int>::iterator it;
1152 
1153  for (it=hCols.begin(); it!=hCols.end(); ++it)
1154  horizontalHeader()->showSection(*it);
1155 }
1156 
1158 {
1159  QHeaderView* hdr = horizontalHeader();
1160 
1161  int nCols = hdr->count();
1162 
1163  for(int i=0; i<nCols; i++)
1164  {
1165  int visCol = hdr->visualIndex(i);
1166 
1167  if(visCol != i)
1168  hdr->moveSection(visCol, i);
1169  }
1170 }
1171 
1172 void te::qt::widgets::DataSetTableView::highlightRow(const int& row, const bool& add)
1173 {
1174  te::da::ObjectIdSet* oids = m_model->getObjectIdSet(row, row);
1175 
1176  if(add)
1177  {
1178  te::da::ObjectId* oid = *oids->begin();
1179 
1180  if(m_delegate->getSelected()->contains(oid))
1181  {
1182  emit deselectOIds(oids);
1183 
1184  delete oids;
1185 
1186  m_delegate->setObjectIdSet(m_layer->getSelected());
1187 
1188  if(m_promotionEnabled)
1189  promote();
1190 
1191  viewport()->repaint();
1192 
1193  return;
1194  }
1195  }
1196 
1197  m_doScroll = false;
1198 
1199  emit selectOIds(oids, add, GetExtent(m_dset, m_model->getPromoter(), row).get());
1200 
1201  if(m_promotionEnabled)
1202  promote();
1203 
1204  viewport()->repaint();
1205 
1206  m_doScroll = true;
1207 }
1208 
1209 void te::qt::widgets::DataSetTableView::highlightRows(const int& initRow, const int& finalRow)
1210 {
1211  int ini,
1212  final;
1213 
1214  if(initRow < finalRow)
1215  {
1216  ini = initRow;
1217  final = finalRow;
1218  }
1219  else
1220  {
1221  ini = finalRow;
1222  final = initRow;
1223  }
1224 
1225  te::da::ObjectIdSet* oids = m_model->getObjectIdSet(ini, final);
1226 
1227  m_doScroll = false;
1228 
1229  emit selectOIds(oids, true, GetExtent(m_dset, m_model->getPromoter(), final).get());
1230 
1231  if(m_promotionEnabled)
1232  promote();
1233 
1234  viewport()->repaint();
1235 
1236  m_doScroll = false;
1237 }
1238 
1240 {
1241  ScopedCursor cursor(Qt::WaitCursor);
1242 
1243  setEnabled(false);
1244  m_model->setEnabled(false);
1245  m_popupFilter->setEnabled(false);
1246 
1247  const te::da::ObjectIdSet* oids = m_delegate->getSelected();
1248  m_model->promote(oids);
1249 
1250  m_popupFilter->setEnabled(true);
1251  m_model->setEnabled(true);
1252  setEnabled(true);
1253 
1254  viewport()->repaint();
1255 
1256  if(scroll)
1257  scrollToTop();
1258 }
1259 
1261 {
1262  //*********************
1263  // Sort by query
1264  //*********************
1265  try
1266  {
1267  ScopedCursor cursor(Qt::WaitCursor);
1268 
1269  std::vector<int> selCols;
1270 
1271  m_orderby.clear();
1272 
1273  int nCols = model()->columnCount();
1274 
1275  for(int i=0; i<nCols; i++)
1276  {
1277  int logRow = horizontalHeader()->logicalIndex(i);
1278  if(selectionModel()->isColumnSelected(logRow, QModelIndex()))
1279  {
1280  m_orderby.push_back(m_dset->getPropertyName((size_t)logRow));
1281  selCols.push_back(logRow);
1282  }
1283  }
1284 
1285  if(selCols.empty())
1286  return;
1287 
1288  std::auto_ptr<te::da::DataSet> dset = GetDataSet(m_layer, m_orderby, asc);
1289 
1290  if(dset.get() == 0)
1291  throw te::common::Exception(tr("Sort operation not supported by the source of data.").toStdString());
1292 
1293  setDataSet(dset.release(), m_encoding);
1294 
1295  viewport()->repaint();
1296 
1297  setUpdatesEnabled(false);
1298 
1299  m_model->getPromoter()->preProcessKeys(m_dset, m_delegate->getSelected()->getPropertyPos());
1300 
1301  setUpdatesEnabled(true);
1302 
1303  if(m_promotionEnabled)
1304  promote();
1305  }
1306  catch(te::common::Exception& e)
1307  {
1308  QMessageBox::information(this, tr("Sorting columns failure"), tr("Could not sort data: ") + e.what());
1309  }
1310 }
1311 
1313 {
1314  m_model->showOIdsVisible(visible);
1315 
1316  horizontalHeader()->viewport()->repaint();
1317 }
1318 
1320 {
1321  if(m_layer == 0)
1322  return;
1323 
1324  try
1325  {
1326  AddColumnDialog dlg(parentWidget());
1327 
1328  std::auto_ptr<te::da::DataSetType> ds_t = m_layer->getSchema();
1329 
1330  std::string dsName = ds_t->getName();
1331  size_t n_prop = ds_t->getProperties().size();
1332  dlg.setTableName(dsName);
1333 
1334  if(dlg.exec() == QDialog::Accepted)
1335  {
1336  te::da::DataSourcePtr ds = GetDataSource(m_layer);
1337 
1338  if(ds.get() == 0)
1339  throw te::common::Exception(tr("Fail to get data source of the layer.").toStdString());
1340 
1341  std::auto_ptr<te::dt::Property> p(dlg.getNewProperty());
1342 
1343  if(p->getName().empty())
1344  throw te::common::Exception(tr("Name must not be empty.").toStdString());
1345 
1346  if(!ds->isPropertyNameValid(p->getName()))
1347  throw te::common::Exception(tr("The property name is invalid.").toStdString());
1348 
1349  if(ds->propertyExists(dsName, p->getName()))
1350  throw te::common::Exception(tr("There already exists a property with this name.").toStdString());
1351 
1352  ds->addProperty(dsName, p.get());
1353 
1354  if(ds->getType().compare("OGR") == 0)
1355  m_model->insertColumns(((int)n_prop-1), 0);
1356 
1357  m_layer->setOutOfDate();
1358 
1359  setLayer(m_layer, false);
1360  }
1361  }
1362  catch(te::common::Exception& e)
1363  {
1364  QMessageBox::information(this, tr("Creating column failure"), tr("The column could not be created: ") + e.what());
1365  }
1366 }
1367 
1369 {
1370  try
1371  {
1372  if(QMessageBox::question(this, tr("Remove column"), tr("Are you sure you want to remove this column?"), QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
1373  {
1374  te::da::DataSourcePtr ds = GetDataSource(m_layer);
1375 
1376  if(ds.get() == 0)
1377  throw te::common::Exception(tr("Fail to get data source of the layer.").toStdString());
1378 
1379  std::auto_ptr<te::da::DataSetType> ds_t = m_layer->getSchema();
1380  std::string dsName = ds_t->getName();
1381 
1382  std::string pName = ds_t->getProperty(column)->getName();
1383 
1384  ds->dropProperty(dsName, pName);
1385 
1386  m_model->removeColumns(column, 0);
1387 
1388  m_layer->setOutOfDate();
1389 
1390  setLayer(m_layer, false);
1391  }
1392  }
1393  catch(te::common::Exception& e)
1394  {
1395  QMessageBox::information(this, tr("Removing column failure"), tr("The column could not be removed: ") + e.what());
1396  }
1397 }
1398 
1400 {
1401  m_autoScrollEnabled = enable;
1402 }
1403 
1405 {
1406  m_promotionEnabled = enable;
1407 
1408  if(m_promotionEnabled)
1409  promote();
1410 
1411  m_popupFilter->setPromotionEnabled(m_promotionEnabled);
1412 }
1413 
1414 void te::qt::widgets::DataSetTableView::removeSelection(const int& initRow, const int& finalRow)
1415 {
1416  QItemSelection toRemove;
1417 
1418  for(int i=initRow; i<=finalRow; i++)
1419  {
1420  QModelIndexList idx = selectionModel()->selectedColumns(i);
1421 
1422  if(!idx.empty())
1423  toRemove.select(idx.first(), idx.last());
1424  }
1425 
1426  selectionModel()->select(toRemove, QItemSelectionModel::Deselect);
1427 }
1428 
1430 {
1431  try
1432  {
1433  ScopedCursor c(Qt::WaitCursor);
1434 
1435  std::vector< std::set<int> > ed;
1436 
1437  std::auto_ptr<te::map::LayerSchema> sch = m_layer->getSchema();
1438 
1439  std::auto_ptr<te::da::DataSet> md = m_model->getEditions(sch.get(), ed);
1440 
1441  te::da::DataSourcePtr ds = GetDataSource(m_layer);
1442 
1443  if(ds.get() == 0)
1444  throw te::common::Exception(tr("Fail to get data source from layer").toStdString());
1445 
1446  te::da::ObjectIdSet* objs = 0;
1447 
1448  te::da::GetEmptyOIDSet(sch.get(), objs);
1449 
1450  std::auto_ptr<te::da::ObjectIdSet> objs1(objs);
1451 
1452  ds->update(sch->getName(), md.get(), ed, objs1->getPropertyPos());
1453 
1454  setLayer(m_layer);
1455  }
1456  catch(te::common::Exception& e)
1457  {
1458  QMessageBox::warning(this, tr("Save edition failure"), e.what());
1459  }
1460 }
1461 
1462 #include "DataSetTableView.moc"
1463 
TEQTWIDGETSEXPORT ChartDisplayWidget * createNormalDistribution(te::da::DataSet *dataset, int propId)
Definition: Utils.cpp:1095
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 &)
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
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.
te::da::DataSet * m_dset
std::auto_ptr< te::da::DataSetTypeCapabilities > m_caps
It models a property definition.
Definition: Property.h:59
void setOldColumnName(const QString &name)
void setTableName(const QString &name)
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.
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)
const std::string & getDataSourceId() const
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:201
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:980
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:352
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:340
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.
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.
size_t getLogicalRow(const size_t &visualRow)
Returns the logical position of the row visualRow.
Definition: Promoter.cpp:184
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)
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.
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.
void showColumn(const int &column)
Shows the hidden column.
void saveEditions()
Saves all editions to the dataset.
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)