1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

Map updates:

Allow selection of which device to tune to frequency.
Support tuning of multiple frequencies per map item.
Update maplibre to maplibregl.
This commit is contained in:
srcejon 2023-12-05 12:30:25 +00:00
parent 78068fd5f2
commit 070f8077b2
9 changed files with 206 additions and 75 deletions

View File

@ -269,12 +269,24 @@ Item {
mapModel.moveToFront(mapModelFiltered.mapRowToSource(index)) mapModel.moveToFront(mapModelFiltered.mapRowToSource(index))
} }
} else if (mouse.button === Qt.RightButton) { } else if (mouse.button === Qt.RightButton) {
if (frequency > 0) { menuItems.clear()
freqMenuItem.text = "Set frequency to " + frequencyString menus.clear()
freqMenuItem.enabled = true if (frequencies.length > 0) {
} else { var deviceSets = mapModel.getDeviceSets()
freqMenuItem.text = "No frequency available" for (var i = 0; i < deviceSets.length; i++) {
freqMenuItem.enabled = false menus.append({
title: "Set " + deviceSets[i] + " to...",
deviceSet: i
})
for (var j = 0; j < frequencies.length; j++) {
menuItems.append({
text: frequencyStrings[j],
frequency: frequencies[j],
deviceSet: deviceSets[i],
menuIndex: i
})
}
}
} }
var c = mapPtr.toCoordinate(Qt.point(mouse.x, mouse.y)) var c = mapPtr.toCoordinate(Qt.point(mouse.x, mouse.y))
coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6) coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6)
@ -308,29 +320,42 @@ Item {
mapModel.moveToFront(mapModelFiltered.mapRowToSource(index)) mapModel.moveToFront(mapModelFiltered.mapRowToSource(index))
} }
} else if (mouse.button === Qt.RightButton) { } else if (mouse.button === Qt.RightButton) {
if (frequency > 0) { menuItems.clear()
freqMenuItem.text = "Set frequency to " + frequencyString menus.clear()
freqMenuItem.enabled = true if (frequencies.length > 0) {
} else { var deviceSets = mapModel.getDeviceSets()
freqMenuItem.text = "No frequency available" for (var i = 0; i < deviceSets.length; i++) {
freqMenuItem.enabled = false menus.append({
title: "Set " + deviceSets[i] + " to...",
deviceSet: i
})
for (var j = 0; j < frequencies.length; j++) {
menuItems.append({
text: frequencyStrings[j],
frequency: frequencies[j],
deviceSet: deviceSets[i],
menuIndex: i
})
}
}
} }
var c = mapPtr.toCoordinate(Qt.point(mouse.x, mouse.y)) var c = mapPtr.toCoordinate(Qt.point(mouse.x, mouse.y))
coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6) coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6)
contextMenu.popup() contextMenu.popup()
} }
} }
ListModel {
id: menus
}
ListModel {
id: menuItems
}
Menu { Menu {
id: contextMenu id: contextMenu
MenuItem { MenuItem {
text: "Set as target" text: "Set as target"
onTriggered: target = true onTriggered: target = true
} }
MenuItem {
id: freqMenuItem
text: "Not set"
onTriggered: mapModel.setFrequency(frequency)
}
MenuItem { MenuItem {
text: "Move to front" text: "Move to front"
onTriggered: mapModel.moveToFront(mapModelFiltered.mapRowToSource(index)) onTriggered: mapModel.moveToFront(mapModelFiltered.mapRowToSource(index))
@ -347,6 +372,38 @@ Item {
id: coordsMenuItem id: coordsMenuItem
text: "" text: ""
} }
Instantiator {
model: menus
delegate: Menu {
//cascade: true
id: contextSubMenu
title: model.title
}
onObjectAdded: function(index, object) {
contextMenu.insertMenu(index, object)
}
onObjectRemoved: function(index, object) {
contextMenu.removeMenu(object)
}
}
Instantiator {
model: menuItems
delegate: MenuItem {
text: model.text
onTriggered: mapModel.setFrequency(model.frequency, model.deviceSet)
}
onObjectAdded: function(index, object) {
// index is index in to menuItems model
// object is the MenuItem
var menuItem = menuItems.get(index)
var menu = menus.get(menuItem.menuIndex)
contextMenu.menuAt(menuItem.menuIndex).insertItem(index, object)
}
onObjectRemoved: function(index, object) {
// Can't use menuItems.get(index) here, as already removed from model
object.menu.removeItem(object)
}
}
} }
} }
} }

