1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-29 03:09:14 -05:00

AIS feature: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-11-20 19:54:13 +01:00
parent f3c5cd0ab5
commit 1972b74099
14 changed files with 294 additions and 45 deletions

View File

@ -242,8 +242,6 @@ void AFC::applySettings(const AFCSettings& settings, const QList<QString>& setti
{
qDebug() << "AFC::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;
QList<QString> reverseAPIKeys;
if (settingsKeys.contains("trackerDeviceSetIndex") || force)
{
removeTrackerFeatureReference();
@ -272,7 +270,7 @@ void AFC::applySettings(const AFCSettings& settings, const QList<QString>& setti
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIFeatureSetIndex") ||
settingsKeys.contains("m_reverseAPIFeatureIndex");
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}
if (force) {

View File

@ -435,6 +435,8 @@ void AFCGUI::applySettings(bool force)
AFC::MsgConfigureAFC* message = AFC::MsgConfigureAFC::create( m_settings, m_settingsKeys, force);
m_afc->getInputMessageQueue()->push(message);
}
m_settingsKeys.clear();
}
void AFCGUI::makeUIConnections()

View File

@ -98,7 +98,7 @@ bool AIS::handleMessage(const Message& cmd)
{
MsgConfigureAIS& cfg = (MsgConfigureAIS&) cmd;
qDebug() << "AIS::handleMessage: MsgConfigureAIS";
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());
return true;
}
@ -127,51 +127,38 @@ bool AIS::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
MsgConfigureAIS *msg = MsgConfigureAIS::create(m_settings, true);
MsgConfigureAIS *msg = MsgConfigureAIS::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return true;
}
else
{
m_settings.resetToDefaults();
MsgConfigureAIS *msg = MsgConfigureAIS::create(m_settings, true);
MsgConfigureAIS *msg = MsgConfigureAIS::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return false;
}
}
void AIS::applySettings(const AISSettings& settings, bool force)
void AIS::applySettings(const AISSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "AIS::applySettings:"
<< " m_title: " << settings.m_title
<< " m_rgbColor: " << settings.m_rgbColor
<< " m_useReverseAPI: " << settings.m_useReverseAPI
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
<< " m_reverseAPIPort: " << settings.m_reverseAPIPort
<< " m_reverseAPIFeatureSetIndex: " << settings.m_reverseAPIFeatureSetIndex
<< " m_reverseAPIFeatureIndex: " << settings.m_reverseAPIFeatureIndex
<< " force: " << force;
QList<QString> reverseAPIKeys;
if ((m_settings.m_title != settings.m_title) || force) {
reverseAPIKeys.append("title");
}
if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) {
reverseAPIKeys.append("rgbColor");
}
qDebug() << "AIS::applySettings:" << settings.getDebugString(settingsKeys, force) << force;
if (settings.m_useReverseAPI)
{
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
(m_settings.m_reverseAPIFeatureSetIndex != settings.m_reverseAPIFeatureSetIndex) ||
(m_settings.m_reverseAPIFeatureIndex != settings.m_reverseAPIFeatureIndex);
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
settingsKeys.contains("reverseAPIAddress") ||
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIFeatureSetIndex") ||
settingsKeys.contains("m_reverseAPIFeatureIndex");
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}
int AIS::webapiSettingsGet(
@ -195,12 +182,12 @@ int AIS::webapiSettingsPutPatch(
AISSettings settings = m_settings;
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);
MsgConfigureAIS *msg = MsgConfigureAIS::create(settings, force);
MsgConfigureAIS *msg = MsgConfigureAIS::create(settings, featureSettingsKeys, force);
m_inputMessageQueue.push(msg);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureAIS *msgToGUI = MsgConfigureAIS::create(settings, force);
MsgConfigureAIS *msgToGUI = MsgConfigureAIS::create(settings, featureSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}
@ -245,6 +232,26 @@ void AIS::webapiFormatFeatureSettings(
response.getAisSettings()->setRollupState(swgRollupState);
}
}
if (!response.getAisSettings()->getVesselColumnIndexes()) {
response.getAisSettings()->setVesselColumnIndexes(new QList<int>());
}
response.getAisSettings()->getVesselColumnIndexes()->clear();
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
response.getAisSettings()->getVesselColumnIndexes()->push_back(settings.m_vesselColumnIndexes[i]);
}
if (!response.getAisSettings()->getVesselColumnSizes()) {
response.getAisSettings()->setVesselColumnSizes(new QList<int>());
}
response.getAisSettings()->getVesselColumnSizes()->clear();
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
response.getAisSettings()->getVesselColumnSizes()->push_back(settings.m_vesselColumnSizes[i]);
}
}
void AIS::webapiUpdateFeatureSettings(
@ -276,9 +283,27 @@ void AIS::webapiUpdateFeatureSettings(
if (settings.m_rollupState && featureSettingsKeys.contains("rollupState")) {
settings.m_rollupState->updateFrom(featureSettingsKeys, response.getAisSettings()->getRollupState());
}
if (featureSettingsKeys.contains("vesselColumnIndexes"))
{
const QList<int> *indexes = response.getAisSettings()->getVesselColumnIndexes();
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
settings.m_vesselColumnIndexes[i] = (*indexes)[i];
}
}
void AIS::webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const AISSettings& settings, bool force)
if (featureSettingsKeys.contains("vesselColumnSizes"))
{
const QList<int> *indexes = response.getAisSettings()->getVesselColumnSizes();
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
settings.m_vesselColumnSizes[i] = (*indexes)[i];
}
}
}
void AIS::webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const AISSettings& settings, bool force)
{
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());

