22 #include "../../../dataaccess/dataset/DataSet.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 "../../../maptools/DataSetLayer.h"
33 #include "../../../maptools/DataSetAdapterLayer.h"
34 #include "../../../maptools/QueryLayer.h"
39 #include <QtGui/QMouseEvent>
44 #include <QMessageBox>
47 QHeaderView(Qt::Horizontal, view),
72 setDropIndicatorShown(
true);
76 setAcceptDrops(
false);
77 setDropIndicatorShown(
false);
98 if(e->button() == Qt::LeftButton)
100 if(m_doDragDrop ==
false)
102 int c = m_view->columnAt(e->pos().x());
104 QItemSelectionModel* sel = m_view->selectionModel();
108 QItemSelectionModel::SelectionFlag selF = (sel->isColumnSelected(c, QModelIndex())) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
110 if(m_view->selectionMode() == QAbstractItemView::SingleSelection)
114 QModelIndex tl = m_view->model()->index(0, c);
115 QModelIndex br = m_view->model()->index(model()->rowCount()-1, c);
117 QItemSelection newSel(tl, br);
119 sel->select(newSel, selF);
127 QPainter painter(&p);
128 QRect r = painter.boundingRect(p.rect(), Qt::AlignCenter,
"Link Table");
129 r = QRect(0, 0, r.width(), r.height());
130 QPoint hotSpot(r.center());
131 QPixmap pixmap(r.size());
133 painter.begin(&pixmap);
134 painter.setPen(QPen(Qt::blue));
135 painter.drawText(r,
"Link Table");
138 QMimeData *mimeData =
new QMimeData;
139 mimeData->setText(
"TerraView: Link Table");
144 std::string sid(ds->getId());
145 mimeData->setData(
"DataSourceId", sid.c_str());
146 std::string stype(ds->getType());
147 mimeData->setData(
"DataSourceType", stype.c_str());
148 m_connInfo = ds->getConnectionInfo();
150 connInfo.setNum((
unsigned long long)&m_connInfo);
151 mimeData->setData(
"DataSourceConnInfo", connInfo.toStdString().c_str());
152 std::string lname(m_layer->getSchema()->getName());
153 mimeData->setData(
"LayerName", lname.c_str());
154 std::string ltytle(m_layer->getTitle());
155 mimeData->setData(
"LayerTitle", ltytle.c_str());
156 std::string lid(m_layer->getId());
157 mimeData->setData(
"LayerId", lid.c_str());
158 std::string ltype(m_layer->getType());
159 mimeData->setData(
"LayerType", ltype.c_str());
162 size_t col = logicalIndexAt(e->pos());
165 mimeData->setData(
"FieldNumber", s.toStdString().c_str());
167 std::string colName = m_dset->getPropertyName(col);
168 mimeData->setData(
"FieldName", colName.c_str());
170 int propType = m_dset->getPropertyDataType(col);
172 mimeData->setData(
"FieldType", s.toStdString().c_str());
175 drag.setMimeData(mimeData);
176 drag.setPixmap(pixmap);
177 drag.setHotSpot(hotSpot);
179 Qt::DropAction dropAction = drag.exec(Qt::LinkAction);
194 QHeaderView::mousePressEvent(e);
199 if(e->source() ==
this || m_acceptDrop ==
false)
202 const QMimeData* mdata = e->mimeData();
203 if(mdata->text() ==
"TerraView: Link Table")
204 e->setAccepted(
true);
206 e->setAccepted(
false);
211 if(e->source() ==
this || m_acceptDrop ==
false)
214 const QMimeData* mdata = e->mimeData();
215 if(mdata->text() ==
"TerraView: Link Table")
216 e->setAccepted(
true);
218 e->setAccepted(
false);
223 if(e->source() ==
this || m_acceptDrop ==
false)
226 const QMimeData* mdata = e->mimeData();
227 std::string text = mdata->text().toStdString();
228 if(text ==
"TerraView: Link Table")
230 e->setDropAction(Qt::LinkAction);
235 m_secondLinkInfo.m_dataSourceId = sds->getId();
236 m_secondLinkInfo.m_dataSourceType = sds->getType();
237 m_secondLinkInfo.m_connInfo = sds->getConnectionInfo();
238 m_secondLinkInfo.m_layerId = m_layer->getId();
239 m_secondLinkInfo.m_layerName = m_layer->getSchema()->getName();
240 m_secondLinkInfo.m_layerTitle = m_layer->getTitle();
241 m_secondLinkInfo.m_layerType = m_layer->getType();
243 if(mdata->data(
"DataSourceId").isNull() ==
false)
245 m_firstLinkInfo.m_dataSourceId = mdata->data(
"DataSourceId").data();
246 m_firstLinkInfo.m_dataSourceType = mdata->data(
"DataSourceType").data();
247 QString connInfo(mdata->data(
"DataSourceConnInfo").data());
248 m_firstLinkInfo.m_connInfo = *(std::map<std::string, std::string>*)connInfo.toULongLong();
249 m_firstLinkInfo.m_layerName = mdata->data(
"LayerName").data();
250 m_firstLinkInfo.m_layerTitle = mdata->data(
"LayerTitle").data();
251 m_firstLinkInfo.m_layerId = mdata->data(
"LayerId").data();
252 m_firstLinkInfo.m_layerType = mdata->data(
"LayerType").data();
254 if(m_firstLinkInfo.m_dataSourceId != m_secondLinkInfo.m_dataSourceId)
256 QMessageBox::warning(
this,
"Link Error",
"The data are from different sources");
260 if(m_firstLinkInfo.m_layerId == m_secondLinkInfo.m_layerId)
262 QMessageBox::warning(
this,
"Link Error",
"The data are from the same layer");
268 QString fromFieldNumber(mdata->data(
"FieldNumber").data());
269 m_firstLinkInfo.m_fieldNumber = fromFieldNumber.toUInt();
270 m_firstLinkInfo.m_fieldName = mdata->data(
"FieldName").data();
271 QString fromFieldType(mdata->data(
"FieldType").data());
272 m_firstLinkInfo.m_fieldType = fromFieldType.toUInt();
274 m_secondLinkInfo.m_fieldNumber = logicalIndexAt(e->pos());
275 m_secondLinkInfo.m_fieldType = m_dset->getPropertyDataType(m_secondLinkInfo.m_fieldNumber);
276 if(m_secondLinkInfo.m_fieldType != m_firstLinkInfo.m_fieldType)
278 QMessageBox::warning(
this,
"Link Error",
"Field types do not match");
281 m_secondLinkInfo.m_fieldName = m_dset->getPropertyName(m_secondLinkInfo.m_fieldNumber);
283 if(mdata->data(
"DataSourceId").isNull() ==
false && m_layer)
284 emit linkTable(m_firstLinkInfo, m_secondLinkInfo);
286 emit linkTable(m_firstLinkInfo.m_fieldName, m_secondLinkInfo.m_fieldName);
295 if(layer->
getType() ==
"DATASETLAYER")
302 else if(layer->
getType() ==
"DATASETADAPTERLAYER")
309 else if(layer->
getType() ==
"QUERYLAYER")
virtual const std::string & getType() const =0
It returns the layer type.
This is the base class for layers.
boost::shared_ptr< DataSource > DataSourcePtr
A layer resulting from a query.
te::da::DataSourcePtr GetDataSource(const te::map::AbstractLayer *layer)
A layer with reference to a DataSetTypeConverter.
A table view for a dataset.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getDataSourceId() const
const std::string & getDataSourceId() const
const std::string & getDataSourceId() const
A dataset is the unit of information manipulated by the data access module of TerraLib.
A layer with reference to a dataset.