View File

@ -282,12 +282,24 @@ Item {
mapModel.moveToFront(mapModelFiltered.mapRowToSource(index)) mapModel.moveToFront(mapModelFiltered.mapRowToSource(index))
} }
} else if (mouse.button === Qt.RightButton) { } else if (mouse.button === Qt.RightButton) {
if (frequency > 0) { menuItems.clear()
freqMenuItem.text = "Set frequency to " + frequencyString menus.clear()
freqMenuItem.enabled = true if (frequencies.length > 0) {
} else { var deviceSets = mapModel.getDeviceSets()
freqMenuItem.text = "No frequency available" for (var i = 0; i < deviceSets.length; i++) {
freqMenuItem.enabled = false menus.append({
title: "Set " + deviceSets[i] + " to...",
deviceSet: i
})
for (var j = 0; j < frequencies.length; j++) {
menuItems.append({
text: frequencyStrings[j],
frequency: frequencies[j],
deviceSet: deviceSets[i],
menuIndex: i
})
}
}
} }
var c = mapPtr.map.toCoordinate(Qt.point(mouse.x, mouse.y)) var c = mapPtr.map.toCoordinate(Qt.point(mouse.x, mouse.y))
coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6) coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6)
@ -321,29 +333,42 @@ Item {
mapModel.moveToFront(mapModelFiltered.mapRowToSource(index)) mapModel.moveToFront(mapModelFiltered.mapRowToSource(index))
} }
} else if (mouse.button === Qt.RightButton) { } else if (mouse.button === Qt.RightButton) {
if (frequency > 0) { menuItems.clear()
freqMenuItem.text = "Set frequency to " + frequencyString menus.clear()
freqMenuItem.enabled = true if (frequencies.length > 0) {
} else { var deviceSets = mapModel.getDeviceSets()
freqMenuItem.text = "No frequency available" for (var i = 0; i < deviceSets.length; i++) {
freqMenuItem.enabled = false menus.append({
title: "Set " + deviceSets[i] + " to...",
deviceSet: i
})
for (var j = 0; j < frequencies.length; j++) {
menuItems.append({
text: frequencyStrings[j],
frequency: frequencies[j],
deviceSet: deviceSets[i],
menuIndex: i
})
}
}
} }
var c = mapPtr.map.toCoordinate(Qt.point(mouse.x, mouse.y)) var c = mapPtr.map.toCoordinate(Qt.point(mouse.x, mouse.y))
coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6) coordsMenuItem.text = "Coords: " + c.latitude.toFixed(6) + ", " + c.longitude.toFixed(6)
contextMenu.popup() contextMenu.popup()
} }
} }
ListModel {
id: menus
}
ListModel {
id: menuItems
}
Menu { Menu {
id: contextMenu id: contextMenu
MenuItem { MenuItem {
text: "Set as target" text: "Set as target"
onTriggered: target = true onTriggered: target = true
} }
MenuItem {
id: freqMenuItem
text: "Not set"
onTriggered: mapModel.setFrequency(frequency)
}
MenuItem { MenuItem {
text: "Move to front" text: "Move to front"
onTriggered: mapModel.moveToFront(mapModelFiltered.mapRowToSource(index)) onTriggered: mapModel.moveToFront(mapModelFiltered.mapRowToSource(index))
@ -360,6 +385,38 @@ Item {
id: coordsMenuItem id: coordsMenuItem
text: "" text: ""
} }
Instantiator {
model: menus
delegate: Menu {
//cascade: true
id: contextSubMenu
title: model.title
}
onObjectAdded: function(index, object) {
contextMenu.insertMenu(index, object)
}
onObjectRemoved: function(index, object) {
contextMenu.removeMenu(object)
}
}
Instantiator {
model: menuItems
delegate: MenuItem {
text: model.text
onTriggered: mapModel.setFrequency(model.frequency, model.deviceSet)
}
onObjectAdded: function(index, object) {
// index is index in to menuItems model
// object is the MenuItem
var menuItem = menuItems.get(index)
var menu = menus.get(menuItem.menuIndex)
contextMenu.menuAt(menuItem.menuIndex).insertItem(index, object)
}
onObjectRemoved: function(index, object) {
// Can't use menuItems.get(index) here, as already removed from model
object.menu.removeItem(object)
}
}
} }
} }
} }

