mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T494, style
* removed some old "foreach" loops * fixed some CLANG warnings
This commit is contained in:
committed by
Mat Sutcliffe
parent
cb084427ec
commit
80ed972e53
@@ -28,6 +28,7 @@
|
||||
using namespace BlackCore;
|
||||
using namespace BlackCore::Context;
|
||||
using namespace BlackMisc::Audio;
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -60,7 +61,7 @@ namespace BlackGui
|
||||
|
||||
void CVoiceRoomsComponent::onVoiceRoomUrlsReturnPressed()
|
||||
{
|
||||
Q_ASSERT(sGui->getIContextOwnAircraft()); // voice room resolution is part of own aircraft
|
||||
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return; }
|
||||
QString url1;
|
||||
QString url2;
|
||||
if (ui->cb_CockpitVoiceRoom1Override->isChecked()) { url1 = ui->le_CockpitVoiceRoomCom1->text().trimmed(); }
|
||||
@@ -70,8 +71,8 @@ namespace BlackGui
|
||||
|
||||
void CVoiceRoomsComponent::setVoiceRoomUrlFieldsReadOnlyState()
|
||||
{
|
||||
bool c1 = ui->cb_CockpitVoiceRoom1Override->isChecked();
|
||||
bool c2 = ui->cb_CockpitVoiceRoom2Override->isChecked();
|
||||
const bool c1 = ui->cb_CockpitVoiceRoom1Override->isChecked();
|
||||
const bool c2 = ui->cb_CockpitVoiceRoom2Override->isChecked();
|
||||
ui->le_CockpitVoiceRoomCom1->setReadOnly(!c1);
|
||||
ui->le_CockpitVoiceRoomCom2->setReadOnly(!c2);
|
||||
CGuiUtility::forceStyleSheetUpdate(this);
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QStringBuilder>
|
||||
#include <Qt>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
|
||||
CVoiceRoom::CVoiceRoom(const QString &voiceRoomUrl, bool connected) :
|
||||
m_connected(connected), m_audioPlaying(false)
|
||||
{
|
||||
@@ -28,83 +28,61 @@ namespace BlackMisc
|
||||
CVariant CVoiceRoom::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAudioPlaying:
|
||||
return CVariant::from(this->isAudioPlaying());
|
||||
case IndexConnected:
|
||||
return CVariant::from(this->isConnected());
|
||||
case IndexChannel:
|
||||
return CVariant::from(this->getChannel());
|
||||
case IndexHostname:
|
||||
return CVariant::from(this->getHostname());
|
||||
case IndexUrl:
|
||||
return CVariant::from(this->getVoiceRoomUrl());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
case IndexAudioPlaying: return CVariant::from(this->isAudioPlaying());
|
||||
case IndexConnected: return CVariant::from(this->isConnected());
|
||||
case IndexChannel: return CVariant::from(this->getChannel());
|
||||
case IndexHostname: return CVariant::from(this->getHostname());
|
||||
case IndexUrl: return CVariant::from(this->getVoiceRoomUrl());
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CVoiceRoom::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CVoiceRoom>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAudioPlaying:
|
||||
this->setAudioPlaying(variant.toBool());
|
||||
break;
|
||||
case IndexConnected:
|
||||
this->setConnected(variant.toBool());
|
||||
break;
|
||||
case IndexChannel:
|
||||
this->setChannel(variant.value<QString>());
|
||||
break;
|
||||
case IndexHostname:
|
||||
this->setHostName(variant.value<QString>());
|
||||
break;
|
||||
case IndexUrl:
|
||||
this->setVoiceRoomUrl(variant.value<QString>());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
case IndexAudioPlaying: this->setAudioPlaying(variant.toBool()); break;
|
||||
case IndexConnected: this->setConnected(variant.toBool()); break;
|
||||
case IndexChannel: this->setChannel(variant.value<QString>()); break;
|
||||
case IndexHostname: this->setHostName(variant.value<QString>()); break;
|
||||
case IndexUrl: this->setVoiceRoomUrl(variant.value<QString>()); break;
|
||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CVoiceRoom::convertToQString(bool /* i18n */) const
|
||||
QString CVoiceRoom::convertToQString(bool i18n) const
|
||||
{
|
||||
if (!this->isValid()) return "Invalid";
|
||||
QString s = this->getVoiceRoomUrl(false);
|
||||
s.append(this->isConnected() ? " connected" : " unconnected");
|
||||
if (this->m_audioPlaying) s.append(" playing");
|
||||
return s;
|
||||
Q_UNUSED(i18n);
|
||||
if (!this->isValid()) { return QStringLiteral("Invalid"); }
|
||||
return this->getVoiceRoomUrl(false) %
|
||||
(this->isConnected() ? u" connected" : u" unconnected") %
|
||||
(m_audioPlaying ? u" playing" : u"");
|
||||
}
|
||||
|
||||
QString CVoiceRoom::getVoiceRoomUrl(bool noProtocol) const
|
||||
{
|
||||
if (!this->isValid()) return {};
|
||||
QString url(noProtocol ? "" : CVoiceRoom::protocolComplete());
|
||||
url.append(this->m_hostname);
|
||||
url.append("/");
|
||||
url.append(this->m_channel);
|
||||
return url;
|
||||
if (!this->isValid()) { return {}; }
|
||||
return (noProtocol ? QStringLiteral("") : CVoiceRoom::protocolComplete()) % m_hostname % u"/" % m_channel;
|
||||
}
|
||||
|
||||
void CVoiceRoom::setVoiceRoomUrl(const QString &serverUrl)
|
||||
{
|
||||
if (serverUrl.isEmpty())
|
||||
{
|
||||
m_hostname = "";
|
||||
m_channel = "";
|
||||
m_hostname.clear();
|
||||
m_channel.clear();
|
||||
}
|
||||
else if (serverUrl.contains("/"))
|
||||
{
|
||||
QString url = serverUrl.trimmed().toLower();
|
||||
url.replace(CVoiceRoom::protocolComplete(), "");
|
||||
url.replace(CVoiceRoom::protocol(), "");
|
||||
QStringList splitParts = url.split("/");
|
||||
const QStringList splitParts = url.split("/");
|
||||
m_hostname = splitParts.at(0);
|
||||
m_channel = splitParts.at(1);
|
||||
}
|
||||
@@ -112,7 +90,7 @@ namespace BlackMisc
|
||||
|
||||
bool CVoiceRoom::isAtis() const
|
||||
{
|
||||
return (this->m_channel.contains("ATIS", Qt::CaseInsensitive));
|
||||
return (m_channel.contains("ATIS", Qt::CaseInsensitive));
|
||||
}
|
||||
} // Voice
|
||||
} // BlackMisc
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace BlackSound
|
||||
const int bytesForAllChannels = m_audioFormat.channelCount() * bytesPerSample;
|
||||
|
||||
qint64 totalLength = 0;
|
||||
foreach(Tone t, m_tones)
|
||||
for (const Tone &t : m_tones)
|
||||
{
|
||||
totalLength += m_audioFormat.sampleRate() * bytesForAllChannels * t.m_durationMs / 1000;
|
||||
}
|
||||
@@ -175,10 +175,10 @@ namespace BlackSound
|
||||
Q_ASSERT(totalLength % bytesForAllChannels == 0);
|
||||
Q_UNUSED(bytesForAllChannels) // suppress warning in release builds
|
||||
|
||||
m_buffer.resize(totalLength);
|
||||
m_buffer.resize(static_cast<int>(totalLength)); // potentially dangerous cast, but I see no use case where the int range on any of our platforms is exceeded
|
||||
unsigned char *bufferPointer = reinterpret_cast<unsigned char *>(m_buffer.data()); // clazy:exclude=detaching-member
|
||||
|
||||
foreach(Tone t, m_tones)
|
||||
for (const Tone &t : m_tones)
|
||||
{
|
||||
qint64 bytesPerTone = m_audioFormat.sampleRate() * bytesForAllChannels * t.m_durationMs / 1000;
|
||||
qint64 last0AmplitudeSample = bytesPerTone; // last sample when amplitude was 0
|
||||
@@ -296,35 +296,31 @@ namespace BlackSound
|
||||
|
||||
// RIFF header
|
||||
if (m_audioFormat.byteOrder() == QAudioFormat::LittleEndian)
|
||||
{
|
||||
memcpy(&header.riff.descriptor.id[0], "RIFF", 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&header.riff.descriptor.id[0], "RIFX", 4);
|
||||
}
|
||||
|
||||
qToLittleEndian<quint32>(quint32(m_buffer.size() + headerLength - 8),
|
||||
qToLittleEndian<quint32>(quint32(static_cast<uint>(m_buffer.size()) + headerLength - 8),
|
||||
reinterpret_cast<unsigned char *>(&header.riff.descriptor.size));
|
||||
memcpy(&header.riff.type[0], "WAVE", 4);
|
||||
|
||||
// WAVE header
|
||||
memcpy(&header.wave.descriptor.id[0], "fmt ", 4);
|
||||
qToLittleEndian<quint32>(quint32(16),
|
||||
reinterpret_cast<unsigned char *>(&header.wave.descriptor.size));
|
||||
qToLittleEndian<quint16>(quint16(1),
|
||||
reinterpret_cast<unsigned char *>(&header.wave.audioFormat));
|
||||
qToLittleEndian<quint16>(quint16(m_audioFormat.channelCount()),
|
||||
reinterpret_cast<unsigned char *>(&header.wave.numChannels));
|
||||
qToLittleEndian<quint32>(quint32(m_audioFormat.sampleRate()),
|
||||
reinterpret_cast<unsigned char *>(&header.wave.sampleRate));
|
||||
qToLittleEndian<quint32>(quint32(m_audioFormat.sampleRate() * m_audioFormat.channelCount() * m_audioFormat.sampleSize() / 8),
|
||||
reinterpret_cast<unsigned char *>(&header.wave.byteRate));
|
||||
qToLittleEndian<quint16>(quint16(m_audioFormat.channelCount() * m_audioFormat.sampleSize() / 8),
|
||||
reinterpret_cast<unsigned char *>(&header.wave.blockAlign));
|
||||
qToLittleEndian<quint16>(quint16(m_audioFormat.sampleSize()),
|
||||
reinterpret_cast<unsigned char *>(&header.wave.bitsPerSample));
|
||||
qToLittleEndian<quint32>(quint32(16), reinterpret_cast<unsigned char *>(&header.wave.descriptor.size));
|
||||
qToLittleEndian<quint16>(quint16(1), reinterpret_cast<unsigned char *>(&header.wave.audioFormat));
|
||||
qToLittleEndian<quint16>(quint16(m_audioFormat.channelCount()), reinterpret_cast<unsigned char *>(&header.wave.numChannels));
|
||||
qToLittleEndian<quint32>(quint32(m_audioFormat.sampleRate()), reinterpret_cast<unsigned char *>(&header.wave.sampleRate));
|
||||
qToLittleEndian<quint32>(quint32(m_audioFormat.sampleRate() * m_audioFormat.channelCount() * m_audioFormat.sampleSize() / 8), reinterpret_cast<unsigned char *>(&header.wave.byteRate));
|
||||
qToLittleEndian<quint16>(quint16(m_audioFormat.channelCount() * m_audioFormat.sampleSize() / 8), reinterpret_cast<unsigned char *>(&header.wave.blockAlign));
|
||||
qToLittleEndian<quint16>(quint16(m_audioFormat.sampleSize()), reinterpret_cast<unsigned char *>(&header.wave.bitsPerSample));
|
||||
|
||||
// DATA header
|
||||
memcpy(&header.data.descriptor.id[0], "data", 4);
|
||||
qToLittleEndian<quint32>(quint32(m_buffer.size()),
|
||||
reinterpret_cast<unsigned char *>(&header.data.descriptor.size));
|
||||
qToLittleEndian<quint32>(quint32(m_buffer.size()), reinterpret_cast<unsigned char *>(&header.data.descriptor.size));
|
||||
|
||||
success = file.write(reinterpret_cast<const char *>(&header), headerLength) == headerLength;
|
||||
success = success && file.write(m_buffer) == m_buffer.size();
|
||||
@@ -336,7 +332,7 @@ namespace BlackSound
|
||||
{
|
||||
if (tones.isEmpty()) { return 0; }
|
||||
qint64 d = 0;
|
||||
foreach(Tone t, tones)
|
||||
for (const Tone &t : tones)
|
||||
{
|
||||
d += t.m_durationMs;
|
||||
}
|
||||
@@ -356,7 +352,7 @@ namespace BlackSound
|
||||
while (len - total > 0)
|
||||
{
|
||||
const qint64 chunkSize = qMin((m_buffer.size() - m_position), (len - total));
|
||||
memcpy(data + total, m_buffer.constData() + m_position, chunkSize);
|
||||
memcpy(data + total, m_buffer.constData() + m_position, static_cast<size_t>(chunkSize));
|
||||
m_position = (m_position + chunkSize) % m_buffer.size();
|
||||
total += chunkSize;
|
||||
if (m_position == 0 &&
|
||||
|
||||
Reference in New Issue
Block a user