Ref T709, added "follow aircraft distance" and timestamp, removed old settings

This commit is contained in:
Klaus Basan
2019-07-27 02:20:41 +02:00
committed by Mat Sutcliffe
parent a5cefcf18c
commit c0b4d38331
8 changed files with 82 additions and 40 deletions

View File

@@ -24,13 +24,15 @@ namespace BlackMisc
CVariant CXSwiftBusSettings::propertyByIndex(const CPropertyIndex &index) const CVariant CXSwiftBusSettings::propertyByIndex(const CPropertyIndex &index) const
{ {
if (index.isMyself()) { return CVariant::from(*this); } if (index.isMyself()) { return CVariant::from(*this); }
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexMaxPlanes: return CVariant::fromValue(m_maxPlanes); case IndexMaxPlanes: return CVariant::fromValue(m_maxPlanes);
case IndexDBusServerAddress: return CVariant::fromValue(QString::fromStdString(m_dBusServerAddress)); case IndexDBusServerAddress: return CVariant::fromValue(QString::fromStdString(m_dBusServerAddress));
case IndexDrawingLabels: return CVariant::fromValue(m_drawingLabels); case IndexDrawingLabels: return CVariant::fromValue(m_drawingLabels);
case IndexMaxDrawingDistance: return CVariant::fromValue(m_maxDrawDistanceNM); case IndexMaxDrawingDistance: return CVariant::fromValue(m_maxDrawDistanceNM);
case IndexFollowAircraftDistance: return CVariant::fromValue(m_followAircraftDistanceM);
default: break; default: break;
} }
return CValueObject::propertyByIndex(index); return CValueObject::propertyByIndex(index);
@@ -39,13 +41,16 @@ namespace BlackMisc
void CXSwiftBusSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) void CXSwiftBusSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{ {
if (index.isMyself()) { (*this) = variant.to<CXSwiftBusSettings>(); return; } if (index.isMyself()) { (*this) = variant.to<CXSwiftBusSettings>(); return; }
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); }
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexMaxPlanes: m_maxPlanes = variant.toInt(); break; case IndexMaxPlanes: m_maxPlanes = variant.toInt(); break;
case IndexDBusServerAddress: m_dBusServerAddress = variant.toStdString(); break; case IndexDBusServerAddress: m_dBusServerAddress = variant.toStdString(); break;
case IndexDrawingLabels: m_drawingLabels = variant.toBool(); break; case IndexDrawingLabels: m_drawingLabels = variant.toBool(); break;
case IndexMaxDrawingDistance: m_maxDrawDistanceNM = variant.toDouble(); break; case IndexMaxDrawingDistance: m_maxDrawDistanceNM = variant.toDouble(); break;
case IndexFollowAircraftDistance: m_followAircraftDistanceM = variant.toInt(); break;
default: default:
CValueObject::setPropertyByIndex(index, variant); CValueObject::setPropertyByIndex(index, variant);
break; break;
@@ -58,6 +63,12 @@ namespace BlackMisc
return QString::fromStdString(CXSwiftBusSettingsQtFree::convertToString()); return QString::fromStdString(CXSwiftBusSettingsQtFree::convertToString());
} }
void CXSwiftBusSettings::setCurrentUtcTime()
{
ITimestampBased::setCurrentUtcTime();
m_msSinceEpochQtFree = m_timestampMSecsSinceEpoch;
}
CStatusMessageList CXSwiftBusSettings::validate() const CStatusMessageList CXSwiftBusSettings::validate() const
{ {
CStatusMessageList msgs; CStatusMessageList msgs;

View File

@@ -39,7 +39,8 @@ namespace BlackMisc
IndexDBusServerAddress = CPropertyIndex::GlobalIndexCXSwiftBusSettings, IndexDBusServerAddress = CPropertyIndex::GlobalIndexCXSwiftBusSettings,
IndexMaxPlanes, IndexMaxPlanes,
IndexDrawingLabels, IndexDrawingLabels,
IndexMaxDrawingDistance IndexMaxDrawingDistance,
IndexFollowAircraftDistance
}; };
//! Default constructor //! Default constructor
@@ -69,6 +70,9 @@ namespace BlackMisc
//! \copydoc CXSwiftBusSettingsQtFree::parseXSwiftBusString //! \copydoc CXSwiftBusSettingsQtFree::parseXSwiftBusString
void parseXSwiftBusStringQt(const QString &json) { this->parseXSwiftBusString(json.toStdString()); } void parseXSwiftBusStringQt(const QString &json) { this->parseXSwiftBusString(json.toStdString()); }
//! Sets both timestamps
virtual void setCurrentUtcTime() override;
//! Valid settings? //! Valid settings?
CStatusMessageList validate() const; CStatusMessageList validate() const;
@@ -82,29 +86,11 @@ namespace BlackMisc
BLACK_METAMEMBER(maxPlanes), BLACK_METAMEMBER(maxPlanes),
BLACK_METAMEMBER(drawingLabels), BLACK_METAMEMBER(drawingLabels),
BLACK_METAMEMBER(maxDrawDistanceNM), BLACK_METAMEMBER(maxDrawDistanceNM),
BLACK_METAMEMBER(followAircraftDistanceM),
BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForComparison | DisabledForHashing) BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForComparison | DisabledForHashing)
); );
}; };
/*!
* Setting for XSwiftBus.
* @deprecated will be changed to JSON Settings
*/
struct TXSwiftBusServer : public TSettingTrait<QString>
{
//! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "xswiftbus/server"; }
//! \copydoc BlackMisc::TSettingTrait::humanReadable
static const QString &humanReadable() { static const QString name("XSwiftBus"); return name; }
//! \copydoc BlackMisc::TSettingTrait::defaultValue
static QString defaultValue() { return "tcp:host=127.0.0.1,port=45001"; }
//! \copydoc BlackMisc::TSettingTrait::isValid
static bool isValid(const QString &dBusAddress, QString &) { return BlackMisc::CDBusServer::isSessionOrSystemAddress(dBusAddress) || BlackMisc::CDBusServer::isQtDBusAddress(dBusAddress); }
};
/*! /*!
* Setting for XSwiftBus. * Setting for XSwiftBus.
*/ */