View File

@ -1189,11 +1189,12 @@ void MapGUI::applyMap2DSettings(bool reloadMap)
if (!m_settings.m_mapBoxStyles.isEmpty()) if (!m_settings.m_mapBoxStyles.isEmpty())
parameters["mapboxgl.mapping.additional_style_urls"] = m_settings.m_mapBoxStyles; parameters["mapboxgl.mapping.additional_style_urls"] = m_settings.m_mapBoxStyles;
} }
if (m_settings.m_mapProvider == "maplibre") if (m_settings.m_mapProvider == "maplibregl")
{ {
parameters["maplibre.access_token"] = m_settings.m_mapBoxAPIKey; parameters["maplibregl.settings_template"] = "maptiler"; // Or "mapbox"
parameters["maplibregl.access_token"] = m_settings.m_maptilerAPIKey;
if (!m_settings.m_mapBoxStyles.isEmpty()) if (!m_settings.m_mapBoxStyles.isEmpty())
parameters["maplibre.mapping.additional_style_urls"] = m_settings.m_mapBoxStyles; parameters["maplibregl.mapping.additional_style_urls"] = m_settings.m_mapBoxStyles;
} }
if (m_settings.m_mapProvider == "osm") if (m_settings.m_mapProvider == "osm")
{ {

View File

@ -90,7 +90,7 @@ void ObjectMapItem::update(SWGSDRangel::SWGMapItem *mapItem)
m_animations.append(new CesiumInterface::Animation(animation)); m_animations.append(new CesiumInterface::Animation(animation));
} }
} }
findFrequency(); findFrequencies();
if (!m_fixedPosition) if (!m_fixedPosition)
{ {
updateTrack(mapItem->getTrack()); updateTrack(mapItem->getTrack());
@ -192,29 +192,33 @@ void PolylineMapItem::update(SWGSDRangel::SWGMapItem *mapItem)
m_bounds = QGeoRectangle(QGeoCoordinate(latMax, lonMin), QGeoCoordinate(latMin, lonMax)); m_bounds = QGeoRectangle(QGeoCoordinate(latMax, lonMin), QGeoCoordinate(latMin, lonMax));
} }
void ObjectMapItem::findFrequency() // Look for a frequency in the text for this object
void ObjectMapItem::findFrequencies()
{ {
// Look for a frequency in the text for this object m_frequencies.clear();
QRegExp re("(([0-9]+(\\.[0-9]+)?) *([kMG])?Hz)"); m_frequencyStrings.clear();
if (re.indexIn(m_text) != -1)
const QRegularExpression re("(([0-9]+(\\.[0-9]+)?) *([kMG])?Hz)");
QRegularExpressionMatchIterator itr = re.globalMatch(m_text);
while (itr.hasNext())
{ {
QStringList capture = re.capturedTexts(); QRegularExpressionMatch match = itr.next();
m_frequency = capture[2].toDouble(); QStringList capture = match.capturedTexts();
double frequency = capture[2].toDouble();
if (capture.length() == 5) if (capture.length() == 5)
{ {
QChar unit = capture[4][0]; QChar unit = capture[4][0];
if (unit == 'k') if (unit == 'k') {
m_frequency *= 1000.0; frequency *= 1000;
else if (unit == 'M') } else if (unit == 'M') {
m_frequency *= 1000000.0; frequency *= 1000000;
else if (unit == 'G') } else if (unit == 'G') {
m_frequency *= 1000000000.0; frequency *= 1000000000;
}
} }
m_frequencyString = capture[0]; m_frequencies.append((qint64)frequency);
} m_frequencyStrings.append(capture[0]);
else
{
m_frequency = 0.0;
} }
} }

