9 #include "../../../common/Exception.h" 
   10 #include "../../../dataaccess/dataset/DataSet.h" 
   11 #include "../../../dataaccess/dataset/ObjectId.h" 
   12 #include "../../../dataaccess/dataset/ObjectIdSet.h" 
   13 #include "../../../dataaccess/datasource/DataSourceCapabilities.h" 
   14 #include "../../../dataaccess/datasource/DataSourceManager.h" 
   15 #include "../../../dataaccess/datasource/DataSourceTransactor.h" 
   16 #include "../../../dataaccess/query/DataSetName.h" 
   17 #include "../../../dataaccess/query/Field.h" 
   18 #include "../../../dataaccess/query/From.h" 
   19 #include "../../../dataaccess/query/OrderBy.h" 
   20 #include "../../../dataaccess/query/OrderByItem.h" 
   21 #include "../../../dataaccess/query/Select.h" 
   22 #include "../../../dataaccess/utils/Utils.h" 
   23 #include "../../../maptools/DataSetLayer.h" 
   24 #include "../../../statistics/qt/StatisticsDialog.h" 
   25 #include "../utils/ScopedCursor.h" 
   29 #include <QtGui/QHeaderView> 
   30 #include <QtGui/QContextMenuEvent> 
   31 #include <QtGui/QMenu> 
   32 #include <QtGui/QCursor> 
   33 #include <QtGui/QPainter> 
   34 #include <QtGui/QMessageBox> 
   51   for(
size_t i=0; i<nProps; i++)
 
   53       cols.push_back((
int)i);
 
   60   int sz = hView->count();
 
   64     for (
int i=0; i<sz; i++)
 
   75   std::vector<int>::iterator it;
 
   77   QMenu* mnu = 
new QMenu(hMnu);
 
   78   mnu->setTitle(QObject::tr(
"Show hidden column"));
 
   81     mnu->setEnabled(
false);
 
   83     for(it=hSecs.begin(); it!=hSecs.end(); ++it)
 
   85       QString cName = hView->model()->headerData(*it, Qt::Horizontal, Qt::DisplayRole).toString();
 
   86       QAction* act = 
new QAction(mnu);
 
   89       act->setData(QVariant(*it));
 
   90       act->setToolTip(QObject::tr(
"Turns column \"") + cName + 
"\" visible.");
 
  100   QAction* act = 
new QAction(hMnu);
 
  101   act->setText(QObject::tr(
"Show all columns"));
 
  126     return (&ds->getCapabilities());
 
  135   fields.push_back(std::auto_ptr<te::da::Field>(
new te::da::Field(
"*")));
 
  143   for(
size_t i=0; i<cols.size(); i++)
 
  146   return std::auto_ptr<te::da::Select>(
new te::da::Select(fields, from, order_by));
 
  156       throw std::string(
"Fail to generate query.");
 
  161       throw std::string(
"Fail to get data source.");
 
  167     return std::auto_ptr<te::da::DataSet>();
 
  195       m_view->horizontalHeader()->installEventFilter(
this);
 
  196       m_view->verticalHeader()->installEventFilter(
this);
 
  197       m_view->viewport()->installEventFilter(
this);
 
  203       m_view->connect(
this, SIGNAL(
sortData(
const bool&)), SLOT(sortByColumns(
const bool&)));
 
  219         return QObject::eventFilter(watched, event);
 
  221       QWidget* vport = 
m_view->viewport();
 
  222       QHeaderView* hHdr = 
m_view->horizontalHeader();
 
  223       QHeaderView* vHdr = 
m_view->verticalHeader();
 
  225       switch(event->type())
 
  227         case QEvent::ContextMenu:
 
  233             QContextMenuEvent* evt = 
static_cast<QContextMenuEvent*
>(event);
 
  234             QPoint pos = evt->globalPos();
 
  236             m_columnPressed = hHdr->logicalIndex(hHdr->visualIndexAt(evt->pos().x()));
 
  240             QAction* act = 
new QAction(
m_hMenu);
 
  241             act->setText(tr(
"Hide column"));
 
  242             act->setToolTip(tr(
"Hides the selected column."));
 
  249               act->setEnabled(
false);
 
  251             m_hMenu->addAction(hMnu->menuAction());
 
  256             QAction* act3 = 
new QAction(
m_hMenu);
 
  257             act3->setText(tr(
"Reset columns order"));
 
  258             act3->setToolTip(tr(
"Put all columns in the original order."));
 
  263             QAction* act5 = 
new QAction(
m_hMenu);
 
  264             act5->setText(tr(
"Sort data ASC"));
 
  265             act5->setToolTip(tr(
"Sort data in ascendent order using selected columns."));
 
  268             QAction* act9 = 
