27 #include "../../../common/Exception.h" 28 #include "../../../core/translator/Translator.h" 29 #include "../../../dataaccess/dataset/ObjectId.h" 30 #include "../../../dataaccess/dataset/ObjectIdSet.h" 31 #include "../../../dataaccess/datasource/DataSourceInfoManager.h" 32 #include "../../../dataaccess/datasource/DataSourceTransactor.h" 33 #include "../../../dataaccess/utils/Utils.h" 34 #include "../../../datatype/SimpleData.h" 35 #include "../../../edit/Feature.h" 36 #include "../../../edit/Repository.h" 37 #include "../../../edit/RepositoryManager.h" 38 #include "../../../edit/qt/core/UndoStackManager.h" 39 #include "../../../edit/qt/tools/AggregateAreaTool.h" 40 #include "../../../edit/qt/tools/CreateLineTool.h" 41 #include "../../../edit/qt/tools/CreatePointTool.h" 42 #include "../../../edit/qt/tools/CreatePolygonTool.h" 43 #include "../../../edit/qt/tools/DeleteGeometryByAreaTool.h" 44 #include "../../../edit/qt/tools/DeleteGeometryTool.h" 45 #include "../../../edit/qt/tools/DeletePartTool.h" 46 #include "../../../edit/qt/tools/EditInfoTool.h" 47 #include "../../../edit/qt/tools/MergeGeometriesTool.h" 48 #include "../../../edit/qt/tools/MoveGeometryTool.h" 49 #include "../../../edit/qt/tools/RotateGeometryTool.h" 50 #include "../../../edit/qt/tools/SplitPolygonTool.h" 51 #include "../../../edit/qt/tools/SubtractAreaTool.h" 52 #include "../../../edit/qt/tools/VertexTool.h" 53 #include "../../../edit/qt/SnapOptionsDialog.h" 54 #include "../../../edit/qt/Utils.h" 55 #include "../../../geometry/GeometryProperty.h" 56 #include "../../../maptools/DataSetLayer.h" 57 #include "../../../memory/DataSet.h" 58 #include "../../../memory/DataSetItem.h" 59 #include "../../widgets/Utils.h" 60 #include "../../widgets/canvas/MapDisplay.h" 61 #include "../../widgets/canvas/MultiThreadMapDisplay.h" 62 #include "../../widgets/layer/explorer/LayerItemView.h" 63 #include "../../widgets/layer/utils/CreateLayerDialog.h" 64 #include "../../af/ApplicationController.h" 65 #include "../../af/events/ApplicationEvents.h" 66 #include "../../af/events/LayerEvents.h" 67 #include "../../af/events/MapEvents.h" 73 #include <QActionGroup> 74 #include <QApplication> 75 #include <QMessageBox> 76 #include <QUndoCommand> 79 #include <boost/ptr_container/ptr_vector.hpp> 93 m_clearEditionAction(0),
94 m_vertexToolAction(0),
95 m_createPolygonToolAction(0),
96 m_createLineToolAction(0),
97 m_moveGeometryToolAction(0),
98 m_rotateGeometryToolAction(0),
99 m_snapOptionsAction(0),
100 m_deleteGeometryToolAction(0),
101 m_aggregateAreaToolAction(0),
102 m_subtractAreaToolAction(0),
103 m_featureAttributesAction(0),
104 m_splitPolygonToolAction(0),
105 m_mergeGeometriesToolAction(0),
106 m_createPointToolAction(0),
107 m_createLayerAction(0),
114 m_layerIsStashed(true),
150 if(layer == 0 || layer->
getSRID() == 0)
152 for (
int i = 0; i <
m_tools.size(); ++i)
158 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"SRID invalid."));
175 std::map<std::string, int> ops;
176 std::map<std::string, te::gm::Geometry*> gms;
180 for(std::map<std::string, te::gm::Geometry*>::iterator it = gms.begin(); it != gms.end(); ++it)
183 QString
id = QString::fromUtf8(it->first.c_str());
186 int v =
id.toInt(&ok);
219 std::list<te::map::AbstractLayerPtr>::iterator it;
222 if((*it)->getId() == id)
233 if (info->getType() !=
"POSTGIS" && info->getType() !=
"OGR")
235 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Under Development to this data source: ") + QString(info->getType().c_str()));
239 if (info->getType() ==
"OGR")
242 std::unique_ptr<te::da::DataSetType> toSchema = layer->getSchema();
244 if (!toSchema->getPrimaryKey() || toSchema->getPrimaryKey()->getProperties().empty())
246 QMessageBox::critical(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Invalid Data Set Primary Key."));
250 std::vector<te::dt::Property*> pkProps = toSchema->getPrimaryKey()->getProperties();
252 bool hasAutoIncrement =
false;
253 for (std::size_t j = 0; j < pkProps.size(); ++j)
261 hasAutoIncrement =
true;
267 if (!hasAutoIncrement)
269 QMessageBox::critical(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"The Primary Key has not auto-increment!"));
279 m_toolBar =
new QToolBar(
"Edit Tool Bar");
285 for (
int i = 0; i <
m_tools.size(); ++i)
431 action =
new QAction(
this);
432 action->setIcon(QIcon::fromTheme(icon));
433 action->setToolTip(tooltip);
434 action->setCheckable(checkable);
435 action->setEnabled(enabled);
436 action->setObjectName(objName);
437 connect(action, SIGNAL(
triggered(
bool)),
this, member);
459 draft->fill(Qt::transparent);
464 std::map<std::string, te::edit::Repository*>::const_iterator it;
465 for (it = repositories.begin(); it != repositories.end(); ++it)
482 std::unique_ptr<te::da::DataSourceTransactor> t;
485 if (layer.get() == 0)
496 std::map<std::string, te::edit::Repository*>::iterator it;
498 std::map<std::string, int> ops;
509 const std::vector<te::edit::Feature*>& features = repo->getAllFeatures();
511 std::map<std::string, te::gm::Geometry*> gs;
513 for(std::vector<te::edit::Feature*>::const_iterator fIt = features.begin(); fIt != features.end(); ++fIt)
526 ops[sOid] = (
int)(*fIt)->getOperationTypeId();
543 std::map<std::string, te::edit::Repository*>::iterator it = repositories.find(layer->getId());
545 if(it != repositories.end())
564 assert(dsource.get());
567 t = dsource->getTransactor();
570 std::unique_ptr<te::map::LayerSchema> schema(layer->getSchema());
571 assert(schema.get());
574 std::vector<std::string> oidPropertyNames;
578 const std::vector<te::edit::Feature*>& features = repo->
getAllFeatures();
581 std::map<te::edit::OperationType, te::mem::DataSet* > featuresTypeDs;
592 assert(gpos != std::string::npos);
595 std::unique_ptr<te::da::DataSet>
ds = layer->getData();
598 for (std::size_t j = 0; j < oidPropertyNames.size(); ++j)
606 std::map<te::edit::OperationType, std::set<int> > propertiesPos;
610 for (std::size_t i = 0; i < features.size(); ++i)
620 const boost::ptr_vector<te::dt::AbstractData>& values = oid->
getValue();
621 if (values.size() != oidPropertyNames.size())
625 for (std::size_t j = 0; j < values.size(); ++j)
626 item->
setValue(oidPropertyNames[j], values[j].clone());
636 switch (features[i]->getOperationTypeId())
638 case te::edit::INSERT:
642 std::vector<std::size_t> objIdIdx;
644 for (std::map<std::size_t, te::dt::AbstractData*>::const_iterator it = features[i]->getData().begin(); it != features[i]->getData().end(); ++it)
646 if (std::find(objIdIdx.begin(), objIdIdx.end(), (
int)it->first) == objIdIdx.end())
647 item->
setValue(it->first, it->second);
653 for (std::size_t j = 0; j < oidPropertyNames.size(); ++j)
659 t->add(layer->getDataSetName(), tempDs, std::map<std::string, std::string>());
665 std::vector<std::size_t> objIdIdx;
668 for (std::map<std::size_t, te::dt::AbstractData*>::const_iterator it = features[i]->getData().begin(); it != features[i]->getData().end(); ++it)
670 if (std::find(objIdIdx.begin(), objIdIdx.end(), (
int)it->first) == objIdIdx.end())
672 item->
setValue(it->first, it->second);
694 std::vector<std::set<int> > properties;
698 std::vector<std::size_t> oidPropertyPosition;
699 for (std::size_t i = 0; i < oidPropertyNames.size(); ++i)
700 oidPropertyPosition.push_back(
te::da::GetPropertyPos(featuresTypeDs[te::edit::UPDATE], oidPropertyNames[i]));
704 t->update(layer->getDataSetName(), featuresTypeDs[
te::edit::UPDATE], properties, oidPropertyPosition);
709 std::map<te::edit::OperationType, te::da::ObjectIdSet* > currentOids;
727 std::unique_ptr<te::da::DataSet> data = layer->getData();
731 std::unique_ptr<te::gm::Envelope> env = data->getExtent(pos);
733 layer->setExtent(*env.get());
737 layer->clearSelected();
754 QMessageBox::critical(this->
get(), tr(
"TerraLib Edit Qt Plugin"), ex.
what());
757 catch (
const std::exception& e)
760 QMessageBox::critical(this->
get(), tr(
"TerraLib Edit Qt Plugin"), e.what());
766 QMessageBox::critical(this->
get(),
767 tr(
"TerraLib Edit Qt Plugin"),
768 tr(
"Unknown error while updating data source information!"));
780 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
804 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
825 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
846 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
883 if (layer.get() == 0)
885 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
907 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
928 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
952 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
966 QMessageBox::critical(this->
get(), tr(
"TerraLib Edit Qt Plugin"), e.
what());
979 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
984 if(layer->getSelected() == 0)
986 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a geometry first!"));
991 if(layer->getSelected()->size() < 2)
993 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"To use this tool, you must select at least two geometries!"));
1012 if (layer.get() == 0)
1014 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
1019 if (layer->getSelected() == 0)
1021 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a geometry first!"));
1026 if (!layer->getSelected()->size())
1028 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"To use this tool, you must select at least one geometry!"));
1044 if (layer.get() == 0)
1046 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
1082 if (layer.get() == 0)
1084 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
1100 if (layer.get() == 0)
1102 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
1119 if (dlg.exec() == QDialog::Accepted)
1124 std::list<te::map::AbstractLayerPtr> list;
1136 std::list<te::map::AbstractLayerPtr> ls;
1150 if (layer.get() == 0)
1152 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
1164 m_undoView->setWindowTitle(tr(
"Edition List"));
1167 m_undoView->setAttribute(Qt::WA_QuitOnClose,
true);
1173 QMessageBox::critical(this->
get(), tr(
"TerraLib Edit Qt Plugin"), e.
what());
1204 for (
int i = 0; i <
m_tools.size(); ++i)
1205 m_tools[i]->setChecked(
false);
1222 std::size_t geomType = 0;
1225 for(QList<QAction*>::iterator it = acts.begin(); it != acts.end(); ++it)
1226 (*it)->setEnabled(enable);
1230 if (layer.get() == 0 || layer->getSRID() == 0)
1234 std::unique_ptr<te::da::DataSetType>
dt = layer->getSchema();
1239 for (QList<QAction*>::iterator it = acts.begin(); it != acts.end(); ++it)
1240 (*it)->setEnabled(
false);
1263 geomType = std::string::npos;
1266 if (geomType == std::string::npos)
1268 for (QList<QAction*>::iterator it = acts.begin(); it != acts.end(); ++it)
1269 (*it)->setEnabled(
false);
1293 action->blockSignals(
true);
1301 action->setChecked(
true);
1302 action->blockSignals(
false);
1312 action->blockSignals(
true);
1313 action->setChecked(
false);
1314 action->blockSignals(
false);
1351 if (layer.get() == 0)
1353 QMessageBox::information(this->
get(), tr(
"TerraLib Edit Qt Plugin"), tr(
"Select a layer first!"));
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
virtual const std::string & getId() const
It returns the layer id.
std::size_t size() const
It returns the collection size, if it is known.
SimpleData< std::string, STRING_TYPE > String
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
te::map::AbstractLayerPtr m_layer
Layer selected.
This event is used to get a single layer selected in layer tree.
An atomic property like an integer or double.
const std::vector< Feature * > & getAllFeatures() const
This is the base class for layers.
boost::shared_ptr< DataSource > DataSourcePtr
virtual const std::string & getTitle() const
It returns the layer title.
A dialog used to configure geometry snap options.
te::qt::widgets::MapDisplay * getDisplay()
virtual const char * what() const
It outputs the exception message.
te::qt::widgets::LayerItemView * m_layerExplorer
A connector of the te::qt::widgets::MapDisplay class to the Application Framework.
SimpleData< boost::int32_t, INT32_TYPE > Int32
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
const boost::ptr_vector< te::dt::AbstractData > & getValue() const
It gets the properties values used to uniquely identify a data set element.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
TEEDITEXPORT te::gm::Geometry * Convert2LayerGeomType(const te::map::AbstractLayerPtr &layer, te::gm::Geometry *geom, int srid)
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
void setLayers(const std::list< te::map::AbstractLayerPtr > &layers)
void drop(std::size_t pos)
It drops a property from the dataset.
This class implements a concrete tool for vertex operations (move, add, etc.).
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
static RepositoryManager & getInstance()
It returns a reference to the singleton instance.
void ObjectId()
ObjectId example.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
This class represents an unique id for a data set element.
This event can be used to retrieve the MapDisplat component.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::string getValueAsString() const
It gets the properties values used to uniquely identify a data set element as string.
void draw(const std::list< te::map::AbstractLayerPtr > &layers)
It draws the given layer list.
virtual AbstractData * clone() const =0
It returns a clone of this object.
TEDATAACCESSEXPORT ObjectIdSet * GenerateOIDSet(DataSet *dataset, const DataSetType *type)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void setMapDisplay(te::qt::widgets::MapDisplay *display)
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
std::list< te::map::AbstractLayerPtr > m_layers
TEDATAACCESSEXPORT void GetOIDPropertyPos(const DataSetType *type, std::vector< std::size_t > &ppos)
void StashGeometries(const te::map::AbstractLayer *layer, const std::map< std::string, te::gm::Geometry * > &geoms, const std::map< std::string, int > &ops)
TEDATAACCESSEXPORT void GetOIDPropertyNames(const DataSetType *type, std::vector< std::string > &pnames)
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
This class represents a repository of geometries and features.
A template for atomic data types (integers, floats, strings and others).
te::qt::af::MapDisplay * m_display
bool isAutoNumber() const
It returns true if the attribute is an autonumber, otherwise it returns false.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEGEOMEXPORT te::gm::Geometry * Validate(te::gm::Geometry *geom)
Get/create a valid version of the geometry given. If the geometry is a polygon or multi polygon...
void GetStashedGeometries(const te::map::AbstractLayer *layer, std::map< std::string, te::gm::Geometry * > &geoms, std::map< std::string, int > &ops)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
void setPropertyDataType(int dt, std::size_t pos)