summaryrefslogtreecommitdiffstats
path: root/examples/widgets/itemviews/addressbook
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@digia.com>2012-11-21 15:45:13 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-22 08:24:26 +0100
commit78a239bc6d344f53cf48e4bceca7d45df69220e6 (patch)
tree954f97b37634b7aa86c75e6833180cab946bce27 /examples/widgets/itemviews/addressbook
parent8a83c1bb5504d34e07ce7cce36c10b6d5a9876bd (diff)
QtBase: examples/widgets/itemviews/addressbook codestyle
Change-Id: I710d67018351c34ef14ac30edcca81aba7ff5ad3 Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'examples/widgets/itemviews/addressbook')
-rw-r--r--examples/widgets/itemviews/addressbook/adddialog.cpp10
-rw-r--r--examples/widgets/itemviews/addressbook/adddialog.h4
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.cpp39
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.h15
-rw-r--r--examples/widgets/itemviews/addressbook/main.cpp3
-rw-r--r--examples/widgets/itemviews/addressbook/mainwindow.cpp29
-rw-r--r--examples/widgets/itemviews/addressbook/mainwindow.h5
-rw-r--r--examples/widgets/itemviews/addressbook/newaddresstab.cpp5
-rw-r--r--examples/widgets/itemviews/addressbook/newaddresstab.h2
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.cpp12
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.h18
11 files changed, 69 insertions, 73 deletions
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 <QtWidgets>
#include "adddialog.h"
+#include <QtWidgets>
+
//! [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 <QtWidgets>
-#include "addresswidget.h"
#include "adddialog.h"
+#include "addresswidget.h"
+
+#include <QtWidgets>
//! [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<QString, QString> >list = table->getList();
+ QList<QPair<QString, QString> >list = table->getList();
QPair<QString, QString> 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<QString, QString> > pairs = table->getList();
+ QList<QPair<QString, QString> > 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<pairs.size(); ++i) {
QPair<QString, QString> 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<QString, QString> > pairs = table->getList();
+ QList<QPair<QString, QString> > 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 <QTabWidget>
-#include <QItemSelection>
-#include "tablemodel.h"
#include "newaddresstab.h"
+#include "tablemodel.h"
+
+#include <QItemSelection>
+#include <QTabWidget>
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 <QtWidgets>
#include "mainwindow.h"
+#include <QApplication>
+
//! [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 <QtWidgets>
#include "mainwindow.h"
+#include <QAction>
+#include <QFileDialog>
+#include <QMenuBar>
+
//! [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 <QtWidgets>
#include "addresswidget.h"
+#include <QMainWindow>
+
//! [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 <QtWidgets>
-#include "newaddresstab.h"
#include "adddialog.h"
+#include "newaddresstab.h"
+
+#include <QtWidgets>
//! [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<QString, QString> > pairs, QObject *parent)
+TableModel::TableModel(QList<QPair<QString, QString> > 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<QString, QString> 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 <QAbstractTableModel>
-#include <QPair>
#include <QList>
+#include <QPair>
//! [0]
class TableModel : public QAbstractTableModel
@@ -51,22 +51,22 @@ class TableModel : public QAbstractTableModel
Q_OBJECT
public:
- TableModel(QObject *parent=0);
- TableModel(QList< QPair<QString, QString> > listofPairs, QObject *parent=0);
+ TableModel(QObject *parent = 0);
+ TableModel(QList<QPair<QString, QString> > 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<QString, QString> > 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<QPair<QString, QString> > getList();
private:
- QList< QPair<QString, QString> > listOfPairs;
+ QList<QPair<QString, QString> > listOfPairs;
};
//! [0]
-#endif
+#endif // TABLEMODEL_H