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

Use MainCore code for managing available channel and feature list.

This commit is contained in:
srcejon 2024-02-14 15:36:22 +00:00
parent b046eac470
commit 607d7db702
6 changed files with 29 additions and 145 deletions

View File

@ -329,15 +329,9 @@ void GS232Controller::applySettings(const GS232ControllerSettings& settings, con
for (const auto& oval : m_availableChannelOrFeatures) for (const auto& oval : m_availableChannelOrFeatures)
{ {
QString itemText = tr("%1%2:%3 %4") if (settings.m_source == oval.getLongId())
.arg(oval.m_kind)
.arg(oval.m_superIndex)
.arg(oval.m_index)
.arg(oval.m_type);
if (settings.m_source == itemText)
{ {
object = m_availableChannelOrFeatures.key(oval); object = oval.m_object;
break; break;
} }
} }
@ -771,52 +765,7 @@ void GS232Controller::networkManagerFinished(QNetworkReply *reply)
void GS232Controller::scanAvailableChannelsAndFeatures() void GS232Controller::scanAvailableChannelsAndFeatures()
{ {
qDebug("GS232Controller::scanAvailableChannelsAndFeatures"); m_availableChannelOrFeatures = MainCore::instance()->getAvailableChannelsAndFeatures(GS232ControllerSettings::m_pipeURIs);
MainCore *mainCore = MainCore::instance();
std::vector<FeatureSet*>& featureSets = mainCore->getFeatureeSets();
m_availableChannelOrFeatures.clear();
for (const auto& featureSet : featureSets)
{
for (int fei = 0; fei < featureSet->getNumberOfFeatures(); fei++)
{
Feature *feature = featureSet->getFeatureAt(fei);
if (GS232ControllerSettings::m_pipeURIs.contains(feature->getURI()) && !m_availableChannelOrFeatures.contains(feature))
{
qDebug("GS232Controller::scanAvailableChannelsAndFeatures: store feature %d:%d %s (%p)",
featureSet->getIndex(), fei, qPrintable(feature->getURI()), feature);
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
GS232ControllerSettings::AvailableChannelOrFeature{"F", featureSet->getIndex(), fei, feature->getIdentifier()};
m_availableChannelOrFeatures[feature] = availableItem;
}
}
}
std::vector<DeviceSet*>& deviceSets = mainCore->getDeviceSets();
for (const auto& deviceSet : deviceSets)
{
DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine;
if (deviceSourceEngine)
{
for (int chi = 0; chi < deviceSet->getNumberOfChannels(); chi++)
{
ChannelAPI *channel = deviceSet->getChannelAt(chi);
if (GS232ControllerSettings::m_pipeURIs.contains(channel->getURI()) && !m_availableChannelOrFeatures.contains(channel))
{
qDebug("GS232Controller::scanAvailableChannelsAndFeatures: store channel %d:%d %s (%p)",
deviceSet->getIndex(), chi, qPrintable(channel->getURI()), channel);
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
GS232ControllerSettings::AvailableChannelOrFeature{"R", deviceSet->getIndex(), chi, channel->getIdentifier()};
m_availableChannelOrFeatures[channel] = availableItem;
}
}
}
}
notifyUpdate(); notifyUpdate();
} }
@ -825,74 +774,41 @@ void GS232Controller::notifyUpdate()
if (getMessageQueueToGUI()) if (getMessageQueueToGUI())
{ {
MsgReportAvailableChannelOrFeatures *msg = MsgReportAvailableChannelOrFeatures::create(); MsgReportAvailableChannelOrFeatures *msg = MsgReportAvailableChannelOrFeatures::create();
msg->getItems() = m_availableChannelOrFeatures.values(); msg->getItems() = m_availableChannelOrFeatures;
getMessageQueueToGUI()->push(msg); getMessageQueueToGUI()->push(msg);
} }
} }
void GS232Controller::handleFeatureAdded(int featureSetIndex, Feature *feature) void GS232Controller::handleFeatureAdded(int featureSetIndex, Feature *feature)
{ {
qDebug("GS232Controller::handleFeatureAdded: featureSetIndex: %d:%d feature: %s (%p)", (void) featureSetIndex;
featureSetIndex, feature->getIndexInFeatureSet(), qPrintable(feature->getURI()), feature); (void) feature;
FeatureSet *featureSet = MainCore::instance()->getFeatureeSets()[featureSetIndex];
if (GS232ControllerSettings::m_pipeURIs.contains(feature->getURI())) scanAvailableChannelsAndFeatures();
{
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
GS232ControllerSettings::AvailableChannelOrFeature{
"F",
featureSet->getIndex(),
feature->getIndexInFeatureSet(),
feature->getIdentifier()
};
m_availableChannelOrFeatures[feature] = availableItem;
notifyUpdate();
}
} }
void GS232Controller::handleFeatureRemoved(int featureSetIndex, Feature *feature) void GS232Controller::handleFeatureRemoved(int featureSetIndex, Feature *feature)
{ {
qDebug("GS232Controller::handleFeatureRemoved: featureSetIndex: %d (%p)", featureSetIndex, feature); (void) featureSetIndex;
(void) feature;
if (m_availableChannelOrFeatures.contains(feature)) scanAvailableChannelsAndFeatures();
{
m_availableChannelOrFeatures.remove(feature);
notifyUpdate();
}
} }
void GS232Controller::handleChannelAdded(int deviceSetIndex, ChannelAPI *channel) void GS232Controller::handleChannelAdded(int deviceSetIndex, ChannelAPI *channel)
{ {
qDebug("GS232Controller::handleChannelAdded: deviceSetIndex: %d:%d channel: %s (%p)", (void) deviceSetIndex;
deviceSetIndex, channel->getIndexInDeviceSet(), qPrintable(channel->getURI()), channel); (void) channel;
DeviceSet *deviceSet = MainCore::instance()->getDeviceSets()[deviceSetIndex];
DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine;
if (deviceSourceEngine && GS232ControllerSettings::m_pipeURIs.contains(channel->getURI())) scanAvailableChannelsAndFeatures();
{
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
GS232ControllerSettings::AvailableChannelOrFeature{
"R",
deviceSet->getIndex(),
channel->getIndexInDeviceSet(),
channel->getIdentifier()
};
m_availableChannelOrFeatures[channel] = availableItem;
notifyUpdate();
}
} }
void GS232Controller::handleChannelRemoved(int deviceSetIndex, ChannelAPI *channel) void GS232Controller::handleChannelRemoved(int deviceSetIndex, ChannelAPI *channel)
{ {
qDebug("GS232Controller::handleChannelRemoved: deviceSetIndex: %d (%p)", deviceSetIndex, channel); (void) deviceSetIndex;
(void) channel;
if (m_availableChannelOrFeatures.contains(channel)) scanAvailableChannelsAndFeatures();
{
m_availableChannelOrFeatures.remove(channel);
notifyUpdate();
}
} }
void GS232Controller::registerPipe(QObject *object) void GS232Controller::registerPipe(QObject *object)
@ -908,22 +824,6 @@ void GS232Controller::registerPipe(QObject *object)
[=](){ this->handlePipeMessageQueue(messageQueue); }, [=](){ this->handlePipeMessageQueue(messageQueue); },
Qt::QueuedConnection Qt::QueuedConnection
); );
QObject::connect(
pipe,
&ObjectPipe::toBeDeleted,
this,
&GS232Controller::handleMessagePipeToBeDeleted
);
}
void GS232Controller::handleMessagePipeToBeDeleted(int reason, QObject* object)
{
if ((reason == 0) && m_availableChannelOrFeatures.contains(object)) // producer
{
qDebug("GS232Controller::handleMessagePipeToBeDeleted: removing channel or feature at (%p)", object);
m_availableChannelOrFeatures.remove(object);
notifyUpdate();
}
} }
void GS232Controller::handlePipeMessageQueue(MessageQueue* messageQueue) void GS232Controller::handlePipeMessageQueue(MessageQueue* messageQueue)