View File

@@ -23,6 +23,8 @@ constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonDB
constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonDrawingLabels[]; constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonDrawingLabels[];
constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonMaxPlanes[]; constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonMaxPlanes[];
constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonMaxDrawDistance[]; constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonMaxDrawDistance[];
constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonFollowAircraftDistanceM[];
constexpr char BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree::JsonTimestamp[];
//! @endcond //! @endcond
namespace BlackMisc namespace BlackMisc
@@ -60,7 +62,15 @@ namespace BlackMisc
{ {
m_maxDrawDistanceNM = settingsDoc[CXSwiftBusSettingsQtFree::JsonMaxDrawDistance].GetDouble(); c++; m_maxDrawDistanceNM = settingsDoc[CXSwiftBusSettingsQtFree::JsonMaxDrawDistance].GetDouble(); c++;
} }
return c == 4; if (settingsDoc.HasMember(CXSwiftBusSettingsQtFree::JsonFollowAircraftDistanceM) && settingsDoc[CXSwiftBusSettingsQtFree::JsonFollowAircraftDistanceM].IsInt())
{
m_followAircraftDistanceM = settingsDoc[CXSwiftBusSettingsQtFree::JsonFollowAircraftDistanceM].GetInt(); c++;
}
if (settingsDoc.HasMember(CXSwiftBusSettingsQtFree::JsonTimestamp) && settingsDoc[CXSwiftBusSettingsQtFree::JsonTimestamp].IsInt64())
{
m_msSinceEpochQtFree = settingsDoc[CXSwiftBusSettingsQtFree::JsonTimestamp].GetInt64(); c++;
}
return c == 6;
} }
std::string CXSwiftBusSettingsQtFree::toXSwiftBusJsonString() const std::string CXSwiftBusSettingsQtFree::toXSwiftBusJsonString() const
@@ -77,6 +87,8 @@ namespace BlackMisc
document.AddMember(JsonDrawingLabels, m_drawingLabels, a); document.AddMember(JsonDrawingLabels, m_drawingLabels, a);
document.AddMember(JsonMaxPlanes, m_maxPlanes, a); document.AddMember(JsonMaxPlanes, m_maxPlanes, a);
document.AddMember(JsonMaxDrawDistance, m_maxDrawDistanceNM, a); document.AddMember(JsonMaxDrawDistance, m_maxDrawDistanceNM, a);
document.AddMember(JsonTimestamp, m_msSinceEpochQtFree, a);
document.AddMember(JsonFollowAircraftDistanceM, m_followAircraftDistanceM, a);
// document[CXSwiftBusSettingsQtFree::JsonDBusServerAddress].SetString(StringRef(m_dBusServerAddress.c_str(), m_dBusServerAddress.size())); // document[CXSwiftBusSettingsQtFree::JsonDBusServerAddress].SetString(StringRef(m_dBusServerAddress.c_str(), m_dBusServerAddress.size()));
// document[CXSwiftBusSettingsQtFree::JsonDrawingLabels].SetBool(m_drawingLabels); // document[CXSwiftBusSettingsQtFree::JsonDrawingLabels].SetBool(m_drawingLabels);
@@ -95,7 +107,9 @@ namespace BlackMisc
return "DBusServer: " + m_dBusServerAddress + return "DBusServer: " + m_dBusServerAddress +
", drawLabels: " + QtFreeUtils::boolToYesNo(m_drawingLabels) + ", drawLabels: " + QtFreeUtils::boolToYesNo(m_drawingLabels) +
", max planes: " + std::to_string(m_maxPlanes) + ", max planes: " + std::to_string(m_maxPlanes) +
", max distance NM: " + std::to_string(m_maxDrawDistanceNM); ", max distance NM: " + std::to_string(m_maxDrawDistanceNM) +
", follow dist m: " + std::to_string(m_followAircraftDistanceM) +
", ts: " + std::to_string(m_msSinceEpochQtFree);
} }
} // ns } // ns
} // ns } // ns

