From 78a239bc6d344f53cf48e4bceca7d45df69220e6 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 21 Nov 2012 15:45:13 +0100 Subject: QtBase: examples/widgets/itemviews/addressbook codestyle Change-Id: I710d67018351c34ef14ac30edcca81aba7ff5ad3 Reviewed-by: hjk --- .../widgets/itemviews/addressbook/adddialog.cpp | 10 +++--- examples/widgets/itemviews/addressbook/adddialog.h | 4 +-- .../itemviews/addressbook/addresswidget.cpp | 39 +++++++++++----------- .../widgets/itemviews/addressbook/addresswidget.h | 15 +++++---- examples/widgets/itemviews/addressbook/main.cpp | 3 +- .../widgets/itemviews/addressbook/mainwindow.cpp | 29 +++++++--------- .../widgets/itemviews/addressbook/mainwindow.h | 5 +-- .../itemviews/addressbook/newaddresstab.cpp | 5 +-- .../widgets/itemviews/addressbook/newaddresstab.h | 2 +- .../widgets/itemviews/addressbook/tablemodel.cpp | 12 +++---- .../widgets/itemviews/addressbook/tablemodel.h | 18 +++++----- 11 files changed, 69 insertions(+), 73 deletions(-) (limited to 'examples/widgets/itemviews/addressbook') diff --git a/examples/widgets/itemviews/addressbook/adddialog.cpp b/examples/widgets/itemviews/addressbook/adddialog.cpp index 77092accc4..8a67a568ee 100644 --- a/examples/widgets/itemviews/addressbook/adddialog.cpp +++ b/examples/widgets/itemviews/addressbook/adddialog.cpp @@ -38,9 +38,10 @@ ** ****************************************************************************/ -#include #include "adddialog.h" +#include + //! [0] AddDialog::AddDialog(QWidget *parent) : QDialog(parent) @@ -71,11 +72,8 @@ AddDialog::AddDialog(QWidget *parent) mainLayout->addLayout(gLayout); setLayout(mainLayout); - connect(okButton, SIGNAL(clicked()), - this, SLOT(accept())); - - connect(cancelButton, SIGNAL(clicked()), - this, SLOT(reject())); + connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); setWindowTitle(tr("Add a Contact")); } diff --git a/examples/widgets/itemviews/addressbook/adddialog.h b/examples/widgets/itemviews/addressbook/adddialog.h index c8eba88805..80122e9029 100644 --- a/examples/widgets/itemviews/addressbook/adddialog.h +++ b/examples/widgets/itemviews/addressbook/adddialog.h @@ -56,7 +56,7 @@ class AddDialog : public QDialog Q_OBJECT public: - AddDialog(QWidget *parent=0); + AddDialog(QWidget *parent = 0); QLineEdit *nameText; QTextEdit *addressText; @@ -68,4 +68,4 @@ private: }; //! [0] -#endif +#endif // ADDDIALOG_H diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp index 1bd9902eda..28c9be92f4 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.cpp +++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp @@ -38,9 +38,10 @@ ** ****************************************************************************/ -#include -#include "addresswidget.h" #include "adddialog.h" +#include "addresswidget.h" + +#include //! [0] AddressWidget::AddressWidget(QWidget *parent) @@ -48,8 +49,8 @@ AddressWidget::AddressWidget(QWidget *parent) { table = new TableModel(this); newAddressTab = new NewAddressTab(this); - connect(newAddressTab, SIGNAL(sendDetails(QString,QString)), - this, SLOT(addEntry(QString,QString))); + connect(newAddressTab, SIGNAL(sendDetails(QString, QString)), + this, SLOT(addEntry(QString, QString))); addTab(newAddressTab, "Address Book"); @@ -74,7 +75,7 @@ void AddressWidget::addEntry() //! [3] void AddressWidget::addEntry(QString name, QString address) { - QList< QPair >list = table->getList(); + QList >list = table->getList(); QPair pair(name, address); if (!list.contains(pair)) { @@ -100,19 +101,18 @@ void AddressWidget::editEntry() QItemSelectionModel *selectionModel = temp->selectionModel(); QModelIndexList indexes = selectionModel->selectedRows(); - QModelIndex index, i; QString name; QString address; int row = -1; - foreach (index, indexes) { + foreach (QModelIndex index, indexes) { row = proxy->mapToSource(index).row(); - i = table->index(row, 0, QModelIndex()); - QVariant varName = table->data(i, Qt::DisplayRole); + QModelIndex nameIndex = table->index(row, 0, QModelIndex()); + QVariant varName = table->data(nameIndex, Qt::DisplayRole); name = varName.toString(); - i = table->index(row, 1, QModelIndex()); - QVariant varAddr = table->data(i, Qt::DisplayRole); + QModelIndex addressIndex = table->index(row, 1, QModelIndex()); + QVariant varAddr = table->data(addressIndex, Qt::DisplayRole); address = varAddr.toString(); } //! [4a] @@ -128,8 +128,8 @@ void AddressWidget::editEntry() if (aDialog.exec()) { QString newAddress = aDialog.addressText->toPlainText(); if (newAddress != address) { - i = table->index(row, 1, QModelIndex()); - table->setData(i, newAddress, Qt::EditRole); + QModelIndex index = table->index(row, 1, QModelIndex()); + table->setData(index, newAddress, Qt::EditRole); } } } @@ -143,9 +143,8 @@ void AddressWidget::removeEntry() QItemSelectionModel *selectionModel = temp->selectionModel(); QModelIndexList indexes = selectionModel->selectedRows(); - QModelIndex index; - foreach (index, indexes) { + foreach (QModelIndex index, indexes) { int row = proxy->mapToSource(index).row(); table->removeRows(row, 1, QModelIndex()); } @@ -193,7 +192,7 @@ void AddressWidget::setupTabs() //! [1] //! [7] -void AddressWidget::readFromFile(QString fileName) +void AddressWidget::readFromFile(const QString &fileName) { QFile file(fileName); @@ -203,13 +202,13 @@ void AddressWidget::readFromFile(QString fileName) return; } - QList< QPair > pairs = table->getList(); + QList > pairs = table->getList(); QDataStream in(&file); in >> pairs; if (pairs.isEmpty()) { QMessageBox::information(this, tr("No contacts in file"), - tr("The file you are attempting to open contains no contacts.")); + tr("The file you are attempting to open contains no contacts.")); } else { for (int i=0; i p = pairs.at(i); @@ -220,7 +219,7 @@ void AddressWidget::readFromFile(QString fileName) //! [7] //! [6] -void AddressWidget::writeToFile(QString fileName) +void AddressWidget::writeToFile(const QString &fileName) { QFile file(fileName); @@ -229,7 +228,7 @@ void AddressWidget::writeToFile(QString fileName) return; } - QList< QPair > pairs = table->getList(); + QList > pairs = table->getList(); QDataStream out(&file); out << pairs; } diff --git a/examples/widgets/itemviews/addressbook/addresswidget.h b/examples/widgets/itemviews/addressbook/addresswidget.h index eab0876912..c0b4200053 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.h +++ b/examples/widgets/itemviews/addressbook/addresswidget.h @@ -41,10 +41,11 @@ #ifndef ADDRESSWIDGET_H #define ADDRESSWIDGET_H -#include -#include -#include "tablemodel.h" #include "newaddresstab.h" +#include "tablemodel.h" + +#include +#include QT_BEGIN_NAMESPACE class QSortFilterProxyModel; @@ -57,9 +58,9 @@ class AddressWidget : public QTabWidget Q_OBJECT public: - AddressWidget(QWidget *parent=0); - void readFromFile(QString fileName); - void writeToFile(QString fileName); + AddressWidget(QWidget *parent = 0); + void readFromFile(const QString &fileName); + void writeToFile(const QString &fileName); public slots: void addEntry(); @@ -79,4 +80,4 @@ private: }; //! [0] -#endif +#endif // ADDRESSWIDGET_H diff --git a/examples/widgets/itemviews/addressbook/main.cpp b/examples/widgets/itemviews/addressbook/main.cpp index 0f821f57e5..a562d6130e 100644 --- a/examples/widgets/itemviews/addressbook/main.cpp +++ b/examples/widgets/itemviews/addressbook/main.cpp @@ -38,9 +38,10 @@ ** ****************************************************************************/ -#include #include "mainwindow.h" +#include + //! [0] int main(int argc, char *argv[]) { diff --git a/examples/widgets/itemviews/addressbook/mainwindow.cpp b/examples/widgets/itemviews/addressbook/mainwindow.cpp index f019f9ce81..dc9ca7e7dc 100644 --- a/examples/widgets/itemviews/addressbook/mainwindow.cpp +++ b/examples/widgets/itemviews/addressbook/mainwindow.cpp @@ -38,9 +38,12 @@ ** ****************************************************************************/ -#include #include "mainwindow.h" +#include +#include +#include + //! [0] MainWindow::MainWindow() { @@ -58,43 +61,37 @@ void MainWindow::createMenus() openAct = new QAction(tr("&Open..."), this); fileMenu->addAction(openAct); - connect(openAct, SIGNAL(triggered()), - this, SLOT(openFile())); + connect(openAct, SIGNAL(triggered()), this, SLOT(openFile())); //! [1a] saveAct = new QAction(tr("&Save As..."), this); fileMenu->addAction(saveAct); - connect(saveAct, SIGNAL(triggered()), - this, SLOT(saveFile())); + connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile())); fileMenu->addSeparator(); exitAct = new QAction(tr("E&xit"), this); fileMenu->addAction(exitAct); - connect(exitAct, SIGNAL(triggered()), - this, SLOT(close())); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); toolMenu = menuBar()->addMenu(tr("&Tools")); addAct = new QAction(tr("&Add Entry..."), this); toolMenu->addAction(addAct); - connect(addAct, SIGNAL(triggered()), - addressWidget, SLOT(addEntry())); + connect(addAct, SIGNAL(triggered()), addressWidget, SLOT(addEntry())); //! [1b] editAct = new QAction(tr("&Edit Entry..."), this); editAct->setEnabled(false); toolMenu->addAction(editAct); - connect(editAct, SIGNAL(triggered()), - addressWidget, SLOT(editEntry())); + connect(editAct, SIGNAL(triggered()), addressWidget, SLOT(editEntry())); toolMenu->addSeparator(); removeAct = new QAction(tr("&Remove Entry"), this); removeAct->setEnabled(false); toolMenu->addAction(removeAct); - connect(removeAct, SIGNAL(triggered()), - addressWidget, SLOT(removeEntry())); + connect(removeAct, SIGNAL(triggered()), addressWidget, SLOT(removeEntry())); connect(addressWidget, SIGNAL(selectionChanged(QItemSelection)), this, SLOT(updateActions(QItemSelection))); @@ -105,9 +102,8 @@ void MainWindow::createMenus() void MainWindow::openFile() { QString fileName = QFileDialog::getOpenFileName(this); - if (!fileName.isEmpty()) { + if (!fileName.isEmpty()) addressWidget->readFromFile(fileName); - } } //! [2] @@ -115,9 +111,8 @@ void MainWindow::openFile() void MainWindow::saveFile() { QString fileName = QFileDialog::getSaveFileName(this); - if (!fileName.isEmpty()) { + if (!fileName.isEmpty()) addressWidget->writeToFile(fileName); - } } //! [3] diff --git a/examples/widgets/itemviews/addressbook/mainwindow.h b/examples/widgets/itemviews/addressbook/mainwindow.h index eec8668cdb..d72aa89169 100644 --- a/examples/widgets/itemviews/addressbook/mainwindow.h +++ b/examples/widgets/itemviews/addressbook/mainwindow.h @@ -41,9 +41,10 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include #include "addresswidget.h" +#include + //! [0] class MainWindow : public QMainWindow { @@ -72,4 +73,4 @@ private: }; //! [0] -#endif +#endif // MAINWINDOW_H diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.cpp b/examples/widgets/itemviews/addressbook/newaddresstab.cpp index 7c8959baa2..b2dd1156a4 100644 --- a/examples/widgets/itemviews/addressbook/newaddresstab.cpp +++ b/examples/widgets/itemviews/addressbook/newaddresstab.cpp @@ -38,9 +38,10 @@ ** ****************************************************************************/ -#include -#include "newaddresstab.h" #include "adddialog.h" +#include "newaddresstab.h" + +#include //! [0] NewAddressTab::NewAddressTab(QWidget *parent) diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.h b/examples/widgets/itemviews/addressbook/newaddresstab.h index e370074d40..2ddd2adff6 100644 --- a/examples/widgets/itemviews/addressbook/newaddresstab.h +++ b/examples/widgets/itemviews/addressbook/newaddresstab.h @@ -55,7 +55,7 @@ class NewAddressTab : public QWidget Q_OBJECT public: - NewAddressTab(QWidget *parent=0); + NewAddressTab(QWidget *parent = 0); public slots: void addEntry(); diff --git a/examples/widgets/itemviews/addressbook/tablemodel.cpp b/examples/widgets/itemviews/addressbook/tablemodel.cpp index 7d21337750..5d18392d4e 100644 --- a/examples/widgets/itemviews/addressbook/tablemodel.cpp +++ b/examples/widgets/itemviews/addressbook/tablemodel.cpp @@ -46,10 +46,10 @@ TableModel::TableModel(QObject *parent) { } -TableModel::TableModel(QList< QPair > pairs, QObject *parent) +TableModel::TableModel(QList > pairs, QObject *parent) : QAbstractTableModel(parent) { - listOfPairs=pairs; + listOfPairs = pairs; } //! [0] @@ -114,9 +114,9 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation, int ro bool TableModel::insertRows(int position, int rows, const QModelIndex &index) { Q_UNUSED(index); - beginInsertRows(QModelIndex(), position, position+rows-1); + beginInsertRows(QModelIndex(), position, position + rows - 1); - for (int row=0; row < rows; row++) { + for (int row = 0; row < rows; ++row) { QPair pair(" ", " "); listOfPairs.insert(position, pair); } @@ -130,9 +130,9 @@ bool TableModel::insertRows(int position, int rows, const QModelIndex &index) bool TableModel::removeRows(int position, int rows, const QModelIndex &index) { Q_UNUSED(index); - beginRemoveRows(QModelIndex(), position, position+rows-1); + beginRemoveRows(QModelIndex(), position, position + rows - 1); - for (int row=0; row < rows; ++row) { + for (int row = 0; row < rows; ++row) { listOfPairs.removeAt(position); } diff --git a/examples/widgets/itemviews/addressbook/tablemodel.h b/examples/widgets/itemviews/addressbook/tablemodel.h index f180231094..6159d2c669 100644 --- a/examples/widgets/itemviews/addressbook/tablemodel.h +++ b/examples/widgets/itemviews/addressbook/tablemodel.h @@ -42,8 +42,8 @@ #define TABLEMODEL_H #include -#include #include +#include //! [0] class TableModel : public QAbstractTableModel @@ -51,22 +51,22 @@ class TableModel : public QAbstractTableModel Q_OBJECT public: - TableModel(QObject *parent=0); - TableModel(QList< QPair > listofPairs, QObject *parent=0); + TableModel(QObject *parent = 0); + TableModel(QList > listofPairs, QObject *parent = 0); int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; Qt::ItemFlags flags(const QModelIndex &index) const; - bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole); - bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex()); - bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex()); - QList< QPair > getList(); + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); + bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); + QList > getList(); private: - QList< QPair > listOfPairs; + QList > listOfPairs; }; //! [0] -#endif +#endif // TABLEMODEL_H -- cgit v1.2.3