mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Ref T82, removed add button for servers, only save
* save will add a new server when not already existing * when saved with same name, it will override values * default values for FSD setup * adjusted validation
This commit is contained in:
@@ -47,7 +47,6 @@ namespace BlackGui
|
|||||||
// Settings server
|
// Settings server
|
||||||
this->connect(ui->pb_RemoveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer);
|
this->connect(ui->pb_RemoveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer);
|
||||||
this->connect(ui->pb_SaveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer);
|
this->connect(ui->pb_SaveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer);
|
||||||
this->connect(ui->pb_AddServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer);
|
|
||||||
this->connect(ui->tvp_Servers, &QTableView::clicked, this, &CSettingsNetworkServersComponent::ps_serverSelected);
|
this->connect(ui->tvp_Servers, &QTableView::clicked, this, &CSettingsNetworkServersComponent::ps_serverSelected);
|
||||||
this->ps_reloadSettings();
|
this->ps_reloadSettings();
|
||||||
}
|
}
|
||||||
@@ -76,47 +75,38 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CSettingsNetworkServersComponent::ps_alterTrafficServer()
|
void CSettingsNetworkServersComponent::ps_alterTrafficServer()
|
||||||
{
|
{
|
||||||
CServer server(ui->form_Server->getServer());
|
const QObject *sender = QObject::sender();
|
||||||
CStatusMessageList msgs = server.validate();
|
const CServer server(ui->form_Server->getServer());
|
||||||
if (!msgs.isEmpty()) { msgs.addCategories(this); }
|
|
||||||
|
|
||||||
CServerList serverList(m_trafficNetworkServers.getThreadLocal());
|
CServerList serverList(m_trafficNetworkServers.getThreadLocal());
|
||||||
QObject *sender = QObject::sender();
|
|
||||||
CStatusMessage msg;
|
CStatusMessage msg;
|
||||||
bool changed = false;
|
|
||||||
bool save = false;
|
|
||||||
if (sender == ui->pb_RemoveServer)
|
if (sender == ui->pb_RemoveServer)
|
||||||
{
|
{
|
||||||
// lenient name removal
|
// lenient name removal
|
||||||
serverList.removeByName(server.getName());
|
serverList.removeByName(server.getName());
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
else if (sender == ui->pb_AddServer)
|
else if (sender == ui->pb_SaveServer)
|
||||||
{
|
{
|
||||||
if (!msgs.isEmpty())
|
CStatusMessageList msgs = server.validate();
|
||||||
|
if (!msgs.isEmpty()) { msgs.addCategories(this); }
|
||||||
|
|
||||||
|
// error?
|
||||||
|
if (msgs.isFailure())
|
||||||
{
|
{
|
||||||
CLogMessage::preformatted(msgs);
|
CLogMessage::preformatted(msgs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
serverList.replaceOrAdd(&CServer::getName, server.getName(), server);
|
serverList.replaceOrAdd(&CServer::getName, server.getName(), server);
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
else if (sender == ui->pb_SaveServer)
|
else
|
||||||
{
|
{
|
||||||
save = true;
|
qFatal("Wrong sender");
|
||||||
if (msgs.isEmpty() && server.hasAddressAndPort())
|
return;
|
||||||
{
|
|
||||||
// update in any case to list before saving if we have a valid form
|
|
||||||
serverList.replaceOrAdd(&CServer::getName, server.getName(), server);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed)
|
msg = m_trafficNetworkServers.setAndSave(serverList);
|
||||||
{
|
this->ps_reloadSettings(); // call manually as local object
|
||||||
msg = save ? m_trafficNetworkServers.setAndSave(serverList) : m_trafficNetworkServers.set(serverList);
|
|
||||||
this->ps_reloadSettings(); // call manually as local object
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!msg.isEmpty())
|
if (!msg.isEmpty())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ class QModelIndex;
|
|||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
namespace Ui { class CSettingsNetworkServersComponent; }
|
namespace Ui { class CSettingsNetworkServersComponent; }
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Components
|
namespace Components
|
||||||
@@ -40,7 +39,7 @@ namespace BlackGui
|
|||||||
explicit CSettingsNetworkServersComponent(QWidget *parent = nullptr);
|
explicit CSettingsNetworkServersComponent(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~CSettingsNetworkServersComponent();
|
virtual ~CSettingsNetworkServersComponent();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Reload settings
|
//! Reload settings
|
||||||
|
|||||||
@@ -120,13 +120,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_AddServer">
|
|
||||||
<property name="text">
|
|
||||||
<string>add</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pb_RemoveServer">
|
<widget class="QPushButton" name="pb_RemoveServer">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|||||||
@@ -26,9 +26,11 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->showEnableInfo(false);
|
this->showEnableInfo(false);
|
||||||
|
this->resetToDefaultValues();
|
||||||
ui->cb_Enabled->setChecked(true);
|
ui->cb_Enabled->setChecked(true);
|
||||||
ui->le_TextCodec->setCompleter(new QCompleter(textCodecNames(true, true), this));
|
ui->le_TextCodec->setCompleter(new QCompleter(textCodecNames(true, true), this));
|
||||||
connect(ui->cb_Enabled, &QCheckBox::toggled, this, &CFsdSetupForm::ps_enabledToggled);
|
connect(ui->cb_Enabled, &QCheckBox::toggled, this, &CFsdSetupForm::enabledToggled);
|
||||||
|
connect(ui->pb_SetDefaults, &QPushButton::clicked, this, &CFsdSetupForm::resetToDefaultValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFsdSetupForm::~CFsdSetupForm()
|
CFsdSetupForm::~CFsdSetupForm()
|
||||||
@@ -100,7 +102,7 @@ namespace BlackGui
|
|||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFsdSetupForm::ps_enabledToggled(bool enabled)
|
void CFsdSetupForm::enabledToggled(bool enabled)
|
||||||
{
|
{
|
||||||
Q_UNUSED(enabled);
|
Q_UNUSED(enabled);
|
||||||
this->setReadOnly(!enabled);
|
this->setReadOnly(!enabled);
|
||||||
@@ -109,5 +111,14 @@ namespace BlackGui
|
|||||||
this->setValue(CFsdSetup());
|
this->setValue(CFsdSetup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CFsdSetupForm::resetToDefaultValues()
|
||||||
|
{
|
||||||
|
ui->cb_AircraftPartsReceive->setChecked(true);
|
||||||
|
ui->cb_AircraftPartsSend->setChecked(true);
|
||||||
|
ui->cb_FastPositionReceive->setChecked(true);
|
||||||
|
ui->cb_FastPositionSend->setChecked(true);
|
||||||
|
ui->le_TextCodec->setText("latin1");
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
namespace Ui { class CFsdSetupForm; }
|
namespace Ui { class CFsdSetupForm; }
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Editors
|
namespace Editors
|
||||||
@@ -35,7 +34,7 @@ namespace BlackGui
|
|||||||
explicit CFsdSetupForm(QWidget *parent = nullptr);
|
explicit CFsdSetupForm(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
~CFsdSetupForm();
|
virtual ~CFsdSetupForm();
|
||||||
|
|
||||||
//! FSD setup from GUI
|
//! FSD setup from GUI
|
||||||
BlackMisc::Network::CFsdSetup getValue() const;
|
BlackMisc::Network::CFsdSetup getValue() const;
|
||||||
@@ -55,17 +54,19 @@ namespace BlackGui
|
|||||||
//! Show the enable info
|
//! Show the enable info
|
||||||
void showEnableInfo(bool visible);
|
void showEnableInfo(bool visible);
|
||||||
|
|
||||||
|
//! Set default values
|
||||||
|
void resetToDefaultValues();
|
||||||
|
|
||||||
//! \name Form class implementations
|
//! \name Form class implementations
|
||||||
//! @{
|
//! @{
|
||||||
virtual void setReadOnly(bool readonly) override;
|
virtual void setReadOnly(bool readonly) override;
|
||||||
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
|
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
private slots:
|
|
||||||
//! Enable / disable
|
|
||||||
void ps_enabledToggled(bool enabled);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! Enable / disable
|
||||||
|
void enabledToggled(bool enabled);
|
||||||
|
|
||||||
QScopedPointer<Ui::CFsdSetupForm> ui;
|
QScopedPointer<Ui::CFsdSetupForm> ui;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>189</width>
|
<width>209</width>
|
||||||
<height>102</height>
|
<height>130</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -81,8 +81,8 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" alignment="Qt::AlignHCenter">
|
<item row="1" column="1" alignment="Qt::AlignHCenter">
|
||||||
<widget class="QCheckBox" name="cb_AircraftPartsSend">
|
<widget class="QCheckBox" name="cb_FastPositionSend">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>send</string>
|
<string>send</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -95,8 +95,8 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1" alignment="Qt::AlignHCenter">
|
<item row="0" column="1" alignment="Qt::AlignHCenter">
|
||||||
<widget class="QCheckBox" name="cb_FastPositionSend">
|
<widget class="QCheckBox" name="cb_AircraftPartsSend">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>send</string>
|
<string>send</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -109,6 +109,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QPushButton" name="pb_SetDefaults">
|
||||||
|
<property name="text">
|
||||||
|
<string>set defaults</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
namespace Ui { class CNetworkServerForm; }
|
namespace Ui { class CNetworkServerForm; }
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Editors
|
namespace Editors
|
||||||
@@ -40,7 +39,7 @@ namespace BlackGui
|
|||||||
explicit CServerForm(QWidget *parent = nullptr);
|
explicit CServerForm(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~CServerForm();
|
virtual ~CServerForm();
|
||||||
|
|
||||||
//! Set server
|
//! Set server
|
||||||
void setServer(const BlackMisc::Network::CServer &server);
|
void setServer(const BlackMisc::Network::CServer &server);
|
||||||
|
|||||||
@@ -91,13 +91,14 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
if (this->getName().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing name")); }
|
if (this->getName().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, "Missing name")); }
|
||||||
if (this->getAddress().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing address")); }
|
if (this->getAddress().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, "Missing address")); }
|
||||||
if (this->getDescription().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing description")); }
|
if (this->getDescription().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing description")); }
|
||||||
if (this->getPort() < 1 || this->getPort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Wrong port")); }
|
if (this->getPort() < 1 || this->getPort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, "Wrong port")); }
|
||||||
msgs.push_back(this->getUser().validate());
|
msgs.push_back(this->getUser().validate());
|
||||||
msgs.push_back(this->getFsdSetup().validate());
|
msgs.push_back(this->getFsdSetup().validate());
|
||||||
msgs.addCategories(cats);
|
msgs.addCategories(cats);
|
||||||
|
msgs.sortBySeverity();
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user