View File

@@ -45,6 +45,12 @@ namespace BlackMisc
//! Get the maximum number of aircraft. //! Get the maximum number of aircraft.
int getMaxPlanes() const { return m_maxPlanes; } int getMaxPlanes() const { return m_maxPlanes; }
//! Set follow aircraft distance
void setFollowAircraftDistanceM(int meters) { m_followAircraftDistanceM = meters; }
//! Get follow aircraft distance
int getFollowAircraftDistanceM() const { return m_followAircraftDistanceM; }
//! Set the maximum distance at which to draw aircraft (nautical miles). //! Set the maximum distance at which to draw aircraft (nautical miles).
double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; } double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; }
@@ -66,12 +72,16 @@ namespace BlackMisc
static constexpr char JsonDrawingLabels[] = "drawinglabels"; static constexpr char JsonDrawingLabels[] = "drawinglabels";
static constexpr char JsonMaxPlanes[] = "maxplanes"; static constexpr char JsonMaxPlanes[] = "maxplanes";
static constexpr char JsonMaxDrawDistance[] = "maxDrawDistance"; static constexpr char JsonMaxDrawDistance[] = "maxDrawDistance";
static constexpr char JsonTimestamp[] = "timestamp";
static constexpr char JsonFollowAircraftDistanceM[] = "followAircraftDistance";
//! @} //! @}
std::string m_dBusServerAddress { "tcp:host=127.0.0.1,port=45001" }; //!< DBus server std::string m_dBusServerAddress { "tcp:host=127.0.0.1,port=45001" }; //!< DBus server
int m_maxPlanes = 100; //!< max. planes in XPlane int m_maxPlanes = 100; //!< max. planes in XPlane
bool m_drawingLabels = true; //!< labels in XPlane int m_followAircraftDistanceM = 200; //!< follow aircraft in distance
double m_maxDrawDistanceNM = 50.0; //!< distance in XPlane bool m_drawingLabels = true; //!< labels in XPlane
double m_maxDrawDistanceNM = 50.0; //!< distance in XPlane
int64_t m_msSinceEpochQtFree = 0; //!< timestamp
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -1061,7 +1061,8 @@ namespace BlackSimPlugin
{ {
if (!this->isConnected()) { return false; } if (!this->isConnected()) { return false; }
if (!m_serviceProxy) { return false; } if (!m_serviceProxy) { return false; }
const CXSwiftBusSettings s = m_xSwiftBusServerSettings.get(); CXSwiftBusSettings s = m_xSwiftBusServerSettings.get();
s.setCurrentUtcTime();
m_serviceProxy->setSettings(s.toXSwiftBusJsonStringQt()); m_serviceProxy->setSettings(s.toXSwiftBusJsonStringQt());
CLogMessage(this).info(u"Send settings: %1") << s.toQString(true); CLogMessage(this).info(u"Send settings: %1") << s.toQString(true);
return true; return true;

View File

@@ -17,7 +17,7 @@ namespace BlackSimPlugin
{ {
CSimulatorXPlaneConfig::CSimulatorXPlaneConfig(QObject *parent) : QObject(parent) CSimulatorXPlaneConfig::CSimulatorXPlaneConfig(QObject *parent) : QObject(parent)
{ {
// void
} }
BlackGui::CPluginConfigWindow *CSimulatorXPlaneConfig::createConfigWindow(QWidget *parent) BlackGui::CPluginConfigWindow *CSimulatorXPlaneConfig::createConfigWindow(QWidget *parent)
@@ -25,5 +25,5 @@ namespace BlackSimPlugin
CSimulatorXPlaneConfigWindow* w = new CSimulatorXPlaneConfigWindow(parent); CSimulatorXPlaneConfigWindow* w = new CSimulatorXPlaneConfigWindow(parent);
return w; return w;
} }
} } // ns
} } // ns