View File

@ -44,19 +44,22 @@ public:
public:
const AISSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureAIS* create(const AISSettings& settings, bool force) {
return new MsgConfigureAIS(settings, force);
static MsgConfigureAIS* create(const AISSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureAIS(settings, settingsKeys, force);
}
private:
AISSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureAIS(const AISSettings& settings, bool force) :
MsgConfigureAIS(const AISSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -104,8 +107,8 @@ private:
void start();
void stop();
void applySettings(const AISSettings& settings, bool force = false);
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const AISSettings& settings, bool force);
void applySettings(const AISSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const AISSettings& settings, bool force);
void scanAvailableChannels();
private slots:

View File

@ -130,7 +130,13 @@ bool AISGUI::handleMessage(const Message& message)
{
qDebug("AISGUI::handleMessage: AIS::MsgConfigureAIS");
const AIS::MsgConfigureAIS& cfg = (AIS::MsgConfigureAIS&) message;
if (cfg.getForce()) {
m_settings = cfg.getSettings();
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
@ -258,9 +264,11 @@ void AISGUI::displaySettings()
bool hidden = m_settings.m_vesselColumnSizes[i] == 0;
header->setSectionHidden(i, hidden);
vesselsMenu->actions().at(i)->setChecked(!hidden);
if (m_settings.m_vesselColumnSizes[i] > 0) {
ui->vessels->setColumnWidth(i, m_settings.m_vesselColumnSizes[i]);
}
header->moveSection(header->visualIndex(i), m_settings.m_vesselColumnIndexes[i]);
}
@ -295,6 +303,12 @@ void AISGUI::onMenuDialogCalled(const QPoint &p)
setTitle(m_settings.m_title);
setTitleColor(m_settings.m_rgbColor);
m_settingsKeys.append("useReverseAPI");
m_settingsKeys.append("reverseAPIAddress");
m_settingsKeys.append("reverseAPIPort");
m_settingsKeys.append("reverseAPIFeatureSetIndex");
m_settingsKeys.append("reverseAPIFeatureIndex");
applySettings();
}
@ -333,9 +347,11 @@ void AISGUI::applySettings(bool force)
{
if (m_doApplySettings)
{
AIS::MsgConfigureAIS* message = AIS::MsgConfigureAIS::create(m_settings, force);
AIS::MsgConfigureAIS* message = AIS::MsgConfigureAIS::create(m_settings, m_settingsKeys, force);
m_ais->getInputMessageQueue()->push(message);
}
m_settingsKeys.clear();
}
void AISGUI::resizeTable()
@ -370,6 +386,8 @@ void AISGUI::vessels_sectionMoved(int logicalIndex, int oldVisualIndex, int newV
(void) oldVisualIndex;
m_settings.m_vesselColumnIndexes[logicalIndex] = newVisualIndex;
m_settingsKeys.append("vesselColumnIndexes");
applySettings();
}
// Column in table resized (when hidden size is 0)
@ -378,6 +396,8 @@ void AISGUI::vessels_sectionResized(int logicalIndex, int oldSize, int newSize)
(void) oldSize;
m_settings.m_vesselColumnSizes[logicalIndex] = newSize;
m_settingsKeys.append("vesselColumnSizes");
applySettings();
}
// Right click in table header - show column select menu

View File

@ -67,6 +67,7 @@ private:
PluginAPI* m_pluginAPI;
FeatureUISet* m_featureUISet;
AISSettings m_settings;
QList<QString> m_settingsKeys;
RollupState m_rollupState;
bool m_doApplySettings;

View File

