Browse Source

Add connections overlay

chirpmodem-v8.0.0
Jon Beniston 2 months ago
parent
commit
852fd6e10c
  1. 2
      plugins/channelrx/radioastronomy/radioastronomy.cpp
  2. 2
      plugins/feature/ais/ais.cpp
  3. 2
      plugins/feature/aprs/aprs.cpp
  4. 3
      plugins/feature/demodanalyzer/demodanalyzer.cpp
  5. 5
      plugins/feature/demodanalyzer/demodanalyzerworker.cpp
  6. 3
      plugins/feature/denoiser/denoiser.cpp
  7. 5
      plugins/feature/denoiser/denoiserworker.cpp
  8. 2
      plugins/feature/map/map.cpp
  9. 3
      plugins/feature/morsedecoder/morsedecoder.cpp
  10. 5
      plugins/feature/morsedecoder/morsedecoderworker.cpp
  11. 2
      plugins/feature/radiosonde/radiosonde.cpp
  12. 2
      plugins/feature/skymap/skymapgui.cpp
  13. 4
      plugins/feature/startracker/startracker.cpp
  14. 6
      sdrbase/availablechannelorfeaturehandler.h
  15. 5
      sdrbase/pipes/datapipes.cpp
  16. 1
      sdrbase/pipes/datapipes.h
  17. 5
      sdrbase/pipes/messagepipes.cpp
  18. 1
      sdrbase/pipes/messagepipes.h
  19. 3
      sdrbase/pipes/objectpipe.cpp
  20. 28
      sdrbase/pipes/objectpipesregistrations.cpp
  21. 6
      sdrbase/pipes/objectpipesregistrations.h
  22. 2
      sdrgui/CMakeLists.txt
  23. 2
      sdrgui/channel/channelgui.cpp
  24. 3
      sdrgui/channel/channelgui.h
  25. 13
      sdrgui/device/devicegui.cpp
  26. 3
      sdrgui/device/devicegui.h
  27. 5
      sdrgui/device/deviceuiset.cpp
  28. 1
      sdrgui/device/deviceuiset.h
  29. 1
      sdrgui/feature/featuregui.cpp
  30. 818
      sdrgui/gui/connectionoverlay.cpp
  31. 118
      sdrgui/gui/connectionoverlay.h
  32. 32
      sdrgui/gui/workspace.cpp
  33. 6
      sdrgui/gui/workspace.h
  34. 1
      sdrgui/mainspectrum/mainspectrumgui.cpp
  35. 216
      sdrgui/mainwindow.cpp
  36. 5
      sdrgui/mainwindow.h
  37. 1
      sdrgui/resources/res.qrc
  38. BIN
      sdrgui/resources/wiring.png

2
plugins/channelrx/radioastronomy/radioastronomy.cpp

@ -68,7 +68,7 @@ RadioAstronomy::RadioAstronomy(DeviceAPI *deviceAPI) : @@ -68,7 +68,7 @@ RadioAstronomy::RadioAstronomy(DeviceAPI *deviceAPI) :
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
m_deviceAPI(deviceAPI),
m_basebandSampleRate(0),
m_availableFeatureHandler({"sdrangel.feature.startracker"}, QStringList{"startracker.target"}),
m_availableFeatureHandler({"sdrangel.feature.startracker"}, QStringList{"startracker.target"}, "RTMF", this),
m_availableRotatorHandler({"sdrangel.feature.gs232controller"}),
m_sweeping(false)
{

2
plugins/feature/ais/ais.cpp

@ -42,7 +42,7 @@ const char* const AIS::m_featureId = "AIS"; @@ -42,7 +42,7 @@ const char* const AIS::m_featureId = "AIS";
AIS::AIS(WebAPIAdapterInterface *webAPIAdapterInterface) :
Feature(m_featureIdURI, webAPIAdapterInterface),
m_availableChannelHandler({"sdrangel.channel.aisdemod"}, QStringList{"ais"})
m_availableChannelHandler({"sdrangel.channel.aisdemod"}, QStringList{"ais"}, "RTMF", this)
{
qDebug("AIS::AIS: webAPIAdapterInterface: %p", webAPIAdapterInterface);
setObjectName(m_featureId);

2
plugins/feature/aprs/aprs.cpp

@ -45,7 +45,7 @@ APRS::APRS(WebAPIAdapterInterface *webAPIAdapterInterface) : @@ -45,7 +45,7 @@ APRS::APRS(WebAPIAdapterInterface *webAPIAdapterInterface) :
Feature(m_featureIdURI, webAPIAdapterInterface),
m_thread(nullptr),
m_worker(nullptr),
m_availableChannelHandler(APRSSettings::m_pipeURIs, QStringList{"packets"})
m_availableChannelHandler(APRSSettings::m_pipeURIs, QStringList{"packets"}, "RTMF", this)
{
qDebug("APRS::APRS: webAPIAdapterInterface: %p", webAPIAdapterInterface);
setObjectName(m_featureId);

3
plugins/feature/demodanalyzer/demodanalyzer.cpp

@ -342,7 +342,7 @@ void DemodAnalyzer::setChannel(ChannelAPI *selectedChannel) @@ -342,7 +342,7 @@ void DemodAnalyzer::setChannel(ChannelAPI *selectedChannel)
if (m_selectedChannel)
{
ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod");
DataFifo *fifo = qobject_cast<DataFifo*>(pipe->m_element);
DataFifo *fifo = pipe ? qobject_cast<DataFifo*>(pipe->m_element) : nullptr;
if ((fifo) && m_running)
{
@ -668,6 +668,7 @@ void DemodAnalyzer::handleDataPipeToBeDeleted(int reason, QObject *object) @@ -668,6 +668,7 @@ void DemodAnalyzer::handleDataPipeToBeDeleted(int reason, QObject *object)
}
m_selectedChannel = nullptr;
m_dataPipe = nullptr; // The pipe and its FIFO are freed by the pipes GC.
}
}

5
plugins/feature/demodanalyzer/demodanalyzerworker.cpp

@ -251,6 +251,7 @@ bool DemodAnalyzerWorker::handleMessage(const Message& cmd) @@ -251,6 +251,7 @@ bool DemodAnalyzerWorker::handleMessage(const Message& cmd)
this,
&DemodAnalyzerWorker::handleData
);
m_dataFifo = nullptr; // It is freed by the pipes GC after being unregistered.
}
return true;
@ -358,6 +359,10 @@ void DemodAnalyzerWorker::handleData() @@ -358,6 +359,10 @@ void DemodAnalyzerWorker::handleData()
{
QMutexLocker mutexLocker(&m_mutex);
if (!m_dataFifo) {
return; // A queued dataReady can arrive after the FIFO was disconnected.
}
while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0))
{
QByteArray::iterator part1begin;

3
plugins/feature/denoiser/denoiser.cpp

@ -343,7 +343,7 @@ void Denoiser::setChannel(ChannelAPI *selectedChannel) @@ -343,7 +343,7 @@ void Denoiser::setChannel(ChannelAPI *selectedChannel)
if (m_selectedChannel)
{
ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod");
DataFifo *fifo = qobject_cast<DataFifo*>(pipe->m_element);
DataFifo *fifo = pipe ? qobject_cast<DataFifo*>(pipe->m_element) : nullptr;
if ((fifo) && m_running)
{
@ -680,6 +680,7 @@ void Denoiser::handleDataPipeToBeDeleted(int reason, QObject *object) @@ -680,6 +680,7 @@ void Denoiser::handleDataPipeToBeDeleted(int reason, QObject *object)
}
m_selectedChannel = nullptr;
m_dataPipe = nullptr; // The pipe and its FIFO are freed by the pipes GC.
}
}

5
plugins/feature/denoiser/denoiserworker.cpp

