From 3fede6cb547b783377e833c9b269d4cecfe47e61 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 6 Sep 2019 20:27:33 +0200 Subject: Cleanup QtWidgets (tools) examples Cleanup QtWidgets tools examples: - use member-init (clang-tidy) - fix includes/don't include QtWidgets globally - include own header first - use nullptr (clang-tidy) - avoid c-style casts - use QVector instead QList - use QItemDelegate instead QStyledItemDelegate Change-Id: Ibe9440cdf711e5cc2138c054864edebe1fc95731 Reviewed-by: Paul Wicking --- examples/widgets/tools/codecs/previewform.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'examples/widgets/tools/codecs/previewform.cpp') diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp index 206b5757cd..ec75ebb9fa 100644 --- a/examples/widgets/tools/codecs/previewform.cpp +++ b/examples/widgets/tools/codecs/previewform.cpp @@ -48,10 +48,19 @@ ** ****************************************************************************/ -#include - #include "previewform.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + // Helpers for creating hex dumps static void indent(QTextStream &str, int indent) { @@ -83,8 +92,7 @@ static void formatHex(QTextStream &str, const QByteArray &data) static void formatPrintableCharacters(QTextStream &str, const QByteArray &data) { - for (int i = 0, size = data.size(); i < size; ++i) { - const char c = data.at(i); + for (const char c : data) { switch (c) { case '\0': str << "\\0"; @@ -179,7 +187,7 @@ PreviewForm::PreviewForm(QWidget *parent) resize(screenGeometry.width() * 2 / 5, screenGeometry.height() / 2); } -void PreviewForm::setCodecList(const QList &list) +void PreviewForm::setCodecList(const QVector &list) { encodingComboBox->clear(); for (const QTextCodec *codec : list) { @@ -226,10 +234,10 @@ void PreviewForm::updateTextEdit() statusLabel->setText(message); statusLabel->setStyleSheet(QStringLiteral("background-color: \"red\";")); } else if (state.invalidChars) { - statusLabel->setText(tr("%1: %n invalid characters", 0, state.invalidChars).arg(name)); + statusLabel->setText(tr("%1: %n invalid characters", nullptr, state.invalidChars).arg(name)); statusLabel->setStyleSheet(QStringLiteral("background-color: \"yellow\";")); } else { - statusLabel->setText(tr("%1: %n bytes converted", 0, encodedData.size()).arg(name)); + statusLabel->setText(tr("%1: %n bytes converted", nullptr, encodedData.size()).arg(name)); statusLabel->setStyleSheet(QString()); } if (success) -- cgit v1.2.3