@ -145,3 +145,96 @@ bool AISSettings::deserialize(const QByteArray& data)
return false;
}
}
void AISSettings::applySettings(const QStringList& settingsKeys, const AISSettings& settings)
{
if (settingsKeys.contains("title")) {
m_title = settings.m_title;
}
if (settingsKeys.contains("rgbColor")) {
m_rgbColor = settings.m_rgbColor;
}
if (settingsKeys.contains("useReverseAPI")) {
m_useReverseAPI = settings.m_useReverseAPI;
}
if (settingsKeys.contains("reverseAPIAddress")) {
m_reverseAPIAddress = settings.m_reverseAPIAddress;
}
if (settingsKeys.contains("reverseAPIPort")) {
m_reverseAPIPort = settings.m_reverseAPIPort;
}
if (settingsKeys.contains("reverseAPIFeatureSetIndex")) {
m_reverseAPIFeatureSetIndex = settings.m_reverseAPIFeatureSetIndex;
}
if (settingsKeys.contains("reverseAPIFeatureIndex")) {
m_reverseAPIFeatureIndex = settings.m_reverseAPIFeatureIndex;
}
if (settingsKeys.contains("workspaceIndex")) {
m_workspaceIndex = settings.m_workspaceIndex;
}
if (settingsKeys.contains("vesselColumnIndexes"))
{
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
m_vesselColumnIndexes[i] = settings.m_vesselColumnIndexes[i];
}
}
if (settingsKeys.contains("vesselColumnSizes"))
{
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
m_vesselColumnSizes[i] = settings.m_vesselColumnSizes[i];
}
}
}
QString AISSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("title") || force) {
ostr << " m_title: " << m_title.toStdString();
}
if (settingsKeys.contains("rgbColor") || force) {
ostr << " m_rgbColor: " << m_rgbColor;
}
if (settingsKeys.contains("useReverseAPI") || force) {
ostr << " m_useReverseAPI: " << m_useReverseAPI;
}
if (settingsKeys.contains("reverseAPIAddress") || force) {
ostr << " m_reverseAPIAddress: " << m_reverseAPIAddress.toStdString();
}
if (settingsKeys.contains("reverseAPIPort") || force) {
ostr << " m_reverseAPIPort: " << m_reverseAPIPort;
}
if (settingsKeys.contains("reverseAPIFeatureSetIndex") || force) {
ostr << " m_reverseAPIFeatureSetIndex: " << m_reverseAPIFeatureSetIndex;
}
if (settingsKeys.contains("reverseAPIFeatureIndex") || force) {
ostr << " m_reverseAPIFeatureIndex: " << m_reverseAPIFeatureIndex;
}
if (settingsKeys.contains("workspaceIndex") || force) {
ostr << " m_workspaceIndex: " << m_workspaceIndex;
}
if (settingsKeys.contains("vesselColumnIndexes"))
{
ostr << "m_vesselColumnIndexes:";
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
ostr << " " << m_vesselColumnIndexes[i];
}
}
if (settingsKeys.contains("vesselColumnSizes"))
{
ostr << "m_vesselColumnSizes:";
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
ostr << " " << m_vesselColumnSizes[i];
}
}
return QString(ostr.str().c_str());
}

View File

@ -50,6 +50,8 @@ struct AISSettings
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; }
void applySettings(const QStringList& settingsKeys, const AISSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
static const QStringList m_pipeTypes;
static const QStringList m_pipeURIs;

View File

@ -1245,6 +1245,18 @@ margin-bottom: 20px;
},
"rollupState" : {
"$ref" : "#/definitions/RollupState"
},
"vesselColumnIndexes" : {
"type" : "array",
"items" : {
"type" : "integer"
}
},
"vesselColumnSizes" : {
"type" : "array",
"items" : {
"type" : "integer"
}
}
},
"description" : "AIS settings"
@ -56629,7 +56641,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2022-11-13T19:59:19.161+01:00
Generated 2022-11-20T11:19:42.122+01:00
</div>
</div>
</div>

View File

@ -18,3 +18,11 @@ AISSettings:
type: integer
rollupState:
$ref: "/doc/swagger/include/RollupState.yaml#/RollupState"
vesselColumnIndexes:
type: array
items:
type: integer
vesselColumnSizes:
type: array
items:
type: integer

View File

@ -18,3 +18,11 @@ AISSettings:
type: integer
rollupState:
$ref: "http://swgserver:8081/api/swagger/include/RollupState.yaml#/RollupState"
vesselColumnIndexes:
type: array
items:
type: integer
vesselColumnSizes:
type: array
items:
type: integer

View File

@ -1245,6 +1245,18 @@ margin-bottom: 20px;
},
"rollupState" : {
"$ref" : "#/definitions/RollupState"
},
"vesselColumnIndexes" : {
"type" : "array",
"items" : {
"type" : "integer"
}
},
"vesselColumnSizes" : {
"type" : "array",
"items" : {
"type" : "integer"
}
}
},
"description" : "AIS settings"
@ -56629,7 +56641,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2022-11-13T19:59:19.161+01:00
Generated 2022-11-20T11:19:42.122+01:00
</div>
</div>
</div>

