From f9bf737d74c2493f7a535048cb4992d3e4cd3c99 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 13 Oct 2015 09:06:58 +0200 Subject: Examples/Doc snippets: Fix single-character string literals. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use character literals where applicable. Change-Id: I79fa5018f05735201ae35ee94ba0d356fcad1056 Reviewed-by: Topi Reiniƶ --- .../widgets/dialogs/classwizard/classwizard.cpp | 38 +++++++++++----------- .../widgets/gestures/imagegestures/imagewidget.cpp | 10 +++--- examples/widgets/graphicsview/boxes/scene.cpp | 4 +-- examples/widgets/itemviews/chart/mainwindow.cpp | 2 +- .../itemviews/editabletreemodel/treemodel.cpp | 2 +- examples/widgets/itemviews/frozencolumn/main.cpp | 6 ++-- examples/widgets/itemviews/interview/model.cpp | 2 +- .../widgets/itemviews/simpledommodel/dommodel.cpp | 2 +- .../itemviews/simpletreemodel/treemodel.cpp | 2 +- examples/widgets/tools/regexp/regexpdialog.cpp | 4 +-- .../regularexpression/regularexpressiondialog.cpp | 4 +-- .../tools/settingseditor/variantdelegate.cpp | 4 +-- .../tutorials/addressbook/part7/addressbook.cpp | 16 ++++----- .../widgets/tutorials/modelview/5_edit/mymodel.cpp | 2 +- examples/widgets/widgets/calculator/calculator.cpp | 2 +- 15 files changed, 50 insertions(+), 50 deletions(-) (limited to 'examples/widgets') diff --git a/examples/widgets/dialogs/classwizard/classwizard.cpp b/examples/widgets/dialogs/classwizard/classwizard.cpp index c913d7b592..d3e366efe6 100644 --- a/examples/widgets/dialogs/classwizard/classwizard.cpp +++ b/examples/widgets/dialogs/classwizard/classwizard.cpp @@ -79,31 +79,31 @@ void ClassWizard::accept() if (field("comment").toBool()) { block += "/*\n"; - block += " " + header.toLatin1() + "\n"; + block += " " + header.toLatin1() + '\n'; block += "*/\n"; - block += "\n"; + block += '\n'; } if (field("protect").toBool()) { - block += "#ifndef " + macroName + "\n"; - block += "#define " + macroName + "\n"; - block += "\n"; + block += "#ifndef " + macroName + '\n'; + block += "#define " + macroName + '\n'; + block += '\n'; } if (field("includeBase").toBool()) { - block += "#include " + baseInclude + "\n"; - block += "\n"; + block += "#include " + baseInclude + '\n'; + block += '\n'; } block += "class " + className; if (!baseClass.isEmpty()) block += " : public " + baseClass; - block += "\n"; + block += '\n'; block += "{\n"; /* qmake ignore Q_OBJECT */ if (field("qobjectMacro").toBool()) { block += " Q_OBJECT\n"; - block += "\n"; + block += '\n'; } block += "public:\n"; @@ -115,7 +115,7 @@ void ClassWizard::accept() block += " " + className + "();\n"; if (field("copyCtor").toBool()) { block += " " + className + "(const " + className + " &other);\n"; - block += "\n"; + block += '\n'; block += " " + className + " &operator=" + "(const " + className + " &other);\n"; } @@ -123,11 +123,11 @@ void ClassWizard::accept() block += "};\n"; if (field("protect").toBool()) { - block += "\n"; + block += '\n'; block += "#endif\n"; } - QFile headerFile(outputDir + "/" + header); + QFile headerFile(outputDir + '/' + header); if (!headerFile.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::warning(0, QObject::tr("Simple Wizard"), QObject::tr("Cannot write file %1:\n%2") @@ -141,12 +141,12 @@ void ClassWizard::accept() if (field("comment").toBool()) { block += "/*\n"; - block += " " + implementation.toLatin1() + "\n"; + block += " " + implementation.toLatin1() + '\n'; block += "*/\n"; - block += "\n"; + block += '\n'; } block += "#include \"" + header.toLatin1() + "\"\n"; - block += "\n"; + block += '\n'; if (field("qobjectCtor").toBool()) { block += className + "::" + className + "(QObject *parent)\n"; @@ -171,7 +171,7 @@ void ClassWizard::accept() block += "{\n"; block += " *this = other;\n"; block += "}\n"; - block += "\n"; + block += '\n'; block += className + " &" + className + "::operator=(const " + className + " &other)\n"; block += "{\n"; @@ -183,7 +183,7 @@ void ClassWizard::accept() } } - QFile implementationFile(outputDir + "/" + implementation); + QFile implementationFile(outputDir + '/' + implementation); if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::warning(0, QObject::tr("Simple Wizard"), QObject::tr("Cannot write file %1:\n%2") @@ -356,9 +356,9 @@ void CodeStylePage::initializePage() if (baseClass.isEmpty()) { baseIncludeLineEdit->clear(); } else if (QRegExp("Q[A-Z].*").exactMatch(baseClass)) { - baseIncludeLineEdit->setText("<" + baseClass + ">"); + baseIncludeLineEdit->setText('<' + baseClass + '>'); } else { - baseIncludeLineEdit->setText("\"" + baseClass.toLower() + ".h\""); + baseIncludeLineEdit->setText('"' + baseClass.toLower() + ".h\""); } } //! [16] diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp index 104095e8fe..28c715c688 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.cpp +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -229,7 +229,7 @@ void ImageWidget::goNextImage() prevImage = currentImage; currentImage = nextImage; if (position+1 < files.size()) - nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); + nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1)); else nextImage = QImage(); } @@ -246,7 +246,7 @@ void ImageWidget::goPrevImage() nextImage = currentImage; currentImage = prevImage; if (position > 0) - prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); + prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1)); else prevImage = QImage(); } @@ -276,12 +276,12 @@ void ImageWidget::goToImage(int index) position = index; if (index > 0) - prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); + prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1)); else prevImage = QImage(); - currentImage = loadImage(path+QLatin1String("/")+files.at(position)); + currentImage = loadImage(path + QLatin1Char('/') + files.at(position)); if (position+1 < files.size()) - nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); + nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1)); else nextImage = QImage(); update(); diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 48bdcb9d93..c9691704cb 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -319,9 +319,9 @@ RenderOptionsDialog::RenderOptionsDialog() while (++it != tokens.end()) { m_parameterNames << name; if (!singleElement) { - m_parameterNames.back() += "["; + m_parameterNames.back() += '['; m_parameterNames.back() += counter + counterPos; - m_parameterNames.back() += "]"; + m_parameterNames.back() += ']'; int j = 8; // position of last digit ++counter[j]; while (j > 0 && counter[j] > '9') { diff --git a/examples/widgets/itemviews/chart/mainwindow.cpp b/examples/widgets/itemviews/chart/mainwindow.cpp index 9a3b372233..a148c3036d 100644 --- a/examples/widgets/itemviews/chart/mainwindow.cpp +++ b/examples/widgets/itemviews/chart/mainwindow.cpp @@ -124,7 +124,7 @@ void MainWindow::loadFile(const QString &fileName) if (!line.isEmpty()) { model->insertRows(row, 1, QModelIndex()); - QStringList pieces = line.split(",", QString::SkipEmptyParts); + QStringList pieces = line.split(',', QString::SkipEmptyParts); model->setData(model->index(row, 0, QModelIndex()), pieces.value(0)); model->setData(model->index(row, 1, QModelIndex()), diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp index 2903dd7d38..2b12c142cd 100644 --- a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp +++ b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp @@ -246,7 +246,7 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent) while (number < lines.count()) { int position = 0; while (position < lines[number].length()) { - if (lines[number].mid(position, 1) != " ") + if (lines[number].at(position) != ' ') break; ++position; } diff --git a/examples/widgets/itemviews/frozencolumn/main.cpp b/examples/widgets/itemviews/frozencolumn/main.cpp index cfdf57135c..1292a7f403 100644 --- a/examples/widgets/itemviews/frozencolumn/main.cpp +++ b/examples/widgets/itemviews/frozencolumn/main.cpp @@ -54,15 +54,15 @@ int main(int argc, char* argv[]) QFile file(":/grades.txt"); if (file.open(QFile::ReadOnly)) { QString line = file.readLine(200); - QStringList list = line.simplified().split(","); + QStringList list = line.simplified().split(','); model->setHorizontalHeaderLabels(list); int row = 0; QStandardItem *newItem = 0; while (file.canReadLine()) { line = file.readLine(200); - if (!line.startsWith("#") && line.contains(",")) { - list= line.simplified().split(","); + if (!line.startsWith('#') && line.contains(',')) { + list = line.simplified().split(','); for (int col = 0; col < list.length(); ++col){ newItem = new QStandardItem(list.at(col)); model->setItem(row, col, newItem); diff --git a/examples/widgets/itemviews/interview/model.cpp b/examples/widgets/itemviews/interview/model.cpp index ba65144cfa..efbb67486b 100644 --- a/examples/widgets/itemviews/interview/model.cpp +++ b/examples/widgets/itemviews/interview/model.cpp @@ -88,7 +88,7 @@ QVariant Model::data(const QModelIndex &index, int role) const if (!index.isValid()) return QVariant(); if (role == Qt::DisplayRole) - return QVariant("Item " + QString::number(index.row()) + ":" + QString::number(index.column())); + return QVariant("Item " + QString::number(index.row()) + ':' + QString::number(index.column())); if (role == Qt::DecorationRole) { if (index.column() == 0) return iconProvider.icon(QFileIconProvider::Folder); diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.cpp b/examples/widgets/itemviews/simpledommodel/dommodel.cpp index f6450abc8b..531957f60b 100644 --- a/examples/widgets/itemviews/simpledommodel/dommodel.cpp +++ b/examples/widgets/itemviews/simpledommodel/dommodel.cpp @@ -88,7 +88,7 @@ QVariant DomModel::data(const QModelIndex &index, int role) const for (int i = 0; i < attributeMap.count(); ++i) { QDomNode attribute = attributeMap.item(i); attributes << attribute.nodeName() + "=\"" - +attribute.nodeValue() + "\""; + +attribute.nodeValue() + '"'; } return attributes.join(' '); case 2: diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp index aaa4685b27..f5cd1a160e 100644 --- a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp +++ b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp @@ -180,7 +180,7 @@ void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent) while (number < lines.count()) { int position = 0; while (position < lines[number].length()) { - if (lines[number].mid(position, 1) != " ") + if (lines[number].at(position) != ' ') break; position++; } diff --git a/examples/widgets/tools/regexp/regexpdialog.cpp b/examples/widgets/tools/regexp/regexpdialog.cpp index 32df8a4b91..8ed1e790fb 100644 --- a/examples/widgets/tools/regexp/regexpdialog.cpp +++ b/examples/widgets/tools/regexp/regexpdialog.cpp @@ -153,8 +153,8 @@ void RegExpDialog::refresh() QString escaped = pattern; escaped.replace("\\", "\\\\"); escaped.replace("\"", "\\\""); - escaped.prepend("\""); - escaped.append("\""); + escaped.prepend('"'); + escaped.append('"'); escapedPatternLineEdit->setText(escaped); QRegExp rx(pattern); diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp index d40b4b325d..6cddc1f6c1 100644 --- a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp +++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp @@ -111,8 +111,8 @@ void RegularExpressionDialog::refresh() QString escaped = pattern; escaped.replace(QLatin1String("\\"), QLatin1String("\\\\")); escaped.replace(QLatin1String("\""), QLatin1String("\\\"")); - escaped.prepend(QLatin1String("\"")); - escaped.append(QLatin1String("\"")); + escaped.prepend(QLatin1Char('"')); + escaped.append(QLatin1Char('"')); escapedPatternLineEdit->setText(escaped); QRegularExpression rx(pattern); diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp index f68082c660..fe2391762b 100644 --- a/examples/widgets/tools/settingseditor/variantdelegate.cpp +++ b/examples/widgets/tools/settingseditor/variantdelegate.cpp @@ -60,7 +60,7 @@ VariantDelegate::VariantDelegate(QObject *parent) dateExp.setPattern("([0-9]{,4})-([0-9]{,2})-([0-9]{,2})"); timeExp.setPattern("([0-9]{,2}):([0-9]{,2}):([0-9]{,2})"); - dateTimeExp.setPattern(dateExp.pattern() + "T" + timeExp.pattern()); + dateTimeExp.setPattern(dateExp.pattern() + 'T' + timeExp.pattern()); } void VariantDelegate::paint(QPainter *painter, @@ -217,7 +217,7 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, value = QSize(sizeExp.cap(1).toInt(), sizeExp.cap(2).toInt()); break; case QVariant::StringList: - value = text.split(","); + value = text.split(','); break; case QVariant::Time: { diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp index 6764423d71..2953ecd7de 100644 --- a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp @@ -421,23 +421,23 @@ void AddressBook::exportAsVCard() //! [export function part2] //! [export function part3] - out << "BEGIN:VCARD" << "\n"; - out << "VERSION:2.1" << "\n"; - out << "N:" << lastName << ";" << firstName << "\n"; + out << "BEGIN:VCARD" << '\n'; + out << "VERSION:2.1" << '\n'; + out << "N:" << lastName << ';' << firstName << '\n'; if (!nameList.isEmpty()) - out << "FN:" << nameList.join(' ') << "\n"; + out << "FN:" << nameList.join(' ') << '\n'; else - out << "FN:" << firstName << "\n"; + out << "FN:" << firstName << '\n'; //! [export function part3] //! [export function part4] address.replace(";", "\\;", Qt::CaseInsensitive); - address.replace("\n", ";", Qt::CaseInsensitive); + address.replace('\n', ";", Qt::CaseInsensitive); address.replace(",", " ", Qt::CaseInsensitive); - out << "ADR;HOME:;" << address << "\n"; - out << "END:VCARD" << "\n"; + out << "ADR;HOME:;" << address << '\n'; + out << "END:VCARD" << '\n'; QMessageBox::information(this, tr("Export Successful"), tr("\"%1\" has been exported as a vCard.").arg(name)); diff --git a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp index 5eb677bb9d..c04c77772f 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp @@ -83,7 +83,7 @@ bool MyModel::setData(const QModelIndex & index, const QVariant & value, int rol { for(int col= 0; col < COLS; col++) { - result += m_gridData[row][col] + " "; + result += m_gridData[row][col] + ' '; } } emit editCompleted( result ); diff --git a/examples/widgets/widgets/calculator/calculator.cpp b/examples/widgets/widgets/calculator/calculator.cpp index e76011ee0d..87061a9868 100644 --- a/examples/widgets/widgets/calculator/calculator.cpp +++ b/examples/widgets/widgets/calculator/calculator.cpp @@ -276,7 +276,7 @@ void Calculator::pointClicked() { if (waitingForOperand) display->setText("0"); - if (!display->text().contains(".")) + if (!display->text().contains('.')) display->setText(display->text() + tr(".")); waitingForOperand = false; } -- cgit v1.2.3