#include "QgsMapToolIdentifyBox.h"
#include <qgsvertexmarker.h>
#include <qgssymbollayer.h>
#include "qgsapplication.h"
#include "QgsMessageLog.h"
QgsMapToolIdentifyAllFeaturesEX::QgsMapToolIdentifyAllFeaturesEX(QgsMapCanvas* canvas)
: QgsMapToolIdentify(canvas)
{
mToolName = tr("Identify All Features");
// set cursor
mCursor = QCursor(Qt::CrossCursor);
}
void QgsMapToolIdentifyAllFeaturesEX::canvasReleaseEvent(QgsMapMouseEvent* e)
{
QPoint point = e->pos() - mInitDragPos;
//点
if (!mSelectionActive || (point.manhattanLength() < QApplication::startDragDistance()))
{
mSelectionActive = false;
mSelectGeometry = QgsGeometry::fromPointXY(toMapCoordinates(e->pos()));
identifyFromGeometry();
}
//矩形
if (mpRubberBand && mSelectionActive)
{
mSelectGeometry = mpRubberBand->asGeometry();
mpRubberBand.reset();
identifyFromGeometry();
}
mSelectionActive = false;
}
void QgsMapToolIdentifyAllFeaturesEX::identifyFromGeometry()
{
if (mCanvas)
{
mCanvas->setSelectionColor(Qt::red);//设置颜色
QList< QgsMapLayer* > layers = mCanvas->layers();
foreach(QgsMapLayer * l, layers)
{
QgsVectorLayer* l1 = qobject_cast<QgsVectorLayer*>(l);
l1->removeSelection();
}
}
//返回选中的结果
QDateTime start = QDateTime::currentDateTime();
QList<IdentifyResult> results = QgsMapToolIdentify::identify(mSelectGeometry, m_mod, LayerType::enum_type::AllLayers);
QDateTime end = QDateTime::currentDateTime();
//QgsMessageLog::logMessage("耗时:"+QString::number((end - start).seconds()), "Messages");
//QList<IdentifyResult> results = QgsMapToolIdentify::identify(mSelectGeometry, m_mod, LayerType::enum_type::AllLayers);
//选择的Features集合
QMap<QString, QList<QgsFeature>> maplist;
//用于显示
QMap<QString,QgsFeatureIds> ids;
for (IdentifyResult var : results)
{
QgsFeature _Feature = var.mFeature;
if (ids.contains(var.mLayer->id())) {
QgsFeatureIds ids1 = ids.value(var.mLayer->id());
ids1.insert(_Feature.id());
ids.insert(var.mLayer->id(), ids1);
}
else {
QgsFeatureIds ids1;
ids1.insert(_Feature.id());
ids.insert(var.mLayer->id(), ids1);
}
}
for (int i = 0; i < results.count(); ++i)
{
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>(results.at(i).mLayer);
//只针对开启编辑图层
/*if (!layer->isEditable()) {
continue;
}*/
if (ids.count() > 0)
layer->selectByIds(ids.value(layer->id()));
QgsFeature feature = results.at(i).mFeature;
if (maplist.contains(layer->id())) {
QList<QgsFeature> sfeatures = maplist.value(layer->id());
sfeatures.append(feature);
maplist.insert(layer->id(), sfeatures);
}
else {
QList<QgsFeature> selectFeatures;
selectFeatures.append(feature);
maplist.insert(layer->id(), selectFeatures);
}
}
//发出选中的Feature信息信号
emit AllfeatureIdentified(maplist);
}
void QgsMapToolIdentifyAllFeaturesEX::clearRubberBand()
{
}
bool QgsMapToolIdentifyAllFeaturesEX::init()
{
open();
return true;
}
void QgsMapToolIdentifyAllFeaturesEX::setMode(IdentifyMode mode)
{
m_mod = mode;
}
void QgsMapToolIdentifyAllFeaturesEX::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape)
{
close();
mCanvas->unsetMapTool(this);
clearRubberBand();
}
emit keyPressEventEx(e);
}
void QgsMapToolIdentifyAllFeaturesEX::keyReleaseEvent(QKeyEvent* e)
{
emit keyReleaseEventEX(e);
}
void QgsMapToolIdentifyAllFeaturesEX::canvasPressEvent(QgsMapMouseEvent* e)
{
if (!mpRubberBand) {
mpRubberBand.reset(new QgsRubberBand(mCanvas, Qgis::GeometryType::Polygon));
/*mpRubberBand->setFillColor(mFillColor);
mpRubberBand->setStrokeColor(mStrokeColor);*/
}
mInitDragPos = e->pos();
}
void QgsMapToolIdentifyAllFeaturesEX::canvasMoveEvent(QgsMapMouseEvent* e)
{
if (e->buttons() != Qt::LeftButton)
return;
QRect rect;
if (!mSelectionActive)
{
mSelectionActive = true;
rect = QRect(e->pos(), e->pos());
}
else
{
rect = QRect(e->pos(), mInitDragPos);
}
if (mpRubberBand)
mpRubberBand->setToCanvasRectangle(rect);
}


zhangiser
- 粉丝: 174
- 资源: 12
最新资源
- 基于PyTorch的MOPSO算法:引导种群逼近Pareto前沿的粒子群优化方法程序研究与应用,基于PyTorch的多目标粒子群算法:MOPSO实现及逼近真实Pareto前沿的种群优化策略,基于pyt
- 车机(飞思卡尔芯片) 系统签名(app公签)
- 如何正确使用deepseek?99%的人都错了.zip
- 基于双边LCC移相控制的无线电能传输系统与PI及MPC模型预测控制实现输出电压恒定,双边LCC移相控制与无线电能传输技术的融合:实现恒定电压PI控制与MPC模型预测控制,双边LCC移相控制,pi控制输
- 零基础使用DeepSeek高效提问技巧.zip
- Multisim仿真工具在模拟电路设计中的首次应用:运算放大器电路构建与测试
- 车机公签,方易通9853 apk签名
- 1000个DeepSeek神级提示词,让你轻松驾驭AI赶紧收藏.zip
- MATLAB代码在线实现:基于最小二乘法的锂电池一阶RC模型参数快速辨识法,基于最小二乘法的锂电池一阶RC模型参数在线辨识MATLAB代码实现,采用最小二乘法在线辨识锂电池一阶RC模型参数的MATLA
- 3个DeepSeek隐藏玩法,99%的人都不知道!.zip
- 横向定标与逆合成孔径雷达ISAR成像的MATLAB仿真程序:精确两步交叉范围缩放法与散射点提取技术研究,**横纵探索:逆合成孔径雷达(ISAR)成像技术与信号处理的精准算法复现**,横向定标 地基逆合
- android安卓原生系统签名,app公签,车机公签
- SPSS workshop (data of construction)
- 全桥与半桥LLC谐振DC-DC变换器的设计与Simulink仿真,包括开环与电压闭环仿真及电路参数计算过程,全桥与半桥LLC谐振DC-DC变换器的设计与Simulink仿真,含开环与电压闭环仿真及电路
- 高速信号链设计中噪声源的影响及优化策略:噪声带宽与信噪比提高方法
- 基于FPGA的永磁同步伺服系统矢量控制设计:集成电流环、速度环与SVPWM模块,采用Verilog实现坐标变换与电机反馈接口,基于FPGA实现永磁同步伺服控制系统的矢量控制与电流环设计:Verilog
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