View File

@ -44,6 +44,10 @@ SWGAISSettings::SWGAISSettings() {
m_reverse_api_feature_index_isSet = false;
rollup_state = nullptr;
m_rollup_state_isSet = false;
vessel_column_indexes = new QList<qint32>();
m_vessel_column_indexes_isSet = false;
vessel_column_sizes = new QList<qint32>();
m_vessel_column_sizes_isSet = false;
}
SWGAISSettings::~SWGAISSettings() {
@ -68,6 +72,10 @@ SWGAISSettings::init() {
m_reverse_api_feature_index_isSet = false;
rollup_state = new SWGRollupState();
m_rollup_state_isSet = false;
vessel_column_indexes = new QList<qint32>();
m_vessel_column_indexes_isSet = false;
vessel_column_sizes = new QList<qint32>();
m_vessel_column_sizes_isSet = false;
}
void
@ -86,6 +94,8 @@ SWGAISSettings::cleanup() {
if(rollup_state != nullptr) {
delete rollup_state;
}
}
SWGAISSettings*
@ -115,6 +125,10 @@ SWGAISSettings::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&rollup_state, pJson["rollupState"], "SWGRollupState", "SWGRollupState");
::SWGSDRangel::setValue(&vessel_column_indexes, pJson["vesselColumnIndexes"], "QList", "qint32");
::SWGSDRangel::setValue(&vessel_column_sizes, pJson["vesselColumnSizes"], "QList", "qint32");
}
QString
@ -155,6 +169,12 @@ SWGAISSettings::asJsonObject() {
if((rollup_state != nullptr) && (rollup_state->isSet())){
toJsonValue(QString("rollupState"), rollup_state, obj, QString("SWGRollupState"));
}
if(vessel_column_indexes && vessel_column_indexes->size() > 0){
toJsonArray((QList<void*>*)vessel_column_indexes, obj, "vesselColumnIndexes", "");
}
if(vessel_column_sizes && vessel_column_sizes->size() > 0){
toJsonArray((QList<void*>*)vessel_column_sizes, obj, "vesselColumnSizes", "");
}
return obj;
}
@ -239,6 +259,26 @@ SWGAISSettings::setRollupState(SWGRollupState* rollup_state) {
this->m_rollup_state_isSet = true;
}
QList<qint32>*
SWGAISSettings::getVesselColumnIndexes() {
return vessel_column_indexes;
}
void
SWGAISSettings::setVesselColumnIndexes(QList<qint32>* vessel_column_indexes) {
this->vessel_column_indexes = vessel_column_indexes;
this->m_vessel_column_indexes_isSet = true;
}
QList<qint32>*
SWGAISSettings::getVesselColumnSizes() {
return vessel_column_sizes;
}
void
SWGAISSettings::setVesselColumnSizes(QList<qint32>* vessel_column_sizes) {
this->vessel_column_sizes = vessel_column_sizes;
this->m_vessel_column_sizes_isSet = true;
}
bool
SWGAISSettings::isSet(){
@ -268,6 +308,18 @@ SWGAISSettings::isSet(){
if(rollup_state && rollup_state->isSet()){
isObjectUpdated = true; break;
}
if(m_vessel_column_indexes_isSet){
isObjectUpdated = true; break;
}
if(vessel_column_indexes && (vessel_column_indexes->size() > 0)){
isObjectUpdated = true; break;
}
if(m_vessel_column_sizes_isSet){
isObjectUpdated = true; break;
}
if(vessel_column_sizes && (vessel_column_sizes->size() > 0)){
isObjectUpdated = true; break;
}
}while(false);
return isObjectUpdated;
}

View File

@ -23,6 +23,7 @@
#include "SWGRollupState.h"
#include <QList>
#include <QString>
#include "SWGObject.h"
@ -67,6 +68,12 @@ public:
SWGRollupState* getRollupState();
void setRollupState(SWGRollupState* rollup_state);
QList<qint32>* getVesselColumnIndexes();
void setVesselColumnIndexes(QList<qint32>* vessel_column_indexes);
QList<qint32>* getVesselColumnSizes();
void setVesselColumnSizes(QList<qint32>* vessel_column_sizes);
virtual bool isSet() override;
@ -95,6 +102,12 @@ private:
SWGRollupState* rollup_state;
bool m_rollup_state_isSet;
QList<qint32>* vessel_column_indexes;
bool m_vessel_column_indexes_isSet;
QList<qint32>* vessel_column_sizes;
bool m_vessel_column_sizes_isSet;
};
}