diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:18:55 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:18:55 (GMT) |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /examples/itemviews/simplewidgetmapper | |
download | Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2 |
Long live Qt 4.5!
Diffstat (limited to 'examples/itemviews/simplewidgetmapper')
-rw-r--r-- | examples/itemviews/simplewidgetmapper/main.cpp | 52 | ||||
-rw-r--r-- | examples/itemviews/simplewidgetmapper/simplewidgetmapper.pro | 9 | ||||
-rw-r--r-- | examples/itemviews/simplewidgetmapper/window.cpp | 134 | ||||
-rw-r--r-- | examples/itemviews/simplewidgetmapper/window.h | 85 |
4 files changed, 280 insertions, 0 deletions
diff --git a/examples/itemviews/simplewidgetmapper/main.cpp b/examples/itemviews/simplewidgetmapper/main.cpp new file mode 100644 index 0000000..055ac21 --- /dev/null +++ b/examples/itemviews/simplewidgetmapper/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "window.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + Window window; + window.show(); + return app.exec(); +} diff --git a/examples/itemviews/simplewidgetmapper/simplewidgetmapper.pro b/examples/itemviews/simplewidgetmapper/simplewidgetmapper.pro new file mode 100644 index 0000000..b2940d7 --- /dev/null +++ b/examples/itemviews/simplewidgetmapper/simplewidgetmapper.pro @@ -0,0 +1,9 @@ +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/itemviews/simplewidgetmapper +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/simplewidgetmapper +INSTALLS += target sources diff --git a/examples/itemviews/simplewidgetmapper/window.cpp b/examples/itemviews/simplewidgetmapper/window.cpp new file mode 100644 index 0000000..406a3d7 --- /dev/null +++ b/examples/itemviews/simplewidgetmapper/window.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +//! [Set up widgets] +Window::Window(QWidget *parent) + : QWidget(parent) +{ + setupModel(); + + nameLabel = new QLabel(tr("Na&me:")); + nameEdit = new QLineEdit(); + addressLabel = new QLabel(tr("&Address:")); + addressEdit = new QTextEdit(); + ageLabel = new QLabel(tr("A&ge (in years):")); + ageSpinBox = new QSpinBox(); + nextButton = new QPushButton(tr("&Next")); + previousButton = new QPushButton(tr("&Previous")); + + nameLabel->setBuddy(nameEdit); + addressLabel->setBuddy(addressEdit); + ageLabel->setBuddy(ageSpinBox); +//! [Set up widgets] + +//! [Set up the mapper] + mapper = new QDataWidgetMapper(this); + mapper->setModel(model); + mapper->addMapping(nameEdit, 0); + mapper->addMapping(addressEdit, 1); + mapper->addMapping(ageSpinBox, 2); + + connect(previousButton, SIGNAL(clicked()), + mapper, SLOT(toPrevious())); + connect(nextButton, SIGNAL(clicked()), + mapper, SLOT(toNext())); + connect(mapper, SIGNAL(currentIndexChanged(int)), + this, SLOT(updateButtons(int))); +//! [Set up the mapper] + +//! [Set up the layout] + QGridLayout *layout = new QGridLayout(); + layout->addWidget(nameLabel, 0, 0, 1, 1); + layout->addWidget(nameEdit, 0, 1, 1, 1); + layout->addWidget(previousButton, 0, 2, 1, 1); + layout->addWidget(addressLabel, 1, 0, 1, 1); + layout->addWidget(addressEdit, 1, 1, 2, 1); + layout->addWidget(nextButton, 1, 2, 1, 1); + layout->addWidget(ageLabel, 3, 0, 1, 1); + layout->addWidget(ageSpinBox, 3, 1, 1, 1); + setLayout(layout); + + setWindowTitle(tr("Simple Widget Mapper")); + mapper->toFirst(); +} +//! [Set up the layout] + +//! [Set up the model] +void Window::setupModel() +{ + model = new QStandardItemModel(5, 3, this); + + QStringList names; + names << "Alice" << "Bob" << "Carol" << "Donald" << "Emma"; + + QStringList addresses; + addresses << "<qt>123 Main Street<br/>Market Town</qt>" + << "<qt>PO Box 32<br/>Mail Handling Service" + "<br/>Service City</qt>" + << "<qt>The Lighthouse<br/>Remote Island</qt>" + << "<qt>47338 Park Avenue<br/>Big City</qt>" + << "<qt>Research Station<br/>Base Camp<br/>Big Mountain</qt>"; + + QStringList ages; + ages << "20" << "31" << "32" << "19" << "26"; + + for (int row = 0; row < 5; ++row) { + QStandardItem *item = new QStandardItem(names[row]); + model->setItem(row, 0, item); + item = new QStandardItem(addresses[row]); + model->setItem(row, 1, item); + item = new QStandardItem(ages[row]); + model->setItem(row, 2, item); + } +} +//! [Set up the model] + +//! [Slot for updating the buttons] +void Window::updateButtons(int row) +{ + previousButton->setEnabled(row > 0); + nextButton->setEnabled(row < model->rowCount() - 1); +} +//! [Slot for updating the buttons] diff --git a/examples/itemviews/simplewidgetmapper/window.h b/examples/itemviews/simplewidgetmapper/window.h new file mode 100644 index 0000000..726d4d6 --- /dev/null +++ b/examples/itemviews/simplewidgetmapper/window.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QDataWidgetMapper; +class QLabel; +class QLineEdit; +class QPushButton; +class QSpinBox; +class QStandardItemModel; +class QTextEdit; +QT_END_NAMESPACE + +//! [Window definition] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + +private slots: + void updateButtons(int row); + +private: + void setupModel(); + + QLabel *nameLabel; + QLabel *addressLabel; + QLabel *ageLabel; + QLineEdit *nameEdit; + QTextEdit *addressEdit; + QSpinBox *ageSpinBox; + QPushButton *nextButton; + QPushButton *previousButton; + + QStandardItemModel *model; + QDataWidgetMapper *mapper; +}; +//! [Window definition] + +#endif |