From 98bf5c5b706ea851589efb18e0dac80768b1beed Mon Sep 17 00:00:00 2001 From: hm Date: Fri, 20 May 2022 17:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=BE=B9=E5=BD=A2=E5=9B=B4=E6=A0=8F?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=92=8C=E5=87=8F=E5=B0=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/MissionUI/MissionUI.cpp | 195 +++++++++++++++++++++++++++-- opmap/mapwidget/geoFencecircle.cpp | 4 +- opmap/mapwidget/geoFenceitem.cpp | 4 +- 3 files changed, 192 insertions(+), 11 deletions(-) diff --git a/App/MissionUI/MissionUI.cpp b/App/MissionUI/MissionUI.cpp index e7bb18c..dd474f6 100644 --- a/App/MissionUI/MissionUI.cpp +++ b/App/MissionUI/MissionUI.cpp @@ -7,7 +7,7 @@ MissionUI::MissionUI(QWidget *parent) : { ui->setupUi(this); setWindowTitle(tr("Mission Table")); - setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); + //setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); //load qss QFile file(":/qss/propertyui.qss"); @@ -728,6 +728,12 @@ void MissionUI::updateFencePolygon(int group,qreal vertex,bool inclusion,QListremoveCellWidget(idx,0); + tableWidget->setItem(idx,0,new QTableWidgetItem(QString::number(group))); + + //tableWidget->removeCellWidget(idx,1); + //tableWidget->setItem(idx,1,new QTableWidgetItem(QString::number(vertex))); + tableWidget->removeCellWidget(idx,2); tableWidget->setItem(idx,2,new QTableWidgetItem(QString::number(vertex))); @@ -759,7 +765,6 @@ void MissionUI::updateFencePolygon(int group,qreal vertex,bool inclusion,QListsetSpan(startIndex,0,endIndex - startIndex,1); //tableWidget->setSpan(startIndex,1,endIndex - startIndex,1); //tableWidget->setSpan(startIndex,2,endIndex - startIndex,1); @@ -768,11 +773,6 @@ void MissionUI::updateFencePolygon(int group,qreal vertex,bool inclusion,QListsetStyleSheet("background-color: #FFFFFF;font :15px 黑体;"); + line->setText(item->data(Qt::DisplayRole).toString()); + widget->removeCellWidget(row,column); + widget->setCellWidget(row,column,line); + + connect(line,&QLineEdit::editingFinished,[=](){ + if(line) + { + QString str = line->text(); + bool ok = false; + str.toInt(&ok); + if(ok) + { + if(str.toInt() >= 3) + { + widget->removeCellWidget(row,column); + item->setText(str); + } + else + { + return; + } + } + + + //得到新的行数 + int startIndex = -1; + bool isGetStart = false; + int endIndex = -1; + int gv = widget->item(row,0)->data(Qt::DisplayRole).toInt();//得到group + for(int i = 0;i< widget->rowCount();i++) + { + if(isGetStart == false)//还没得到开头 + { + if(gv == widget->item(i,0)->data(Qt::DisplayRole).toInt()) + { + startIndex = i; + isGetStart = true; + } + } + else//已经得到开头,寻找结束项 + { + + if(gv != widget->item(i,0)->data(Qt::DisplayRole).toInt()) + { + endIndex = i; + break; + } + else//相等的情况 + { + if(i == (widget->rowCount() - 1))//最后一个 + { + if(gv == widget->item(i,0)->data(Qt::DisplayRole).toInt()) + { + endIndex = i; + break; + } + } + } + } + } + + if((startIndex == -1)&&(endIndex == -1)) + { + return; + } + + //在当前选中的这一行下方插入一个点增加一个点 + int newVertex = str.toInt(); + int oldVertex = widget->rowSpan(row,0); + qDebug() << "row" << newVertex << oldVertex << startIndex << endIndex << gv; + if(newVertex > oldVertex)//增加 + { + for(int i = 0;i<(newVertex - oldVertex);i++) + { + bool inclusion = widget->item(startIndex,3)->checkState()?(true):(false); + + qreal lat1 = widget->item(startIndex + 1,4)->data(Qt::DisplayRole).toDouble(); + qreal lng1 = widget->item(startIndex + 1,5)->data(Qt::DisplayRole).toDouble(); + + qreal lat2 = widget->item(startIndex,4)->data(Qt::DisplayRole).toDouble(); + qreal lng2 = widget->item(startIndex,5)->data(Qt::DisplayRole).toDouble(); + + + qreal lat = (lat1 +lat2)/2.0; + qreal lng = (lng1 +lng2)/2.0; + + + widget->insertRow(endIndex - 1); + + widget->removeCellWidget(endIndex - 1,0); + widget->setItem(endIndex - 1,0,new QTableWidgetItem(QString::number(gv))); //第一列的内容设置为index + + widget->removeCellWidget(endIndex - 1,1); + widget->setItem(endIndex - 1,1,new QTableWidgetItem(tr("Polygon"))); + + widget->removeCellWidget(endIndex - 1,2); + widget->setItem(endIndex - 1,2,new QTableWidgetItem(QString::number(newVertex))); + + + QString inclusionName; + switch (inclusion) { + case 1: + inclusionName = tr("inclusion"); + break; + case 0: + inclusionName = tr("exclusion"); + break; + default: + break; + } + + QTableWidgetItem *item3 = new QTableWidgetItem(inclusionName); + item3->setCheckState((inclusion)?(Qt::Checked):(Qt::Unchecked)); + + widget->removeCellWidget(endIndex - 1,3); + widget->setItem(endIndex - 1,3,item3); + + widget->removeCellWidget(endIndex - 1,4); + widget->setItem(endIndex - 1,4,new QTableWidgetItem(QString::number(lat ,'f',7))); + + widget->removeCellWidget(endIndex - 1,5); + widget->setItem(endIndex - 1,5,new QTableWidgetItem(QString::number(lng ,'f',7))); + } + } + else if(newVertex < oldVertex)//减少 + { + qDebug() << "del" << endIndex; + for(int i = 0;i<(oldVertex - newVertex);i++) + { + widget->removeRow(endIndex - i); + + qDebug() << "idx" << endIndex - i; + } + } + else + { + + } + + + + + int gidx = widget->item(row,0)->data(Qt::DisplayRole).toInt();//得到group + //找到开始的idx + int StartIdx = widget->item(row,0)->row(); + for (int i = 0; i < widget->rowCount(); ++i) { + if(widget->item(i,0)->data(Qt::DisplayRole).toInt() == gidx) + { + StartIdx = i; + break; + } + } + + int SpanCount = widget->rowSpan(row,0); + + QString type = widget->item(StartIdx,1)->data(Qt::DisplayRole).toString();//得到type + qreal par = widget->item(StartIdx,2)->data(Qt::DisplayRole).toDouble();//得到par + bool inclusion = widget->item(StartIdx,3)->checkState()?(true):(false); + + + //从头获取所有点 + QList latlng; + latlng.clear(); + + for(int i = StartIdx;i<(StartIdx + SpanCount);i++) + { + qreal latitude = widget->item(i,4)->data(Qt::DisplayRole).toDouble(); + qreal longitude = widget->item(i,5)->data(Qt::DisplayRole).toDouble(); + + latlng.push_back(QPointF(latitude,longitude)); + } + + emit setFencePolygon(gidx,par,inclusion,latlng); + + } + }); + } } else if(column == 3) { diff --git a/opmap/mapwidget/geoFencecircle.cpp b/opmap/mapwidget/geoFencecircle.cpp index e5007c5..5f7cb29 100644 --- a/opmap/mapwidget/geoFencecircle.cpp +++ b/opmap/mapwidget/geoFencecircle.cpp @@ -13,8 +13,8 @@ geoFencecircle::geoFencecircle(int group, bool inclusion, int version, internals this->setAcceptHoverEvents(true); this->setZValue(3); - this->setFlag(QGraphicsItem::ItemIsMovable, true); - this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); + //this->setFlag(QGraphicsEllipseItem::ItemIsMovable, true); + //this->setFlag(QGraphicsEllipseItem::ItemIgnoresTransformations, true); //this->setFlag(QGraphicsItem::ItemIsSelectable, true);//这个有bug m_version = version; diff --git a/opmap/mapwidget/geoFenceitem.cpp b/opmap/mapwidget/geoFenceitem.cpp index 6d01f74..6e0f30b 100644 --- a/opmap/mapwidget/geoFenceitem.cpp +++ b/opmap/mapwidget/geoFenceitem.cpp @@ -10,8 +10,8 @@ geoFenceitem::geoFenceitem(int group, bool inclusion, int version, internals::Po this->setAcceptHoverEvents(true); this->setZValue(3); - this->setFlag(QGraphicsItem::ItemIsMovable, true); - this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); + //this->setFlag(QGraphicsPolygonItem::ItemIsMovable, true); + //this->setFlag(QGraphicsPolygonItem::ItemIgnoresTransformations, true); //this->setFlag(QGraphicsItem::ItemIsSelectable, true);//这个有bug