29 #include "../pathplanner/waypointdialog.h"
32 QItemSelectionModel *selectionModel)
36 , selection(selectionModel)
38 connect(model, &QAbstractItemModel::rowsInserted,
this, &ModelMapProxy::rowsInserted);
39 connect(model, &QAbstractItemModel::rowsRemoved,
this, &ModelMapProxy::rowsRemoved);
40 connect(selection, &QItemSelectionModel::currentRowChanged,
this,
41 &ModelMapProxy::currentRowChanged);
42 connect(model, &QAbstractItemModel::dataChanged,
this, &ModelMapProxy::dataChanged);
44 &ModelMapProxy::selectedWPChanged);
46 &ModelMapProxy::WPValuesChanged);
53 void ModelMapProxy::WPValuesChanged(WayPointItem *wp)
59 model->
setData(index, wp->Coord().Lat(), Qt::EditRole);
61 model->
setData(index, wp->Coord().Lng(), Qt::EditRole);
64 model->
setData(index, wp->Altitude(), Qt::EditRole);
72 void ModelMapProxy::currentRowChanged(QModelIndex current, QModelIndex previous)
81 myMap->setSelectedWP(list);
91 selection->clearSelection();
92 foreach (WayPointItem *wp, list) {
93 QModelIndex index = model->index(wp->Number(), 0);
94 selection->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
103 ModelMapProxy::overlayType ModelMapProxy::overlayTranslate(
int type)
106 case Waypoint::MODE_ENDPOINT:
107 case Waypoint::MODE_VECTOR:
110 case Waypoint::MODE_CIRCLERIGHT:
111 return OVERLAY_CURVE_RIGHT;
113 case Waypoint::MODE_CIRCLELEFT:
114 return OVERLAY_CURVE_LEFT;
131 void ModelMapProxy::createOverlay(WayPointItem *from, WayPointItem *to,
132 ModelMapProxy::overlayType type, QColor color,
double radius = 0)
134 if (from == NULL || to == NULL || from == to)
138 myMap->WPLineCreate(from, to, color);
140 case OVERLAY_CIRCLE_RIGHT:
141 myMap->WPCircleCreate(to, from,
true, color);
143 case OVERLAY_CIRCLE_LEFT:
144 myMap->WPCircleCreate(to, from,
false, color);
146 case OVERLAY_CURVE_RIGHT:
147 myMap->WPCurveCreate(to, from, radius,
true, color);
149 case OVERLAY_CURVE_LEFT:
150 myMap->WPCurveCreate(to, from, radius,
false, color);
164 void ModelMapProxy::createOverlay(WayPointItem *from, HomeItem *to, ModelMapProxy::overlayType type,
167 if (from == NULL || to == NULL)
171 myMap->WPLineCreate(to, from, color);
173 case OVERLAY_CIRCLE_RIGHT:
174 myMap->WPCircleCreate(to, from,
true, color);
176 case OVERLAY_CIRCLE_LEFT:
177 myMap->WPCircleCreate(to, from,
false, color);
188 void ModelMapProxy::refreshOverlays()
190 myMap->deleteAllOverlays();
193 WayPointItem *wp_current = NULL;
194 WayPointItem *wp_next = NULL;
195 overlayType wp_next_overlay;
199 overlayType wp_current_overlay =
201 createOverlay(wp_current, myMap->Home, wp_current_overlay, Qt::green);
206 wp_next_overlay = overlayTranslate(
210 createOverlay(wp_current, wp_next, wp_next_overlay, Qt::green,
224 return myMap->WPFind(number);
233 void ModelMapProxy::rowsRemoved(
const QModelIndex &parent,
int first,
int last)
237 for (
int x = last;
x > first - 1;
x--) {
248 void ModelMapProxy::dataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
250 Q_UNUSED(bottomRight);
262 for (
int x = topLeft.row();
x <= bottomRight.row();
x++) {
263 for (
int column = topLeft.column(); column <= bottomRight.column(); column++) {
271 desc = index.
data(Qt::DisplayRole).toString();
272 item->SetDescription(desc);
275 latlng = item->Coord();
277 latlng.
SetLat(index.data(Qt::DisplayRole).toDouble());
278 item->SetCoord(latlng);
281 latlng = item->Coord();
283 latlng.
SetLng(index.data(Qt::DisplayRole).toDouble());
284 item->SetCoord(latlng);
288 altitude = index.
data(Qt::DisplayRole).toDouble();
289 item->SetAltitude(altitude);
297 item->setFlag(QGraphicsItem::ItemIsMovable, !index.data(Qt::DisplayRole).toBool());
311 void ModelMapProxy::rowsInserted(
const QModelIndex &parent,
int first,
int last)
314 for (
int x = first;
x < last + 1;
x++) {
319 QString desc = index.
data(Qt::DisplayRole).toString();
321 latlng.
SetLat(index.data(Qt::DisplayRole).toDouble());
323 latlng.
SetLng(index.data(Qt::DisplayRole).toDouble());
325 altitude = index.
data(Qt::DisplayRole).toDouble();
326 myMap->WPInsert(latlng, altitude, desc,
x);
338 model->removeRow(number, QModelIndex());
348 model->insertRow(model->
rowCount(), QModelIndex());
351 model->
setData(index, coord.
Lat(), Qt::EditRole);
353 model->
setData(index, coord.
Lng(), Qt::EditRole);
ModelMapProxy(QObject *parent, TLMapWidget *map, FlightDataModel *model, QItemSelectionModel *selectionModel)
void deleteAll()
When all the waypoints are deleted graphically, update the model.
void deleteWayPoint(int number)
When a waypoint is deleted graphically, delete from the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const
Return the number of waypoints.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
FlightDataModel::removeRows Remove waypoints from the model.
void createWayPoint(internals::PointLatLng coord)
When a waypoint is created graphically, insert into the end of the model.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
FlightDataModel::setData Set the data at a given location.
WayPointItem * findWayPointNumber(int number)
Get the handle to a waypoint graphical item.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
FlightDataModel::data Fetch the data from the model.