new QAction(
m_hMenu);
 
  269             act9->setText(tr(
"Sort data DESC"));
 
  270             act9->setToolTip(tr(
"Sort data in descendent order using selected columns."));
 
  275             QAction* act6 = 
new QAction(
m_hMenu);
 
  276             act6->setText(tr(
"Statistics"));
 
  277             act6->setToolTip(tr(
"Show the statistics summary of the selected colunm."));
 
  282             QAction* act7 = 
new QAction(
m_hMenu);
 
  283             act7->setText(tr(
"Add column"));
 
  284             act7->setToolTip(tr(
"Adds a column to the table."));
 
  287             bool updatePermition = 
false;
 
  289               updatePermition = 
true;
 
  291             act7->setEnabled(updatePermition);
 
  293             QAction* act8 = 
new QAction(
m_hMenu);
 
  294             act8->setText(tr(
"Remove column"));
 
  295             act8->setToolTip(tr(
"Removes a column from the table."));
 
  298             act8->setEnabled(updatePermition);
 
  301             connect(act, SIGNAL(triggered()), SLOT(
hideColumn()));
 
  302             connect(hMnu, SIGNAL(triggered(QAction*)), SLOT(
showColumn(QAction*)));
 
  303             connect(act8, SIGNAL(triggered()), SLOT(
removeColumn()));
 
  305             m_view->connect(act2, SIGNAL(triggered()), SLOT(showAllColumns()));
 
  306             m_view->connect(act3, SIGNAL(triggered()), SLOT(resetColumnsOrder()));
 
  307             m_view->connect(act7, SIGNAL(triggered()), SLOT(addColumn()));
 
  310             connect (act5, SIGNAL(triggered()), SLOT(
sortDataAsc()));
 
  311             connect (act9, SIGNAL(triggered()), SLOT(
sortDataDesc()));
 
  315           else if(watched == vport)
 
  318           else if(watched == vHdr)
 
  322             QContextMenuEvent* evt = 
static_cast<QContextMenuEvent*
>(event);
 
  323             QPoint pos = evt->globalPos();
 
  326             QAction* act = 
new QAction(
m_vMenu);
 
  327             act->setText(tr(
"Enable auto scroll"));
 
  328             act->setToolTip(tr(
"Goes to the selected row."));
 
  330             act->setCheckable(
true);
 
  340             act->setText(tr(
"Promote selected rows"));
 
  341             act->setToolTip(tr(
"Reorder rows"));
 
  355       return QObject::eventFilter(watched, event);
 
  387       int column = act->data().toInt();
 
  397       statisticDialog.exec();
 
  457 m_autoScrollEnabled(false),
 
  466   horizontalHeader()->setMovable(
true);
 
  469   setSelectionMode(QAbstractItemView::MultiSelection);
 
  481   connect(verticalHeader(), SIGNAL(selectedRow(
const int&, 
const bool&)), SLOT(
highlightRow(
const int&, 
const bool&)));
 
  482   connect(verticalHeader(), SIGNAL(selectedRows(
const int&, 
const int&)), SLOT(
highlightRows(
const int&, 
const int&)));
 
  495   setLayerSchema(m_layer->getSchema().get());
 
  503     setSelectionMode((dsc->getType().compare(
"OGR") == 0) ? SingleSelection : MultiSelection);
 
  504     setSelectionBehavior((dsc->getType().compare(
"OGR") == 0) ? QAbstractItemView::SelectColumns : QAbstractItemView::SelectItems);
 
  510   m_model->setDataSet(dset);
 
  512   std::vector<int> geoCols;
 
  513   std::vector<int>::iterator it;
 
  516   for(it = geoCols.begin(); it != geoCols.end(); ++it)
 
  519   m_popupFilter->setDataSet(dset);
 
  520   m_delegate->setDataSet(dset);
 
  530   m_delegate->setObjectIdSet(objs);
 
  534   m_model->getPromoter()->preProcessKeys(m_dset, objs->
getPropertyPos());
 
  539   m_delegate->setObjectIdSet(oids);
 
  541   if(m_autoScrollEnabled && oids != 0 && oids->
size() > 0)
 
  543     size_t row = m_model->getPromoter()->map2Row(*oids->
begin());
 
  545     scrollTo(m_model->index((
int)row, 0));
 
  548   viewport()->repaint();
 
  553   horizontalHeader()->hideSection(column);
 
  558   horizontalHeader()->showSection(column);
 
  563   std::vector<int> hCols = m_popupFilter->getHiddenColumns();
 
  564   std::vector<int>::iterator it;
 
  566   for (it=hCols.begin(); it!=hCols.end(); ++it)
 
  567     horizontalHeader()->showSection(*it);
 
  572   QHeaderView* hdr = horizontalHeader();
 
  574   int nCols = hdr->count();
 
  576   for(
int i=0; i<nCols; i++)
 
  578     int visCol = hdr->visualIndex(i);
 
  581       hdr->moveSection(visCol, i);
 
  595     if(m_delegate->getSelected()->contains(oid))
 
  597       emit deselectOIds(oids);
 
  601       m_delegate->setObjectIdSet(m_layer->getSelected());
 
  603       viewport()->repaint();
 
  609   emit selectOIds(oids, add);
 
  617   if(initRow < finalRow)
 
  632   emit selectOIds(oids, 
true);
 
  634   viewport()->repaint();
 
  642   m_model->setEnabled(
false);
 
  643   m_popupFilter->setEnabled(
false);
 
  646   m_model->promote(oids);
 
  648   m_popupFilter->setEnabled(
true);
 
  649   m_model->setEnabled(
true);
 
  655   viewport()->repaint();
 
  669     std::vector<int> selCols;
 
  671     int nCols = model()->columnCount();
 
  673     for(
int i=0; i<nCols; i++)
 
  675       int logCol = verticalHeader()->logicalIndex(i);
 
  677       if(selectionModel()->isColumnSelected(i, QModelIndex()))
 
  678         selCols.push_back(i);
 
  684     std::auto_ptr<te::da::DataSet> dset = 