View File

@ -27,6 +27,7 @@
#include "feature/feature.h" #include "feature/feature.h"
#include "util/message.h" #include "util/message.h"
#include "maincore.h"
#include "gs232controllersettings.h" #include "gs232controllersettings.h"
@ -110,14 +111,14 @@ public:
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION
public: public:
QList<GS232ControllerSettings::AvailableChannelOrFeature>& getItems() { return m_availableChannelOrFeatures; } QList<MainCore::AvailableChannelOrFeature>& getItems() { return m_availableChannelOrFeatures; }
static MsgReportAvailableChannelOrFeatures* create() { static MsgReportAvailableChannelOrFeatures* create() {
return new MsgReportAvailableChannelOrFeatures(); return new MsgReportAvailableChannelOrFeatures();
} }
private: private:
QList<GS232ControllerSettings::AvailableChannelOrFeature> m_availableChannelOrFeatures; QList<MainCore::AvailableChannelOrFeature> m_availableChannelOrFeatures;
MsgReportAvailableChannelOrFeatures() : MsgReportAvailableChannelOrFeatures() :
Message() Message()
@ -212,7 +213,8 @@ private:
QThread *m_thread; QThread *m_thread;
GS232ControllerWorker *m_worker; GS232ControllerWorker *m_worker;
GS232ControllerSettings m_settings; GS232ControllerSettings m_settings;
QHash<QObject*, GS232ControllerSettings::AvailableChannelOrFeature> m_availableChannelOrFeatures; //QHash<QObject*, GS232ControllerSettings::AvailableChannelOrFeature> m_availableChannelOrFeatures;
QList<MainCore::AvailableChannelOrFeature> m_availableChannelOrFeatures;
QObject *m_selectedPipe; QObject *m_selectedPipe;
QTimer m_timer; QTimer m_timer;
@ -239,7 +241,7 @@ private slots:
void handleChannelAdded(int deviceSetIndex, ChannelAPI *channel); void handleChannelAdded(int deviceSetIndex, ChannelAPI *channel);
void handleFeatureRemoved(int featureSetIndex, Feature *feature); void handleFeatureRemoved(int featureSetIndex, Feature *feature);
void handleChannelRemoved(int deviceSetIndex, ChannelAPI *feature); void handleChannelRemoved(int deviceSetIndex, ChannelAPI *feature);
void handleMessagePipeToBeDeleted(int reason, QObject* object); //void handleMessagePipeToBeDeleted(int reason, QObject* object);
void handlePipeMessageQueue(MessageQueue* messageQueue); void handlePipeMessageQueue(MessageQueue* messageQueue);
void scanSerialPorts(); void scanSerialPorts();
}; };