View File

@@ -65,6 +65,7 @@ namespace BlackSimPlugin
s.setDBusServerAddressQt(ui->comp_SettingsXSwiftBus->getDBusAddress()); s.setDBusServerAddressQt(ui->comp_SettingsXSwiftBus->getDBusAddress());
s.setMaxDrawDistanceNM(ui->ds_MaxDrawDistanceNM->value()); s.setMaxDrawDistanceNM(ui->ds_MaxDrawDistanceNM->value());
s.setMaxPlanes(ui->sb_MaxAircraft->value()); s.setMaxPlanes(ui->sb_MaxAircraft->value());
s.setFollowAircraftDistanceM(ui->sb_FollowAircraftDistanceM->value());
s.setDrawingLabels(ui->cb_DrawLabels->isChecked()); s.setDrawingLabels(ui->cb_DrawLabels->isChecked());
return s; return s;
} }
@@ -73,6 +74,7 @@ namespace BlackSimPlugin
{ {
ui->comp_SettingsXSwiftBus->set(settings.getDBusServerAddressQt()); ui->comp_SettingsXSwiftBus->set(settings.getDBusServerAddressQt());
ui->sb_MaxAircraft->setValue(settings.getMaxPlanes()); ui->sb_MaxAircraft->setValue(settings.getMaxPlanes());
ui->sb_FollowAircraftDistanceM->setValue(settings.getFollowAircraftDistanceM());
ui->cb_DrawLabels->setChecked(settings.isDrawingLabels()); ui->cb_DrawLabels->setChecked(settings.isDrawingLabels());
ui->ds_MaxDrawDistanceNM->setValue(settings.getMaxDrawDistanceNM()); ui->ds_MaxDrawDistanceNM->setValue(settings.getMaxDrawDistanceNM());
} }

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>250</width> <width>250</width>
<height>272</height> <height>298</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
@@ -113,20 +113,37 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="4" column="0">
<widget class="QLabel" name="lbl_Labels"> <widget class="QLabel" name="lbl_Labels">
<property name="text"> <property name="text">
<string>Labels</string> <string>Labels</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="4" column="1">
<widget class="QCheckBox" name="cb_DrawLabels"> <widget class="QCheckBox" name="cb_DrawLabels">
<property name="text"> <property name="text">
<string>draw labels</string> <string>draw labels</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_FollowAircraftDistance">
<property name="text">
<string>Follow aircraft distance</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="sb_FollowAircraftDistanceM">
<property name="suffix">
<string>m</string>
</property>
<property name="maximum">
<number>300</number>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@@ -143,6 +160,7 @@
<tabstops> <tabstops>
<tabstop>sb_MaxAircraft</tabstop> <tabstop>sb_MaxAircraft</tabstop>
<tabstop>ds_MaxDrawDistanceNM</tabstop> <tabstop>ds_MaxDrawDistanceNM</tabstop>
<tabstop>sb_FollowAircraftDistanceM</tabstop>
<tabstop>cb_DrawLabels</tabstop> <tabstop>cb_DrawLabels</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>