@ -198,6 +198,7 @@ bool DenoiserWorker::handleMessage(const Message& cmd) @@ -198,6 +198,7 @@ bool DenoiserWorker::handleMessage(const Message& cmd)
this,
&DenoiserWorker::handleData
);
m_dataFifo = nullptr; // It is freed by the pipes GC after being unregistered.
}
return true;
@ -301,6 +302,10 @@ void DenoiserWorker::handleData() @@ -301,6 +302,10 @@ void DenoiserWorker::handleData()
{
QMutexLocker mutexLocker(&m_mutex);
if (!m_dataFifo) {
return; // A queued dataReady can arrive after the FIFO was disconnected.
}
while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0))
{
QByteArray::iterator part1begin;

2
plugins/feature/map/map.cpp

@ -43,7 +43,7 @@ const char* const Map::m_featureId = "Map"; @@ -43,7 +43,7 @@ const char* const Map::m_featureId = "Map";
Map::Map(WebAPIAdapterInterface *webAPIAdapterInterface) :
Feature(m_featureIdURI, webAPIAdapterInterface),
m_availableChannelOrFeatureHandler(MapSettings::m_pipeURIs, QStringList{"mapitems"}),
m_availableChannelOrFeatureHandler(MapSettings::m_pipeURIs, QStringList{"mapitems"}, "RTMF", this),
m_multiplier(0.0)
{
qDebug("Map::Map: webAPIAdapterInterface: %p", webAPIAdapterInterface);

3
plugins/feature/morsedecoder/morsedecoder.cpp

@ -388,7 +388,7 @@ void MorseDecoder::setChannel(ChannelAPI *selectedChannel) @@ -388,7 +388,7 @@ void MorseDecoder::setChannel(ChannelAPI *selectedChannel)
if (m_selectedChannel)
{
ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod");
DataFifo *fifo = qobject_cast<DataFifo*>(pipe->m_element);
DataFifo *fifo = pipe ? qobject_cast<DataFifo*>(pipe->m_element) : nullptr;
if ((fifo) && m_running)
{
@ -703,6 +703,7 @@ void MorseDecoder::handleDataPipeToBeDeleted(int reason, QObject *object) @@ -703,6 +703,7 @@ void MorseDecoder::handleDataPipeToBeDeleted(int reason, QObject *object)
}
m_selectedChannel = nullptr;
m_dataPipe = nullptr; // The pipe and its FIFO are freed by the pipes GC.
}
}

5
plugins/feature/morsedecoder/morsedecoderworker.cpp

@ -303,6 +303,7 @@ bool MorseDecoderWorker::handleMessage(const Message& cmd) @@ -303,6 +303,7 @@ bool MorseDecoderWorker::handleMessage(const Message& cmd)
this,
&MorseDecoderWorker::handleData
);
m_dataFifo = nullptr; // It is freed by the pipes GC after being unregistered.
}
return true;
@ -366,6 +367,10 @@ void MorseDecoderWorker::handleData() @@ -366,6 +367,10 @@ void MorseDecoderWorker::handleData()
{
QMutexLocker mutexLocker(&m_mutex);
if (!m_dataFifo) {
return; // A queued dataReady can arrive after the FIFO was disconnected.
}
while ((m_dataFifo->fill() > 0) && (m_inputMessageQueue.size() == 0))
{
QByteArray::iterator part1begin;

2
plugins/feature/radiosonde/radiosonde.cpp

@ -40,7 +40,7 @@ const char* const Radiosonde::m_featureId = "Radiosonde"; @@ -40,7 +40,7 @@ const char* const Radiosonde::m_featureId = "Radiosonde";
Radiosonde::Radiosonde(WebAPIAdapterInterface *webAPIAdapterInterface) :
Feature(m_featureIdURI, webAPIAdapterInterface),
m_availableChannelHandler({"sdrangel.channel.radiosondedemod"}, QStringList{"radiosonde"})
m_availableChannelHandler({"sdrangel.channel.radiosondedemod"}, QStringList{"radiosonde"}, "RTMF", this)
{
qDebug("Radiosonde::Radiosonde: webAPIAdapterInterface: %p", webAPIAdapterInterface);
setObjectName(m_featureId);

2
plugins/feature/skymap/skymapgui.cpp

@ -201,7 +201,7 @@ SkyMapGUI::SkyMapGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature * @@ -201,7 +201,7 @@ SkyMapGUI::SkyMapGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *
m_featureUISet(featureUISet),
m_doApplySettings(true),
m_source(nullptr),
m_availableChannelOrFeatureHandler(SkyMapSettings::m_pipeURIs, {"target", "skymap.target"}),
m_availableChannelOrFeatureHandler(SkyMapSettings::m_pipeURIs, {"target", "skymap.target"}, "RTMF", this),
m_ready(false)
{
m_feature = feature;

4
plugins/feature/startracker/startracker.cpp

@ -49,8 +49,8 @@ StarTracker::StarTracker(WebAPIAdapterInterface *webAPIAdapterInterface) : @@ -49,8 +49,8 @@ StarTracker::StarTracker(WebAPIAdapterInterface *webAPIAdapterInterface) :
Feature(m_featureIdURI, webAPIAdapterInterface),
m_thread(nullptr),
m_worker(nullptr),
m_availableChannelHandler({"sdrangel.channel.radioastronomy"}, QStringList{"startracker.display"}),
m_availableFeatureHandler({"sdrangel.feature.satellitetracker", "sdrangel.feature.skymap"})
m_availableChannelHandler({"sdrangel.channel.radioastronomy"}, QStringList{"startracker.display"}, "RTMF", this),
m_availableFeatureHandler({"sdrangel.feature.satellitetracker", "sdrangel.feature.skymap"}, "RTMF", this)
{
qDebug("StarTracker::StarTracker: webAPIAdapterInterface: %p", webAPIAdapterInterface);
setObjectName(m_featureId);

6
sdrbase/availablechannelorfeaturehandler.h

@ -33,7 +33,8 @@ class SDRBASE_API AvailableChannelOrFeatureHandler : public QObject @@ -33,7 +33,8 @@ class SDRBASE_API AvailableChannelOrFeatureHandler : public QObject
public:
// Use this constructor to just keep track of available channels and features with specified URIs and kinds
AvailableChannelOrFeatureHandler(QStringList uris, const QString& kinds = "RTMF") :
AvailableChannelOrFeatureHandler(QStringList uris, const QString& kinds = "RTMF", QObject *parent = nullptr) :
QObject(parent),
m_uris(uris),
m_kinds(kinds)
{
@ -41,7 +42,8 @@ public: @@ -41,7 +42,8 @@ public:
}
// Use this constructor to keep track of available channels and features with specified URIs and kinds and register pipes with the given names to them
AvailableChannelOrFeatureHandler(QStringList uris, QStringList pipeNames, const QString& kinds = "RTMF") :
AvailableChannelOrFeatureHandler(QStringList uris, QStringList pipeNames, const QString& kinds = "RTMF", QObject* parent = nullptr) :
QObject(parent),
m_uris(uris),
m_pipeNames(pipeNames),
m_kinds(kinds)

5
sdrbase/pipes/datapipes.cpp

@ -52,6 +52,11 @@ void DataPipes::getDataPipes(const QObject *producer, const QString& type, QList @@ -52,6 +52,11 @@ void DataPipes::getDataPipes(const QObject *producer, const QString& type, QList
return m_registrations.getPipes(producer, type, pipes);
}
QList<ObjectPipesRegistrations::Connection> DataPipes::getConnections()
{
return m_registrations.getConnections();
}
void DataPipes::startGC()
{
qDebug("DataPipes::startGC");

1
sdrbase/pipes/datapipes.h

@ -42,6 +42,7 @@ public: @@ -42,6 +42,7 @@ public:
ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
void getDataPipes(const QObject *producer, const QString& type, QList<ObjectPipe*>& pipes);
QList<ObjectPipesRegistrations::Connection> getConnections();
private:
DataFifoStore m_dataFifoStore;

5
sdrbase/pipes/messagepipes.cpp

@ -52,6 +52,11 @@ void MessagePipes::getMessagePipes(const QObject *producer, const QString& type, @@ -52,6 +52,11 @@ void MessagePipes::getMessagePipes(const QObject *producer, const QString& type,
return m_registrations.getPipes(producer, type, pipes);
}
QList<ObjectPipesRegistrations::Connection> MessagePipes::getConnections()
{
return m_registrations.getConnections();
}
void MessagePipes::startGC()
{
qDebug("MessagePipes::startGC");

1
sdrbase/pipes/messagepipes.h

@ -42,6 +42,7 @@ public: @@ -42,6 +42,7 @@ public:
ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
void getMessagePipes(const QObject *producer, const QString& type, QList<ObjectPipe*>& pipes);
QList<ObjectPipesRegistrations::Connection> getConnections();
private:
MessageQueueStore m_messageQueueStore;

3
sdrbase/pipes/objectpipe.cpp

@ -47,9 +47,8 @@ int ObjectPipe::getGCCount() const { @@ -47,9 +47,8 @@ int ObjectPipe::getGCCount() const {
int ObjectPipe::decreaseGCCount()
{
if (m_gcCount > 0) {
return m_gcCount--;
return --m_gcCount;
} else {
return m_gcCount;
}
}

28
sdrbase/pipes/objectpipesregistrations.cpp

@ -71,6 +71,10 @@ ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject * @@ -71,6 +71,10 @@ ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject *
if (!m_pipeMap.contains(std::make_tuple(producer, consumer, typeId))) {
m_pipeMap[std::make_tuple(producer, consumer, typeId)] = pipe;
}
// A pipe revived before GC may now belong to a new object at the old
// address, so make sure that object's destruction is also tracked.
connect(producer, SIGNAL(destroyed(QObject*)), this, SLOT(removeProducer(QObject*)), Qt::UniqueConnection);
connect(consumer, SIGNAL(destroyed(QObject*)), this, SLOT(removeConsumer(QObject*)), Qt::UniqueConnection);
return pipe;
}
}
@ -91,14 +95,15 @@ ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject * @@ -91,14 +95,15 @@ ObjectPipe *ObjectPipesRegistrations::registerProducerToConsumer(const QObject *
m_producerAndTypeIdPipes[std::make_tuple(producer, typeId)].push_back(m_pipes.back());
m_pipeMap[std::make_tuple(producer, consumer, typeId)] = m_pipes.back();
connect(producer, SIGNAL(destroyed(QObject*)), this, SLOT(removeProducer(QObject*)));
connect(consumer, SIGNAL(destroyed(QObject*)), this, SLOT(removeConsumer(QObject*)));
connect(producer, SIGNAL(destroyed(QObject*)), this, SLOT(removeProducer(QObject*)), Qt::UniqueConnection);
connect(consumer, SIGNAL(destroyed(QObject*)), this, SLOT(removeConsumer(QObject*)), Qt::UniqueConnection);
return m_pipes.back();
}
ObjectPipe *ObjectPipesRegistrations::unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type)
{
QMutexLocker mlock(&m_mutex);
ObjectPipe *pipe = nullptr;
if (m_typeIds.contains(type))
@ -159,6 +164,18 @@ void ObjectPipesRegistrations::getPipes(const QObject *producer, const QString& @@ -159,6 +164,18 @@ void ObjectPipesRegistrations::getPipes(const QObject *producer, const QString&
}
}
QList<ObjectPipesRegistrations::Connection> ObjectPipesRegistrations::getConnections()
{
QMutexLocker lock(&m_mutex);
QList<Connection> connections;
for (const ObjectPipe *pipe : m_pipes) {
if (pipe->getGCCount() == 0) {
connections.append({pipe->m_producer, pipe->m_consumer, m_types.value(pipe->m_typeId)});
}
}
return connections;
}
void ObjectPipesRegistrations::processGC()
{
QMutexLocker mlock(&m_mutex);
@ -171,6 +188,11 @@ void ObjectPipesRegistrations::processGC() @@ -171,6 +188,11 @@ void ObjectPipesRegistrations::processGC()
{
if ((*itPipe)->decreaseGCCount() == 0) // delete on this pass
{
const auto key = std::make_tuple((*itPipe)->m_producer, (*itPipe)->m_consumer,
(*itPipe)->m_typeId);
if (m_pipeMap.value(key, nullptr) == *itPipe) {
m_pipeMap.remove(key);
}
m_objectPipeElementsStore->deleteElement((*itPipe)->m_element);
delete *itPipe;
itPipe = m_pipes.erase(itPipe);
@ -216,7 +238,7 @@ void ObjectPipesRegistrations::removeProducer(QObject *producer) @@ -216,7 +238,7 @@ void ObjectPipesRegistrations::removeProducer(QObject *producer)
while (itP != m_pipeMap.end())
{
if (std::get<0>(itP.key())) {
if (std::get<0>(itP.key()) == producer) {
itP = m_pipeMap.erase(itP);
} else {
++itP;

6
sdrbase/pipes/objectpipesregistrations.h

@ -37,6 +37,11 @@ class SDRBASE_API ObjectPipesRegistrations : public QObject @@ -37,6 +37,11 @@ class SDRBASE_API ObjectPipesRegistrations : public QObject
{
Q_OBJECT
public:
struct Connection {
const QObject *producer;
const QObject *consumer;
QString type;
};
enum PipeDeletionReason
{
PipeProducerDeleted,
@ -50,6 +55,7 @@ public: @@ -50,6 +55,7 @@ public:
ObjectPipe *registerProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
ObjectPipe *unregisterProducerToConsumer(const QObject *producer, const QObject *consumer, const QString& type);
void getPipes(const QObject *producer, const QString& type, QList<ObjectPipe*>& pipes);
QList<Connection> getConnections();
void processGC();
private slots:

2
sdrgui/CMakeLists.txt

@ -104,6 +104,7 @@ set(sdrgui_SOURCES @@ -104,6 +104,7 @@ set(sdrgui_SOURCES
gui/valuedialz.cpp
gui/welcomedialog.cpp
gui/workspace.cpp
gui/connectionoverlay.cpp
gui/workspaceselectiondialog.cpp
gui/workspacewindow.cpp
gui/wsspectrumsettingsdialog.cpp
@ -243,6 +244,7 @@ set(sdrgui_HEADERS @@ -243,6 +244,7 @@ set(sdrgui_HEADERS
gui/workspace.h
gui/workspaceselectiondialog.h
gui/workspacewindow.h
gui/connectionoverlay.h
gui/wsspectrumsettingsdialog.h
gui/wrappingdatetimeedit.h
gui/wrappingdial.h

2
sdrgui/channel/channelgui.cpp

@ -58,6 +58,7 @@ ChannelGUI::ChannelGUI(QWidget *parent) : @@ -58,6 +58,7 @@ ChannelGUI::ChannelGUI(QWidget *parent) :
.arg(palette().dark().color().darker(115).name())));
m_indexLabel = new QLabel();
m_indexLabel->setObjectName("connectionIndexLabel");
m_indexLabel->setFixedSize(50, 16);
m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }");
m_indexLabel->setText(tr("X%1:%2").arg(m_deviceSetIndex).arg(m_channelIndex));
@ -464,6 +465,7 @@ void ChannelGUI::setTitle(const QString& title) @@ -464,6 +465,7 @@ void ChannelGUI::setTitle(const QString& title)
void ChannelGUI::setTitleColor(const QColor& c)
{
m_indexLabelColor = c;
m_indexLabel->setStyleSheet(tr("QLabel { background-color: %1; color: %2; }")
.arg(c.name())
.arg(getTitleColor(c).name())

3
sdrgui/channel/channelgui.h

@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
#define SDRGUI_CHANNEL_CHANNELGUI_H_
#include <QMdiSubWindow>
#include <QColor>
#include <QMap>
#include "gui/qtcompatibility.h"
@ -80,6 +81,7 @@ public: @@ -80,6 +81,7 @@ public:
void sizeToContents();
void setTitle(const QString& title);
void setTitleColor(const QColor& c);
QColor getIndexLabelColor() const { return m_indexLabelColor; }
void setDeviceType(DeviceType type);
void setDisplayedame(const QString& name);
DeviceType getDeviceType() const { return m_deviceType; }
@ -120,6 +122,7 @@ private: @@ -120,6 +122,7 @@ private:
DeviceType m_deviceType;
int m_deviceSetIndex;
int m_channelIndex;
QColor m_indexLabelColor = QColor(128, 128, 128);
RollupContents* m_rollupContents;
QLabel *m_indexLabel;

13
sdrgui/device/devicegui.cpp

@ -55,6 +55,7 @@ DeviceGUI::DeviceGUI(QWidget *parent) : @@ -55,6 +55,7 @@ DeviceGUI::DeviceGUI(QWidget *parent) :
.arg(palette().dark().color().darker(115).name()));
m_indexLabel = new QLabel();
m_indexLabel->setObjectName("connectionIndexLabel");
m_indexLabel->setFixedSize(32, 16);
m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }");
m_indexLabel->setText(tr("X:%1").arg(m_deviceSetIndex));
@ -448,7 +449,7 @@ void DeviceGUI::setIndex(int index) @@ -448,7 +449,7 @@ void DeviceGUI::setIndex(int index)
void DeviceGUI::setDeviceType(DeviceType type)
{
m_deviceType = type;
m_indexLabel->setStyleSheet(tr("QLabel { background-color: %1; qproperty-alignment: AlignCenter; }").arg(getDeviceTypeColor()));
m_indexLabel->setStyleSheet(tr("QLabel { background-color: %1; qproperty-alignment: AlignCenter; }").arg(getDeviceTypeColor().name()));
}
void DeviceGUI::setToolTip(const QString& tooltip)
@ -456,18 +457,18 @@ void DeviceGUI::setToolTip(const QString& tooltip) @@ -456,18 +457,18 @@ void DeviceGUI::setToolTip(const QString& tooltip)
m_titleLabel->setToolTip(tooltip);
}
QString DeviceGUI::getDeviceTypeColor()
QColor DeviceGUI::getDeviceTypeColor() const
{
switch(m_deviceType)
{
case DeviceRx:
return "rgb(0, 128, 0)";
return QColor(0, 128, 0);
case DeviceTx:
return "rgb(204, 0, 0)";
return QColor(204, 0, 0);
case DeviceMIMO:
return "rgb(0, 0, 192)";
return QColor(0, 0, 192);
default:
return "rgb(128, 128, 128)";
return QColor(128, 128, 128);
}
}

3
sdrgui/device/devicegui.h

@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
#include <QtGlobal>
#include <QString>
#include <QColor>
#include <QByteArray>
#include <QWidget>
#include <QLabel>
@ -73,6 +74,7 @@ public: @@ -73,6 +74,7 @@ public:
void sizeToContents();
void setDeviceType(DeviceType type);
DeviceType getDeviceType() const { return m_deviceType; }
QColor getDeviceTypeColor() const;
void setTitle(const QString& title);
QString getTitle() const override;
void setDefaultTitle(const QString& title) { m_defaultTitle = title; }
@ -111,7 +113,6 @@ protected slots: @@ -111,7 +113,6 @@ protected slots:
private:
bool isOnMovingPad();
QString getDeviceTypeColor();
QString getDeviceTypeTag();
QLabel *m_indexLabel;

5
sdrgui/device/deviceuiset.cpp

@ -205,6 +205,11 @@ ChannelGUI *DeviceUISet::getChannelGUIAt(int channelIndex) @@ -205,6 +205,11 @@ ChannelGUI *DeviceUISet::getChannelGUIAt(int channelIndex)
return m_channelInstanceRegistrations[channelIndex].m_gui;
}
int DeviceUISet::getChannelTypeAt(int channelIndex) const
{
return m_channelInstanceRegistrations[channelIndex].m_channelType;
}
// Serialization is only used for Device and Spectrum settings in a Device preset
// To include channels, use a Device Set preset via loadDeviceSetSettings/saveDeviceSetSettings

1
sdrgui/device/deviceuiset.h

@ -86,6 +86,7 @@ public: @@ -86,6 +86,7 @@ public:
void deleteChannel(int channelIndex);
ChannelAPI *getChannelAt(int channelIndex);
ChannelGUI *getChannelGUIAt(int channelIndex);
int getChannelTypeAt(int channelIndex) const; // 0: Rx, 1: Tx, 2: MIMO
QByteArray serialize() const override;
bool deserialize(const QByteArray& data) override;

1
sdrgui/feature/featuregui.cpp

@ -56,6 +56,7 @@ FeatureGUI::FeatureGUI(QWidget *parent) : @@ -56,6 +56,7 @@ FeatureGUI::FeatureGUI(QWidget *parent) :
.arg(palette().dark().color().darker(115).name()));
m_indexLabel = new QLabel();
m_indexLabel->setObjectName("connectionIndexLabel");
m_indexLabel->setFixedSize(40, 16);
m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }");
m_indexLabel->setText(tr("F:%1").arg(m_featureIndex));

818
sdrgui/gui/connectionoverlay.cpp

@ -0,0 +1,818 @@ @@ -0,0 +1,818 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// Some code by AI //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "connectionoverlay.h"
#include <QEvent>
#include <QHash>
#include <QPair>
#include <QLineF>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QPainter>
#include <QPainterPath>
#include <QPainterPathStroker>
#include <QPaintEvent>
#include <QRegion>
#include <QVector>
#include <QtMath>
ConnectionOverlay::ConnectionOverlay(QMdiArea *mdi) :
QWidget(mdi),
m_mdi(mdi)
{
// QMdiArea scrolls its viewport children; keep the overlay fixed above the viewport.
setAttribute(Qt::WA_TransparentForMouseEvents);
setAttribute(Qt::WA_TranslucentBackground);
setGeometry(mdi->viewport()->geometry());
mdi->viewport()->installEventFilter(this);
m_animationTimer.setInterval(33);
connect(&m_animationTimer, &QTimer::timeout, this, &ConnectionOverlay::animate);
m_clock.start();
hide();
}
bool ConnectionOverlay::sameConnections(const QList<Connection>& a, const QList<Connection>& b)
{
if (a.size() != b.size()) {
return false;
}
for (int i = 0; i < a.size(); ++i)
{
const Connection& x = a[i];
const Connection& y = b[i];
if (x.source.data() != y.source.data() || x.target.data() != y.target.data() ||
x.sourceLabel != y.sourceLabel || x.targetLabel != y.targetLabel ||
x.flowLabel != y.flowLabel || x.sourceWorkspace != y.sourceWorkspace ||
x.targetWorkspace != y.targetWorkspace || x.kind != y.kind ||
x.direction != y.direction || x.color != y.color) {
return false;
}
}
return true;
}
void ConnectionOverlay::setConnections(const QList<Connection>& connections)
{
// Connections are refreshed periodically; only relayout when something changed.
if (sameConnections(connections, m_connections)) {
return;
}
m_connections = connections;
m_indexLabels.clear();
// Cache each title ID widget so paths can anchor beside it and avoid painting over it.
for (const Connection& connection : m_connections)
{
for (QMdiSubWindow *window : {connection.source.data(), connection.target.data()})
{
if (window && !m_indexLabels.contains(window)) {
m_indexLabels.insert(window, window->findChild<QWidget*>("connectionIndexLabel"));
}
}
}
watchWindows();
invalidateLayout();
}
void ConnectionOverlay::watchWindows()
{
// Cached routes depend on the connected windows' geometry and their ID labels.
for (const QPointer<QObject>& object : m_watched)
{
if (object) {
object->removeEventFilter(this);
}
}
m_watched.clear();
for (auto it = m_indexLabels.constBegin(); it != m_indexLabels.constEnd(); ++it)
{
for (QObject *object : {static_cast<QObject*>(it.key()), static_cast<QObject*>(it.value().data())})
{
if (object)
{
object->installEventFilter(this);
m_watched.append(object);
}
}
}
}
void ConnectionOverlay::setOverlayVisible(bool visible)
{
setVisible(visible);
if (visible)
{
setGeometry(m_mdi->viewport()->geometry());
raise();
m_layoutDirty = true;
relayout();
m_animationTimer.start();
}
else
{
m_animationTimer.stop();
m_pulseRegion = QRegion();
}
}
bool ConnectionOverlay::eventFilter(QObject *object, QEvent *event)
{
const QEvent::Type type = event->type();
if (object == m_mdi->viewport())
{
if (type == QEvent::Resize || type == QEvent::Move || type == QEvent::Show)
{
setGeometry(m_mdi->viewport()->geometry());
if (isVisible()) {
raise();
}
invalidateLayout();
}
else if (type == QEvent::ChildAdded || type == QEvent::ChildRemoved)
{
invalidateLayout(); // A window joined or left this workspace.
}
}
else if (type == QEvent::Move || type == QEvent::Resize || type == QEvent::Show ||
type == QEvent::Hide || type == QEvent::WindowStateChange || type == QEvent::ParentChange)
{
invalidateLayout(); // A connected window or its ID label moved, e.g. when scrolling.
}
return QWidget::eventFilter(object, event);
}
void ConnectionOverlay::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange || event->type() == QEvent::PaletteChange) {
invalidateLayout();
}
QWidget::changeEvent(event);
}
void ConnectionOverlay::invalidateLayout()
{
// Remember the cache is stale even while hidden (e.g. in a background dock tab),
// so showEvent() can relayout. Coalesce bursts (e.g. scrolling) into one relayout.
m_layoutDirty = true;
if (!isVisible() || m_relayoutPending) {
return;
}
m_relayoutPending = true;
QMetaObject::invokeMethod(this, [this]() { relayout(); }, Qt::QueuedConnection);
}
void ConnectionOverlay::relayout()
{
m_relayoutPending = false;
if (!isVisible() || !m_layoutDirty) {
return;
}
computeLayout();
update();
}
void ConnectionOverlay::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
// Changes while hidden were not laid out. The viewport's own Show event arrives
// before this widget is visible, so it cannot trigger the relayout itself.
if (m_layoutDirty)
{
computeLayout();
update();
}
}
static QPointF viewportEdge(const QRectF& bounds, const QPointF& outside)
{
return QPointF(qBound(bounds.left(), outside.x(), bounds.right()),
qBound(bounds.top(), outside.y(), bounds.bottom()));
}
static QString scrollArrow(const QRectF& bounds, const QPointF& outside)
{
if (outside.y() < bounds.top()) {
return QString::fromUtf8("↑");
}
if (outside.y() > bounds.bottom()) {
return QString::fromUtf8("↓");
}
if (outside.x() < bounds.left()) {
return QString::fromUtf8("←");
}
return QString::fromUtf8("→");
}
static QPainterPath roundedRoute(const QVector<QPointF>& points)
{
QPainterPath path(points.first());
for (int i = 1; i + 1 < points.size(); ++i)
{
const QPointF incoming = points[i] - points[i - 1];
const QPointF outgoing = points[i + 1] - points[i];
const qreal incomingLength = QLineF(points[i - 1], points[i]).length();
const qreal outgoingLength = QLineF(points[i], points[i + 1]).length();
if (incomingLength < 1 || outgoingLength < 1 ||
qAbs(incoming.x() * outgoing.y() - incoming.y() * outgoing.x()) < 0.01)
{
path.lineTo(points[i]);
continue;
}
const qreal radius = qMin<qreal>(18, qMin(incomingLength, outgoingLength) / 2);
path.lineTo(points[i] - incoming * (radius / incomingLength));
path.quadTo(points[i], points[i] + outgoing * (radius / outgoingLength));
}
path.lineTo(points.last());
return path;
}
static int crossingCost(const QPainterPath& path, const QRectF& sourceBox, const QRectF& targetBox)
{
// Count samples drawn over a window body. An endpoint can be inside a window,
// e.g. the source's own title bar, or an ID label covered by an overlapping
// window. The route may then leave that window at the start, or arrive in it
// at the end, but any other part inside a window is a crossing.
constexpr int samples = 80;
QPointF points[samples + 1];
for (int i = 0; i <= samples; ++i) {
points[i] = path.pointAtPercent(qreal(i) / samples);
}
int cost = 0;
for (const QRectF& box : {sourceBox, targetBox})
{
if (box.isEmpty()) {
continue;
}
const QRectF body = box.adjusted(-2, -2, 2, 2);
int first = 0;
while (first <= samples && body.contains(points[first])) {
++first; // Leading run inside, leaving the start window
}
int last = samples;
while (last >= first && body.contains(points[last])) {
--last; // Trailing run inside, arriving in the end window
}
for (int i = first; i <= last; ++i)
{
if (body.contains(points[i])) {
++cost;
}
}
}
return cost;
}
static QPainterPath connectionPath(const QPointF& from, const QPointF& to,
int fromSide, int toSide, const QRectF& sourceBox,
const QRectF& targetBox, const QRectF& bounds)
{
constexpr qreal labelLead = 14;
const QPointF curveFrom = from + QPointF(fromSide * labelLead, 0);
const QPointF curveTo = to + QPointF(toSide * labelLead, 0);
const QPointF delta = curveTo - curveFrom;
const qreal handle = qBound<qreal>(32, qAbs(delta.x()) * 0.35 + qAbs(delta.y()) * 0.3, 180);
const QPointF firstControl = fromSide == 0 ? curveFrom + delta * 0.3 :
curveFrom + QPointF(fromSide * handle, 0);
const QPointF lastControl = toSide == 0 ? curveTo - delta * 0.3 :
curveTo + QPointF(toSide * handle, 0);
QPainterPath direct(from);
if (fromSide != 0) {
direct.lineTo(curveFrom);
}
direct.cubicTo(firstControl, lastControl, curveTo);
if (toSide != 0) {
direct.lineTo(to);
}
if (sourceBox.isEmpty() || targetBox.isEmpty()) {
return direct;
}
// Prefer the route that crosses windows least, then the shortest. Crossing can
// be unavoidable (e.g. an endpoint covered by the other window), and then the
// direct route is usually clearer than a long detour around both windows.
QPainterPath bestRoute = direct;
int bestCost = crossingCost(direct, sourceBox, targetBox);
qreal bestLength = direct.length();
if (bestCost == 0) {
return direct;
}
auto consider = [&](const QPainterPath& candidate) {
const qreal length = candidate.length();
if (bestCost == 0 && length >= bestLength) {
return; // Cannot beat a shorter clear route
}
const int cost = crossingCost(candidate, sourceBox, targetBox);
if (cost < bestCost || (cost == bestCost && length < bestLength))
{
bestRoute = candidate;
bestCost = cost;
bestLength = length;
}
};
// Try an outer route around both windows, and nearer horizontal lanes.
constexpr qreal clearance = 24;
const bool separatedBelow = sourceBox.bottom() + 2 * clearance < targetBox.top();
const bool separatedAbove = targetBox.bottom() + 2 * clearance < sourceBox.top();
const qreal laneY = separatedBelow ? (sourceBox.bottom() + targetBox.top()) / 2 :
(separatedAbove ? (targetBox.bottom() + sourceBox.top()) / 2 :
qMax(sourceBox.bottom(), targetBox.bottom()) + clearance);
const qreal rightX = qMax(sourceBox.right(),
separatedBelow || separatedAbove ? sourceBox.right() : targetBox.right()) + clearance;
const qreal leftX = qMin(to.x() - 30, targetBox.left() - clearance);
QVector<QPointF> route;
route.append(from);
const qreal topY = qMin(sourceBox.top(), targetBox.top()) - clearance;
if (topY >= bounds.top() + 4)
{
route.append(QPointF(from.x() + clearance, from.y()));
route.append(QPointF(from.x() + clearance, topY));
route.append(QPointF(rightX, topY));
}
else
{
route.append(QPointF(rightX, from.y()));
}
route.append(QPointF(rightX, laneY));
route.append(QPointF(leftX, laneY));
route.append(QPointF(leftX, to.y()));
route.append(to);
consider(roundedRoute(route));
const qreal exitXs[] = {
from.x() + clearance,
qMax(from.x() + clearance, targetBox.right() + clearance),
qMax(from.x() + clearance, sourceBox.right() + clearance)
};
const qreal laneYs[] = {
topY, sourceBox.top() - clearance, targetBox.top() - clearance,
laneY, sourceBox.bottom() + clearance, targetBox.bottom() + clearance
};
for (qreal candidateY : laneYs)
{
if (candidateY < bounds.top() + 4 || candidateY > bounds.bottom() - 4 ||
qAbs(candidateY - from.y()) < 6) {
continue;
}
for (qreal exitX : exitXs)
{
// A downward exit within the source would run through its controls.
const bool insideSourceX = exitX > sourceBox.left() && exitX < sourceBox.right();
const bool throughSourceBody = insideSourceX &&
qMax(qMin(from.y(), candidateY), sourceBox.top() + 26) <
qMin(qMax(from.y(), candidateY), sourceBox.bottom());
if (throughSourceBody) {
continue;
}
consider(roundedRoute({
from,
QPointF(exitX, from.y()),
QPointF(exitX, candidateY),
QPointF(leftX, candidateY),
QPointF(leftX, to.y()),
to
}));
}
}
// A source directly below its target has no upper lane. Turn just below
// the source title and leave on the left, instead of circling both windows.
if (targetBox.bottom() <= sourceBox.top() + clearance) {
const qreal leftExitX = qMin(sourceBox.left(), targetBox.left()) - clearance;
const qreal turnY = qMax(from.y() + clearance, targetBox.bottom() + clearance);
if (leftExitX >= bounds.left() + 4 && turnY <= bounds.bottom() - 4) {
consider(roundedRoute({
from,
QPointF(from.x() + clearance, from.y()),
QPointF(from.x() + clearance, turnY),
QPointF(leftExitX, turnY),
QPointF(leftExitX, to.y()),
to
}));
}
}
return bestRoute;
}
bool ConnectionOverlay::computeLayout()
{
m_layoutDirty = false;
m_routes.clear();
const QList<QMdiSubWindow*> localWindows = m_mdi->subWindowList();
const QRectF bounds = rect().adjusted(8, 8, -8, -8);
const QPoint viewportOffset = m_mdi->viewport()->pos() - pos();
const QFontMetrics metrics(font());
m_clipRegion = QRegion(rect());
QRegion paintedRegion;
QVector<QRectF> labelObstacles; // Title ID labels, then each label as it is placed
// Stubs to other workspaces that leave the same anchor fan out vertically, so
// their lines and labels do not sit on top of each other.
QHash<QPair<QMdiSubWindow*, int>, int> stubCounts;
const qreal stubSpacing = metrics.height() + 14;
auto fanOffset = [&](QMdiSubWindow *window, int side) -> qreal {
const int n = stubCounts[qMakePair(window, side)]++;
const int step = (n + 1) / 2; // 0, 1, 1, 2, 2, ...
return (n % 2 ? step : -step) * stubSpacing; // 0, +1, -1, +2, -2, ...
};
QPainterPathStroker maskStroker;
maskStroker.setWidth(20);
maskStroker.setCapStyle(Qt::RoundCap);
maskStroker.setJoinStyle(Qt::RoundJoin);
for (auto it = m_indexLabels.constBegin(); it != m_indexLabels.constEnd(); ++it)
{
QMdiSubWindow *window = it.key();
QWidget *indexLabel = it.value().data();
if (!window || !localWindows.contains(window) || !indexLabel || !indexLabel->isVisible()) {
continue;
}
const QPoint labelTopLeft = window->geometry().topLeft() +
indexLabel->mapTo(window, QPoint(0, 0)) + viewportOffset;
const QRect indexRect = QRect(labelTopLeft, indexLabel->size()).adjusted(-2, -2, 2, 2);
m_clipRegion -= indexRect;
labelObstacles.append(indexRect);
}
// The overlay is a sibling of the scrolling viewport, so translate MDI
// window coordinates before using their title labels as endpoints.
auto anchorFor = [this, &viewportOffset](QMdiSubWindow *window, int side) -> QPointF {
QWidget *indexLabel = m_indexLabels.value(window).data();
const QPoint insideWindow = indexLabel && indexLabel->isVisible() ?
indexLabel->mapTo(window, QPoint(side < 0 ? -10 : indexLabel->width() + 10,
indexLabel->height() / 2)) :
QPoint(side < 0 ? -10 : 48, 12);
return QPointF(window->geometry().topLeft() + insideWindow + viewportOffset);
};
for (const Connection& connection : m_connections)
{
if (!connection.source || !connection.target) {
continue;
}
const bool sourceLocal = localWindows.contains(connection.source.data());
const bool targetLocal = localWindows.contains(connection.target.data());
if (!sourceLocal && !targetLocal) {
continue;
}
if (sourceLocal && (connection.source->parentWidget() != m_mdi->viewport() ||
!connection.source->isVisible() || connection.source->isMinimized())) {
continue;
}
if (targetLocal && (connection.target->parentWidget() != m_mdi->viewport() ||
!connection.target->isVisible() || connection.target->isMinimized())) {
continue;
}
const int sourceSide = 1; // Device ID, or the producer of a pipe.
const int targetSide = -1; // Inputs meet the left side of channel, spectrum, and feature IDs.
const QPointF sourceAnchor = sourceLocal ? anchorFor(connection.source.data(), sourceSide) : QPointF();
const QPointF targetAnchor = targetLocal ? anchorFor(connection.target.data(), targetSide) : QPointF();
const bool sourceVisible = sourceLocal && bounds.contains(sourceAnchor);
const bool targetVisible = targetLocal && bounds.contains(targetAnchor);
// This workspace draws a link only when at least one endpoint is on screen.
if (!sourceVisible && !targetVisible) {
continue;
}
Route route;
QPointF markerEdge;
bool crossWorkspace = false;
int stubDirection = 0; // Which way a cross-workspace stub goes from its window
// Scrolled endpoints point to a viewport edge. An endpoint in another
// workspace instead gets a short labeled stub beside the local window.
if (sourceVisible && targetVisible)
{
route.from = sourceAnchor;
route.to = targetAnchor;
}
else if (sourceVisible && targetLocal)
{
route.from = sourceAnchor;
route.to = viewportEdge(bounds, targetAnchor);
markerEdge = route.to;
route.marker = scrollArrow(bounds, targetAnchor) + " " + connection.targetLabel;
}
else if (targetVisible && sourceLocal)
{
route.from = viewportEdge(bounds, sourceAnchor);
route.to = targetAnchor;
markerEdge = route.from;
route.marker = scrollArrow(bounds, sourceAnchor) + " " + connection.sourceLabel;
}
else if (sourceVisible)
{
route.from = sourceAnchor;
route.marker = QString("W%1 · %2").arg(connection.targetWorkspace).arg(connection.targetLabel);
if (!connection.flowLabel.isEmpty()) {
route.marker += " · " + connection.flowLabel; // One label per stub, at its tip
}
const qreal markerWidth = metrics.horizontalAdvance(route.marker) + 8;
const qreal stubLength = 90;
const qreal stubY = qBound(bounds.top() + 4, route.from.y() + fanOffset(connection.source.data(), sourceSide),
bounds.bottom() - 4);
// Stubs leave to the right. Near the right edge there is no room for the
// stub and its label, so go left instead, past the window's ID label.
stubDirection = route.from.x() + stubLength + markerWidth + 10 <= bounds.right() ? 1 : -1;
const qreal tipX = stubDirection > 0 ? route.from.x() + stubLength :
qMax(bounds.left() + markerWidth + 10, route.from.x() - stubLength - 60);
route.to = QPointF(tipX, stubY);
route.stubTip = 1;
crossWorkspace = true;
}
else
{
route.to = targetAnchor;
route.marker = QString("W%1 · %2").arg(connection.sourceWorkspace).arg(connection.sourceLabel);
if (!connection.flowLabel.isEmpty()) {
route.marker += " · " + connection.flowLabel; // One label per stub, at its tip
}
const qreal markerWidth = metrics.horizontalAdvance(route.marker) + 8;
const qreal stubLength = 90;
// Stubs arrive from the left. Near the left edge there is no room for the
// stub and its label, so come from the right instead, past the ID label.
stubDirection = route.to.x() - stubLength - markerWidth - 10 >= bounds.left() ? -1 : 1;
const qreal tipX = stubDirection < 0 ? route.to.x() - stubLength :
qMin(bounds.right() - markerWidth - 10, route.to.x() + stubLength + 60);
const qreal stubY = qBound(bounds.top() + 4, route.to.y() + fanOffset(connection.target.data(), targetSide),
bounds.bottom() - 4);
route.from = QPointF(tipX, stubY);
route.stubTip = -1;
crossWorkspace = true;
}
const QPointF& from = route.from;
const QPointF& to = route.to;
route.color = connection.color.isValid() ? connection.color.lighter(150) :
(connection.kind == PipeLink ? QColor(238, 183, 77) : QColor(56, 204, 228));
route.kind = connection.kind;
route.direction = connection.direction;
route.sourceBox = sourceVisible ?
QRectF(connection.source->geometry().translated(viewportOffset)) : QRectF();
route.targetBox = targetVisible ?
QRectF(connection.target->geometry().translated(viewportOffset)) : QRectF();
// A stub flipped to the other side goes straight out, behind its ID label.
route.fromSide = sourceVisible && stubDirection >= 0 ? sourceSide : 0;
route.toSide = targetVisible && stubDirection <= 0 ? targetSide : 0;
route.path = connectionPath(from, to, route.fromSide, route.toSide,
route.sourceBox, route.targetBox, bounds);
route.length = route.path.length();
if (!connection.flowLabel.isEmpty() && !crossWorkspace) // Stubs include it in their marker
{
const qreal labelWidth = metrics.horizontalAdvance(connection.flowLabel) + 10;
const qreal labelHeight = metrics.height() + 4;
// Beside each route's own midpoint, so labels of fanned stubs separate too.
const QPointF midpoint = route.path.pointAtPercent(0.5);
const qreal labelX = midpoint.x() - labelWidth / 2;
const qreal labelY = midpoint.y() - labelHeight - 6;
route.flowLabel = connection.flowLabel;
route.flowLabelRect = QRectF(qBound(bounds.left() + 4, labelX,
qMax(bounds.left() + 4, bounds.right() - labelWidth - 4)),
qBound(bounds.top() + 4, labelY,
qMax(bounds.top() + 4, bounds.bottom() - labelHeight - 4)),
labelWidth, labelHeight);
}
if (!route.marker.isEmpty())
{
const qreal labelWidth = metrics.horizontalAdvance(route.marker) + 8;
const qreal labelHeight = metrics.height() + 4;
const QPointF remoteAnchor = sourceVisible ? to : from;
// A stub's label continues from its tip, in the direction the stub goes.
const qreal labelX = crossWorkspace ?
(stubDirection > 0 ? remoteAnchor.x() + 6 : remoteAnchor.x() - labelWidth - 6) :
(markerEdge.x() >= bounds.right() - 1 ?
markerEdge.x() - labelWidth - 8 : markerEdge.x() + 8);
const qreal labelY = crossWorkspace ?
remoteAnchor.y() - labelHeight / 2 :
(markerEdge.y() >= bounds.bottom() - 1 ?
markerEdge.y() - labelHeight - 8 : markerEdge.y() + 8);
route.markerRect = QRectF(qBound(bounds.left() + 4, labelX,
qMax(bounds.left() + 4, bounds.right() - labelWidth - 4)),
qBound(bounds.top() + 4, labelY,
qMax(bounds.top() + 4, bounds.bottom() - labelHeight - 4)),
labelWidth, labelHeight);
}
m_routes.append(route);
}
// Resolve remaining label overlaps. Place workspace and scroll markers first, as
// they sit at route ends, then flow labels. Each label moves up or down by whole
// label heights to the nearest free position inside the viewport.
auto placeLabel = [&](QRectF& label) {
if (label.isEmpty()) {
return;
}
const qreal step = label.height() + 4;
for (int attempt = 0; attempt < 16; ++attempt)
{
const int n = (attempt + 1) / 2;
const QRectF candidate = label.translated(0, (attempt % 2 ? n : -n) * step);
if (candidate.top() < bounds.top() + 4 || candidate.bottom() > bounds.bottom() - 4) {
continue;
}
bool clear = true;
for (const QRectF& obstacle : labelObstacles)
{
if (candidate.adjusted(-2, -2, 2, 2).intersects(obstacle))
{
clear = false;
break;
}
}
if (clear)
{
label = candidate;
break;
}
}
labelObstacles.append(label);
};
for (Route& route : m_routes)
{
const qreal before = route.markerRect.center().y();
placeLabel(route.markerRect);
const qreal dy = route.markerRect.center().y() - before;
if (route.stubTip != 0 && !qFuzzyIsNull(dy))
{
// Keep a moved stub label on the end of its own line.
QPointF& tip = route.stubTip > 0 ? route.to : route.from;
tip.ry() += dy;
route.path = connectionPath(route.from, route.to, route.fromSide, route.toSide,
route.sourceBox, route.targetBox, bounds);
route.length = route.path.length();
}
}
for (Route& route : m_routes) {
placeLabel(route.flowLabelRect);
}
// Only now are the routes final, so build the painted region.
for (Route& route : m_routes)
{
QRegion routeRegion(maskStroker.createStroke(route.path).toFillPolygon().toPolygon(), Qt::WindingFill);
routeRegion += QRectF(route.from.x() - 9, route.from.y() - 9, 18, 18).toAlignedRect();
routeRegion += QRectF(route.to.x() - 9, route.to.y() - 9, 18, 18).toAlignedRect();
for (const QRectF& label : {route.markerRect, route.flowLabelRect})
{
if (!label.isEmpty()) {
routeRegion += label.toAlignedRect().adjusted(-2, -2, 2, 2);
}
}
route.bounds = routeRegion.boundingRect();
paintedRegion += routeRegion;
}
paintedRegion &= m_clipRegion;
// A full-size widget above QOpenGLWidget spectra can occlude their entire
// viewport. Give the overlay only the pixels needed by its drawing.
if (paintedRegion.isEmpty()) {
paintedRegion = QRegion(0, 0, 1, 1);
}
if (mask() != paintedRegion)
{
// An empty mask means the whole widget was painted.
const QRegion oldMask = mask().isEmpty() ? QRegion(rect()) : mask();
setMask(paintedRegion);
// setMask() asks the QMdiArea to repaint what the overlay no longer covers,
// but the opaque viewport above it is not repainted, leaving trails of old
// routes. Repaint the viewport (and its sub windows) there explicitly.
const QRegion exposed = oldMask - paintedRegion;
if (!exposed.isEmpty()) {
m_mdi->viewport()->update(exposed.translated(pos() - m_mdi->viewport()->pos()));
}
return true;
}
return false;
}
QVector<ConnectionOverlay::Pulse> ConnectionOverlay::pulses() const
{
QVector<Pulse> result;
for (const Route& route : m_routes)
{
if (route.direction == NoDirection || route.length <= 32) {
continue;
}
const int flowCount = route.direction == BothDirections ? 2 : 1;
const int pulsesPerFlow = route.length > 360 ? 2 : 1;
for (int flow = 0; flow < flowCount; ++flow)
{
const bool reverse = route.direction == Reverse || (route.direction == BothDirections && flow == 1);
for (int pulse = 0; pulse < pulsesPerFlow; ++pulse)
{
qreal progress = m_phase + qreal(pulse) / pulsesPerFlow;
if (progress >= 1.0) {
progress -= 1.0;
}
if (reverse) {
progress = 1.0 - progress;
}
const qreal tailProgress = qBound<qreal>(0, progress + (reverse ? 0.025 : -0.025), 1);
result.append({route.path.pointAtPercent(tailProgress), route.path.pointAtPercent(progress), route.color});
}
}
}
return result;
}
QRegion ConnectionOverlay::pulsesRegion(const QVector<Pulse>& pulses) const
{
QRegion region;
for (const Pulse& pulse : pulses) {
region += QRectF(pulse.tail, pulse.head).normalized().adjusted(-9, -9, 9, 9).toAlignedRect();
}
return region;
}
void ConnectionOverlay::animate()
{
if (!isVisible()) {
return; // Workspace is a background tab, or minimized.
}
// Only the pulses move, so repaint just where they were and where they are now.
m_phase = (m_clock.elapsed() % 2400) / 2400.0;
const QRegion region = pulsesRegion(pulses());
const QRegion dirty = m_pulseRegion | region;
m_pulseRegion = region;
if (!dirty.isEmpty()) {
update(dirty);
}
}
void ConnectionOverlay::paintEvent(QPaintEvent *event)
{
// Paint current geometry rather than a stale cache. This paint is clipped to the
// old mask, so repaint again only if the mask changed.
if (m_layoutDirty && computeLayout()) {
update();
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setClipRegion(m_clipRegion & event->region());
const QRegion& dirty = event->region();
for (const Route& route : m_routes)
{
if (!dirty.intersects(route.bounds)) {
continue;
}
const QColor& color = route.color;
// drawPath also fills with the current brush. The preceding edge draws
// its endpoint dots with a solid brush, so clear it before every path.
painter.setBrush(Qt::NoBrush);
painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 35), 6,
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.drawPath(route.path);
painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 180), 2.2,
route.kind == PipeLink ? Qt::DashLine : Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.drawPath(route.path);
painter.setBrush(QColor(color.red(), color.green(), color.blue(), 220));
painter.setPen(QPen(palette().window().color(), 1.5));
painter.drawEllipse(route.from, 4, 4);
painter.drawEllipse(route.to, 4, 4);
}
for (const Pulse& pulse : pulses())
{
const QColor& color = pulse.color;
painter.setBrush(Qt::NoBrush);
painter.setPen(QPen(QColor(color.red(), color.green(), color.blue(), 210), 4,
Qt::SolidLine, Qt::RoundCap));
painter.drawLine(pulse.tail, pulse.head);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(color.red(), color.green(), color.blue(), 130));
painter.drawEllipse(pulse.head, 7, 7);
painter.setBrush(QColor(255, 255, 255, 245));
painter.drawEllipse(pulse.head, 3, 3);
}
for (const Route& route : m_routes)
{
if (!route.flowLabel.isEmpty() && dirty.intersects(route.flowLabelRect.toAlignedRect()))
{
painter.setPen(QPen(route.color, 1));
painter.setBrush(QColor(24, 28, 32, 235));
painter.drawRoundedRect(route.flowLabelRect, 3, 3);
painter.setPen(Qt::white);
painter.drawText(route.flowLabelRect, Qt::AlignCenter, route.flowLabel);
}
if (!route.marker.isEmpty() && dirty.intersects(route.markerRect.toAlignedRect()))
{
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(24, 28, 32, 235));
painter.drawRoundedRect(route.markerRect, 3, 3);
painter.setPen(Qt::white);
painter.drawText(route.markerRect, Qt::AlignCenter, route.marker);
}
}
}

118
sdrgui/gui/connectionoverlay.h

@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// Some code by AI //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRGUI_GUI_CONNECTIONOVERLAY_H_
#define SDRGUI_GUI_CONNECTIONOVERLAY_H_
#include <QElapsedTimer>
#include <QColor>
#include <QHash>
#include <QList>
#include <QPainterPath>
#include <QRegion>
#include <QVector>
#include <QPointer>
#include <QTimer>
#include <QWidget>
class QMdiArea;
class QMdiSubWindow;
// A non-interactive drawing layer above one workspace's MDI windows, showing connections between windows.
class ConnectionOverlay : public QWidget
{
Q_OBJECT
public:
enum Kind { DeviceLink, PipeLink };
enum Direction { NoDirection, Forward, Reverse, BothDirections };
struct Connection {
QPointer<QMdiSubWindow> source;
QPointer<QMdiSubWindow> target;
QString sourceLabel;
QString targetLabel;
QString flowLabel;
int sourceWorkspace = -1;
int targetWorkspace = -1;
Kind kind = DeviceLink;
Direction direction = Forward;
QColor color;
};
explicit ConnectionOverlay(QMdiArea *mdi);
void setConnections(const QList<Connection>& connections);
void setOverlayVisible(bool visible);
protected:
bool eventFilter(QObject *object, QEvent *event) override;
void changeEvent(QEvent *event) override;
void showEvent(QShowEvent *event) override;
void paintEvent(QPaintEvent *event) override;
private:
// Geometry for one drawn connection, cached until windows move or connections change.
struct Route {
QPainterPath path;
qreal length = 0;
QRect bounds;
QPointF from;
QPointF to;
QColor color;
Kind kind = DeviceLink;
Direction direction = Forward;
QString flowLabel;
QRectF flowLabelRect;
QString marker;
QRectF markerRect;
// Inputs to connectionPath(), kept so a stub can be rerouted to follow its label.
int fromSide = 0;
int toSide = 0;
QRectF sourceBox;
QRectF targetBox;
int stubTip = 0; // Cross-workspace stub: 1 if to is its tip, -1 if from is
};
struct Pulse {
QPointF tail;
QPointF head;
QColor color;
};
QMdiArea *m_mdi;
QList<Connection> m_connections;
QHash<QMdiSubWindow*, QPointer<QWidget>> m_indexLabels;
QList<QPointer<QObject>> m_watched;
QVector<Route> m_routes;
QRegion m_clipRegion; // Everything except the title ID labels
QRegion m_pulseRegion; // Area covered by the pulses last painted
qreal m_phase = 0;
bool m_layoutDirty = true; // Cached routes no longer match the windows
bool m_relayoutPending = false; // A queued relayout() is outstanding
QElapsedTimer m_clock;
QTimer m_animationTimer;
static bool sameConnections(const QList<Connection>& a, const QList<Connection>& b);
void watchWindows();
void invalidateLayout();
void relayout();
bool computeLayout(); // Returns true if the mask changed
QVector<Pulse> pulses() const;
QRegion pulsesRegion(const QVector<Pulse>& pulses) const;
void animate();
};
#endif // SDRGUI_GUI_CONNECTIONOVERLAY_H_

32
sdrgui/gui/workspace.cpp

@ -57,6 +57,7 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : @@ -57,6 +57,7 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) :
m_mdi->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_mdi->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setWidget(m_mdi);
m_connectionOverlay = new ConnectionOverlay(m_mdi);
setWindowTitle(tr("W%1").arg(m_index));
setObjectName(tr("W%1").arg(m_index));
@ -180,6 +181,15 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : @@ -180,6 +181,15 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) :
m_tabSubWindows->setToolTip("Display sub windows in tabs");
m_tabSubWindows->setFixedSize(20, 20);
m_connectionOverlayButton = new ButtonSwitch();
m_connectionOverlayButton->setCheckable(true);
m_connectionOverlayButton->setFixedSize(20, 20);
// Must match the shortcut created in MainWindow. NativeText shows Cmd on macOS.
m_connectionOverlayButton->setToolTip(QString("Show device, channel, spectrum and feature connections (%1)")
.arg(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_L).toString(QKeySequence::NativeText)));
QIcon connectionOverlayIcon(":/wiring.png");
m_connectionOverlayButton->setIcon(connectionOverlayIcon);
m_normalButton = new QPushButton();
QIcon normalIcon(":/dock.png");
m_normalButton->setIcon(normalIcon);
@ -211,6 +221,7 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : @@ -211,6 +221,7 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) :
m_titleBarLayout->addWidget(m_stackVerticalSubWindows);
m_titleBarLayout->addWidget(m_stackSubWindows);
m_titleBarLayout->addWidget(m_tabSubWindows);
m_titleBarLayout->addWidget(m_connectionOverlayButton);
m_titleBarLayout->addStretch(1);
m_titleBarLayout->addWidget(m_mcpServerButton);
#ifndef ANDROID
@ -315,6 +326,9 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : @@ -315,6 +326,9 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) :
&Workspace::tabSubWindows
);
QObject::connect(m_connectionOverlayButton, &ButtonSwitch::clicked,
this, &Workspace::connectionOverlayToggled);
QObject::connect(
m_normalButton,
&QPushButton::clicked,
@ -357,6 +371,7 @@ Workspace::~Workspace() @@ -357,6 +371,7 @@ Workspace::~Workspace()
delete m_closeButton;
delete m_normalButton;
delete m_tabSubWindows;
delete m_connectionOverlayButton;
delete m_stackSubWindows;
delete m_stackVerticalSubWindows;
delete m_tileSubWindows;
@ -389,6 +404,17 @@ void Workspace::setIndex(int index) @@ -389,6 +404,17 @@ void Workspace::setIndex(int index)
m_titleLabel->setText(windowTitle());
}
void Workspace::setConnectionOverlayVisible(bool visible)
{
m_connectionOverlayButton->doToggle(visible);
m_connectionOverlay->setOverlayVisible(visible);
}
void Workspace::setConnections(const QList<ConnectionOverlay::Connection>& connections)
{
m_connectionOverlay->setConnections(connections);
}
QList<QMdiSubWindow *> Workspace::getSubWindowList() const
{
return m_mdi->subWindowList();
@ -915,6 +941,9 @@ void Workspace::subWindowActivated(QMdiSubWindow *activatedWindow) @@ -915,6 +941,9 @@ void Workspace::subWindowActivated(QMdiSubWindow *activatedWindow)
emit focused(this);
}
if (m_connectionOverlay->isVisible()) {
m_connectionOverlay->raise();
}
if (activatedWindow && m_tabSubWindows->isChecked())
{
// Move other windows out of the way
@ -1025,6 +1054,9 @@ void Workspace::addToMdiArea(QMdiSubWindow *sub) @@ -1025,6 +1054,9 @@ void Workspace::addToMdiArea(QMdiSubWindow *sub)
connect(sub, &QObject::destroyed, this, &Workspace::layoutSubWindows);
m_mdi->addSubWindow(sub);
sub->show();
if (m_connectionOverlay->isVisible()) {
m_connectionOverlay->raise();
}
// Auto-stack when sub-window's widgets are rolled up
ChannelGUI *channel = qobject_cast<ChannelGUI *>(sub);
if (channel) {

6
sdrgui/gui/workspace.h

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#include "export.h"
#include "featureadddialog.h"
#include "device/deviceapi.h"
#include "connectionoverlay.h"
class QHBoxLayout;
class QLabel;
@ -70,6 +71,8 @@ public: @@ -70,6 +71,8 @@ public:
void updateStartStopButton(bool checked);
void updateMCPServerButton(bool available, bool running, int port);
QToolButton *getMenuButton() const { return m_menuButton; }
void setConnectionOverlayVisible(bool visible);
void setConnections(const QList<ConnectionOverlay::Connection>& connections);
private:
int m_index;
@ -90,6 +93,8 @@ private: @@ -90,6 +93,8 @@ private:
QPushButton *m_stackVerticalSubWindows;
QPushButton *m_stackSubWindows;
ButtonSwitch *m_tabSubWindows;
ButtonSwitch *m_connectionOverlayButton;
ConnectionOverlay *m_connectionOverlay;
QWidget *m_titleBar;
QHBoxLayout *m_titleBarLayout;
QLabel *m_titleLabel;
@ -132,6 +137,7 @@ public slots: @@ -132,6 +137,7 @@ public slots:
signals:
void focused(Workspace *workspace); // The user is working in this workspace
void connectionOverlayToggled(bool visible);
void addRxDevice(Workspace *inWorkspace, int deviceIndex);
void addTxDevice(Workspace *inWorkspace, int deviceIndex);
void addMIMODevice(Workspace *inWorkspace, int deviceIndex);

1
sdrgui/mainspectrum/mainspectrumgui.cpp

@ -56,6 +56,7 @@ MainSpectrumGUI::MainSpectrumGUI(GLSpectrum *spectrum, GLSpectrumGUI *spectrumGU @@ -56,6 +56,7 @@ MainSpectrumGUI::MainSpectrumGUI(GLSpectrum *spectrum, GLSpectrumGUI *spectrumGU
setMinimumSize(m_MinimumWidth, m_MinimumHeight);
m_indexLabel = new QLabel();
m_indexLabel->setObjectName("connectionIndexLabel");
m_indexLabel->setFixedSize(32, 16);
m_indexLabel->setStyleSheet("QLabel { background-color: rgb(128, 128, 128); qproperty-alignment: AlignCenter; }");
m_indexLabel->setText(tr("X:%1").arg(m_deviceSetIndex));

216
sdrgui/mainwindow.cpp

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include <QProgressDialog>
#include <QLabel>
#include <QToolButton>
#include <QShortcut>
#include <QFile>
#include <QFileInfo>
#include <QFileDialog>
@ -49,6 +50,7 @@ @@ -49,6 +50,7 @@
#include <QMenuBar>
#include <QStatusBar>
#include <QScreen>
#include <QHash>
#include "device/devicegui.h"
#include "device/deviceapi.h"
@ -78,6 +80,7 @@ @@ -78,6 +80,7 @@
#include "gui/fftdialog.h"
#include "gui/fftwisdomdialog.h"
#include "gui/workspace.h"
#include "gui/connectionoverlay.h"
#include "gui/featurepresetsdialog.h"
#include "gui/devicesetpresetsdialog.h"
#include "gui/commandsdialog.h"
@ -131,6 +134,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse @@ -131,6 +134,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse
m_currentWorkspace(nullptr),
m_mainCore(MainCore::instance()),
m_dspEngine(DSPEngine::instance()),
m_connectionOverlayEnabled(false),
m_lastEngineState(DeviceAPI::StNotStarted),
m_dateTimeWidget(nullptr),
m_showSystemWidget(nullptr),
@ -207,6 +211,16 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse @@ -207,6 +211,16 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(1000);
m_connectionOverlayRefreshTimer.setInterval(500);
connect(&m_connectionOverlayRefreshTimer, &QTimer::timeout,
this, &MainWindow::updateConnectionOverlays);
// One application-wide shortcut: a shortcut on each workspace's button would be
// ambiguous with several docked workspaces, and would miss floating ones.
QShortcut *connectionOverlayShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_L), this);
connectionOverlayShortcut->setContext(Qt::ApplicationShortcut);
connect(connectionOverlayShortcut, &QShortcut::activated, this, [this]() {
setConnectionOverlayEnabled(!m_connectionOverlayEnabled);
});
splash->showStatusMessage("load settings...", Qt::white);
qDebug() << "MainWindow::MainWindow: load settings...";
@ -298,6 +312,7 @@ MainWindow::~MainWindow() @@ -298,6 +312,7 @@ MainWindow::~MainWindow()
{
qDebug() << "MainWindow::~MainWindow";
setConnectionOverlayEnabled(false);
m_statusTimer.stop();
m_apiServer->stop();
delete m_apiServer;
@ -765,6 +780,7 @@ void RemoveDeviceSetFSM::removeSink() @@ -765,6 +780,7 @@ void RemoveDeviceSetFSM::removeSink()
void RemoveDeviceSetFSM::removeUI()
{
qDebug() << "RemoveDeviceSetFSM::removeUI";
m_mainWindow->m_connectionOverlayRefreshTimer.stop();
// Remove transitions, as we will delete the object (DSPDevice*Engine) that is the source of these signals
m_states[0]->removeTransition(m_t1);
@ -784,8 +800,10 @@ void RemoveDeviceSetFSM::removeUI() @@ -784,8 +800,10 @@ void RemoveDeviceSetFSM::removeUI()
}
// As for features: QObject only drops an object's connections in ~QObject, so a signal can
// still reach the GUI after the derived destructor has deleted its ui object.
QObject::disconnect(m_deviceUISet->m_deviceAPI, nullptr, m_deviceUISet->m_deviceGUI, nullptr);
delete m_deviceUISet->m_deviceGUI;
DeviceGUI *deviceGUI = m_deviceUISet->m_deviceGUI;
m_deviceUISet->m_deviceGUI = nullptr;
QObject::disconnect(m_deviceUISet->m_deviceAPI, nullptr, deviceGUI, nullptr);
delete deviceGUI;
m_deviceUISet->m_deviceAPI->resetSamplingDeviceId();
if (!m_deviceMIMOEngine) {
m_deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
@ -870,6 +888,11 @@ void RemoveDeviceSetFSM::removeDeviceSet() @@ -870,6 +888,11 @@ void RemoveDeviceSetFSM::removeDeviceSet()
);
}
if (m_mainWindow->m_connectionOverlayEnabled)
{
m_mainWindow->updateConnectionOverlays();
m_mainWindow->m_connectionOverlayRefreshTimer.start();
}
emit m_mainWindow->m_mainCore->deviceSetRemoved(m_deviceSetIndex);
}
@ -913,6 +936,7 @@ RemoveAllWorkspacesFSM::RemoveAllWorkspacesFSM(MainWindow *mainWindow, QObject * @@ -913,6 +936,7 @@ RemoveAllWorkspacesFSM::RemoveAllWorkspacesFSM(MainWindow *mainWindow, QObject *
void RemoveAllWorkspacesFSM::removeDeviceSets()
{
qDebug() << "RemoveAllWorkspacesFSM::removeDeviceSets";
m_mainWindow->setConnectionOverlayEnabled(false);
m_removeAllDeviceSetsFSM->start();
}
@ -932,6 +956,7 @@ void RemoveAllWorkspacesFSM::removeWorkspaces() @@ -932,6 +956,7 @@ void RemoveAllWorkspacesFSM::removeWorkspaces()
LoadConfigurationFSM::LoadConfigurationFSM(MainWindow *mainWindow, const Configuration *configuration, QProgressDialog *waitBox, QObject *parent) :
MainWindowFSM(mainWindow, parent),
m_configuration(configuration),
m_overlayEnabledBeforeLoad(mainWindow->m_connectionOverlayEnabled),
m_waitBox(waitBox)
{
// Create FSM
@ -1194,6 +1219,8 @@ void LoadConfigurationFSM::restoreGeometry() @@ -1194,6 +1219,8 @@ void LoadConfigurationFSM::restoreGeometry()
if (m_waitBox) {
m_waitBox->setValue(100);
}
// Re-enable only now, so the refresh timer doesn't walk device sets while they are being created.
m_mainWindow->setConnectionOverlayEnabled(m_overlayEnabledBeforeLoad);
}
InitFSM::InitFSM(MainWindow *mainWindow, SDRangelSplash *splash, bool loadDefault, bool showConfigs, QObject *parent) :
@ -2260,6 +2287,7 @@ void MainWindow::createStatusBar() @@ -2260,6 +2287,7 @@ void MainWindow::createStatusBar()
void MainWindow::closeEvent(QCloseEvent *closeEvent)
{
qDebug("MainWindow::closeEvent");
m_connectionOverlayRefreshTimer.stop();
if (!m_settingsSaved)
{
@ -2274,6 +2302,8 @@ void MainWindow::closeEvent(QCloseEvent *closeEvent) @@ -2274,6 +2302,8 @@ void MainWindow::closeEvent(QCloseEvent *closeEvent)
m_settingsSaved = true;
}
setConnectionOverlayEnabled(false);
if (m_deviceUIs.size() > 0)
{
CloseFSM *fsm = new CloseFSM(this);
@ -2675,11 +2705,181 @@ void MainWindow::handleWorkspaceVisibility(Workspace *workspace, bool visibility @@ -2675,11 +2705,181 @@ void MainWindow::handleWorkspaceVisibility(Workspace *workspace, bool visibility
m_currentWorkspace = workspace;
}
void MainWindow::setConnectionOverlayEnabled(bool enabled)
{
m_connectionOverlayEnabled = enabled;
for (Workspace *workspace : m_workspaces) {
workspace->setConnectionOverlayVisible(enabled);
}
if (enabled)
{
updateConnectionOverlays();
m_connectionOverlayRefreshTimer.start();
}
else
{
m_connectionOverlayRefreshTimer.stop();
}
}
void MainWindow::updateConnectionOverlays()
{
if (!m_connectionOverlayEnabled) {
return;
}
struct Endpoint {
QMdiSubWindow *window;
QString label;
int workspace;
bool feature;
QColor linkColor;
};
QHash<const QObject*, Endpoint> endpoints;
QList<ConnectionOverlay::Connection> connections;
for (DeviceUISet *deviceUI : m_deviceUIs)
{
if (!deviceUI || !deviceUI->m_deviceGUI) {
continue;
}
DeviceGUI *device = deviceUI->m_deviceGUI;
const QString tag = device->getDeviceType() == DeviceGUI::DeviceTx ? "T" :
(device->getDeviceType() == DeviceGUI::DeviceMIMO ? "M" : "R");
const QString deviceLabel = QString("%1:%2").arg(tag).arg(deviceUI->getIndex());
const QColor deviceColor = device->getDeviceTypeColor();
const Endpoint deviceEndpoint{device, deviceLabel, device->getWorkspaceIndex(), false, deviceColor};
endpoints.insert(device, deviceEndpoint);
endpoints.insert(deviceUI->m_deviceAPI, deviceEndpoint);
auto appendDeviceConnection = [&](QMdiSubWindow *target, const QString& label,
int targetWorkspace, ConnectionOverlay::Direction direction) {
if (!target) {
return;
}
ConnectionOverlay::Connection connection;
connection.source = device;
connection.target = target;
connection.sourceLabel = deviceLabel;
connection.targetLabel = label;
connection.flowLabel = "IQ";
connection.sourceWorkspace = device->getWorkspaceIndex();
connection.targetWorkspace = targetWorkspace;
connection.direction = direction;
connection.color = deviceColor;
connections.append(connection);
};
const ConnectionOverlay::Direction spectrumDirection =
device->getDeviceType() == DeviceGUI::DeviceTx ? ConnectionOverlay::Reverse :
(device->getDeviceType() == DeviceGUI::DeviceMIMO ? ConnectionOverlay::BothDirections : ConnectionOverlay::Forward);
if (deviceUI->m_mainSpectrumGUI)
{
appendDeviceConnection(deviceUI->m_mainSpectrumGUI, deviceLabel + " spectrum",
deviceUI->m_mainSpectrumGUI->getWorkspaceIndex(), spectrumDirection);
}
for (int channelIndex = 0; channelIndex < deviceUI->getNumberOfChannels(); ++channelIndex)
{
ChannelGUI *channel = deviceUI->getChannelGUIAt(channelIndex);
if (!channel) {
continue;
}
const QString channelLabel = QString("%1%2:%3").arg(tag).arg(deviceUI->getIndex()).arg(channel->getIndex());
const int type = deviceUI->getChannelTypeAt(channelIndex);
const ConnectionOverlay::Direction direction = type == 1 ? ConnectionOverlay::Reverse :
(type == 2 ? ConnectionOverlay::BothDirections : ConnectionOverlay::Forward);
appendDeviceConnection(channel, channelLabel, channel->getWorkspaceIndex(), direction);
const Endpoint endpoint{channel, channelLabel, channel->getWorkspaceIndex(), false,
channel->getIndexLabelColor()};
endpoints.insert(channel, endpoint);
if (ChannelAPI *channelAPI = deviceUI->getChannelAt(channelIndex)) {
endpoints.insert(channelAPI, endpoint);
}
}
}
for (FeatureUISet *featureUI : m_featureUIs)
{
if (!featureUI) {
continue;
}
for (int featureIndex = 0; featureIndex < featureUI->getNumberOfFeatures(); ++featureIndex)
{
FeatureGUI *featureGUI = featureUI->getFeatureGuiAt(featureIndex);
if (!featureGUI) {
continue;
}
const Endpoint endpoint{featureGUI, QString("F%1").arg(featureGUI->getIndex()),
featureGUI->getWorkspaceIndex(), true, QColor()};
endpoints.insert(featureGUI, endpoint);
if (Feature *feature = featureUI->getFeatureAt(featureIndex)) {
endpoints.insert(feature, endpoint);
}
}
}
QList<ObjectPipesRegistrations::Connection> pipes = m_mainCore->getDataPipes().getConnections();
pipes.append(m_mainCore->getMessagePipes().getConnections());
// A message pipe may terminate at a helper QObject owned by a channel or
// feature. Walk its parent chain to find the window represented in the graph.
auto endpointFor = [&endpoints](const QObject *object) -> const Endpoint* {
for (const QObject *current = object; current; current = current->parent())
{
auto found = endpoints.constFind(current);
if (found != endpoints.constEnd()) {
return &found.value();
}
}
return nullptr;
};
QHash<QMdiSubWindow*, QHash<QMdiSubWindow*, int>> pipeConnectionIndices;
for (const ObjectPipesRegistrations::Connection& pipe : pipes)
{
const Endpoint *sourceEndpoint = endpointFor(pipe.producer);
const Endpoint *targetEndpoint = endpointFor(pipe.consumer);
if (!sourceEndpoint || !targetEndpoint) {
continue;
}
const Endpoint& source = *sourceEndpoint;
const Endpoint& target = *targetEndpoint;
if (source.window == target.window || (!source.feature && !target.feature)) {
continue;
}
const int existingIndex = pipeConnectionIndices.value(source.window).value(target.window, -1);
if (existingIndex >= 0)
{
if (pipe.type == "demod") {
connections[existingIndex].flowLabel = "Audio";
}
continue;
}
ConnectionOverlay::Connection connection;
connection.source = source.window;
connection.target = target.window;
connection.sourceLabel = source.label;
connection.targetLabel = target.label;
connection.flowLabel = pipe.type == "demod" ? "Audio" : "Data";
connection.sourceWorkspace = source.workspace;
connection.targetWorkspace = target.workspace;
connection.kind = ConnectionOverlay::PipeLink;
connection.direction = ConnectionOverlay::Forward;
connection.color = source.linkColor.isValid() ? source.linkColor : target.linkColor;
pipeConnectionIndices[source.window].insert(target.window, connections.size());
connections.append(connection);
}
for (Workspace *workspace : m_workspaces) {
workspace->setConnections(connections);
}
}
void MainWindow::addWorkspace()
{
int workspaceIndex = m_workspaces.size();
auto *workspace = new Workspace(workspaceIndex);
m_workspaces.push_back(workspace);
workspace->setConnectionOverlayVisible(m_connectionOverlayEnabled);
connect(workspace, &Workspace::connectionOverlayToggled, this, &MainWindow::setConnectionOverlayEnabled);
if (workspace->getMenuButton()) {
createMenuBar(workspace->getMenuButton());
}
@ -3266,7 +3466,9 @@ void MainWindow::sampleSourceChange(int deviceSetIndex, int newDeviceIndex, Work @@ -3266,7 +3466,9 @@ void MainWindow::sampleSourceChange(int deviceSetIndex, int newDeviceIndex, Work
// deletes old UI and input object
deviceUISet->m_deviceAPI->getSampleSource()->setMessageQueueToGUI(nullptr); // have source stop sending messages to the GUI
delete deviceUISet->m_deviceGUI;
DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI;
deviceUISet->m_deviceGUI = nullptr;
delete oldDeviceGUI;
deviceUISet->m_deviceAPI->resetSamplingDeviceId();
deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput(deviceUISet->m_deviceAPI->getSampleSource());
deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
@ -3309,7 +3511,9 @@ void MainWindow::sampleSinkChange(int deviceSetIndex, int newDeviceIndex, Worksp @@ -3309,7 +3511,9 @@ void MainWindow::sampleSinkChange(int deviceSetIndex, int newDeviceIndex, Worksp
// deletes old UI and output object
deviceUISet->m_deviceAPI->getSampleSink()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI
delete m_deviceUIs[deviceSetIndex]->m_deviceGUI;
DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI;
deviceUISet->m_deviceGUI = nullptr;
delete oldDeviceGUI;
deviceUISet->m_deviceAPI->resetSamplingDeviceId();
deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput(deviceUISet->m_deviceAPI->getSampleSink());
deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
@ -3353,7 +3557,9 @@ void MainWindow::sampleMIMOChange(int deviceSetIndex, int newDeviceIndex, Worksp @@ -3353,7 +3557,9 @@ void MainWindow::sampleMIMOChange(int deviceSetIndex, int newDeviceIndex, Worksp
// deletes old UI and output object
deviceUISet->m_deviceAPI->getSampleMIMO()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI
delete deviceUISet->m_deviceGUI;
DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI;
deviceUISet->m_deviceGUI = nullptr;
delete oldDeviceGUI;
deviceUISet->m_deviceAPI->resetSamplingDeviceId();
deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleMIMOPluginInstanceMIMO(deviceUISet->m_deviceAPI->getSampleMIMO());

5
sdrgui/mainwindow.h

@ -235,6 +235,7 @@ public: @@ -235,6 +235,7 @@ public:
private:
const Configuration *m_configuration;
bool m_overlayEnabledBeforeLoad;
// The dialog is created with WA_DeleteOnClose and this FSM outlives it,
// so a bare pointer can dangle between states. QPointer makes the null
// checks in the state handlers mean what they are written to mean.
@ -332,6 +333,8 @@ private: @@ -332,6 +333,8 @@ private:
PluginManager* m_pluginManager;
QTimer m_statusTimer;
QTimer m_connectionOverlayRefreshTimer;
bool m_connectionOverlayEnabled;
int m_lastEngineState;
QMenuBar *m_menuBar;
@ -363,6 +366,8 @@ private: @@ -363,6 +366,8 @@ private:
void saveFeatureSetPresetSettings(FeatureSetPreset* preset, int featureSetIndex);
FeatureGUI *getMCPServerGUI(Feature **feature = nullptr) const;
void updateMCPServerButton();
void setConnectionOverlayEnabled(bool enabled);
void updateConnectionOverlays();
QString openGLVersion() const;
void createMenuBar(QToolButton *button) const;

1
sdrgui/resources/res.qrc

@ -154,6 +154,7 @@ @@ -154,6 +154,7 @@
<file>stackvertical.png</file>
<file>stackcolumns.png</file>
<file>tab.png</file>
<file>wiring.png</file>
<file>clockfile.png</file>
<file>clockcurrent.png</file>
<file>mouse.png</file>

BIN
sdrgui/resources/wiring.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Loading…
Cancel
Save