Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require C++17, port from deprecated qAsConst to std::as_const #290

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(TARGET Qt6::Core)
set(CMAKE_CXX_STANDARD 17)
endif()

# Default to hidden visibility for symbols
set(CMAKE_C_VISIBILITY_PRESET hidden)
Expand Down
7 changes: 0 additions & 7 deletions examples/bank_gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
#include <QString>
#include <QTableWidget>
#include <QVBoxLayout>

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // We enable C++17 with Qt6, and std::random_shuffle is gone in 17
#include <random>
#endif

#include <algorithm>

Expand Down Expand Up @@ -91,13 +88,9 @@ MainWindow::MainWindow(QWidget *parent)

void MainWindow::clearResults()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // We enable C++17 with Qt6, and std::random_shuffle is gone in 17
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(mBankCodes.begin(), mBankCodes.end(), g);
#else
std::random_shuffle(mBankCodes.begin(), mBankCodes.end());
#endif
for (int row = 0; row < mBankCodes.count(); ++row) {
auto *item = new QTableWidgetItem(mBankCodes.at(row));
mTableWidget->setItem(row, Columns::Code, item);
Expand Down
12 changes: 6 additions & 6 deletions kdwsdl2cpp/src/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TypeCollector
void registerDerivedClasses()
{
XSD::ComplexType::List complexTypes = m_allTypes.complexTypes();
for (const XSD::ComplexType &derivedType : qAsConst(complexTypes)) {
for (const XSD::ComplexType &derivedType : std::as_const(complexTypes)) {
const QName base = derivedType.baseTypeName();
if (!base.isEmpty()) {
// Look for the base class and register type. Linear search, maybe we should use a QHash...
Expand All @@ -120,7 +120,7 @@ class TypeCollector
QSet<QName> typesToProcess = m_allUsedTypes;
do {
m_alsoUsedTypes.clear();
for (const QName &typeName : qAsConst(typesToProcess)) {
for (const QName &typeName : std::as_const(typesToProcess)) {
if (typeName.isEmpty()) {
continue;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ class MessageCollector
PortType portType = wsdl.findPortType(binding.portTypeName());
const Operation::List operations = portType.operations();
// qDebug() << "portType" << portType.name() << operations.count() << "operations";
for (const Operation &operation : qAsConst(operations)) {
for (const Operation &operation : std::as_const(operations)) {
// qDebug() << " operation" << operation.operationType() << operation.name();
switch (operation.operationType()) {
case Operation::OneWayOperation:
Expand Down Expand Up @@ -298,7 +298,7 @@ void Converter::cleanupUnusedTypes()
QSet<QString> usedTypesStrings; // for debug
QSet<QName> usedElementNames;
Message::List newMessages;
for (const QName &messageName : qAsConst(usedMessageNames)) {
for (const QName &messageName : std::as_const(usedMessageNames)) {
// qDebug() << "used message:" << messageName;
Message message = mWSDL.findMessage(messageName);
newMessages.append(message);
Expand Down Expand Up @@ -395,13 +395,13 @@ void Converter::convertTypes()

XSD::SimpleType::List simpleTypes = types.simpleTypes();
qDebug() << "Converting" << simpleTypes.count() << "simple types";
for (const XSD::SimpleType &simpleType : qAsConst(simpleTypes)) {
for (const XSD::SimpleType &simpleType : std::as_const(simpleTypes)) {
convertSimpleType(&simpleType, simpleTypes);
}

XSD::ComplexType::List complexTypes = types.complexTypes();
qDebug() << "Converting" << complexTypes.count() << "complex types";
for (const XSD::ComplexType &complexType : qAsConst(complexTypes)) {
for (const XSD::ComplexType &complexType : std::as_const(complexTypes)) {
convertComplexType(&complexType);
}
}
Expand Down
12 changes: 6 additions & 6 deletions kdwsdl2cpp/src/converter_clientstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool Converter::convertClientService()
QSet<QName> uniqueBindings = mWSDL.uniqueBindings(service);
// qDebug() << "Looking at" << service.name() << uniqueBindings;

for (const QName &bindingName : qAsConst(uniqueBindings)) {
for (const QName &bindingName : std::as_const(uniqueBindings)) {
const Binding binding = mWSDL.findBinding(bindingName);

QString className = KODE::Style::className(service.name());
Expand Down Expand Up @@ -360,7 +360,7 @@ bool Converter::convertClientService()
}
} // end of for each operation

for (const SoapBinding::Header &header : qAsConst(soapHeaders)) {
for (const SoapBinding::Header &header : std::as_const(soapHeaders)) {
createHeader(header, newClass);
}
bindingClasses.append(newClass);
Expand All @@ -374,7 +374,7 @@ bool Converter::convertClientService()
}

// for each operation, create a job class
for (const Operation &operation : qAsConst(operations)) {
for (const Operation &operation : std::as_const(operations)) {
Operation::OperationType opType = operation.operationType();
if (opType != Operation::SolicitResponseOperation && opType != Operation::RequestResponseOperation) {
continue;
Expand Down Expand Up @@ -495,7 +495,7 @@ bool Converter::convertClientService()
slotCode += QLatin1String("_reply = _reply.childValues().at(0);") + COMMENT;
}

for (const Part &part : qAsConst(outputParts)) {
for (const Part &part : std::as_const(outputParts)) {
const QString varName = mNameMapper.escape(QLatin1String("result") + upperlize(part.name()));
const KODE::MemberVariable member(varName, QString());
slotCode.addBlock(
Expand All @@ -504,7 +504,7 @@ bool Converter::convertClientService()
addJobResultMember(jobClass, part, varName, inputGetters);
}
}
for (const SoapBinding::Header &header : qAsConst(outputHeaders)) {
for (const SoapBinding::Header &header : std::as_const(outputHeaders)) {
const QName messageName = header.message();
const QString partName = header.part();
const Message message = mWSDL.findMessage(messageName);
Expand Down Expand Up @@ -761,7 +761,7 @@ bool Converter::convertClientCall(const Operation &operation, const Binding &bin
code.unindent();
Q_ASSERT(soapStyle(binding) == SoapBinding::DocumentStyle); // RPC with multiple return values? impossible, we generate a single wrapper

for (const Part &part : qAsConst(outParts)) {
for (const Part &part : std::as_const(outParts)) {
const QString argType = mTypeMap.localType(part.type(), part.element());
Q_ASSERT(!argType.isEmpty());
const QString lowerName = lowerlize(part.name());
Expand Down
8 changes: 4 additions & 4 deletions kdwsdl2cpp/src/converter_complextype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ void Converter::createComplexTypeSerializer(KODE::Class &newClass, const XSD::Co
if (elements.at(0).isQualified()) {
marshalCode += QLatin1String("mainValue.setQualified(true);") + COMMENT;
}
demarshalCode += "for (const KDSoapValue& val : qAsConst(args)) {";
demarshalCode += "for (const KDSoapValue& val : std::as_const(args)) {";
demarshalCode.indent();
demarshalCode += "const QString _name = val.name();";
} else {
Expand Down Expand Up @@ -614,7 +614,7 @@ void Converter::createComplexTypeSerializer(KODE::Class &newClass, const XSD::Co
demarshalCode.addBlock(deserializer.demarshalArray("val"));
} else {
bool first = true;
for (const XSD::Element &elem : qAsConst(elements)) {
for (const XSD::Element &elem : std::as_const(elements)) {

const QString elemName = elem.name();
const QString typeName = mTypeMap.localType(elem.type());
Expand Down Expand Up @@ -688,12 +688,12 @@ void Converter::createComplexTypeSerializer(KODE::Class &newClass, const XSD::Co
marshalCode += "KDSoapValueList attribs;";

demarshalCode += "const QList<KDSoapValue> attribs = args.attributes();";
demarshalCode += "for (const KDSoapValue& val : qAsConst(attribs)) {";
demarshalCode += "for (const KDSoapValue& val : std::as_const(attribs)) {";
demarshalCode.indent();
demarshalCode += "const QString _name = val.name();";

bool first = true;
for (const XSD::Attribute &attribute : qAsConst(attributes)) {
for (const XSD::Attribute &attribute : std::as_const(attributes)) {
const QString attrName = attribute.name();
if (attrName.isEmpty()) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions kdwsdl2cpp/src/converter_serverstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Converter::convertServerService()

QSet<QName> uniqueBindings = mWSDL.uniqueBindings(service);

for (const QName &bindingName : qAsConst(uniqueBindings)) {
for (const QName &bindingName : std::as_const(uniqueBindings)) {
// qDebug() << "binding" << bindingName;
const Binding binding = mWSDL.findBinding(bindingName);

Expand Down Expand Up @@ -161,7 +161,7 @@ void Converter::generateServerMethod(KODE::Code &code, const Binding &binding, c
// bool isBuiltin = false;
// bool isComplex = false;
Part retPart;
for (const Part &outPart : qAsConst(outParts) /* only one */) {
for (const Part &outPart : std::as_const(outParts) /* only one */) {
retType = mTypeMap.localType(outPart.type(), outPart.element());
retInputType = mTypeMap.localInputType(outPart.type(), outPart.element());
// isBuiltin = mTypeMap.isBuiltinType( outPart.type(), outPart.element() );
Expand Down
4 changes: 2 additions & 2 deletions kdwsdl2cpp/src/converter_simpletype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void Converter::convertSimpleType(const XSD::SimpleType *type, const XSD::Simple
baseCtor.addArgument(mTypeMap.localInputType(currentType, QName()) + " value");
QString beginLine = "setValue(";
QString endLine = ")";
for (const QName &base : qAsConst(parentBasicTypes)) {
for (const QName &base : std::as_const(parentBasicTypes)) {
beginLine += mTypeMap.localType(base) + '(';
endLine += ')';
}
Expand Down Expand Up @@ -294,7 +294,7 @@ void Converter::createSimpleTypeSerializer(KODE::Class &newClass, const XSD::Sim
const QStringList enums = type->facetEnums();
NameMapper nameMapper;
QStringList escapedEnums;
for (const QString &facetEnum : qAsConst(enums)) {
for (const QString &facetEnum : std::as_const(enums)) {
escapedEnums.append(nameMapper.escape(escapeEnum(facetEnum)));
}

Expand Down
2 changes: 1 addition & 1 deletion kdwsdl2cpp/src/creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Creator::setImplementationFileName(const QString &implementationFileName)

void Creator::setClasses(const KODE::Class::List &list)
{
for (const KODE::Class &newClass : qAsConst(list)) {
for (const KODE::Class &newClass : std::as_const(list)) {
_file.insertClass(newClass);
}
}
Expand Down
2 changes: 1 addition & 1 deletion kdwsdl2cpp/wsdl/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Binding::saveXML(ParserContext *context, QDomDocument &document, QDomElemen

mSoapBinding.synthesizeBinding(context, document, element);

for (const BindingOperation &operation : qAsConst(mOperations)) {
for (const BindingOperation &operation : std::as_const(mOperations)) {
operation.saveXML(&mSoapBinding, context, document, element);
}
}
Expand Down
4 changes: 2 additions & 2 deletions kdwsdl2cpp/wsdl/definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void Definitions::fixUpDefinitions(/*ParserContext *context, const QDomElement &
if (mServices.isEmpty()) {
if (!mBindings.isEmpty()) {
qDebug() << "No service tag found in the wsdl file, generating one service per binding";
for (const Binding &bind : qAsConst(mBindings)) {
for (const Binding &bind : std::as_const(mBindings)) {
Service service(mTargetNamespace);
service.setName(bind.name() + "Service");

Expand All @@ -194,7 +194,7 @@ void Definitions::fixUpDefinitions(/*ParserContext *context, const QDomElement &
} else {
Q_ASSERT(!mPortTypes.isEmpty());
qDebug() << "No service or binding tag found in the wsdl file, generating only messages";
for (const PortType &portType : qAsConst(mPortTypes)) {
for (const PortType &portType : std::as_const(mPortTypes)) {
Binding binding(mTargetNamespace);
binding.setName(portType.name() + "Binding");
binding.setPortTypeName(QName(portType.nameSpace(), portType.name()));
Expand Down
4 changes: 2 additions & 2 deletions kdwsdl2cpp/wsdl/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Part::List Message::parts() const

Part Message::partByName(const QString &name) const
{
for (const Part &part : qAsConst(mParts)) {
for (const Part &part : std::as_const(mParts)) {
if (part.name() == name) { // # namespace comparison needed too?
return part;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ void Message::saveXML(ParserContext *context, QDomDocument &document, QDomElemen
context->messageHandler()->warning(QLatin1String("Message: 'name' required"));
}

for (const Part &part : qAsConst(mParts)) {
for (const Part &part : std::as_const(mParts)) {
part.saveXML(context, document, element);
}
}
4 changes: 2 additions & 2 deletions kdwsdl2cpp/wsdl/operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void Operation::saveXML(ParserContext *context, QDomDocument &document, QDomElem
case SolicitResponseOperation:
mOutput.saveXML(context, QLatin1String("output"), document, element);
mInput.saveXML(context, QLatin1String("input"), document, element);
for (const Fault &fault : qAsConst(mFaults)) {
for (const Fault &fault : std::as_const(mFaults)) {
fault.saveXML(context, document, element);
}
break;
Expand All @@ -164,7 +164,7 @@ void Operation::saveXML(ParserContext *context, QDomDocument &document, QDomElem
default:
mInput.saveXML(context, QLatin1String("input"), document, element);
mOutput.saveXML(context, QLatin1String("output"), document, element);
for (const Fault &fault : qAsConst(mFaults)) {
for (const Fault &fault : std::as_const(mFaults)) {
fault.saveXML(context, document, element);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion kdwsdl2cpp/wsdl/porttype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void PortType::saveXML(ParserContext *context, QDomDocument &document, QDomEleme
context->messageHandler()->warning(QLatin1String("PortType: 'name' required"));
}

for (const Operation &operation : qAsConst(mOperations)) {
for (const Operation &operation : std::as_const(mOperations)) {
operation.saveXML(context, document, element);
}
}
2 changes: 1 addition & 1 deletion kdwsdl2cpp/wsdl/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void Service::saveXML(ParserContext *context, const Binding::List *bindings, QDo
context->messageHandler()->warning(QLatin1String("Service: 'name' required"));
}

for (const Port &port : qAsConst(mPorts)) {
for (const Port &port : std::as_const(mPorts)) {
port.saveXML(context, bindings, document, element);
}
}
2 changes: 1 addition & 1 deletion kdwsdl2cpp/wsdl/soapbinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ void SoapBinding::synthesizePort(ParserContext *context, QDomDocument &document,

bool SoapBinding::Headers::contains(const Header &other) const
{
for (const Header &header : qAsConst(*this)) {
for (const Header &header : std::as_const(*this)) {
if (header.mMessage == other.mMessage && header.mPart == other.mPart && header.mUse == other.mUse &&
#if 0
header.mEncodingStyle == other.mEncodingStyle &&
Expand Down
4 changes: 2 additions & 2 deletions src/KDSoapClient/KDSoapMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void KDSoapMessage::setUse(Use use)

KDSoapMessage KDSoapHeaders::header(const QString &name) const
{
for (const KDSoapMessage &header : qAsConst(*this)) {
for (const KDSoapMessage &header : std::as_const(*this)) {
if (header.name() == name) {
return header;
}
Expand All @@ -209,7 +209,7 @@ KDSoapMessage KDSoapHeaders::header(const QString &name) const

KDSoapMessage KDSoapHeaders::header(const QString &name, const QString &namespaceUri) const
{
for (const KDSoapMessage &header : qAsConst(*this)) {
for (const KDSoapMessage &header : std::as_const(*this)) {
// qDebug() << "header(" << name << "," << namespaceUri << "): Looking at" << header.name() << "," << header.namespaceUri();
if (header.name() == name && (namespaceUri.isEmpty() || header.namespaceUri() == namespaceUri)) {
return header;
Expand Down
4 changes: 2 additions & 2 deletions src/KDSoapClient/KDSoapMessageAddressingProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static void writeKDSoapValueVariant(QXmlStreamWriter &writer, const KDSoapValue
static void writeKDSoapValueListHierarchy(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, const QString &addressingNS,
const KDSoapValueList &values)
{
for (const KDSoapValue &value : qAsConst(values)) {
for (const KDSoapValue &value : std::as_const(values)) {
const QString topLevelName = value.name();
writer.writeStartElement(addressingNS, topLevelName);

Expand Down Expand Up @@ -363,7 +363,7 @@ void KDSoapMessageAddressingProperties::writeMessageAddressingProperties(KDSoapN
writer.writeEndElement();
}

for (const KDSoapMessageRelationship::Relationship &relationship : qAsConst(d->relationships)) {
for (const KDSoapMessageRelationship::Relationship &relationship : std::as_const(d->relationships)) {
if (relationship.uri.isEmpty()) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/KDSoapClient/KDSoapMessageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

static QStringView namespaceForPrefix(const QXmlStreamNamespaceDeclarations &decls, const QString &prefix)
{
for (const QXmlStreamNamespaceDeclaration &decl : qAsConst(decls)) {
for (const QXmlStreamNamespaceDeclaration &decl : std::as_const(decls)) {
if (decl.prefix() == prefix) {
return decl.namespaceUri();
}
Expand Down
4 changes: 2 additions & 2 deletions src/KDSoapClient/KDSoapMessageWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ QByteArray KDSoapMessageWriter::messageToXml(const KDSoapMessage &message, const
// and xsi:type attributes that refer to n1, which isn't defined in the body...
namespacePrefixes.writeNamespace(writer, messageNamespace, QLatin1String("n1") /*make configurable?*/);
writer.writeStartElement(soapEnvelope, QLatin1String("Header"));
for (const KDSoapMessage &header : qAsConst(persistentHeaders)) {
for (const KDSoapMessage &header : std::as_const(persistentHeaders)) {
header.writeChildren(namespacePrefixes, writer, header.use(), messageNamespace, true);
}
for (const KDSoapMessage &header : qAsConst(headers)) {
for (const KDSoapMessage &header : std::as_const(headers)) {
header.writeChildren(namespacePrefixes, writer, header.use(), messageNamespace, true);
}
if (message.hasMessageAddressingProperties()) {
Expand Down
4 changes: 2 additions & 2 deletions src/KDSoapClient/KDSoapPendingCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ static void debugHelper(const QByteArray &data, const QList<QNetworkReply::RawHe
const bool optHttp = options.contains("http") || options.contains("https");
const bool optReformat = options.contains("reformat");
quint8 indentation = 4;
for (const QByteArray &opt : qAsConst(options)) {
for (const QByteArray &opt : std::as_const(options)) {
if (opt.startsWith("indent=")) { // krazy:exclude=strings
indentation = opt.mid(7).toUShort();
}
}

QByteArray toOutput;
if (optHttp) {
for (const QNetworkReply::RawHeaderPair &header : qAsConst(headerList)) {
for (const QNetworkReply::RawHeaderPair &header : std::as_const(headerList)) {
if (!header.first.isEmpty()) {
toOutput += header.first + ": ";
}
Expand Down
Loading