GetDataSet(m_layer, m_dset, selCols, asc);
 
  687       throw te::common::Exception(tr(
"Sort operation not supported by the source of data.").toStdString());
 
  689     setDataSet(dset.release());
 
  691     viewport()->repaint();
 
  693     setUpdatesEnabled(
false);
 
  695      m_model->getPromoter()->preProcessKeys(m_dset, m_delegate->getSelected()->getPropertyPos());
 
  697     setUpdatesEnabled(
true);
 
  701     QMessageBox::information(
this, tr(
"Sorting columns failure"), tr(
"Could not sort data: ") + e.
what());
 
  707   m_model->showOIdsVisible(visible);
 
  709   horizontalHeader()->viewport()->repaint();
 
  721     std::auto_ptr<te::da::DataSetType> ds_t = m_layer->getSchema();
 
  723     std::string dsName = ds_t->getName();
 
  724     size_t n_prop = ds_t->getProperties().size();
 
  727     if(dlg.exec() == QDialog::Accepted)
 
  736       if(p->getName().empty())
 
  739       if(!ds->isPropertyNameValid(p->getName()))
 
  742       if(ds->propertyExists(dsName, p->getName()))
 
  745       ds->addProperty(dsName, p.get());
 
  747       m_model->insertColumns((
int)n_prop-1, 0);
 
  754     QMessageBox::information(
this, tr(
"Creating column failure"), tr(
"The column could not be created: ") + e.
what());
 
  762     if(QMessageBox::question(
this, tr(
"Remove column"), tr(
"Are you sure you want to remove this column?"), QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
 
  769       std::auto_ptr<te::da::DataSetType> ds_t = m_layer->getSchema();
 
  770       std::string dsName = ds_t->getName();
 
  772       std::string pName = ds_t->getProperty(column)->getName();
 
  774       ds->dropProperty(dsName, pName);
 
  776       m_model->removeColumns(column, 0);
 
  783     QMessageBox::information(
this, tr(
"Removing column failure"), tr(
"The column could not be removed: ") + e.
what());
 
  789   m_autoScrollEnabled = enable;
 
  795   QItemSelection toRemove;
 
  797   for(
int i=initRow; i<=finalRow; i++)
 
  799     QModelIndexList idx = selectionModel()->selectedColumns(i);
 
  802       toRemove.select(idx.first(), idx.last());
 
  805   selectionModel()->select(toRemove, QItemSelectionModel::Deselect);
 
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos. 
 
A layer with reference to a dataset. 
 
void showColumn(const int &column)
Shows the hidden column. 
 
const std::vector< std::size_t > & getPropertyPos() const 
It returns the property positions used to generated the oids. 
 
Defines an mechanism for logical ordering of rows. 
 
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. ...
 
A delegate for highlight the selected object ids. 
 
This class represents a set of unique ids created in the same context. i.e. from the same data set...
 
A class that models the name of a dataset used in a From clause. 
 
bool eventFilter(QObject *watched, QEvent *event)
 
void setPromoter(Promoter *promoter)
Sets the promoter being used. 
 
te::qt::widgets::DataSetTableView * m_view
 
DataSetTableModel * m_model
The model to be used. 
 
This is the base class for layers. 
 
void addColumn()
Add column to the table. 
 
A Select models a query to be used when retrieving data from a DataSource. 
 
virtual te::common::AccessPolicy getAccessPolicy() const =0
It returns the read and write permission associated to the dataset. 
 
void promote()
Promotes the highlighted rows. 
 
QAction * GetShowAllMenu(QHeaderView *hView, te::da::DataSet *dset, QMenu *hMnu)
 
const te::da::DataSourceCapabilities * m_caps
 
void selectObjects(const int &initRow, const int &finalRow)
 
void hideColumn(const int &column)
Hides the column at position column. 
 
A table model representing a te::da::DataSet. 
 
void GetCapabilities(OGRDataSource *ds, te::da::DataSourceCapabilities &caps)
 
The Field class can be used to model an expression that takes part of the output items of a SELECT...
 
void showAllColumns()
Shows all hidden columns. 
 
boost::ptr_vector< FromItem > From
It models the FROM clause for a query. 
 
virtual std::auto_ptr< LayerSchema > getSchema() const =0
It returns the layer schema. 
 
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it. 
 
void removeSelection(const int &initRow, const int &finalRow)
 
void setDataSourceCapabilities(const te::da::DataSourceCapabilities *caps)
 
te::dt::Property * getNewProperty() const 
 
const std::string & getDataSourceId() const 
 
void highlightRow(const int &row, const bool &add)
Used to highlight the data when the mouse is clicked over a row in the table. 
 
virtual const char * what() const 
It outputs the exception message. 
 
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
 
A class that can be used in an ORDER BY clause to sort the items of a resulting query. 
 
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...
 
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers. 
 
Defines a vertical header for a dataset table view. 
 
void setAutoScrollEnabled(const bool &enable)
Enable / disable auto-scroll. 
 
std::vector< int > getHiddenColumns()
 
Promoter * getPromoter()
Returns the pointer to the promoter being used. 
 
void enableAutoScroll(const bool &)
 
DataSetTableView(QWidget *parent=0)
Constructor. 
 
std::vector< int > GetHiddenSections(QHeaderView *hView, te::da::DataSet *dset)
 
std::size_t size() const 
It returns the object id set size. 
 
A Qt dialog for inserting columns into a table. 
 
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos. 
 
boost::shared_ptr< DataSource > DataSourcePtr
 
boost::ptr_vector< OrderByItem > OrderBy
A class that can be used to model an ORDER BY clause. 
 
void setTableName(const std::string &name)
 
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator begin() const 
Returns an iterator for the object ids in container. 
 
std::auto_ptr< te::da::Select > GetSelectExpression(const std::string &tableName, const te::da::DataSet *set, const std::vector< int > &cols, const bool &asc)
 
TablePopupFilter(te::qt::widgets::DataSetTableView *view)
Contructor. 
 
A customized table view for te::map::AbstractLayer objects. Uses a te::qt::widgets::DataSetModel as i...
 
void setEnabled(const bool &enabled)
 
~TablePopupFilter()
Destructor. 
 
This class represents an unique id for a data set element. 
 
void setDataSet(te::da::DataSet *dset)
 
bool IsGeometryColumn(te::da::DataSet *dset, const size_t &col)
 
void setStatistics(te::da::DataSet *dataSet, const std::string prop)
 
A class that models the description of a dataset. 
 
void highlightRows(const int &initRow, const int &finalRow)
Select all rows from initRow to finalRow. 
 
void setLayer(const te::map::AbstractLayer *layer)
Sets the layer to be presented. 
 
An specialization of QItemDelegate to be used with te::map::AbstractTable objects. 
 
void showColumn(QAction *act)
 
void sortData(const bool &)
 
TablePopupFilter * m_popupFilter
The menus popup filter. 
 
void sortByColumns(const bool &asc)
Sort by the selected columns. 
 
A table view for a dataset. 
 
void removeColumn(const int &column)
 
void selectObject(const int &, const bool &)
 
void highlightOIds(const te::da::ObjectIdSet *oids)
Highlights the objects identified by oids. 
 
static DataSourceManager & getInstance()
It returns a reference to the singleton instance. 
 
void GetGeometryColumnsPositions(te::da::DataSet *dset, std::vector< int > &cols)
 
te::da::DataSourcePtr GetDataSource(const te::map::AbstractLayer *layer)
 
virtual ~DataSetTableView()
Virtual destructor. 
 
A dataset is the unit of information manipulated by the data access module of TerraLib. 
 
void setDataSet(te::da::DataSet *dset)
Updates the data set being visualized. 
 
A model based on te::da::DataSet. 
 
void setAutoScrollEnabled()
 
QMenu * GetHiddenColumnsMenu(QHeaderView *hView, te::da::DataSet *dset, QMenu *hMnu)
 
void setOIdsColumnsVisible(const bool &visible)
Shows or hides the icon sinalizing the columns that identify each row. 
 
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)
 
HighlightDelegate * m_delegate
Delegate used for rendering selected rows. 
 
void resetColumnsOrder()
Shows columns in the original order. 
 
virtual void setColor(const QColor &c)
Update the color group. 
 
An object that when created shows a cursor during its scope. 
 
A vertical header used for selecting rows at a table view.