Fixed clazy warnings: pass large objects by reference to const.

This commit is contained in:
Mat Sutcliffe
2018-12-17 16:43:54 +00:00
parent e40af8132c
commit 9f85a7b560
27 changed files with 49 additions and 47 deletions

View File

@@ -523,7 +523,7 @@ namespace BlackCore
return this->getInfoObjectCount(entity, m_sharedInfoDataReader);
}
QString CWebDataServices::getDbReadersLog(const QString separator) const
QString CWebDataServices::getDbReadersLog(const QString &separator) const
{
QStringList report;
if (m_dbInfoDataReader) { report << m_dbInfoDataReader->getName() + ": " + m_dbInfoDataReader->getReadLog().getSummary(); }
@@ -536,7 +536,7 @@ namespace BlackCore
return report.join(separator);
}
QString CWebDataServices::getReadersLog(const QString separator) const
QString CWebDataServices::getReadersLog(const QString &separator) const
{
const QString db = this->getDbReadersLog(separator);
QStringList report;

View File

@@ -445,10 +445,10 @@ namespace BlackCore
int getSharedInfoObjectCount(BlackMisc::Network::CEntityFlags::Entity entity) const;
//! For all available DB readers the log info is generated
QString getDbReadersLog(const QString separator = "\n") const;
QString getDbReadersLog(const QString &separator = "\n") const;
//! For all available readers the log info is generated
QString getReadersLog(const QString separator = "\n") const;
QString getReadersLog(const QString &separator = "\n") const;
//! Has already successfully connect swift DB?
bool hasSuccesfullyConnectedSwiftDb() const;

View File

@@ -142,13 +142,13 @@ namespace BlackGui
ui->tvp_StashAircraftModels->updateContainerMaybeAsync(models);
}
int CDbStashComponent::unstashModels(QSet<int> keys)
int CDbStashComponent::unstashModels(const QSet<int> &keys)
{
if (keys.isEmpty()) { return 0; }
return ui->tvp_StashAircraftModels->removeDbKeys(keys);
}
int CDbStashComponent::unstashModels(QStringList modelStrings)
int CDbStashComponent::unstashModels(const QStringList &modelStrings)
{
if (modelStrings.isEmpty()) { return 0; }
return ui->tvp_StashAircraftModels->removeModelsWithModelString(modelStrings);

View File

@@ -74,10 +74,10 @@ namespace BlackGui
BlackMisc::CStatusMessage validateStashModel(const BlackMisc::Simulation::CAircraftModel &model, bool allowReplace) const;
//! Unstash given models with keys
int unstashModels(QSet<int> keys);
int unstashModels(const QSet<int> &keys);
//! Unstash given models by model string
int unstashModels(QStringList modelStrings);
int unstashModels(const QStringList &modelStrings);
//! Unstash given models
int unstashModels(const BlackMisc::Simulation::CAircraftModelList &models);

View File

@@ -179,7 +179,7 @@ namespace BlackGui
ui->tw_SpecializedViews->setCurrentIndex(tabIndex);
}
CAircraftModelList CMappingComponent::findModelsStartingWith(const QString modelName, Qt::CaseSensitivity cs)
CAircraftModelList CMappingComponent::findModelsStartingWith(const QString &modelName, Qt::CaseSensitivity cs)
{
Q_ASSERT(ui->tvp_AircraftModels);
return ui->tvp_AircraftModels->container().findModelsStartingWith(modelName, cs);

View File

@@ -84,7 +84,7 @@ namespace BlackGui
void setTab(TabWidget tab);
//! Find models starting with
BlackMisc::Simulation::CAircraftModelList findModelsStartingWith(const QString modelName, Qt::CaseSensitivity cs);
BlackMisc::Simulation::CAircraftModelList findModelsStartingWith(const QString &modelName, Qt::CaseSensitivity cs);
signals:
//! Request a text message

View File

@@ -293,7 +293,7 @@ namespace BlackGui
styleSheet;
}
bool CTextMessageComponent::isCorrespondingTextMessageTabSelected(CTextMessage textMessage) const
bool CTextMessageComponent::isCorrespondingTextMessageTabSelected(const CTextMessage &textMessage) const
{
if (!this->isVisibleWidgetHack()) { return false; }
if (!textMessage.hasValidRecipient()) { return false; }

View File

@@ -100,7 +100,7 @@ namespace BlackGui
void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const;
//! Command line was entered
void commandEntered(const QString commandLine, const BlackMisc::CIdentifier &originator);
void commandEntered(const QString &commandLine, const BlackMisc::CIdentifier &originator);
private:
QScopedPointer<Ui::CTextMessageComponent> ui;
@@ -137,7 +137,7 @@ namespace BlackGui
BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const;
//! For this text message's recepient, is the current tab selected?
bool isCorrespondingTextMessageTabSelected(BlackMisc::Network::CTextMessage textMessage) const;
bool isCorrespondingTextMessageTabSelected(const BlackMisc::Network::CTextMessage &textMessage) const;
//! Network connected?
bool isNetworkConnected() const;

View File

@@ -103,7 +103,7 @@ namespace BlackGui
Q_UNUSED(paintEvent);
}
void CValidationIndicator::setBackgroundColor(const QString colorName)
void CValidationIndicator::setBackgroundColor(const QString &colorName)
{
if (colorName.isEmpty())
{

View File

@@ -72,7 +72,7 @@ namespace BlackGui
QScopedPointer<Ui::CValidationIndicator> ui;
//! Set background color
void setBackgroundColor(const QString colorName);
void setBackgroundColor(const QString &colorName);
QTimer m_resetTimer; //!< reset to neutral
QString m_originalStyleSheet; //!< stored, to be able to reset

View File

@@ -259,7 +259,7 @@ namespace BlackGui
{
public:
//! Constructor
CValueObjectFormatter(int alignment = alignDefault(), bool i18n = true, QList<int> supportedRoles = roleDisplay()) : CDefaultFormatter(alignment, i18n, supportedRoles) {}
CValueObjectFormatter(int alignment = alignDefault(), bool i18n = true, const QList<int> &supportedRoles = roleDisplay()) : CDefaultFormatter(alignment, i18n, supportedRoles) {}
//! \copydoc CDefaultFormatter::displayRole
virtual BlackMisc::CVariant displayRole(const BlackMisc::CVariant &valueObject) const override;
@@ -344,7 +344,7 @@ namespace BlackGui
{
public:
//! Constructor
CPhysiqalQuantiyFormatter(MU unit = MU::defaultUnit(), int digits = 2, int alignment = alignRightVCenter(), bool withUnit = true, bool i18n = true, QList<int> supportedRoles = roleDisplay()) : CValueObjectFormatter(alignment, i18n, supportedRoles), m_unit(unit), m_digits(digits), m_withUnit(withUnit) {}
CPhysiqalQuantiyFormatter(MU unit = MU::defaultUnit(), int digits = 2, int alignment = alignRightVCenter(), bool withUnit = true, bool i18n = true, const QList<int> &supportedRoles = roleDisplay()) : CValueObjectFormatter(alignment, i18n, supportedRoles), m_unit(unit), m_digits(digits), m_withUnit(withUnit) {}
//! \copydoc BlackGui::Models::CDefaultFormatter::displayRole
virtual BlackMisc::CVariant displayRole(const BlackMisc::CVariant &physicalQuantity) const override

View File

@@ -101,7 +101,7 @@ namespace BlackGui
{
if (messages.isEmpty()) { return ""; }
QString html("<table>");
for (CTextMessage msg : messages)
for (const CTextMessage &msg : messages)
{
html += toHtml(msg, withFrom, withTo);
}

View File

@@ -119,7 +119,7 @@ namespace BlackInput
}
}
for (CJoystickDeviceInput input : m_joystickDeviceInputs)
for (const CJoystickDeviceInput &input : m_joystickDeviceInputs)
{
const qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0;
bool isPressed = state.rgbButtons[buttonIndex] & 0x80;

View File

@@ -83,7 +83,7 @@ namespace BlackMisc
return this->getApplication() == Unknown && m_exePath.isNull();
}
QString CApplicationInfo::asOtherSwiftVersionString(const QString separator) const
QString CApplicationInfo::asOtherSwiftVersionString(const QString &separator) const
{
return QStringLiteral("Version; ") % this->getVersionString() % QStringLiteral(" os: ") % this->getPlatform() % separator %
QStringLiteral("exe.path: ") % this->getExecutablePath() % separator %

View File

@@ -129,7 +129,7 @@ namespace BlackMisc
bool isNull() const;
//! Formatted info
QString asOtherSwiftVersionString(const QString separator = " | ") const;
QString asOtherSwiftVersionString(const QString &separator = " | ") const;
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;

View File

@@ -110,13 +110,13 @@ namespace BlackMisc
return connection.name().contains(p2pConnectionName());
}
bool CDBusServer::dBusAddressToHostAndPort(QString address, QString &host, int &port)
bool CDBusServer::dBusAddressToHostAndPort(const QString &address, QString &host, int &port)
{
address = address.trimmed().toLower().replace(' ', "");
if (address.contains("host=") || address.contains("port="))
const QString canonicalAddress = address.trimmed().toLower().replace(' ', "");
if (canonicalAddress.contains("host=") || canonicalAddress.contains("port="))
{
// "tcp:host=foo.com,port=123"
const QStringList parts(address.split(','));
const QStringList parts(canonicalAddress.split(','));
for (const QString &part : parts)
{
// "host=" or "tcp:host="
@@ -145,7 +145,7 @@ namespace BlackMisc
}
}
bool CDBusServer::dBusAddressToHostAndPort(QString dbusAddress, QString &o_host, QString &o_port)
bool CDBusServer::dBusAddressToHostAndPort(const QString &dbusAddress, QString &o_host, QString &o_port)
{
int port;
const bool s = dBusAddressToHostAndPort(dbusAddress, o_host, port);

View File

@@ -126,10 +126,10 @@ namespace BlackMisc
static bool isP2PConnection(const QDBusConnection &connection);
//! Extract host and port from a DBus address
static bool dBusAddressToHostAndPort(QString dbusAddress, QString &o_host, int &o_port);
static bool dBusAddressToHostAndPort(const QString &dbusAddress, QString &o_host, int &o_port);
//! Extract host and port from a DBus address
static bool dBusAddressToHostAndPort(QString dbusAddress, QString &o_host, QString &o_port);
static bool dBusAddressToHostAndPort(const QString &dbusAddress, QString &o_host, QString &o_port);
//! Is the given connection one of the default connections?
static bool isQtDefaultConnection(const QDBusConnection &connection);

View File

@@ -82,7 +82,7 @@ namespace BlackMisc
return encryptToByteArray(plaintextArray);
}
QByteArray SimpleCrypt::encryptToByteArray(QByteArray plaintext)
QByteArray SimpleCrypt::encryptToByteArray(const QByteArray &plaintext)
{
if (m_keyParts.isEmpty())
{
@@ -159,7 +159,7 @@ namespace BlackMisc
return cypherString;
}
QString SimpleCrypt::encryptToString(QByteArray plaintext)
QString SimpleCrypt::encryptToString(const QByteArray &plaintext)
{
QByteArray cypher = encryptToByteArray(plaintext);
QString cypherString = QString::fromLatin1(cypher.toBase64());
@@ -175,7 +175,7 @@ namespace BlackMisc
return plaintext;
}
QString SimpleCrypt::decryptToString(QByteArray cypher)
QString SimpleCrypt::decryptToString(const QByteArray &cypher)
{
QByteArray ba = decryptToByteArray(cypher);
QString plaintext = QString::fromUtf8(ba, ba.size());
@@ -191,7 +191,7 @@ namespace BlackMisc
return ba;
}
QByteArray SimpleCrypt::decryptToByteArray(QByteArray cypher)
QByteArray SimpleCrypt::decryptToByteArray(const QByteArray &cypher)
{
if (m_keyParts.isEmpty())
{

View File

@@ -147,7 +147,7 @@ namespace BlackMisc
a cyphertext the result. The result is a base64 encoded version of the binary array that is the
actual result of the encryption, so it can be stored easily in a text format.
*/
QString encryptToString(QByteArray plaintext) ;
QString encryptToString(const QByteArray &plaintext) ;
/**
Encrypts the @arg plaintext string with the key the class was initialized with, and returns
@@ -165,7 +165,7 @@ namespace BlackMisc
This method returns a byte array, that is useable for storing a binary format. If you need
a string you can store in a text file, use encryptToString() instead.
*/
QByteArray encryptToByteArray(QByteArray plaintext) ;
QByteArray encryptToByteArray(const QByteArray &plaintext) ;
/**
Decrypts a cyphertext string encrypted with this class with the set key back to the
@@ -192,7 +192,7 @@ namespace BlackMisc
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QString decryptToString(QByteArray cypher) ;
QString decryptToString(const QByteArray &cypher) ;
/**
Decrypts a cyphertext binary encrypted with this class with the set key back to the
@@ -201,7 +201,7 @@ namespace BlackMisc
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QByteArray decryptToByteArray(QByteArray cypher) ;
QByteArray decryptToByteArray(const QByteArray &cypher) ;
/**
Enum to describe options that have been used for the encryption. Currently only one, but

View File

@@ -608,7 +608,7 @@ namespace BlackMisc
struct CValuePage::Element
{
Element(const QString &key, const QString &name, int metaType, Validator validator, const CVariant &defaultValue) :
Element(const QString &key, const QString &name, int metaType, const Validator &validator, const CVariant &defaultValue) :
m_key(key), m_name(name), m_metaType(metaType), m_validator(validator), m_default(defaultValue)
{}
const QString m_key;
@@ -624,7 +624,7 @@ namespace BlackMisc
bool m_saved = false;
};
CValuePage::Element &CValuePage::createElement(const QString &keyTemplate, const QString &name, int metaType, Validator validator, const CVariant &defaultValue)
CValuePage::Element &CValuePage::createElement(const QString &keyTemplate, const QString &name, int metaType, const Validator &validator, const CVariant &defaultValue)
{
if (parent()->objectName().isEmpty() && keyTemplate.contains("%OwnerName%"))
{
@@ -667,7 +667,7 @@ namespace BlackMisc
return element;
}
void CValuePage::setNotifySlot(Element &element, NotifySlot slot)
void CValuePage::setNotifySlot(Element &element, const NotifySlot &slot)
{
element.m_notifySlot = slot;
}

View File

@@ -456,7 +456,7 @@ namespace BlackMisc
protected:
//! \private Connect a function to be called (only once) when the owner's objectName changes.
void onOwnerNameChanged(std::function<void()> function)
void onOwnerNameChanged(const std::function<void()> &function)
{
connectOnce(m_page->parent(), &QObject::objectNameChanged, [function](const QString &) { function(); });
}

View File

@@ -84,10 +84,10 @@ namespace BlackMisc
//! \param metaType The Qt metatype ID of the value object's expected type.
//! \param validator Optional functor which returns true if the value is valid.
//! \param defaultValue Optional value which is used in case the value is invalid.
Element &createElement(const QString &key, const QString &name, int metaType, Validator validator, const CVariant &defaultValue);
Element &createElement(const QString &key, const QString &name, int metaType, const Validator &validator, const CVariant &defaultValue);
//! Set the functor to call to notify that the value corresponding to the element's key was modified.
void setNotifySlot(Element &element, NotifySlot slot);
void setNotifySlot(Element &element, const NotifySlot &slot);
//! True if the currently paged value corresponds to a valid key.
bool isInitialized(const Element &element) const;

View File

@@ -59,7 +59,7 @@ namespace BlackMisc
Q_UNUSED(ok);
}
CWorker *CWorker::fromTaskImpl(QObject *owner, const QString &name, int typeId, std::function<CVariant()> task)
CWorker *CWorker::fromTaskImpl(QObject *owner, const QString &name, int typeId, const std::function<CVariant()> &task)
{
auto *worker = new CWorker(task);
emit worker->aboutToStart();

View File

@@ -268,8 +268,8 @@ namespace BlackMisc
void ps_runTask();
private:
CWorker(std::function<CVariant()> task) : m_task(task) {}
static CWorker *fromTaskImpl(QObject *owner, const QString &name, int typeId, std::function<CVariant()> task);
CWorker(const std::function<CVariant()> &task) : m_task(task) {}
static CWorker *fromTaskImpl(QObject *owner, const QString &name, int typeId, const std::function<CVariant()> &task);
template <typename R>
R resultNoWait() { Q_ASSERT(m_result.canConvert<R>()); return m_result.value<R>(); }

View File

@@ -387,7 +387,7 @@ namespace BlackSimPlugin
},
Qt::QueuedConnection));
m_connectionGuard.append(connect(this, &ISimulator::ownAircraftModelChanged, this, [ = ](CAircraftModel model)
m_connectionGuard.append(connect(this, &ISimulator::ownAircraftModelChanged, this, [ = ](const CAircraftModel &model)
{
if (!m_monitorWidget) return;
m_monitorWidget->appendSendingCall("ownAircraftModelChanged", model.toQString());

View File

@@ -16,6 +16,8 @@
#include <SimConnect.h>
#include <array>
// clazy:excludeall=function-args-by-ref
using namespace BlackMisc;
bool loadAndResolveSimConnect(bool manifestProbing)

View File

@@ -171,7 +171,7 @@ namespace BlackCoreTest
mutable ConnectGuard m_guard;
mutable std::function<void(const ExpectUnit *)> m_onDone;
void onDone(std::function<void(const ExpectUnit *)> callback) const { m_onDone = callback; }
void onDone(const std::function<void(const ExpectUnit *)> &callback) const { m_onDone = callback; }
// Helper traits class. Given T is a pointer-to-member-of-U, ClassOf<T>::type is U.
template <class T> struct ClassOf;