diff options
Diffstat (limited to 'examples/widgets/tools/completer')
-rw-r--r-- | examples/widgets/tools/completer/fsmodel.h | 2 | ||||
-rw-r--r-- | examples/widgets/tools/completer/mainwindow.cpp | 41 | ||||
-rw-r--r-- | examples/widgets/tools/completer/mainwindow.h | 21 |
3 files changed, 39 insertions, 25 deletions
diff --git a/examples/widgets/tools/completer/fsmodel.h b/examples/widgets/tools/completer/fsmodel.h index 7b2e7b7dab..587e08b192 100644 --- a/examples/widgets/tools/completer/fsmodel.h +++ b/examples/widgets/tools/completer/fsmodel.h @@ -62,7 +62,7 @@ class FileSystemModel : public QFileSystemModel { public: - FileSystemModel(QObject *parent = 0); + FileSystemModel(QObject *parent = nullptr); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; }; //! [0] diff --git a/examples/widgets/tools/completer/mainwindow.cpp b/examples/widgets/tools/completer/mainwindow.cpp index 114ff0fd7c..b50e0a5456 100644 --- a/examples/widgets/tools/completer/mainwindow.cpp +++ b/examples/widgets/tools/completer/mainwindow.cpp @@ -48,13 +48,28 @@ ** ****************************************************************************/ -#include <QtWidgets> -#include "fsmodel.h" #include "mainwindow.h" +#include "fsmodel.h" + +#include <QAction> +#include <QApplication> +#include <QCheckBox> +#include <QComboBox> +#include <QCompleter> +#include <QGridLayout> +#include <QHeaderView> +#include <QLabel> +#include <QLineEdit> +#include <QMenuBar> +#include <QMessageBox> +#include <QSpinBox> +#include <QStandardItemModel> +#include <QStringListModel> +#include <QTreeView> //! [0] MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), completer(0), lineEdit(0) + : QMainWindow(parent) { createMenu(); @@ -64,8 +79,8 @@ MainWindow::MainWindow(QWidget *parent) modelLabel->setText(tr("Model")); modelCombo = new QComboBox; - modelCombo->addItem(tr("QFileSytemModel")); - modelCombo->addItem(tr("QFileSytemModel that shows full path")); + modelCombo->addItem(tr("QFileSystemModel")); + modelCombo->addItem(tr("QFileSystemModel that shows full path")); modelCombo->addItem(tr("Country list")); modelCombo->addItem(tr("Word list")); modelCombo->setCurrentIndex(0); @@ -144,17 +159,17 @@ void MainWindow::createMenu() connect(aboutAct, &QAction::triggered, this, &MainWindow::about); connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); - QMenu* fileMenu = menuBar()->addMenu(tr("File")); + QMenu *fileMenu = menuBar()->addMenu(tr("File")); fileMenu->addAction(exitAction); - QMenu* helpMenu = menuBar()->addMenu(tr("About")); + QMenu *helpMenu = menuBar()->addMenu(tr("About")); helpMenu->addAction(aboutAct); helpMenu->addAction(aboutQtAct); } //! [4] //! [5] -QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName) +QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName) { QFile file(fileName); if (!file.open(QFile::ReadOnly)) @@ -170,7 +185,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName) while (!file.atEnd()) { QByteArray line = file.readLine(); if (!line.isEmpty()) - words << line.trimmed(); + words << QString::fromUtf8(line.trimmed()); } #ifndef QT_NO_CURSOR @@ -191,8 +206,8 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName) for (int i = 0; i < words.count(); ++i) { QModelIndex countryIdx = m->index(i, 0); QModelIndex symbolIdx = m->index(i, 1); - QString country = words[i].mid(0, words[i].length() - 2).trimmed(); - QString symbol = words[i].right(2); + QString country = words.at(i).mid(0, words[i].length() - 2).trimmed(); + QString symbol = words.at(i).right(2); m->setData(countryIdx, country); m->setData(symbolIdx, symbol); } @@ -233,7 +248,7 @@ void MainWindow::changeModel() case 0: { // Unsorted QFileSystemModel QFileSystemModel *fsModel = new QFileSystemModel(completer); - fsModel->setRootPath(""); + fsModel->setRootPath(QString()); completer->setModel(fsModel); contentsLabel->setText(tr("Enter file path")); } @@ -243,7 +258,7 @@ void MainWindow::changeModel() { // FileSystemModel that shows full paths FileSystemModel *fsModel = new FileSystemModel(completer); completer->setModel(fsModel); - fsModel->setRootPath(""); + fsModel->setRootPath(QString()); contentsLabel->setText(tr("Enter file path")); } break; diff --git a/examples/widgets/tools/completer/mainwindow.h b/examples/widgets/tools/completer/mainwindow.h index 2bb351ec47..6e6238bf32 100644 --- a/examples/widgets/tools/completer/mainwindow.h +++ b/examples/widgets/tools/completer/mainwindow.h @@ -59,7 +59,6 @@ class QComboBox; class QCompleter; class QLabel; class QLineEdit; -class QProgressBar; class QCheckBox; class QSpinBox; QT_END_NAMESPACE @@ -70,7 +69,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); private slots: void about(); @@ -83,16 +82,16 @@ private slots: //! [1] private: void createMenu(); - QAbstractItemModel *modelFromFile(const QString& fileName); + QAbstractItemModel *modelFromFile(const QString &fileName); - QComboBox *caseCombo; - QComboBox *modeCombo; - QComboBox *modelCombo; - QSpinBox *maxVisibleSpinBox; - QCheckBox *wrapCheckBox; - QCompleter *completer; - QLabel *contentsLabel; - QLineEdit *lineEdit; + QComboBox *caseCombo = nullptr; + QComboBox *modeCombo = nullptr; + QComboBox *modelCombo = nullptr; + QSpinBox *maxVisibleSpinBox = nullptr; + QCheckBox *wrapCheckBox = nullptr; + QCompleter *completer = nullptr; + QLabel *contentsLabel = nullptr; + QLineEdit *lineEdit = nullptr; }; //! [1] |