summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLena Biliaieva <lena.biliaieva@qt.io>2023-12-15 12:55:40 +0100
committerLena Biliaieva <lena.biliaieva@qt.io>2023-12-15 16:56:03 +0100
commit421fee811f8a6610c874bf3473b004d924b02b8c (patch)
tree32b0b99c8f3b8e8e401ed638f09422d8da2ca796
parentca63a0b4c19fed8cab73b2707d560f48087d3c51 (diff)
Review QtOpcUa Viewer Ex: Refactor string literals
Replaced QLatin1String with QLatin1StringView. Replaced QStringLiteral with _s operator. Task-number: QTBUG-119786 Pick-to: 6.7 Change-Id: I0e1cb6d39f8185dca56ab2671c86c5b19cfb1673 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
-rw-r--r--examples/opcua/opcuaviewer/certificatedialog.cpp6
-rw-r--r--examples/opcua/opcuaviewer/main.cpp12
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.cpp17
-rw-r--r--examples/opcua/opcuaviewer/opcuamodel.cpp22
-rw-r--r--examples/opcua/opcuaviewer/treeitem.cpp40
-rw-r--r--examples/opcua/opcuaviewer/treeitem.h8
6 files changed, 58 insertions, 47 deletions
diff --git a/examples/opcua/opcuaviewer/certificatedialog.cpp b/examples/opcua/opcuaviewer/certificatedialog.cpp
index c1c14b9..49b9e84 100644
--- a/examples/opcua/opcuaviewer/certificatedialog.cpp
+++ b/examples/opcua/opcuaviewer/certificatedialog.cpp
@@ -46,9 +46,11 @@ int CertificateDialog::showCertificate(const QString &message, const QByteArray
void CertificateDialog::saveCertificate()
{
+ using namespace Qt::Literals::StringLiterals;
+
const QByteArray digest = m_cert.digest();
- const QString path = m_trustListDirectory + QLatin1Char('/')
- + QLatin1String(digest.toHex()) + QLatin1String(".der");
+ const QString path = m_trustListDirectory + '/'_L1
+ + QLatin1StringView(digest.toHex()) + ".der"_L1;
QFile file(path);
if (file.open(QIODevice::WriteOnly)) {
diff --git a/examples/opcua/opcuaviewer/main.cpp b/examples/opcua/opcuaviewer/main.cpp
index b391fef..5fb2ad9 100644
--- a/examples/opcua/opcuaviewer/main.cpp
+++ b/examples/opcua/opcuaviewer/main.cpp
@@ -6,22 +6,24 @@
#include <QCommandLineParser>
#include <QCommandLineOption>
+using namespace Qt::Literals::StringLiterals;
+
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR));
- QCoreApplication::setApplicationName(QLatin1String("Qt OpcUa Viewer"));
+ QCoreApplication::setApplicationVersion(QLatin1StringView(QT_VERSION_STR));
+ QCoreApplication::setApplicationName("Qt OpcUa Viewer"_L1);
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
- parser.addPositionalArgument(QLatin1String("url"), QLatin1String("The url to open."));
+ parser.addPositionalArgument("url"_L1, "The url to open."_L1);
parser.process(app);
const auto positionalArguments = parser.positionalArguments();
- const auto initialUrl = positionalArguments.value(0, QLatin1String("opc.tcp://localhost:48010"));
+ const auto initialUrl = positionalArguments.value(0, "opc.tcp://localhost:48010"_L1);
MainWindow mainWindow(initialUrl.trimmed());
- mainWindow.setWindowTitle(QLatin1String("Qt OPC UA viewer"));
+ mainWindow.setWindowTitle("Qt OPC UA viewer"_L1);
mainWindow.show();
return QCoreApplication::exec();
}
diff --git a/examples/opcua/opcuaviewer/mainwindow.cpp b/examples/opcua/opcuaviewer/mainwindow.cpp
index e313327..ae3d3d7 100644
--- a/examples/opcua/opcuaviewer/mainwindow.cpp
+++ b/examples/opcua/opcuaviewer/mainwindow.cpp
@@ -19,6 +19,8 @@
#include <QOpcUaHistoryReadRawRequest>
+using namespace Qt::Literals::StringLiterals;
+
static MainWindow *mainWindowGlobal = nullptr;
static QtMessageHandler oldMessageHandler = nullptr;
@@ -50,11 +52,11 @@ static void messageHandler(QtMsgType type, const QMessageLogContext &context, co
message = QObject::tr("Debug");
break;
}
- message += QLatin1String(": ");
+ message += ": "_L1;
message += msg;
const QString contextStr =
- QStringLiteral(" (%1:%2, %3)").arg(context.file).arg(context.line).arg(context.function);
+ u" (%1:%2, %3)"_s.arg(context.file).arg(context.line).arg(context.function);
// Logging messages from backends are sent from different threads and need to be
// synchronized with the GUI thread.
@@ -248,8 +250,7 @@ void MainWindow::getEndpointsComplete(const QList<QOpcUaEndpointDescription> &en
int index = 0;
for (const auto &endpoint : endpoints) {
const QString mode = QVariant::fromValue(endpoint.securityMode()).toString();
- const QString endpointName = QStringLiteral("%1 (%2)")
- .arg(endpoint.securityPolicy(), mode);
+ const QString endpointName = u"%1 (%2)"_s.arg(endpoint.securityPolicy(), mode);
ui->endpoints->addItem(endpointName, index++);
}
}
@@ -389,21 +390,21 @@ void MainWindow::showErrorDialog(QOpcUaErrorState *errorState)
case QOpcUaErrorState::ConnectionStep::CertificateValidation: {
CertificateDialog dlg(this);
msg += tr("Server certificate validation failed with error 0x%1 (%2).\nClick 'Abort' to abort the connect, or 'Ignore' to continue connecting.")
- .arg(static_cast<ulong>(errorState->errorCode()), 8, 16, QLatin1Char('0')).arg(statuscode);
+ .arg(static_cast<ulong>(errorState->errorCode()), 8, 16, '0'_L1).arg(statuscode);
result = dlg.showCertificate(msg, m_endpoint.serverCertificate(), m_pkiConfig.trustListDirectory());
errorState->setIgnoreError(result == 1);
}
break;
case QOpcUaErrorState::ConnectionStep::OpenSecureChannel:
- msg += tr("OpenSecureChannel failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, QLatin1Char('0')).arg(statuscode);
+ msg += tr("OpenSecureChannel failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, '0'_L1).arg(statuscode);
QMessageBox::warning(this, tr("Connection Error"), msg);
break;
case QOpcUaErrorState::ConnectionStep::CreateSession:
- msg += tr("CreateSession failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, QLatin1Char('0')).arg(statuscode);
+ msg += tr("CreateSession failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, '0'_L1).arg(statuscode);
QMessageBox::warning(this, tr("Connection Error"), msg);
break;
case QOpcUaErrorState::ConnectionStep::ActivateSession:
- msg += tr("ActivateSession failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, QLatin1Char('0')).arg(statuscode);
+ msg += tr("ActivateSession failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, '0'_L1).arg(statuscode);
QMessageBox::warning(this, tr("Connection Error"), msg);
break;
}
diff --git a/examples/opcua/opcuaviewer/opcuamodel.cpp b/examples/opcua/opcuaviewer/opcuamodel.cpp
index d663f22..08d7e46 100644
--- a/examples/opcua/opcuaviewer/opcuamodel.cpp
+++ b/examples/opcua/opcuaviewer/opcuamodel.cpp
@@ -60,33 +60,35 @@ QVariant OpcUaModel::data(const QModelIndex &index, int role) const
QVariant OpcUaModel::headerData(int section, Qt::Orientation orientation, int role) const
{
+ using namespace Qt::Literals::StringLiterals;
+
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Vertical)
- return QStringLiteral("Row %1").arg(section);
+ return u"Row %1"_s.arg(section);
switch (section) {
case 0:
- return QStringLiteral("BrowseName");
+ return u"BrowseName"_s;
case 1:
- return QStringLiteral("Value");
+ return u"Value"_s;
case 2:
- return QStringLiteral("NodeClass");
+ return u"NodeClass"_s;
case 3:
- return QStringLiteral("DataType");
+ return u"DataType"_s;
case 4:
- return QStringLiteral("NodeId");
+ return u"NodeId"_s;
case 5:
- return QStringLiteral("DisplayName");
+ return u"DisplayName"_s;
case 6:
- return QStringLiteral("Description");
+ return u"Description"_s;
case 7:
- return QStringLiteral("Historizing");
+ return u"Historizing"_s;
default:
break;
}
- return QStringLiteral("Column %1").arg(section);
+ return u"Column %1"_s.arg(section);
}
QModelIndex OpcUaModel::index(int row, int column, const QModelIndex &parent) const
diff --git a/examples/opcua/opcuaviewer/treeitem.cpp b/examples/opcua/opcuaviewer/treeitem.cpp
index b6cefe4..8211990 100644
--- a/examples/opcua/opcuaviewer/treeitem.cpp
+++ b/examples/opcua/opcuaviewer/treeitem.cpp
@@ -17,6 +17,8 @@
#include <QMetaEnum>
#include <QPixmap>
+using namespace Qt::Literals::StringLiterals;
+
const int numberOfDisplayColumns = 8; // NodeId, Value, NodeClass, DataType, BrowseName, DisplayName, Description, Historizing
TreeItem::TreeItem(OpcUaModel *model) : QObject(nullptr)
@@ -271,31 +273,31 @@ QString TreeItem::variantToString(const QVariant &value, const QString &typeNode
QString concat;
for (int i = 0, size = list.size(); i < size; ++i) {
if (i)
- concat.append(QLatin1Char('\n'));
+ concat.append('\n'_L1);
concat.append(variantToString(list.at(i), typeNodeId));
}
return concat;
}
- if (typeNodeId == QLatin1String("ns=0;i=19")) { // StatusCode
+ if (typeNodeId == "ns=0;i=19"_L1) { // StatusCode
const char *name = QMetaEnum::fromType<QOpcUa::UaStatusCode>().valueToKey(value.toInt());
- return name ? QLatin1String(name) : QLatin1String("Unknown StatusCode");
+ return name ? QLatin1StringView(name) : "Unknown StatusCode"_L1;
}
- if (typeNodeId == QLatin1String("ns=0;i=2")) // Char
+ if (typeNodeId == "ns=0;i=2"_L1) // Char
return QString::number(value.toInt());
- if (typeNodeId == QLatin1String("ns=0;i=3")) // SChar
+ if (typeNodeId == "ns=0;i=3"_L1) // SChar
return QString::number(value.toUInt());
- if (typeNodeId == QLatin1String("ns=0;i=4")) // Int16
+ if (typeNodeId == "ns=0;i=4"_L1) // Int16
return QString::number(value.toInt());
- if (typeNodeId == QLatin1String("ns=0;i=5")) // UInt16
+ if (typeNodeId == "ns=0;i=5"_L1) // UInt16
return QString::number(value.toUInt());
if (value.metaType().id() == QMetaType::QByteArray)
- return QLatin1String("0x") + value.toByteArray().toHex();
+ return "0x"_L1 + value.toByteArray().toHex();
if (value.metaType().id() == QMetaType::QDateTime)
return value.toDateTime().toString(Qt::ISODate);
if (value.canConvert<QOpcUaQualifiedName>()) {
const auto name = value.value<QOpcUaQualifiedName>();
- return QStringLiteral("[NamespaceIndex: %1, Name: \"%2\"]").arg(name.namespaceIndex()).arg(name.name());
+ return u"[NamespaceIndex: %1, Name: \"%2\"]"_s.arg(name.namespaceIndex()).arg(name.name());
}
if (value.canConvert<QOpcUaLocalizedText>()) {
const auto text = value.value<QOpcUaLocalizedText>();
@@ -307,15 +309,15 @@ QString TreeItem::variantToString(const QVariant &value, const QString &typeNode
}
if (value.canConvert<QOpcUaComplexNumber>()) {
const auto complex = value.value<QOpcUaComplexNumber>();
- return QStringLiteral("[Real: %1, Imaginary: %2]").arg(complex.real()).arg(complex.imaginary());
+ return u"[Real: %1, Imaginary: %2]"_s.arg(complex.real()).arg(complex.imaginary());
}
if (value.canConvert<QOpcUaDoubleComplexNumber>()) {
const auto complex = value.value<QOpcUaDoubleComplexNumber>();
- return QStringLiteral("[Real: %1, Imaginary: %2]").arg(complex.real()).arg(complex.imaginary());
+ return u"[Real: %1, Imaginary: %2]"_s.arg(complex.real()).arg(complex.imaginary());
}
if (value.canConvert<QOpcUaXValue>()) {
const auto xv = value.value<QOpcUaXValue>();
- return QStringLiteral("[X: %1, Value: %2]").arg(xv.x()).arg(xv.value());
+ return u"[X: %1, Value: %2]"_s.arg(xv.x()).arg(xv.value());
}
if (value.canConvert<QOpcUaEUInformation>()) {
const auto info = value.value<QOpcUaEUInformation>();
@@ -323,20 +325,20 @@ QString TreeItem::variantToString(const QVariant &value, const QString &typeNode
}
if (value.canConvert<QOpcUaAxisInformation>()) {
const auto info = value.value<QOpcUaAxisInformation>();
- return QStringLiteral("[EUInformation: %1, EURange: %2, Title: %3 , AxisScaleType: %4, AxisSteps: %5]").arg(
+ return u"[EUInformation: %1, EURange: %2, Title: %3 , AxisScaleType: %4, AxisSteps: %5]"_s.arg(
euInformationToString(info.engineeringUnits()), rangeToString(info.eURange()), localizedTextToString(info.title()),
info.axisScaleType() == QOpcUa::AxisScale::Linear ? "Linear" : (info.axisScaleType() == QOpcUa::AxisScale::Ln) ? "Ln" : "Log",
numberArrayToString(info.axisSteps()));
}
if (value.canConvert<QOpcUaExpandedNodeId>()) {
const auto id = value.value<QOpcUaExpandedNodeId>();
- return QStringLiteral("[NodeId: \"%1\", ServerIndex: \"%2\", NamespaceUri: \"%3\"]").arg(
+ return u"[NodeId: \"%1\", ServerIndex: \"%2\", NamespaceUri: \"%3\"]"_s.arg(
id.nodeId()).arg(id.serverIndex()).arg(id.namespaceUri());
}
if (value.canConvert<QOpcUaArgument>()) {
const auto a = value.value<QOpcUaArgument>();
- return QStringLiteral("[Name: \"%1\", DataType: \"%2\", ValueRank: \"%3\", ArrayDimensions: %4, Description: %5]").arg(
+ return u"[Name: \"%1\", DataType: \"%2\", ValueRank: \"%3\", ArrayDimensions: %4, Description: %5]"_s.arg(
a.name(), a.dataTypeId()).arg(a.valueRank()).arg(numberArrayToString(a.arrayDimensions()),
localizedTextToString(a.description()));
}
@@ -352,7 +354,7 @@ QString TreeItem::variantToString(const QVariant &value, const QString &typeNode
return decodedValue.toString();
}
- return QStringLiteral("[TypeId: \"%1\", Encoding: %2, Body: 0x%3]").arg(obj.encodingTypeId(),
+ return u"[TypeId: \"%1\", Encoding: %2, Body: 0x%3]"_s.arg(obj.encodingTypeId(),
obj.encoding() == QOpcUaExtensionObject::Encoding::NoBody ?
"NoBody" : (obj.encoding() == QOpcUaExtensionObject::Encoding::ByteString ?
"ByteString" : "XML")).arg(obj.encodedBody().isEmpty() ? "0" : QString(obj.encodedBody().toHex()));
@@ -366,16 +368,16 @@ QString TreeItem::variantToString(const QVariant &value, const QString &typeNode
QString TreeItem::localizedTextToString(const QOpcUaLocalizedText &text) const
{
- return QStringLiteral("[Locale: \"%1\", Text: \"%2\"]").arg(text.locale(), text.text());
+ return u"[Locale: \"%1\", Text: \"%2\"]"_s.arg(text.locale(), text.text());
}
QString TreeItem::rangeToString(const QOpcUaRange &range) const
{
- return QStringLiteral("[Low: %1, High: %2]").arg(range.low()).arg(range.high());
+ return u"[Low: %1, High: %2]"_s.arg(range.low()).arg(range.high());
}
QString TreeItem::euInformationToString(const QOpcUaEUInformation &info) const
{
- return QStringLiteral("[UnitId: %1, NamespaceUri: \"%2\", DisplayName: %3, Description: %4]").arg(info.unitId()).arg(
+ return u"[UnitId: %1, NamespaceUri: \"%2\", DisplayName: %3, Description: %4]"_s.arg(info.unitId()).arg(
info.namespaceUri(), localizedTextToString(info.displayName()), localizedTextToString(info.description()));
}
diff --git a/examples/opcua/opcuaviewer/treeitem.h b/examples/opcua/opcuaviewer/treeitem.h
index 8a18b5d..30ca366 100644
--- a/examples/opcua/opcuaviewer/treeitem.h
+++ b/examples/opcua/opcuaviewer/treeitem.h
@@ -67,13 +67,15 @@ private:
template <typename T>
QString TreeItem::numberArrayToString(const QList<T> &vec) const
{
- QString list(QLatin1Char('['));
+ using namespace Qt::Literals::StringLiterals;
+
+ QString list('['_L1);
for (int i = 0, size = vec.size(); i < size; ++i) {
if (i)
- list.append(QLatin1Char(';'));
+ list.append(';'_L1);
list.append(QString::number(vec.at(i)));
}
- list.append(QLatin1Char(']'));
+ list.append(']'_L1);
return list;
}