View File

@ -546,21 +546,15 @@ void GS232ControllerGUI::updateSerialPortList(const QStringList& serialPorts)
ui->serialPort->blockSignals(false); ui->serialPort->blockSignals(false);
} }
void GS232ControllerGUI::updatePipeList(const QList<GS232ControllerSettings::AvailableChannelOrFeature>& sources) void GS232ControllerGUI::updatePipeList(const QList<MainCore::AvailableChannelOrFeature>& sources)
{ {
QString currentText = ui->sources->currentText(); QString currentText = ui->sources->currentText();
QString newText; QString newText;
ui->sources->blockSignals(true); ui->sources->blockSignals(true);
ui->sources->clear(); ui->sources->clear();
for (const auto& source : sources) for (const auto& source : sources) {
{ ui->sources->addItem(source.getLongId());
QString name = tr("%1%2:%3 %4")
.arg(source.m_kind)
.arg(source.m_superIndex)
.arg(source.m_index)
.arg(source.m_type);
ui->sources->addItem(name);
} }
int index = ui->sources->findText(m_settings.m_source); int index = ui->sources->findText(m_settings.m_source);

View File

@ -90,7 +90,7 @@ private:
void setProtocol(GS232ControllerSettings::Protocol protocol); void setProtocol(GS232ControllerSettings::Protocol protocol);
void setPrecision(); void setPrecision();
void updateConnectionWidgets(); void updateConnectionWidgets();
void updatePipeList(const QList<GS232ControllerSettings::AvailableChannelOrFeature>& sources); void updatePipeList(const QList<MainCore::AvailableChannelOrFeature>& sources);
void updateSerialPortList(); void updateSerialPortList();
void updateSerialPortList(const QStringList& serialPorts); void updateSerialPortList(const QStringList& serialPorts);
bool handleMessage(const Message& message); bool handleMessage(const Message& message);

View File

@ -31,21 +31,6 @@ class Serializable;
struct GS232ControllerSettings struct GS232ControllerSettings
{ {
struct AvailableChannelOrFeature
{
QString m_kind; //!< "R" for channel, "F" for feature
int m_superIndex;
int m_index;
QString m_type;
AvailableChannelOrFeature() = default;
AvailableChannelOrFeature(const AvailableChannelOrFeature&) = default;
AvailableChannelOrFeature& operator=(const AvailableChannelOrFeature&) = default;
bool operator==(const AvailableChannelOrFeature& a) const {
return (m_kind == a.m_kind) && (m_superIndex == a.m_superIndex) && (m_index == a.m_index) && (m_type == a.m_type);
}
};
float m_azimuth; float m_azimuth;
float m_elevation; float m_elevation;
QString m_serialPort; QString m_serialPort;

View File

@ -345,6 +345,7 @@ void SkyMapGUI::on_source_currentIndexChanged(int index)
} }
else else
{ {
ui->track->setChecked(false);
ui->track->setEnabled(false); ui->track->setEnabled(false);
} }
} }
@ -413,6 +414,7 @@ void SkyMapGUI::displaySettings()
} }
else else
{ {
ui->track->setChecked(false);
ui->track->setEnabled(false); ui->track->setEnabled(false);
} }
initSkyMap(); initSkyMap();
@ -1047,6 +1049,7 @@ void SkyMapGUI::updateSourceList()
else else
{ {
ui->source->setCurrentIndex(-1); ui->source->setCurrentIndex(-1);
ui->track->setChecked(false);
ui->track->setEnabled(false); ui->track->setEnabled(false);
} }