View File

@ -77,7 +77,7 @@ public:
void update(SWGSDRangel::SWGMapItem *mapItem) override; void update(SWGSDRangel::SWGMapItem *mapItem) override;
protected: protected:
void findFrequency(); void findFrequencies();
void updateTrack(QList<SWGSDRangel::SWGMapCoordinate *> *track); void updateTrack(QList<SWGSDRangel::SWGMapCoordinate *> *track);
void updatePredictedTrack(QList<SWGSDRangel::SWGMapCoordinate *> *track); void updatePredictedTrack(QList<SWGSDRangel::SWGMapCoordinate *> *track);
@ -92,8 +92,8 @@ protected:
QString m_image; QString m_image;
int m_imageRotation; int m_imageRotation;
QString m_text; QString m_text;
double m_frequency; // Frequency to set QList<qint64> m_frequencies; // Frequencies that can be tuned (currently only extracted from text)
QString m_frequencyString; QStringList m_frequencyStrings;
bool m_fixedPosition; // Don't record/display track bool m_fixedPosition; // Don't record/display track
QList<QGeoCoordinate *> m_predictedTrackCoords; QList<QGeoCoordinate *> m_predictedTrackCoords;
QList<QDateTime *> m_predictedTrackDateTimes; QList<QDateTime *> m_predictedTrackDateTimes;

View File

