添加多选选择器,尝试修复插入的bug
This commit is contained in:
+148
-11
@@ -131,6 +131,33 @@ WayPointLine *OPMapWidget::WPLineCreate(HomeItem *from, WayPointItem *to, QColor
|
||||
ret->setOpacity(overlayOpacity);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OPMapWidget::WPLineDelete(WayPointItem *from, WayPointItem *to)
|
||||
{
|
||||
WayPointLine *line = WPLineFind(from,to);
|
||||
|
||||
if(line)
|
||||
{
|
||||
delete line;
|
||||
}
|
||||
}
|
||||
|
||||
WayPointLine *OPMapWidget::WPLineFind(WayPointItem *from, WayPointItem *to)
|
||||
{
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointLine *w = qgraphicsitem_cast<WayPointLine *>(i);
|
||||
|
||||
if (w) {
|
||||
if (w->WPLineFrom() == from) {
|
||||
return w;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WayPointCircle *OPMapWidget::WPCircleCreate(WayPointItem *center, double radius, bool clockwise, QColor color, bool dashed, int width)
|
||||
{
|
||||
if (!center | !radius) {
|
||||
@@ -285,6 +312,16 @@ void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
|
||||
WPLineCreate(WPFind(Item->Number() - 1),Item,Qt::green,false,2);
|
||||
//qDebug() << "OPMapWidget" << Item->Number() <<QString::number(LatLng.Lat(),'f',8) << QString::number(LatLng.Lng(),'f',8);
|
||||
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w) {
|
||||
qDebug() << "all number" << w->Number() << w->snumber;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
emit MouseDoubleClickEvent(event);
|
||||
@@ -357,19 +394,91 @@ WayPointItem *OPMapWidget::WPCreate(const distBearingAltitude &relativeCoord, co
|
||||
|
||||
void OPMapWidget::WPInsert(const int &position)
|
||||
{
|
||||
internals::PointLatLng latlng;
|
||||
|
||||
WayPointItem *w = WPFind(position);
|
||||
WayPointItem *item_old0 = WPFind(position-1);
|
||||
WayPointItem *item_old1 = WPFind(position);
|
||||
WayPointItem *item_old2 = WPFind(position+1);
|
||||
|
||||
//删除连线
|
||||
if((item_old1)&&(item_old2))
|
||||
{
|
||||
WPLineDelete(item_old1,item_old2);
|
||||
}
|
||||
//删除连线
|
||||
if((item_old1)&&(item_old0))
|
||||
{
|
||||
WPLineDelete(item_old0,item_old1);
|
||||
|
||||
internals::PointLatLng latlng1 = item_old0->Coord();
|
||||
internals::PointLatLng latlng2 = item_old1->Coord();
|
||||
|
||||
latlng.SetLat((latlng1.Lat() + latlng2.Lat())/2);
|
||||
latlng.SetLng((latlng1.Lng() + latlng2.Lng())/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(item_old1)
|
||||
{
|
||||
latlng = item_old1->Coord();
|
||||
}
|
||||
}
|
||||
|
||||
if(item_old1)//如果指定的点存在,那么就可以在这之前插入一个点
|
||||
{
|
||||
WayPointItem *item = WPCreate(latlng,item_old1->Altitude());
|
||||
|
||||
item->SetNumber(position);
|
||||
|
||||
setSelectedWP(item);
|
||||
item->emitWPProperty();
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w) {
|
||||
|
||||
if(w->Number()>position)
|
||||
{
|
||||
w->SetNumber(w->Number() -1);
|
||||
}
|
||||
|
||||
qDebug() << "renumber" << w->Number() << w->snumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WayPointItem *w_next = WPFind(item->Number() + 1);
|
||||
if(w_next)
|
||||
{
|
||||
WPLineCreate(item,w_next,Qt::green,false,2);
|
||||
|
||||
WayPointItem *w_next_1 = WPFind(w_next->Number() + 1);
|
||||
if(w_next_1)
|
||||
{
|
||||
WPLineCreate(w_next,w_next_1,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
|
||||
WayPointItem *w_last = WPFind(item->Number() - 1);
|
||||
if(w_last)
|
||||
{
|
||||
WPLineCreate(w_last,item,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w) {
|
||||
qDebug() << "all number" << w->Number() << w->snumber;
|
||||
}
|
||||
}
|
||||
|
||||
WayPointItem *item = new WayPointItem(w->Coord(),w->Altitude(), map);
|
||||
|
||||
item->SetNumber(position);
|
||||
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
|
||||
emit WPInserted(position, item);
|
||||
setOverlayOpacity(overlayOpacity);
|
||||
//return item;
|
||||
}
|
||||
void OPMapWidget::WPInsert(WayPointItem *item, const int &position)
|
||||
{
|
||||
@@ -426,20 +535,45 @@ WayPointItem *OPMapWidget::WPInsert(distBearingAltitude const & relative, QStrin
|
||||
|
||||
void OPMapWidget::WPDelete(WayPointItem *item)
|
||||
{
|
||||
emit WPDeleted(item->Number(), item);
|
||||
int number = item->Number();
|
||||
|
||||
emit WPDeleted(number, item);
|
||||
delete item;
|
||||
|
||||
//当前选中为上一点
|
||||
WayPointItem *w = WPFind(number -1);
|
||||
if(w)
|
||||
{
|
||||
setSelectedWP(w);
|
||||
w->emitWPProperty();
|
||||
|
||||
WayPointItem *w_next = WPFind(w->Number() + 1);
|
||||
if(w_next)
|
||||
{
|
||||
WPLineCreate(w,w_next,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WayPointItem *ww = WPFind(number);
|
||||
if(ww)
|
||||
{
|
||||
setSelectedWP(ww);
|
||||
ww->emitWPProperty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void OPMapWidget::WPDelete(int number)
|
||||
{
|
||||
WayPointItem *w = WPFind(number);
|
||||
|
||||
if (w) {
|
||||
qDebug() << "delete" <<w->Number();
|
||||
emit WPDeleted(w->Number(), w);
|
||||
delete w;
|
||||
}
|
||||
|
||||
|
||||
//当前选中为上一点
|
||||
WayPointItem *item = WPFind(number -1);
|
||||
if(item)
|
||||
@@ -452,7 +586,10 @@ void OPMapWidget::WPDelete(int number)
|
||||
{
|
||||
WPLineCreate(item,item_next,Qt::green,false,2);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
qDebug() << "can not find next fine";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -521,6 +521,11 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
void WPLineDelete(WayPointItem *from, WayPointItem *to);
|
||||
WayPointLine *WPLineFind(WayPointItem *from, WayPointItem *to);
|
||||
|
||||
|
||||
void WPDelete(WayPointItem *item);
|
||||
void WPDelete(int number);
|
||||
void WPDeleteAll();
|
||||
@@ -531,6 +536,9 @@ public slots:
|
||||
WayPointItem *WPInsert(internals::PointLatLng const & coord, int const & altitude, QString const & description, int const & position);
|
||||
WayPointItem *WPInsert(const distBearingAltitude &relative, const QString &description, const int &position);
|
||||
|
||||
|
||||
|
||||
|
||||
void WPotherPoint(int number);
|
||||
|
||||
void RipMap();
|
||||
|
||||
@@ -383,19 +383,6 @@ void WayPointItem::SetReached(const bool &value)
|
||||
{
|
||||
reached = value;
|
||||
emit WPValuesChanged(this);
|
||||
if (value) {
|
||||
//picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png"));
|
||||
} else {
|
||||
if (!isMagic) {
|
||||
if ((this->flags() & QGraphicsItem::ItemIsMovable) == QGraphicsItem::ItemIsMovable) {
|
||||
//picture.load(QString::fromUtf8(":/markers/images/marker.png"));
|
||||
} else {
|
||||
//picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png"));
|
||||
}
|
||||
} else {
|
||||
//picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png"));
|
||||
}
|
||||
}
|
||||
this->update();
|
||||
}
|
||||
void WayPointItem::SetShowNumber(const bool &value)
|
||||
@@ -426,10 +413,14 @@ void WayPointItem::SetShowNumber(const bool &value)
|
||||
void WayPointItem::WPDeleted(const int &onumber, WayPointItem *waypoint)
|
||||
{
|
||||
Q_UNUSED(waypoint);
|
||||
|
||||
int n = property.seq;
|
||||
if (property.seq > onumber) {
|
||||
if (n > onumber) {
|
||||
SetNumber(--n);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
void WayPointItem::WPInserted(const int &onumber, WayPointItem *waypoint)
|
||||
{
|
||||
@@ -438,8 +429,10 @@ void WayPointItem::WPInserted(const int &onumber, WayPointItem *waypoint)
|
||||
}
|
||||
|
||||
if (waypoint != this) {
|
||||
if (onumber <= property.seq) {
|
||||
SetNumber(++property.seq);
|
||||
|
||||
int n = property.seq;
|
||||
if (onumber <= n) {
|
||||
SetNumber(++n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,16 @@ void WayPointLine::waypointdeleted()
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
void WayPointLine::WPLinedelete(WayPointItem *from, WayPointItem *to)
|
||||
{
|
||||
Q_UNUSED(from)
|
||||
Q_UNUSED(to)
|
||||
|
||||
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void WayPointLine::setOpacitySlot(qreal opacity)
|
||||
{
|
||||
setOpacity(opacity);
|
||||
|
||||
@@ -68,6 +68,19 @@ private:
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
public slots:
|
||||
|
||||
QGraphicsItem *WPLineFrom(void)
|
||||
{
|
||||
return this->source;
|
||||
}
|
||||
|
||||
QGraphicsItem *WPLineTo(void)
|
||||
{
|
||||
return this->destination;
|
||||
}
|
||||
|
||||
|
||||
void WPLinedelete(WayPointItem *from, WayPointItem *to);
|
||||
void refreshLocations();
|
||||
void waypointdeleted();
|
||||
void setOpacitySlot(qreal opacity);
|
||||
|
||||
Reference in New Issue
Block a user