@ -516,8 +516,8 @@ QHash<int, QByteArray> ObjectMapModel::roleNames() const
roles[bubbleColourRole] = "bubbleColour"; roles[bubbleColourRole] = "bubbleColour";
roles[selectedRole] = "selected"; roles[selectedRole] = "selected";
roles[targetRole] = "target"; roles[targetRole] = "target";
roles[frequencyRole] = "frequency"; roles[frequenciesRole] = "frequencies";
roles[frequencyStringRole] = "frequencyString"; roles[frequencyStringsRole] = "frequencyStrings";
roles[predictedGroundTrack1Role] = "predictedGroundTrack1"; roles[predictedGroundTrack1Role] = "predictedGroundTrack1";
roles[predictedGroundTrack2Role] = "predictedGroundTrack2"; roles[predictedGroundTrack2Role] = "predictedGroundTrack2";
roles[groundTrack1Role] = "groundTrack1"; roles[groundTrack1Role] = "groundTrack1";
@ -675,10 +675,10 @@ QVariant ObjectMapModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue(m_selected[row]); return QVariant::fromValue(m_selected[row]);
case targetRole: case targetRole:
return QVariant::fromValue(m_target == row); return QVariant::fromValue(m_target == row);
case frequencyRole: case frequenciesRole:
return QVariant::fromValue(mapItem->m_frequency); return QVariant::fromValue(mapItem->m_frequencies);
case frequencyStringRole: case frequencyStringsRole:
return QVariant::fromValue(mapItem->m_frequencyString); return QVariant::fromValue(mapItem->m_frequencyStrings);
case predictedGroundTrack1Role: case predictedGroundTrack1Role:
{ {
if ( (m_displayAllGroundTracks || (m_displaySelectedGroundTracks && m_selected[row])) if ( (m_displayAllGroundTracks || (m_displaySelectedGroundTracks && m_selected[row]))
@ -780,12 +780,6 @@ void ObjectMapModel::setDisplayAllGroundTracks(bool displayGroundTracks)
allUpdated(); allUpdated();
} }
void ObjectMapModel::setFrequency(double frequency)
{
// Set as centre frequency
ChannelWebAPIUtils::setCenterFrequency(0, frequency);
}
void ObjectMapModel::track3D(int index) void ObjectMapModel::track3D(int index)
{ {
if (index < m_items.count()) if (index < m_items.count())
@ -795,6 +789,22 @@ void ObjectMapModel::track3D(int index)
} }
} }
QStringList ObjectMapModel::getDeviceSets() const
{
return MainCore::instance()->getDeviceSetIds(true, true, false); // FIXME: MIMO currently disabled, as we can't get channel stream indexes
}
void ObjectMapModel::setFrequency(qint64 frequency, const QString& deviceSetId)
{
unsigned int deviceSetIndex;
if (MainCore::getDeviceSetIndexFromId(deviceSetId, deviceSetIndex))
{
// Set as centre frequency
ChannelWebAPIUtils::setCenterFrequency(deviceSetIndex, frequency);
}
}
void ObjectMapModel::splitTracks(ObjectMapItem *item) void ObjectMapModel::splitTracks(ObjectMapItem *item)
{ {
if (item->m_takenTrackCoords.size() > 1) if (item->m_takenTrackCoords.size() > 1)

View File

@ -211,8 +211,8 @@ public:
bubbleColourRole = MapModel::lastRole + 4, bubbleColourRole = MapModel::lastRole + 4,
selectedRole = MapModel::lastRole + 5, selectedRole = MapModel::lastRole + 5,
targetRole = MapModel::lastRole + 6, targetRole = MapModel::lastRole + 6,
frequencyRole = MapModel::lastRole + 7, frequenciesRole = MapModel::lastRole + 7,
frequencyStringRole = MapModel::lastRole + 8, frequencyStringsRole = MapModel::lastRole + 8,
predictedGroundTrack1Role = MapModel::lastRole + 9, predictedGroundTrack1Role = MapModel::lastRole + 9,
predictedGroundTrack2Role = MapModel::lastRole + 10, predictedGroundTrack2Role = MapModel::lastRole + 10,
groundTrack1Role = MapModel::lastRole + 11, groundTrack1Role = MapModel::lastRole + 11,
@ -244,8 +244,10 @@ public:
void setDisplayNames(bool displayNames); void setDisplayNames(bool displayNames);
void setDisplaySelectedGroundTracks(bool displayGroundTracks); void setDisplaySelectedGroundTracks(bool displayGroundTracks);
void setDisplayAllGroundTracks(bool displayGroundTracks); void setDisplayAllGroundTracks(bool displayGroundTracks);
Q_INVOKABLE void setFrequency(double frequency);
Q_INVOKABLE void track3D(int index); Q_INVOKABLE void track3D(int index);
Q_INVOKABLE QStringList getDeviceSets() const;
Q_INVOKABLE void setFrequency(qint64 frequency, const QString& deviceSet);
Q_INVOKABLE void viewChanged(double bottomLeftLongitude, double bottomRightLongitude); Q_INVOKABLE void viewChanged(double bottomLeftLongitude, double bottomRightLongitude);

View File

@ -66,7 +66,7 @@ const QStringList MapSettings::m_mapProviders = {
QStringLiteral("esri"), QStringLiteral("esri"),
QStringLiteral("mapbox"), QStringLiteral("mapbox"),
QStringLiteral("mapboxgl"), QStringLiteral("mapboxgl"),
QStringLiteral("maplibre") QStringLiteral("maplibregl")
}; };
MapSettings::MapSettings() : MapSettings::MapSettings() :

View File

@ -95,7 +95,7 @@
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>MapLibre</string> <string>MapLibreGL</string>
</property> </property>
</item> </item>
</widget> </widget>