From 0948de26bca9a68a354b436895bdf9e2db9c4288 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Tue, 8 Jun 2010 04:40:42 +1000 Subject: initial connman bearer backend. still needs work, debugging, additional threading support, and probably refactoring. This includes a connman dbus service wrapper that has more functionality than is needed by the bearer backend but still missing some 'set' functionality for a complete connman wrapper. Developed with wifi/desktop on 'lucid' kubuntu, using the connman available at http://ppa.launchpad.net/indicator-network-developers/ppa/ubuntu --- src/plugins/bearer/bearer.pro | 3 +- src/plugins/bearer/connman/connman.pro | 19 + src/plugins/bearer/connman/main.cpp | 93 ++ src/plugins/bearer/connman/qconnmanengine.cpp | 651 ++++++++++++ src/plugins/bearer/connman/qconnmanengine.h | 144 +++ .../bearer/connman/qconnmanservice_linux.cpp | 1038 ++++++++++++++++++++ .../bearer/connman/qconnmanservice_linux_p.h | 377 +++++++ 7 files changed, 2324 insertions(+), 1 deletion(-) create mode 100644 src/plugins/bearer/connman/connman.pro create mode 100644 src/plugins/bearer/connman/main.cpp create mode 100644 src/plugins/bearer/connman/qconnmanengine.cpp create mode 100644 src/plugins/bearer/connman/qconnmanengine.h create mode 100644 src/plugins/bearer/connman/qconnmanservice_linux.cpp create mode 100644 src/plugins/bearer/connman/qconnmanservice_linux_p.h diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index f95e8af..6d8f7f2 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -4,7 +4,8 @@ contains(QT_CONFIG, dbus) { contains(QT_CONFIG, icd) { SUBDIRS += icd } else { - SUBDIRS += networkmanager generic + SUBDIRS += generic + !mac:SUBDIRS += connman networkmanager } } diff --git a/src/plugins/bearer/connman/connman.pro b/src/plugins/bearer/connman/connman.pro new file mode 100644 index 0000000..4be752b --- /dev/null +++ b/src/plugins/bearer/connman/connman.pro @@ -0,0 +1,19 @@ +TARGET = qconnmanbearer +include(../../qpluginbase.pri) + +QT = core network dbus + +HEADERS += qconnmanservice_linux_p.h \ + qconnmanengine.h \ + ../qnetworksession_impl.h \ + ../qbearerengine_impl.h + +SOURCES += main.cpp \ + qconnmanservice_linux.cpp \ + qconnmanengine.cpp \ + ../qnetworksession_impl.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target + diff --git a/src/plugins/bearer/connman/main.cpp b/src/plugins/bearer/connman/main.cpp new file mode 100644 index 0000000..d483cf0 --- /dev/null +++ b/src/plugins/bearer/connman/main.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qconnmanengine.h" + +#include + +#include + +#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_DBUS + +QT_BEGIN_NAMESPACE + +class QConnmanEnginePlugin : public QBearerEnginePlugin +{ +public: + QConnmanEnginePlugin(); + ~QConnmanEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QConnmanEnginePlugin::QConnmanEnginePlugin() +{ +} + +QConnmanEnginePlugin::~QConnmanEnginePlugin() +{ +} + +QStringList QConnmanEnginePlugin::keys() const +{ + return QStringList() << QLatin1String("connman"); +} + +QBearerEngine *QConnmanEnginePlugin::create(const QString &key) const +{ + if (key == QLatin1String("connman")) { + QConnmanEngine *engine = new QConnmanEngine; + if (engine->connmanAvailable()) + return engine; + else + delete engine; + } + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QConnmanEnginePlugin) +Q_EXPORT_PLUGIN2(qconnmanbearer, QConnmanEnginePlugin) + +QT_END_NAMESPACE + +#endif +#endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/connman/qconnmanengine.cpp b/src/plugins/bearer/connman/qconnmanengine.cpp new file mode 100644 index 0000000..e4cab92 --- /dev/null +++ b/src/plugins/bearer/connman/qconnmanengine.cpp @@ -0,0 +1,651 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qconnmanengine.h" +#include "qconnmanservice_linux_p.h" +#include "../qnetworksession_impl.h" + +#include + +#include + +#include + +#include +#include +//#include +#include +#include +#include + +#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_DBUS + +QT_BEGIN_NAMESPACE + +QConnmanEngine::QConnmanEngine(QObject *parent) +: QBearerEngineImpl(parent), + connmanManager(new QConnmanManagerInterface(this)) +{ +// qWarning() << Q_FUNC_INFO; +} + +QConnmanEngine::~QConnmanEngine() +{ +} + +bool QConnmanEngine::connmanAvailable() const +{ + QMutexLocker locker(&mutex); + return connmanManager->isValid(); +} + +void QConnmanEngine::initialize() +{ + connect(connmanManager,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(propertyChangedContext(QString,QString,QDBusVariant))); + + foreach(const QString techPath, connmanManager->getTechnologies()) { + QConnmanTechnologyInterface *tech; + tech = new QConnmanTechnologyInterface(techPath, this); + + connect(tech,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(technologyPropertyChangedContext(QString,QString,QDBusVariant))); + + foreach(const QString devicePath,tech->getDevices()) { + QConnmanDeviceInterface *dev; + dev = new QConnmanDeviceInterface(devicePath); + connect(dev,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(devicePropertyChangedContext(QString,QString,QDBusVariant))); + deviceMap.insert(techPath,QStringList() << devicePath); + } + } + // Get current list of access points. + getConfigurations(); +} + +QList QConnmanEngine::getConfigurations() +{ + QMutexLocker locker(&mutex); + foundConfigurations.clear(); + getNetworkListing(); + return foundConfigurations; +} + +void QConnmanEngine::getNetworkListing() +{ + QMutexLocker locker(&mutex); + + QMapIterator i(deviceMap); + while(i.hasNext()) { + i.next(); + QConnmanDeviceInterface dev(i.value().at(0)); + if(dev.isValid()) { + foreach(const QString network,dev.getNetworks()) { + addNetworkConfiguration(network); + } + } + } +} + +void QConnmanEngine::doRequestUpdate() +{ + getConfigurations(); + emit updateCompleted(); +} + +QString QConnmanEngine::getInterfaceFromId(const QString &id) +{ + QMutexLocker locker(&mutex); + + QString servicePath = serviceFromId(id); + QString netPath = getNetworkForService(servicePath); + + QMapIterator i(deviceMap); + while(i.hasNext()) { + i.next(); + if(i.value().count() > 0) { + QConnmanDeviceInterface dev(i.value().at(0)); + foreach(const QString network, dev.getNetworks()) { + if(network == netPath) { + return dev.getInterface(); + } + } + } + } + return QString(); +} + +bool QConnmanEngine::hasIdentifier(const QString &id) +{ + QMutexLocker locker(&mutex); + return accessPointConfigurations.contains(id); +} + +QString QConnmanEngine::bearerName(const QString &id) +{ + QMutexLocker locker(&mutex); + QConnmanServiceInterface serv(serviceFromId(id)); + QString connectionType = serv.getType(); + + if (connectionType == "ethernet") + return QLatin1String("Ethernet"); + else if (connectionType == "wifi") + return QLatin1String("WLAN"); + else if (connectionType == "cellular") { + QString mode = serv.getMode(); + if(mode == "gprs" || mode == "edge") { + return QLatin1String("2G"); + } else if(mode == "umts") { + return QLatin1String("WCDMA"); + } + } + else if (connectionType == "wimax") + return QLatin1String("WIMAX"); + + return QString(); +} + +void QConnmanEngine::connectToId(const QString &id) +{ + QMutexLocker locker(&mutex); + QConnmanServiceInterface serv(serviceFromId(id)); + if(!serv.isValid()) { + emit connectionError(id, InterfaceLookupError); + } else { + serv.connect(); + } +} + +void QConnmanEngine::disconnectFromId(const QString &id) +{ + QMutexLocker locker(&mutex); + QConnmanServiceInterface serv(serviceFromId(id)); + if(!serv.isValid()) { + emit connectionError(id, DisconnectionError); + } else { + serv.disconnect(); + } +} + +void QConnmanEngine::requestUpdate() +{ + QMutexLocker locker(&mutex); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} + +QString QConnmanEngine::serviceFromId(const QString &id) +{ + QMutexLocker locker(&mutex); + foreach(QString service, connmanManager->getServices()) { + if (id == QString::number(qHash(service))) + return service; + } + + return QString(); +} + +QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) +{ + QMutexLocker locker(&mutex); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + +quint64 QConnmanEngine::bytesWritten(const QString &id) +{//TODO use connman counter API + QMutexLocker locker(&mutex); + quint64 result = 0; + QString devFile = getInterfaceFromId(id); + QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); + if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + return result; +} + +quint64 QConnmanEngine::bytesReceived(const QString &id) +{//TODO use connman counter API + QMutexLocker locker(&mutex); + quint64 result = 0; + QString devFile = getInterfaceFromId(id); + QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); + if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&rx); + in >> result; + rx.close(); + } + return result; +} + +quint64 QConnmanEngine::startTime(const QString &/*id*/) +{ + // TODO + QMutexLocker locker(&mutex); + if (activeTime.isNull()) { + return 0; + } + return activeTime.secsTo(QDateTime::currentDateTime()); +} + +QNetworkConfigurationManager::Capabilities QConnmanEngine::capabilities() const +{ + return QNetworkConfigurationManager::ForcedRoaming | + QNetworkConfigurationManager::DataStatistics | + QNetworkConfigurationManager::CanStartAndStopInterfaces; +} + +QNetworkSessionPrivate *QConnmanEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl; +} + +QNetworkConfigurationPrivatePointer QConnmanEngine::defaultConfiguration() +{ + return QNetworkConfigurationPrivatePointer(); +} + + +QString QConnmanEngine::getServiceForNetwork(const QString &netPath) +{ + QMutexLocker locker(&mutex); + QConnmanNetworkInterface network(netPath, this); + foreach(QString service,connmanManager->getServices()) { + QConnmanServiceInterface serv(service,this); + if(serv.getName() == network.getName() + && network.getSignalStrength() == serv.getSignalStrength()) { + return service; + } + } + return QString(); +} + +QString QConnmanEngine::getNetworkForService(const QString &servPath) +{ + QMutexLocker locker(&mutex); + QMap map; + + QMapIterator i(deviceMap); + while(i.hasNext()) { + i.next(); + if(i.value().count() > 0) { + QConnmanDeviceInterface device(i.value().at(0)); + QMap netMapStrength; + + foreach(const QString netPath, knownNetworks[device.getType()]) { + QConnmanNetworkInterface network1(netPath, this); + QString netname = network1.getName(); + qint32 sigStrength = network1.getSignalStrength(); + + if(netMapStrength.contains(netname) + && netMapStrength.value(netname) < sigStrength) { + netMapStrength.remove(netname); + map.remove(netname); + } + netMapStrength.insert(netname, sigStrength); + map.insert(netname,netPath); + } + } + } + + QConnmanServiceInterface *serv; + serv = new QConnmanServiceInterface(servPath); + if(map.contains(serv->getName())) { + return map.value(serv->getName()); + } + return QString(); +} + +void QConnmanEngine::propertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) +{ +// qDebug() << __FUNCTION__ << path << item; + QMutexLocker locker(&mutex); + + if(item == "Technologies") { + QDBusArgument arg = qvariant_cast(value.variant()); + QStringList newlist = qdbus_cast(arg); + if(newlist.count() > 0) { + QMap oldtech = technologies; + + foreach(const QString listPath, newlist) { + if(!oldtech.contains(listPath)) { + QConnmanTechnologyInterface *tech; + tech = new QConnmanTechnologyInterface(listPath,this); + connect(tech,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(technologyPropertyChangedContext(QString,QString,QDBusVariant))); + technologies.insert(listPath, tech); + } + } + + foreach(const QString old, oldtech.keys()) { + if(!newlist.contains(old)) { + QConnmanTechnologyInterface *tech = oldtech.value(old); + disconnect(tech,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(technologyPropertyChangedContext(QString,QString,QDBusVariant))); + + technologies.remove(old); + getNetworkListing(); + } + } + } + } +} + +void QConnmanEngine::servicePropertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) +{ +// qDebug() << __FUNCTION__ << path << item; + QMutexLocker locker(&mutex); + if(item == "State") { + configurationChange(QString::number(qHash(path))); + if(value.variant().toString() == "failure") { + QConnmanServiceInterface serv(path); + qDebug() <<__FUNCTION__ <<"Error" << serv.getError(); + emit connectionError(QString::number(qHash(path)), ConnectError); + } + } +} + +void QConnmanEngine::networkPropertyChangedContext(const QString &path,const QString &item, const QDBusVariant &/*value*/) +{ +// qDebug() << __FUNCTION__ << path << item; + QMutexLocker locker(&mutex); +} + +void QConnmanEngine::devicePropertyChangedContext(const QString &path,const QString &item,const QDBusVariant &value) +{ +// qDebug() << __FUNCTION__ << path << item << value.variant(); + QMutexLocker locker(&mutex); + if(item == "Networks") { + QDBusArgument arg = qvariant_cast(value.variant()); + QStringList remainingNetworks = qdbus_cast(arg); + + QConnmanDeviceInterface dev(path); + QStringList oldnetworks = knownNetworks[dev.getType()]; + if(remainingNetworks.count() != oldnetworks.count()) { + + foreach(const QString netPath, remainingNetworks) { + if(!oldnetworks.contains(netPath)) { + addNetworkConfiguration(netPath); + } + } + + foreach(const QString netPath, oldnetworks) { + QString servicePath = getServiceForNetwork(netPath); + if(!remainingNetworks.contains(netPath)) { + if(servicePath.isEmpty()) { + removeConfiguration(netPath); + } else { + if(!remainingNetworks.contains(servicePath)) { + removeConfiguration(QString::number(qHash(servicePath))); + } + } + } + } + } + } +} + +void QConnmanEngine::technologyPropertyChangedContext(const QString & path, const QString &item, const QDBusVariant &value) +{ +// qWarning() << __FUNCTION__ << path << item << value.variant(); +// if(item == "Devices") { +// QDBusArgument arg = qvariant_cast(value.variant()); +// QStringList list = qdbus_cast(arg); +// } + if(item == "State") { + if(value.variant().toString() == "enabled") { + } + if(value.variant().toString() == "offline") { + deviceMap.remove(path); + } + if(value.variant().toString() == "available") { + QConnmanTechnologyInterface tech(connmanManager->getPathForTechnology(path)); + foreach(const QString devPath, tech.getDevices()) { + QConnmanDeviceInterface *dev; + dev = new QConnmanDeviceInterface(devPath,this); + connect(dev,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(devicePropertyChangedContext(QString,QString,QDBusVariant))); + + deviceMap.insert(path,QStringList() << devPath); + } + } + } +} + +void QConnmanEngine::configurationChange(const QString &id) +{ + QMutexLocker locker(&mutex); + bool changed = false; + + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + QString servicePath = serviceFromId(id); + QConnmanServiceInterface *serv; + serv = new QConnmanServiceInterface(servicePath); + QString networkName = serv->getName(); + QNetworkConfiguration::StateFlags curState = getStateForService(servicePath); + + ptr->mutex.lock(); + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } + + if (ptr->name != networkName) { + ptr->name = networkName; + changed = true; + } + + if (ptr->state != curState) { + ptr->state = curState; + changed = true; + } + + ptr->mutex.unlock(); + + if (changed) { + locker.unlock(); + emit configurationChanged(ptr); + locker.relock(); + } + + } + locker.unlock(); + emit updateCompleted(); +} + +QNetworkConfiguration::StateFlags QConnmanEngine::getStateForService(const QString &service) +{ + qWarning() << __FUNCTION__; + QMutexLocker locker(&mutex); + QConnmanServiceInterface serv(service); + QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined; + if(serv.isFavorite()) { + flag = ( flag | QNetworkConfiguration::Discovered); + } else { + flag = QNetworkConfiguration::Undefined; + } + + if(serv.getState() == "ready" || serv.getState() == "online") { + flag = ( flag | QNetworkConfiguration::Active); + } + + return flag; +} + +QString QConnmanEngine::typeToBearer(const QString &type) +{ + QMutexLocker locker(&mutex); + if(type == "wifi") + return "WLAN"; + if(type == "ethernet") + return "Ethernet"; + if(type == "bluetooth") + return "Bluetooth"; + if(type == "cellular") { + return "Cellular"; + // not handled: CDMA2000 HSPA + } + if(type == "wimax") + return "WiMax"; +// if(type == "gps") +// if(type == "vpn") + + return "Unknown"; +} + +void QConnmanEngine::removeConfiguration(const QString &netpath) +{ + QMutexLocker locker(&mutex); + const QString id = QString::number(qHash(netpath)); + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); + QConnmanDeviceInterface device(netpath.section("/",0,5),this); + locker.unlock(); + knownNetworks[device.getType()].removeAll(netpath); + emit configurationRemoved(ptr); + locker.relock(); + } +} + +void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) +{ +// qWarning() << __FUNCTION__ << networkPath; + QMutexLocker locker(&mutex); + + QConnmanNetworkInterface *network; + network = new QConnmanNetworkInterface(networkPath, this); + QString servicePath = getServiceForNetwork(networkPath); + QConnmanServiceInterface *serv; + + QString id; + if(servicePath.isEmpty()) { + id = QString::number(qHash(networkPath)); + } else { + id = QString::number(qHash(servicePath)); + } + if (!accessPointConfigurations.contains(id)) { + connect(network,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(networkPropertyChangedContext(QString,QString, QDBusVariant))); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + + QString networkName = network->getName(); + + if(networkName.isEmpty()) + networkName = "Hidden Network"; + + QString bearerName; + + QConnmanDeviceInterface device(networkPath.section("/",0,5),this); + if(servicePath.isEmpty()) { + bearerName = typeToBearer(device.getType()); + } else { + serv = new QConnmanServiceInterface(servicePath,this); + bearerName = typeToBearer(serv->getType()); + connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); + } + knownNetworks[device.getType()]<< networkPath; + + if(bearerName == "Cellular") { + QString mode = serv->getMode(); + if(mode == "gprs" || mode == "edge") { + bearerName = "2G"; + } else if(mode == "umts") { + bearerName = "WCDMA"; + } + networkName = serv->getAPN(); + } + + cpPriv->name = networkName; + cpPriv->isValid = true; + cpPriv->id = id; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->bearer = bearerName; + + if(network->getWifiSecurity() == "none") { + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + } else { + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + } + + if(servicePath.isEmpty()) + cpPriv->state = QNetworkConfiguration::Undefined; + else + cpPriv->state = getStateForService(servicePath); + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ptr->id, ptr); + foundConfigurations.append(cpPriv); + locker.unlock(); + emit configurationAdded(ptr); + locker.relock(); + } +} + +QT_END_NAMESPACE + +#endif // QT_NO_DBUS +#endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/connman/qconnmanengine.h b/src/plugins/bearer/connman/qconnmanengine.h new file mode 100644 index 0000000..849d8c9 --- /dev/null +++ b/src/plugins/bearer/connman/qconnmanengine.h @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCONNMANENGINE_P_H +#define QCONNMANENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "../qbearerengine_impl.h" + +#include "qconnmanservice_linux_p.h" + +#include +#include + +#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_DBUS + +QT_BEGIN_NAMESPACE + +class QConnmanEngine : public QBearerEngineImpl +{ + Q_OBJECT + +public: + QConnmanEngine(QObject *parent = 0); + ~QConnmanEngine(); + + bool connmanAvailable() const; + + virtual QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + virtual QString bearerName(const QString &id); + + virtual void connectToId(const QString &id); + virtual void disconnectFromId(const QString &id); + + Q_INVOKABLE void initialize(); + Q_INVOKABLE void requestUpdate(); + + QNetworkSession::State sessionStateForId(const QString &id); + QNetworkSessionPrivate *createSessionBackend(); + + virtual quint64 bytesWritten(const QString &id); + virtual quint64 bytesReceived(const QString &id); + virtual quint64 startTime(const QString &id); + + + virtual QNetworkConfigurationManager::Capabilities capabilities() const; + virtual QNetworkConfigurationPrivatePointer defaultConfiguration(); + + void configurationChange(const QString &id); + QList getConfigurations(); + + +private Q_SLOTS: + + void doRequestUpdate(); + void servicePropertyChangedContext(const QString &,const QString &,const QDBusVariant &); + void networkPropertyChangedContext(const QString &,const QString &,const QDBusVariant &); + void devicePropertyChangedContext(const QString &,const QString &,const QDBusVariant &); + void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); + void technologyPropertyChangedContext(const QString &,const QString &, const QDBusVariant &); + +private: + QConnmanManagerInterface *connmanManager; + + QList foundConfigurations; + void getNetworkListing(); + + QString getServiceForNetwork(const QString &network); + QString getNetworkForService(const QString &network); + + QString serviceFromId(const QString &id); + QString networkFromId(const QString &id); + + QNetworkConfiguration::StateFlags getStateForService(const QString &service); + QString typeToBearer(const QString &type); + + void removeConfiguration(const QString &path); + void addNetworkConfiguration(const QString &worknetPath); + QDateTime activeTime; + + + QMap technologies; + QMap knownNetworks; + QMap deviceMap; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_DBUS +#endif // QT_NO_BEARERMANAGEMENT + +#endif + diff --git a/src/plugins/bearer/connman/qconnmanservice_linux.cpp b/src/plugins/bearer/connman/qconnmanservice_linux.cpp new file mode 100644 index 0000000..ca76ffd --- /dev/null +++ b/src/plugins/bearer/connman/qconnmanservice_linux.cpp @@ -0,0 +1,1038 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qconnmanservice_linux_p.h" + + +QT_BEGIN_NAMESPACE +static QDBusConnection dbusConnection = QDBusConnection::systemBus(); + + +QConnmanManagerInterface::QConnmanManagerInterface( QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + QLatin1String(CONNMAN_MANAGER_PATH), + CONNMAN_MANAGER_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanManagerInterface::~QConnmanManagerInterface() +{ +} + +void QConnmanManagerInterface::connectNotify(const char *signal) +{ +if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { + if(!connection().connect(QLatin1String(CONNMAN_SERVICE), + QLatin1String(CONNMAN_MANAGER_PATH), + QLatin1String(CONNMAN_MANAGER_INTERFACE), + QLatin1String("PropertyChanged"), + this,SIGNAL(propertyChanged(const QString &, const QDBusVariant & )))) { + qWarning() << "PropertyCHanged not connected"; + } + } + + if (QLatin1String(signal) == SIGNAL(stateChanged(QString))) { + if (!connection().connect(QLatin1String(CONNMAN_SERVICE), + QLatin1String(CONNMAN_MANAGER_PATH), + QLatin1String(CONNMAN_MANAGER_INTERFACE), + QLatin1String("StateChanged"), + this,SIGNAL(stateChanged(const QString&)))) { + qWarning() << "StateChanged not connected"; + + } + } + if (QLatin1String(signal) == SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))) { + QConnmanDBusHelper *helper; + helper = new QConnmanDBusHelper(this); + + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + QLatin1String(CONNMAN_MANAGER_PATH), + QLatin1String(CONNMAN_MANAGER_INTERFACE), + QLatin1String("PropertyChanged"), + helper,SLOT(propertyChanged(QString,QDBusVariant))); + + + QObject::connect(helper,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &)), + this,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &))); + } +} + +void QConnmanManagerInterface::disconnectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QVariant))) { + + } +} + +QVariant QConnmanManagerInterface::getProperty(const QString &property) +{ + QVariant var; + QVariantMap map = getProperties(); + if (map.contains(property)) { + var = map.value(property); + } else { + qDebug() << "does not contain" << property; + } + return var; +} + +QVariantMap QConnmanManagerInterface::getProperties() +{ + QDBusReply reply = this->call(QLatin1String("GetProperties")); + return reply.value(); +} + +QString QConnmanManagerInterface::getState() +{ + QDBusReply reply = this->call("GetState"); + return reply.value(); +} + +bool QConnmanManagerInterface::setProperty(const QString &name, const QDBusVariant &value) +{ + Q_UNUSED(name); + Q_UNUSED(value); + return false; +} + +QDBusObjectPath QConnmanManagerInterface::createProfile(const QString &/*name*/) +{ + return QDBusObjectPath(); +} + +bool QConnmanManagerInterface::removeProfile(QDBusObjectPath /*path*/) +{ + return false; +} + +bool QConnmanManagerInterface::requestScan(const QString &type) +{ + QDBusReply reply = this->call(QLatin1String("RequestScan"), QVariant::fromValue(type)); + + bool ok = true; + if(reply.error().type() == QDBusError::InvalidArgs) { + qWarning() << reply.error().message(); + ok = false; + } + return ok; +} + +bool QConnmanManagerInterface::enableTechnology(const QString &type) +{ + QDBusReply > reply = this->call(QLatin1String("EnableTechnology"), QVariant::fromValue(type)); + bool ok = true; + if(reply.error().type() == QDBusError::InvalidArgs) { + qWarning() << reply.error().message(); + ok = false; + } + return ok; +} + +bool QConnmanManagerInterface::disableTechnology(const QString &type) +{ + QDBusReply > reply = this->call(QLatin1String("DisableTechnology"), QVariant::fromValue(type)); + bool ok = true; + if(reply.error().type() == QDBusError::InvalidArgs) { + qWarning() << reply.error().message(); + ok = false; + } + return ok; +} + +QDBusObjectPath QConnmanManagerInterface::connectService(QVariantMap &map) +{ + QDBusReply reply = this->call(QLatin1String("ConnectService"), QVariant::fromValue(map)); + if(!reply.isValid()) { + qDebug() << reply.error().message(); + + } + return reply; +} + +void QConnmanManagerInterface::registerAgent(QDBusObjectPath &/*path*/) +{ +} + +void QConnmanManagerInterface::unregisterAgent(QDBusObjectPath /*path*/) +{ +} + +void QConnmanManagerInterface::registerCounter(QDBusObjectPath /*path*/, quint32 /*interval*/) +{ +} + +void QConnmanManagerInterface::unregisterCounter(QDBusObjectPath /*path*/) +{ +} + +QString QConnmanManagerInterface::requestSession(const QString &bearerName) +{ + QDBusReply > reply = this->call(QLatin1String("RequestSession"), QVariant::fromValue(bearerName)); + return QString(); +} + +void QConnmanManagerInterface::releaseSession() +{ + QDBusReply > reply = this->call(QLatin1String("ReleaseSession")); +} + + +QDBusObjectPath QConnmanManagerInterface::lookupService(const QString &service) +{ + QDBusReply reply = this->call(QLatin1String("LookupService"), QVariant::fromValue(service)); + if(!reply.isValid()) { + qDebug() << reply.error().message(); + } + return reply; +} + +// properties + +QStringList QConnmanManagerInterface::getAvailableTechnologies() +{ + QVariant var = getProperty("AvailableTechnologies"); + return qdbus_cast(var); +} + +QStringList QConnmanManagerInterface::getEnabledTechnologies() +{ + QVariant var = getProperty("EnabledTechnologies"); + return qdbus_cast(var); +} + +QStringList QConnmanManagerInterface::getConnectedTechnologies() +{ + QVariant var = getProperty("ConnectedTechnologies"); + return qdbus_cast(var); +} + +QString QConnmanManagerInterface::getDefaultTechnology() +{ + QVariant var = getProperty("DefaultTechnology"); + return qdbus_cast(var); +} + +bool QConnmanManagerInterface::getOfflineMode() +{ + QVariant var = getProperty("OfflineMode"); + return qdbus_cast(var); +} + +QString QConnmanManagerInterface::getActiveProfile() +{ + QVariant var = getProperty("ActiveProfile"); + return qdbus_cast(var); +} + +QStringList QConnmanManagerInterface::getProfiles() +{ + QVariant var = getProperty("Profiles"); + return qdbus_cast(var); +} + +QStringList QConnmanManagerInterface::getTechnologies() +{ + QVariant var = getProperty("Technologies"); + return qdbus_cast(var); +} + +QStringList QConnmanManagerInterface::getServices() +{ + QVariant var = getProperty("Services"); + return qdbus_cast(var); +} + +QString QConnmanManagerInterface::getPathForTechnology(const QString &name) +{ + foreach(const QString path, getTechnologies()) { + if(path.contains(name)) { + return path; + } + } + return ""; +} + +QConnmanNetworkInterface::QConnmanNetworkInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_NETWORK_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanNetworkInterface::~QConnmanNetworkInterface() +{ +} + +void QConnmanNetworkInterface::connectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { + if(!connection().connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_NETWORK_INTERFACE), + QLatin1String("PropertyChanged"), + this,SIGNAL(propertyChanged(QString,QDBusVariant))) ) { + qWarning() << "network properties not connected"; + } + } + if (QLatin1String(signal) == SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))) { + QConnmanDBusHelper *helper; + helper = new QConnmanDBusHelper(this); + + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_NETWORK_INTERFACE), + QLatin1String("PropertyChanged"), + helper,SLOT(propertyChanged(QString,QDBusVariant))); + + QObject::connect(helper,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &)), + this,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &))); + } +} + +void QConnmanNetworkInterface::disconnectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { + + } +} + +QVariantMap QConnmanNetworkInterface::getProperties() +{ + QDBusReply reply = this->call(QLatin1String("GetProperties")); + return reply.value(); +} + +QVariant QConnmanNetworkInterface::getProperty(const QString &property) +{ + QVariant var; + QVariantMap map = getProperties(); + if (map.contains(property)) { + var = map.value(property); + } + return var; +} + +//properties + +QString QConnmanNetworkInterface::getAddress() +{ + QVariant var = getProperty("Address"); + return qdbus_cast(var); +} + +QString QConnmanNetworkInterface::getName() +{ + QVariant var = getProperty("Name"); + return qdbus_cast(var); +} + +bool QConnmanNetworkInterface::isConnected() +{ + QVariant var = getProperty("Connected"); + return qdbus_cast(var); +} + +quint8 QConnmanNetworkInterface::getSignalStrength() +{ + QVariant var = getProperty("Strength"); + return qdbus_cast(var); +} + +QString QConnmanNetworkInterface::getDevice() +{ + QVariant var = getProperty("Device"); + return qdbus_cast(var); +} + +QString QConnmanNetworkInterface::getWifiSsid() +{ + QVariant var = getProperty("WiFi.SSID"); + return qdbus_cast(var); +} + +QString QConnmanNetworkInterface::getWifiMode() +{ + QVariant var = getProperty("WiFi.Mode"); + return qdbus_cast(var); +} + +QString QConnmanNetworkInterface::getWifiSecurity() +{ + QVariant var = getProperty("WiFi.Security"); + return qdbus_cast(var); +} + +QString QConnmanNetworkInterface::getWifiPassphrase() +{ + QVariant var = getProperty("WiFi.Passphrase"); + return qdbus_cast(var); +} + + +////////////////////////// + +QConnmanProfileInterface::QConnmanProfileInterface(const QString &dbusPathName,QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_PROFILE_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanProfileInterface::~QConnmanProfileInterface() +{ +} + +void QConnmanProfileInterface::connectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_PROFILE_INTERFACE), + QLatin1String("PropertyChanged"), + this,SIGNAL(propertyChanged(QString,QDBusVariant))); + } +} + +void QConnmanProfileInterface::disconnectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString, QVariant))) { + + } +} + +QVariantMap QConnmanProfileInterface::getProperties() +{ + QDBusReply reply = this->call(QLatin1String("GetProperties")); + return reply.value(); +} + +QVariant QConnmanProfileInterface::getProperty(const QString &property) +{ + QVariant var; + QVariantMap map = getProperties(); + if (map.contains(property)) { + var = map.value(property); + } else { + qDebug() <<__FUNCTION__<< "Could not find" << property; + } + return var; +} + +// properties +QString QConnmanProfileInterface::getName() +{ + + QVariant var = getProperty("Name"); + return qdbus_cast(var); +} + +bool QConnmanProfileInterface::isOfflineMode() +{ + QVariant var = getProperty("OfflineMode"); + return qdbus_cast(var); +} + +QStringList QConnmanProfileInterface::getServices() +{ + QVariant var = getProperty("Services"); + return qdbus_cast(var); +} + +/////////////////////////// +QConnmanServiceInterface::QConnmanServiceInterface(const QString &dbusPathName,QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_SERVICE_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanServiceInterface::~QConnmanServiceInterface() +{ +} + +void QConnmanServiceInterface::connectNotify(const char *signal) +{ +// qWarning() << __FUNCTION__ << signal << this->path(); + + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_SERVICE_INTERFACE), + QLatin1String("PropertyChanged"), + this,SIGNAL(propertyChanged(QString,QDBusVariant))); + } + if (QLatin1String(signal) == SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))) { + QConnmanDBusHelper *helper; + helper = new QConnmanDBusHelper(this); + + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_SERVICE_INTERFACE), + QLatin1String("PropertyChanged"), + helper,SLOT(propertyChanged(QString,QDBusVariant))); + + QObject::connect(helper,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &)), + this,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &))); + } +} + +void QConnmanServiceInterface::disconnectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QVariant))) { + + } +} + +QVariantMap QConnmanServiceInterface::getProperties() +{ + QDBusReply reply = this->call(QLatin1String("GetProperties")); + return reply.value(); +} + +QVariant QConnmanServiceInterface::getProperty(const QString &property) +{ + QVariant var; + QVariantMap map = getProperties(); + if (map.contains(property)) { + var = map.value(property); + } else { +// qDebug() <<__FUNCTION__<< "Could not find" << property; + } + return var; +} + +// clearProperty +void QConnmanServiceInterface::connect() +{ + QDBusReply reply = this->call(QLatin1String("Connect")); +} + +void QConnmanServiceInterface::disconnect() +{ + QDBusReply reply = this->call(QLatin1String("Disconnect")); +} + +void QConnmanServiceInterface::remove() +{ + QDBusReply reply = this->call(QLatin1String("Remove")); +} + +// void moveBefore(QDBusObjectPath &service); +// void moveAfter(QDBusObjectPath &service); + +// properties +QString QConnmanServiceInterface::getState() +{ + QVariant var = getProperty("State"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getError() +{ + QVariant var = getProperty("Error"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getName() +{ + QVariant var = getProperty("Name"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getType() +{ + QVariant var = getProperty("Type"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getMode() +{ + QVariant var = getProperty("Mode"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getSecurity() +{ + QVariant var = getProperty("Security"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getPassphrase() +{ + QVariant var = getProperty("Passphrase"); + return qdbus_cast(var); +} + +bool QConnmanServiceInterface::isPassphraseRequired() +{ + QVariant var = getProperty("PassphraseRequired"); + return qdbus_cast(var); +} + +quint8 QConnmanServiceInterface::getSignalStrength() +{ + QVariant var = getProperty("Strength"); + return qdbus_cast(var); +} + +bool QConnmanServiceInterface::isFavorite() +{ + QVariant var = getProperty("Favorite"); + return qdbus_cast(var); +} + +bool QConnmanServiceInterface::isImmutable() +{ + QVariant var = getProperty("Immutable"); + return qdbus_cast(var); +} + +bool QConnmanServiceInterface::isAutoConnect() +{ + QVariant var = getProperty("AutoConnect"); + return qdbus_cast(var); +} + +bool QConnmanServiceInterface::isSetupRequired() +{ + QVariant var = getProperty("SetupRequired"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getAPN() +{ + QVariant var = getProperty("APN"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getMCC() +{ + QVariant var = getProperty("MCC"); + return qdbus_cast(var); +} + +QString QConnmanServiceInterface::getMNC() +{ + QVariant var = getProperty("MNC"); + return qdbus_cast(var); +} + +bool QConnmanServiceInterface::isRoaming() +{ + QVariant var = getProperty("Roaming"); + return qdbus_cast(var); +} + +QStringList QConnmanServiceInterface::getNameservers() +{ + QVariant var = getProperty("NameServers"); + return qdbus_cast(var); +} + +QStringList QConnmanServiceInterface::getDomains() +{ + QVariant var = getProperty("Domains"); + return qdbus_cast(var); +} + +QVariantMap QConnmanServiceInterface::getIPv4() +{ + QVariant var = getProperty("IPv4"); + return qdbus_cast(var); +} + +QVariantMap QConnmanServiceInterface::getIPv4Configuration() +{ + QVariant var = getProperty("IPv4.Configuration"); + return qdbus_cast(var); +} + +QVariantMap QConnmanServiceInterface::getProxy() +{ + QVariant var = getProperty("Proxy"); + return qdbus_cast(var); +} + +QVariantMap QConnmanServiceInterface::getEthernet() +{ + QVariant var = getProperty("Ethernet"); + return qdbus_cast(var); +} + +bool QConnmanServiceInterface::isOfflineMode() +{ + QVariant var = getProperty("OfflineMode"); + return qdbus_cast(var); +} + +QStringList QConnmanServiceInterface::getServices() +{ + QVariant var = getProperty("Services"); + return qdbus_cast(var); +} + + +////////////////////////// +QConnmanTechnologyInterface::QConnmanTechnologyInterface(const QString &dbusPathName,QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_TECHNOLOGY_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanTechnologyInterface::~QConnmanTechnologyInterface() +{ +} + +void QConnmanTechnologyInterface::connectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_TECHNOLOGY_INTERFACE), + QLatin1String("PropertyChanged"), + this,SIGNAL(propertyChanged(QString,QDBusVariant))); + } + if (QLatin1String(signal) == SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))) { + QConnmanDBusHelper *helper; + helper = new QConnmanDBusHelper(this); + + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_TECHNOLOGY_INTERFACE), + QLatin1String("PropertyChanged"), + helper,SLOT(propertyChanged(QString,QDBusVariant))); + + QObject::connect(helper,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &)), + this,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &))); + } +} + +void QConnmanTechnologyInterface::disconnectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QVariant))) { + + } +} + +QVariantMap QConnmanTechnologyInterface::getProperties() +{ + QDBusReply reply = this->call(QLatin1String("GetProperties")); + return reply.value(); +} + +QVariant QConnmanTechnologyInterface::getProperty(const QString &property) +{ + QVariant var; + QVariantMap map = getProperties(); + if (map.contains(property)) { + var = map.value(property); + } + return var; +} + +// properties +QString QConnmanTechnologyInterface::getState() +{ + QVariant var = getProperty("State"); + return qdbus_cast(var); +} + +QString QConnmanTechnologyInterface::getName() +{ + QVariant var = getProperty("Name"); + return qdbus_cast(var); +} + +QString QConnmanTechnologyInterface::getType() +{ + QVariant var = getProperty("Type"); + return qdbus_cast(var); +} + + +QStringList QConnmanTechnologyInterface::getDevices() +{ + QVariant var = getProperty("Devices"); + return qdbus_cast(var); +} + + +////////////////////////////////// +QConnmanAgentInterface::QConnmanAgentInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_AGENT_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanAgentInterface::~QConnmanAgentInterface() +{ +} + +void QConnmanAgentInterface::connectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { +// dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), +// this->path(), +// QLatin1String(CONNMAN_NETWORK_INTERFACE), +// QLatin1String("PropertyChanged"), +// this,SIGNAL(propertyChanged(const QString &, QVariant &))); + } +} + +void QConnmanAgentInterface::disconnectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString, QDBusVariant))) { + + } +} + + +void QConnmanAgentInterface::release() +{ +} + +void QConnmanAgentInterface::reportError(QDBusObjectPath &/*path*/, const QString &/*error*/) +{ +} + +//dict QConnmanAgentInterface::requestInput(QDBusObjectPath &path, dict fields) +//{ +//} + +void QConnmanAgentInterface::cancel() +{ +} + + +///////////////////////////////////////// + +QConnmanDeviceInterface::QConnmanDeviceInterface(const QString &dbusPathName,QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_DEVICE_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanDeviceInterface::~QConnmanDeviceInterface() +{ +} + +void QConnmanDeviceInterface::connectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QDBusVariant))) { + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_DEVICE_INTERFACE), + QLatin1String("PropertyChanged"), + this,SIGNAL(propertyChanged(QString,QDBusVariant))); + + } + if (QLatin1String(signal) == SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))) { + QConnmanDBusHelper *helper; + helper = new QConnmanDBusHelper(this); + + dbusConnection.connect(QLatin1String(CONNMAN_SERVICE), + this->path(), + QLatin1String(CONNMAN_DEVICE_INTERFACE), + QLatin1String("PropertyChanged"), + helper,SLOT(propertyChanged(QString,QDBusVariant))); + + QObject::connect(helper,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &)), + this,SIGNAL(propertyChangedContext(const QString &,const QString &,const QDBusVariant &))); + } +} + +void QConnmanDeviceInterface::disconnectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChanged(QString,QVariant))) { + + } +} + +QVariantMap QConnmanDeviceInterface::getProperties() +{ + QDBusReply reply = this->call(QLatin1String("GetProperties")); + return reply.value(); +} + +bool QConnmanDeviceInterface::setProperty(const QString &name, const QDBusVariant &value) +{ + +// QList args; + qWarning() << __FUNCTION__ << name << value.variant(); +// args << qVariantFromValue(name); +// args << qVariantFromValue(value); + + QDBusMessage reply = this->call(QLatin1String("SetProperty"),name, qVariantFromValue(value)); +qWarning() << reply.errorMessage(); + + return true; +} + +void QConnmanDeviceInterface::scan() +{ + QDBusReply reply = this->call(QLatin1String("ProposeScan")); + if(!reply.isValid()) { + qDebug() << reply.error().message(); + } +} + +QVariant QConnmanDeviceInterface::getProperty(const QString &property) +{ + QVariant var; + QVariantMap map = getProperties(); + if (map.contains(property)) { + var = map.value(property); + } + return var; +} + +//properties +QString QConnmanDeviceInterface::getAddress() +{ + QVariant var = getProperty("Address"); + return qdbus_cast(var); +} + +QString QConnmanDeviceInterface::getName() +{ + QVariant var = getProperty("Name"); + return qdbus_cast(var); +} + +QString QConnmanDeviceInterface::getType() +{ + QVariant var = getProperty("Type"); + return qdbus_cast(var); +} + +QString QConnmanDeviceInterface::getInterface() +{ + QVariant var = getProperty("Interface"); + return qdbus_cast(var); +} + +bool QConnmanDeviceInterface::isPowered() +{ + QVariant var = getProperty("Powered"); + return qdbus_cast(var); +} + +quint16 QConnmanDeviceInterface::getScanInterval() +{ + QVariant var = getProperty("ScanInterval"); + return qdbus_cast(var); +} + +bool QConnmanDeviceInterface::setScanInterval(const QString & interval) +{ +// QList args; +// args << qVariantFromValue(name) +// << value.variant(); + +// QDBusMessage reply = this->callWithArgumentList(QDBus::AutoDetect,QLatin1String("SetProperty"),args); + + return setProperty("ScanInterval", QDBusVariant(interval)); +} + +bool QConnmanDeviceInterface::isScanning() +{ + QVariant var = getProperty("Scanning"); + return qdbus_cast(var); +} + +QStringList QConnmanDeviceInterface::getNetworks() +{ + QVariant var = getProperty("Networks"); + return qdbus_cast(var); +} + +bool QConnmanDeviceInterface::setEnabled(bool powered) +{ + QList args; + args << qVariantFromValue(QString("Powered")) + << qVariantFromValue(QDBusVariant(powered)); + + QDBusMessage reply = this->callWithArgumentList(QDBus::AutoDetect,QLatin1String("SetProperty"),args); + qWarning() << reply.errorMessage() << reply.errorName(); + return true; +} + +QConnmanDBusHelper::QConnmanDBusHelper(QObject * parent) + : QObject(parent) +{ +} + +QConnmanDBusHelper::~QConnmanDBusHelper() +{ +} + +void QConnmanDBusHelper::propertyChanged(const QString &item, const QDBusVariant &var) +{ + QDBusMessage msg = this->message(); +// qWarning() << sender(); + // qWarning() << msg.interface() << msg.path() << item << var.variant() <<"\n"; + Q_EMIT propertyChangedContext(msg.path() ,item, var); +} + +///////////////// +QT_END_NAMESPACE diff --git a/src/plugins/bearer/connman/qconnmanservice_linux_p.h b/src/plugins/bearer/connman/qconnmanservice_linux_p.h new file mode 100644 index 0000000..9475296 --- /dev/null +++ b/src/plugins/bearer/connman/qconnmanservice_linux_p.h @@ -0,0 +1,377 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCONNMANSERVICE_H +#define QCONNMANSERVICE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifndef __CONNMAN_DBUS_H + +#define CONNMAN_SERVICE "org.moblin.connman" +#define CONNMAN_PATH "/org/moblin/connman" + +#define CONNMAN_DEBUG_INTERFACE CONNMAN_SERVICE ".Debug" +#define CONNMAN_ERROR_INTERFACE CONNMAN_SERVICE ".Error" +#define CONNMAN_AGENT_INTERFACE CONNMAN_SERVICE ".Agent" +#define CONNMAN_COUNTER_INTERFACE CONNMAN_SERVICE ".Counter" + +#define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" +#define CONNMAN_MANAGER_PATH "/" + +#define CONNMAN_TASK_INTERFACE CONNMAN_SERVICE ".Task" +#define CONNMAN_PROFILE_INTERFACE CONNMAN_SERVICE ".Profile" +#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" +#define CONNMAN_DEVICE_INTERFACE CONNMAN_SERVICE ".Device" +#define CONNMAN_NETWORK_INTERFACE CONNMAN_SERVICE ".Network" +#define CONNMAN_PROVIDER_INTERFACE CONNMAN_SERVICE ".Provider" +#define CONNMAN_TECHNOLOGY_INTERFACE CONNMAN_SERVICE ".Technology" +#endif + +QT_BEGIN_NAMESPACE + +QT_END_NAMESPACE + + +QT_BEGIN_NAMESPACE + +class QConnmanManagerInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanManagerInterface( QObject *parent = 0); + ~QConnmanManagerInterface(); + + QDBusObjectPath path() const; + + QVariantMap getProperties(); + bool setProperty(const QString &name, const QDBusVariant &value); + QDBusObjectPath createProfile(const QString &name); + bool removeProfile(QDBusObjectPath path); + bool requestScan(const QString &type); + bool enableTechnology(const QString &type); + bool disableTechnology(const QString &type); + QDBusObjectPath connectService(QVariantMap &map); + void registerAgent(QDBusObjectPath &path); + void unregisterAgent(QDBusObjectPath path); + void registerCounter(QDBusObjectPath path, quint32 interval); + void unregisterCounter(QDBusObjectPath path); + + QString requestSession(const QString &bearerName); + void releaseSession(); + + // properties + QString getState(); + QStringList getAvailableTechnologies(); + QStringList getEnabledTechnologies(); + QStringList getConnectedTechnologies(); + QString getDefaultTechnology(); + bool getOfflineMode(); + QString getActiveProfile(); + QStringList getProfiles(); + QStringList getTechnologies(); + QStringList getServices(); + QDBusObjectPath lookupService(const QString &); + + QString getPathForTechnology(const QString &tech); + + +Q_SIGNALS: + void propertyChanged(const QString &, const QDBusVariant &value); + void stateChanged(const QString &); + void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); + +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + QVariant getProperty(const QString &); +}; + + +class QConnmanNetworkInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanNetworkInterface(const QString &dbusPathName, QObject *parent = 0); + ~QConnmanNetworkInterface(); + + QVariantMap getProperties(); + + //properties + QString getAddress(); + QString getName(); + bool isConnected(); + quint8 getSignalStrength(); + QString getDevice(); + QString getWifiSsid(); + QString getWifiMode(); + QString getWifiSecurity(); + QString getWifiPassphrase(); + +Q_SIGNALS: + void propertyChanged(const QString &, const QDBusVariant &value); + void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + QVariant getProperty(const QString &); +}; + +class QConnmanProfileInterfacePrivate; +class QConnmanProfileInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanProfileInterface(const QString &dbusPathName,QObject *parent = 0); + ~QConnmanProfileInterface(); + + QVariantMap getProperties(); +// properties + QString getName(); + bool isOfflineMode(); + QStringList getServices(); + +Q_SIGNALS: + void propertyChanged(const QString &, const QDBusVariant &value); +private: + QConnmanProfileInterfacePrivate *d; + +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + QVariant getProperty(const QString &); +}; + +class QConnmanServiceInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanServiceInterface(const QString &dbusPathName,QObject *parent = 0); + ~QConnmanServiceInterface(); + + QVariantMap getProperties(); + // clearProperty + void connect(); + void disconnect(); + void remove(); + // void moveBefore(QDBusObjectPath &service); + // void moveAfter(QDBusObjectPath &service); + +// properties + QString getState(); + QString getError(); + QString getName(); + QString getType(); + QString getMode(); + QString getSecurity(); + QString getPassphrase(); + bool isPassphraseRequired(); + quint8 getSignalStrength(); + bool isFavorite(); + bool isImmutable(); + bool isAutoConnect(); + bool isSetupRequired(); + QString getAPN(); + QString getMCC(); + QString getMNC(); + bool isRoaming(); + QStringList getNameservers(); + QStringList getDomains(); + QVariantMap getIPv4(); + QVariantMap getIPv4Configuration(); + QVariantMap getProxy(); + QVariantMap getEthernet(); + + bool isOfflineMode(); + QStringList getServices(); + +Q_SIGNALS: + void propertyChanged(const QString &, const QDBusVariant &value); + void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); + +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + QVariant getProperty(const QString &); +}; + +class QConnmanTechnologyInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanTechnologyInterface(const QString &dbusPathName,QObject *parent = 0); + ~QConnmanTechnologyInterface(); + + QVariantMap getProperties(); +// properties + QString getState(); + QString getName(); + QString getType(); + + QStringList getDevices(); + +Q_SIGNALS: + void propertyChanged(const QString &, const QDBusVariant &value); + void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + QVariant getProperty(const QString &); + +}; + +class QConnmanAgentInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanAgentInterface(const QString &dbusPathName,QObject *parent = 0); + ~QConnmanAgentInterface(); + + void release(); + void reportError(QDBusObjectPath &path, const QString &error); +// dict requestInput(QDBusObjectPath &path, dict fields); + void cancel(); +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); +}; + +//class QConnmanCounterInterfacePrivate; +//class QConnmanCounterInterface : public QDBusAbstractInterface +//{ +// Q_OBJECT +// +//public: +// +// QConnmanCounterInterface(QObject *parent = 0); +// ~QConnmanCounterInterface(); +// +// void release(); +//private: +// QConnmanCounterInterfacePrivate *d; +//}; + +class QConnmanDeviceInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanDeviceInterface(const QString &dbusPathName,QObject *parent = 0); + ~QConnmanDeviceInterface(); + + QVariantMap getProperties(); + void scan(); + +//properties + QString getAddress(); + QString getName(); + QString getType(); + QString getInterface(); + bool isPowered(); + quint16 getScanInterval(); + bool setScanInterval(const QString &interval); + + bool isScanning(); + QStringList getNetworks(); + bool setEnabled(bool powered); + bool setProperty(const QString &name, const QDBusVariant &value); + +Q_SIGNALS: + void propertyChanged(const QString &, const QDBusVariant &value); + void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + QVariant getProperty(const QString &); + +}; + +class QConnmanDBusHelper: public QObject, protected QDBusContext + { + Q_OBJECT + public: + QConnmanDBusHelper(QObject *parent = 0); + ~QConnmanDBusHelper(); + + public slots: + void propertyChanged(const QString &, const QDBusVariant &); + +Q_SIGNALS: + void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); +}; + +QT_END_NAMESPACE + +#endif //QCONNMANSERVICE_H -- cgit v0.12 From 066fe8ab70508af6310c49e6eb9cdd74962b6401 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Tue, 22 Jun 2010 04:14:21 +1000 Subject: fix ghost ap issue, and dont block on connect --- src/plugins/bearer/connman/qconnmanengine.cpp | 276 ++++++++++++++++++-------- src/plugins/bearer/connman/qconnmanengine.h | 41 +++- 2 files changed, 235 insertions(+), 82 deletions(-) diff --git a/src/plugins/bearer/connman/qconnmanengine.cpp b/src/plugins/bearer/connman/qconnmanengine.cpp index e4cab92..c1df710 100644 --- a/src/plugins/bearer/connman/qconnmanengine.cpp +++ b/src/plugins/bearer/connman/qconnmanengine.cpp @@ -51,7 +51,6 @@ #include #include -//#include #include #include #include @@ -65,7 +64,6 @@ QConnmanEngine::QConnmanEngine(QObject *parent) : QBearerEngineImpl(parent), connmanManager(new QConnmanManagerInterface(this)) { -// qWarning() << Q_FUNC_INFO; } QConnmanEngine::~QConnmanEngine() @@ -98,6 +96,7 @@ void QConnmanEngine::initialize() deviceMap.insert(techPath,QStringList() << devicePath); } } + // Get current list of access points. getConfigurations(); } @@ -113,7 +112,6 @@ QList QConnmanEngine::getConfigurations() void QConnmanEngine::getNetworkListing() { QMutexLocker locker(&mutex); - QMapIterator i(deviceMap); while(i.hasNext()) { i.next(); @@ -126,6 +124,8 @@ void QConnmanEngine::getNetworkListing() } } + + void QConnmanEngine::doRequestUpdate() { getConfigurations(); @@ -141,16 +141,16 @@ QString QConnmanEngine::getInterfaceFromId(const QString &id) QMapIterator i(deviceMap); while(i.hasNext()) { - i.next(); - if(i.value().count() > 0) { - QConnmanDeviceInterface dev(i.value().at(0)); - foreach(const QString network, dev.getNetworks()) { - if(network == netPath) { - return dev.getInterface(); - } - } - } - } + i.next(); + if(i.value().count() > 0) { + QConnmanDeviceInterface dev(i.value().at(0)); + foreach(const QString network, dev.getNetworks()) { + if(network == netPath) { + return dev.getInterface(); + } + } + } + } return QString(); } @@ -187,12 +187,13 @@ QString QConnmanEngine::bearerName(const QString &id) void QConnmanEngine::connectToId(const QString &id) { QMutexLocker locker(&mutex); - QConnmanServiceInterface serv(serviceFromId(id)); - if(!serv.isValid()) { - emit connectionError(id, InterfaceLookupError); - } else { - serv.connect(); - } + QConnmanConnectThread *thread; + thread = new QConnmanConnectThread(this); + thread->setServicePath(serviceFromId(id)); + thread->setIdentifier(id); + connect(thread,SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), + this,SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError))); + thread->start(); } void QConnmanEngine::disconnectFromId(const QString &id) @@ -234,9 +235,24 @@ QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) if (!ptr->isValid) { return QNetworkSession::Invalid; - } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + + } + QString service = serviceFromId(id); + QConnmanServiceInterface serv(service); + QString servState = serv.getState(); + + if(servState == "idle" || servState == "failure") { + return QNetworkSession::Disconnected; + } + + if(servState == "association" || servState == "configuration" || servState == "login") { + return QNetworkSession::Connecting; + } + if(servState == "ready" || servState == "online") { return QNetworkSession::Connected; - } else if ((ptr->state & QNetworkConfiguration::Discovered) == + } + + if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { return QNetworkSession::Disconnected; } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { @@ -324,14 +340,14 @@ QString QConnmanEngine::getNetworkForService(const QString &servPath) QMutexLocker locker(&mutex); QMap map; - QMapIterator i(deviceMap); - while(i.hasNext()) { - i.next(); - if(i.value().count() > 0) { - QConnmanDeviceInterface device(i.value().at(0)); - QMap netMapStrength; + QMapIterator i(deviceMap); + while(i.hasNext()) { + i.next(); + if(i.value().count() > 0) { + QConnmanDeviceInterface device(i.value().at(0)); + QMap netMapStrength; + foreach(const QString netPath, knownNetworks[device.getType()]) { - foreach(const QString netPath, knownNetworks[device.getType()]) { QConnmanNetworkInterface network1(netPath, this); QString netname = network1.getName(); qint32 sigStrength = network1.getSignalStrength(); @@ -355,10 +371,19 @@ QString QConnmanEngine::getNetworkForService(const QString &servPath) return QString(); } -void QConnmanEngine::propertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) +void QConnmanEngine::propertyChangedContext(const QString &/*path*/,const QString &item, const QDBusVariant &value) { -// qDebug() << __FUNCTION__ << path << item; QMutexLocker locker(&mutex); + if(item == "Services") { + QDBusArgument arg = qvariant_cast(value.variant()); + QStringList list = qdbus_cast(arg); + + if(list.count() > accessPointConfigurations.count()) { + foreach(const QString service, list) { + addServiceConfiguration(service); + } + } + } if(item == "Technologies") { QDBusArgument arg = qvariant_cast(value.variant()); @@ -392,52 +417,47 @@ void QConnmanEngine::propertyChangedContext(const QString &path,const QString &i void QConnmanEngine::servicePropertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) { -// qDebug() << __FUNCTION__ << path << item; +// qWarning() << __FUNCTION__ << path << item << value.variant(); QMutexLocker locker(&mutex); - if(item == "State") { + if(item == "State") { configurationChange(QString::number(qHash(path))); if(value.variant().toString() == "failure") { QConnmanServiceInterface serv(path); - qDebug() <<__FUNCTION__ <<"Error" << serv.getError(); - emit connectionError(QString::number(qHash(path)), ConnectError); + emit connectionError(QString::number(qHash(path)), ConnectError); } } } -void QConnmanEngine::networkPropertyChangedContext(const QString &path,const QString &item, const QDBusVariant &/*value*/) +void QConnmanEngine::networkPropertyChangedContext(const QString &/*path*/,const QString &/*item*/, const QDBusVariant &/*value*/) { -// qDebug() << __FUNCTION__ << path << item; QMutexLocker locker(&mutex); } -void QConnmanEngine::devicePropertyChangedContext(const QString &path,const QString &item,const QDBusVariant &value) +void QConnmanEngine::devicePropertyChangedContext(const QString &devpath,const QString &item,const QDBusVariant &value) { -// qDebug() << __FUNCTION__ << path << item << value.variant(); QMutexLocker locker(&mutex); if(item == "Networks") { QDBusArgument arg = qvariant_cast(value.variant()); - QStringList remainingNetworks = qdbus_cast(arg); - - QConnmanDeviceInterface dev(path); - QStringList oldnetworks = knownNetworks[dev.getType()]; - if(remainingNetworks.count() != oldnetworks.count()) { + QStringList remainingNetworks = qdbus_cast(arg); + QConnmanDeviceInterface device(devpath); + QStringList oldnetworks = knownNetworks[device.getType()]; + if(remainingNetworks.count() > oldnetworks.count()) { foreach(const QString netPath, remainingNetworks) { if(!oldnetworks.contains(netPath)) { addNetworkConfiguration(netPath); } } - + } else { foreach(const QString netPath, oldnetworks) { QString servicePath = getServiceForNetwork(netPath); if(!remainingNetworks.contains(netPath)) { if(servicePath.isEmpty()) { - removeConfiguration(netPath); + removeConfiguration(QString::number(qHash(netPath))); } else { - if(!remainingNetworks.contains(servicePath)) { - removeConfiguration(QString::number(qHash(servicePath))); - } + removeConfiguration(QString::number(qHash(servicePath))); } + knownNetworks[device.getType()].removeAll(netPath); } } } @@ -446,17 +466,11 @@ void QConnmanEngine::devicePropertyChangedContext(const QString &path,const QStr void QConnmanEngine::technologyPropertyChangedContext(const QString & path, const QString &item, const QDBusVariant &value) { -// qWarning() << __FUNCTION__ << path << item << value.variant(); -// if(item == "Devices") { -// QDBusArgument arg = qvariant_cast(value.variant()); -// QStringList list = qdbus_cast(arg); -// } + if(item == "Devices") { + QDBusArgument arg = qvariant_cast(value.variant()); + QStringList list = qdbus_cast(arg); + } if(item == "State") { - if(value.variant().toString() == "enabled") { - } - if(value.variant().toString() == "offline") { - deviceMap.remove(path); - } if(value.variant().toString() == "available") { QConnmanTechnologyInterface tech(connmanManager->getPathForTechnology(path)); foreach(const QString devPath, tech.getDevices()) { @@ -464,51 +478,49 @@ void QConnmanEngine::technologyPropertyChangedContext(const QString & path, cons dev = new QConnmanDeviceInterface(devPath,this); connect(dev,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(devicePropertyChangedContext(QString,QString,QDBusVariant))); - deviceMap.insert(path,QStringList() << devPath); } } + if(value.variant().toString() == "offline") { + deviceMap.remove(path); + } } } void QConnmanEngine::configurationChange(const QString &id) { QMutexLocker locker(&mutex); - bool changed = false; if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); QString servicePath = serviceFromId(id); QConnmanServiceInterface *serv; serv = new QConnmanServiceInterface(servicePath); QString networkName = serv->getName(); + QNetworkConfiguration::StateFlags curState = getStateForService(servicePath); ptr->mutex.lock(); if (!ptr->isValid) { ptr->isValid = true; - changed = true; } if (ptr->name != networkName) { ptr->name = networkName; - changed = true; } if (ptr->state != curState) { ptr->state = curState; - changed = true; } ptr->mutex.unlock(); - if (changed) { - locker.unlock(); - emit configurationChanged(ptr); - locker.relock(); - } + locker.unlock(); + emit configurationChanged(ptr); + locker.relock(); } locker.unlock(); @@ -517,7 +529,6 @@ void QConnmanEngine::configurationChange(const QString &id) QNetworkConfiguration::StateFlags QConnmanEngine::getStateForService(const QString &service) { - qWarning() << __FUNCTION__; QMutexLocker locker(&mutex); QConnmanServiceInterface serv(service); QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined; @@ -555,23 +566,76 @@ QString QConnmanEngine::typeToBearer(const QString &type) return "Unknown"; } -void QConnmanEngine::removeConfiguration(const QString &netpath) +void QConnmanEngine::removeConfiguration(const QString &id) { QMutexLocker locker(&mutex); - const QString id = QString::number(qHash(netpath)); + if (accessPointConfigurations.contains(id)) { QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); - QConnmanDeviceInterface device(netpath.section("/",0,5),this); locker.unlock(); - knownNetworks[device.getType()].removeAll(netpath); emit configurationRemoved(ptr); locker.relock(); } } +void QConnmanEngine::addServiceConfiguration(const QString &servicePath) +{ + + QMutexLocker locker(&mutex); + QConnmanServiceInterface *serv; + serv = new QConnmanServiceInterface(servicePath); + const QString netPath = getNetworkForService(servicePath); + + QConnmanNetworkInterface *network; + network = new QConnmanNetworkInterface(netPath, this); + + const QString id = QString::number(qHash(servicePath)); + + if (!accessPointConfigurations.contains(id)) { + QConnmanDeviceInterface device(netPath.section("/",0,5),this); + knownNetworks[device.getType()]<< netPath; +// knownNetworks << servicePath; + connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + + QString networkName = serv->getName(); + + if(serv->getType() == "Cellular") { + networkName = serv->getAPN(); + } + + cpPriv->name = networkName; + cpPriv->isValid = true; + cpPriv->id = id; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->bearer = bearerName(id); + + if(serv->getSecurity() == "none") { + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + } else { + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + } + + connect(network,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(networkPropertyChangedContext(QString,QString, QDBusVariant))); + + cpPriv->state = getStateForService(servicePath); + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ptr->id, ptr); + foundConfigurations.append(cpPriv); + + locker.unlock(); + emit configurationAdded(ptr); + locker.relock(); + emit updateCompleted(); + } +} + void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) { -// qWarning() << __FUNCTION__ << networkPath; QMutexLocker locker(&mutex); QConnmanNetworkInterface *network; @@ -580,11 +644,18 @@ void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) QConnmanServiceInterface *serv; QString id; + QConnmanDeviceInterface device(networkPath.section("/",0,5),this); + if(servicePath.isEmpty()) { id = QString::number(qHash(networkPath)); } else { id = QString::number(qHash(servicePath)); + serv = new QConnmanServiceInterface(servicePath,this); + connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); } + knownNetworks[device.getType()]<< networkPath; + if (!accessPointConfigurations.contains(id)) { connect(network,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(networkPropertyChangedContext(QString,QString, QDBusVariant))); @@ -598,16 +669,13 @@ void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) QString bearerName; - QConnmanDeviceInterface device(networkPath.section("/",0,5),this); if(servicePath.isEmpty()) { + QString devicePath = networkPath.section("/",0,5); + QConnmanDeviceInterface device(devicePath,this); bearerName = typeToBearer(device.getType()); } else { - serv = new QConnmanServiceInterface(servicePath,this); bearerName = typeToBearer(serv->getType()); - connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); } - knownNetworks[device.getType()]<< networkPath; if(bearerName == "Cellular") { QString mode = serv->getMode(); @@ -642,7 +710,57 @@ void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) locker.unlock(); emit configurationAdded(ptr); locker.relock(); + emit updateCompleted(); + } +} + +bool QConnmanEngine::requiresPolling() const +{ + return false; +} + + +QConnmanConnectThread::QConnmanConnectThread(QObject *parent) + :QThread(parent), + servicePath(), identifier() +{ +} + +QConnmanConnectThread::~QConnmanConnectThread() +{ +} + +void QConnmanConnectThread::stop() +{ + if(currentThread() != this) { + QMetaObject::invokeMethod(this, "quit", + Qt::QueuedConnection); + } else { + quit(); } + wait(); +} + +void QConnmanConnectThread::run() +{ + QConnmanServiceInterface serv(servicePath); + if(!serv.isValid()) { + emit connectionError(identifier, QBearerEngineImpl::InterfaceLookupError); + } else { + serv.connect(); + } +} + +void QConnmanConnectThread::setServicePath(const QString &path) +{ + QMutexLocker locker(&mutex); + servicePath = path; +} + +void QConnmanConnectThread::setIdentifier(const QString &id) +{ + QMutexLocker locker(&mutex); + identifier = id; } QT_END_NAMESPACE diff --git a/src/plugins/bearer/connman/qconnmanengine.h b/src/plugins/bearer/connman/qconnmanengine.h index 849d8c9..b5f1488 100644 --- a/src/plugins/bearer/connman/qconnmanengine.h +++ b/src/plugins/bearer/connman/qconnmanengine.h @@ -59,12 +59,14 @@ #include #include +#include #ifndef QT_NO_BEARERMANAGEMENT #ifndef QT_NO_DBUS QT_BEGIN_NAMESPACE +class QConnmanConnectThread; class QConnmanEngine : public QBearerEngineImpl { Q_OBJECT @@ -114,6 +116,7 @@ private: QConnmanManagerInterface *connmanManager; QList foundConfigurations; + void getNetworkListing(); QString getServiceForNetwork(const QString &network); @@ -125,14 +128,46 @@ private: QNetworkConfiguration::StateFlags getStateForService(const QString &service); QString typeToBearer(const QString &type); - void removeConfiguration(const QString &path); + void removeConfiguration(const QString &servicePath); + void addServiceConfiguration(const QString &servicePath); void addNetworkConfiguration(const QString &worknetPath); QDateTime activeTime; QMap technologies; - QMap knownNetworks; - QMap deviceMap; + // QStringList knownNetworks; + + QMap knownNetworks; + QMap deviceMap; + +protected: + bool requiresPolling() const; + QConnmanConnectThread *connThread; +}; + +class QConnmanConnectThread : public QThread +{ + Q_OBJECT + +public: + QConnmanConnectThread(QObject *parent = 0); + ~QConnmanConnectThread(); + bool keepRunning; + void stop(); + void setServicePath(const QString &path); + void setIdentifier(const QString &id); + +Q_SIGNALS: + void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error); + +protected: + void run(); + QString servicePath; + QString identifier; + +private: + QMutex mutex; + }; QT_END_NAMESPACE -- cgit v0.12 From 361f409d513b7360b1a6f919799cc1948835aef3 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 28 Jun 2010 09:30:53 +1000 Subject: fix actions regarding removal of connman. make tests pass on desktop --- src/plugins/bearer/connman/qconnmanengine.cpp | 162 ++++++++++++++------------ src/plugins/bearer/connman/qconnmanengine.h | 10 +- 2 files changed, 91 insertions(+), 81 deletions(-) diff --git a/src/plugins/bearer/connman/qconnmanengine.cpp b/src/plugins/bearer/connman/qconnmanengine.cpp index c1df710..bdff815 100644 --- a/src/plugins/bearer/connman/qconnmanengine.cpp +++ b/src/plugins/bearer/connman/qconnmanengine.cpp @@ -91,9 +91,14 @@ void QConnmanEngine::initialize() foreach(const QString devicePath,tech->getDevices()) { QConnmanDeviceInterface *dev; dev = new QConnmanDeviceInterface(devicePath); - connect(dev,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(devicePropertyChangedContext(QString,QString,QDBusVariant))); - deviceMap.insert(techPath,QStringList() << devicePath); + if(!deviceMap.value(techPath).contains(devicePath)) { + connect(dev,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(devicePropertyChangedContext(QString,QString,QDBusVariant))); + deviceMap.insert(techPath,QStringList() << devicePath); + foreach(const QString network,dev->getNetworks()) { + serviceNetworks.insert(getServiceForNetwork(network),network); + } + } } } @@ -104,9 +109,28 @@ void QConnmanEngine::initialize() QList QConnmanEngine::getConfigurations() { QMutexLocker locker(&mutex); - foundConfigurations.clear(); + // foundConfigurations.clear(); getNetworkListing(); - return foundConfigurations; + QList fetchedConfigurations; + QNetworkConfigurationPrivate* cpPriv = 0; + + for (int i = 0; i < foundConfigurations.count(); ++i) { + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + cpPriv = foundConfigurations.at(i); + + config->name = cpPriv->name; + config->isValid = cpPriv->isValid; + config->id = cpPriv->id; + config->state = cpPriv->state; + config->type = cpPriv->type; + config->roamingSupported = cpPriv->roamingSupported; + config->purpose = cpPriv->purpose; + config->bearer = cpPriv->bearer; + + fetchedConfigurations.append(config); + } + return fetchedConfigurations; +// return foundConfigurations; } void QConnmanEngine::getNetworkListing() @@ -128,6 +152,7 @@ void QConnmanEngine::getNetworkListing() void QConnmanEngine::doRequestUpdate() { + connmanManager->requestScan(""); getConfigurations(); emit updateCompleted(); } @@ -135,23 +160,7 @@ void QConnmanEngine::doRequestUpdate() QString QConnmanEngine::getInterfaceFromId(const QString &id) { QMutexLocker locker(&mutex); - - QString servicePath = serviceFromId(id); - QString netPath = getNetworkForService(servicePath); - - QMapIterator i(deviceMap); - while(i.hasNext()) { - i.next(); - if(i.value().count() > 0) { - QConnmanDeviceInterface dev(i.value().at(0)); - foreach(const QString network, dev.getNetworks()) { - if(network == netPath) { - return dev.getInterface(); - } - } - } - } - return QString(); + return configInterfaces.value(id); } bool QConnmanEngine::hasIdentifier(const QString &id) @@ -216,7 +225,7 @@ void QConnmanEngine::requestUpdate() QString QConnmanEngine::serviceFromId(const QString &id) { QMutexLocker locker(&mutex); - foreach(QString service, connmanManager->getServices()) { + foreach(const QString service, serviceNetworks.keys()) { if (id == QString::number(qHash(service))) return service; } @@ -241,7 +250,7 @@ QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) QConnmanServiceInterface serv(service); QString servState = serv.getState(); - if(servState == "idle" || servState == "failure") { + if(serv.isFavorite() && servState == "idle" || servState == "failure") { return QNetworkSession::Disconnected; } @@ -335,43 +344,8 @@ QString QConnmanEngine::getServiceForNetwork(const QString &netPath) return QString(); } -QString QConnmanEngine::getNetworkForService(const QString &servPath) -{ - QMutexLocker locker(&mutex); - QMap map; - - QMapIterator i(deviceMap); - while(i.hasNext()) { - i.next(); - if(i.value().count() > 0) { - QConnmanDeviceInterface device(i.value().at(0)); - QMap netMapStrength; - foreach(const QString netPath, knownNetworks[device.getType()]) { - - QConnmanNetworkInterface network1(netPath, this); - QString netname = network1.getName(); - qint32 sigStrength = network1.getSignalStrength(); - - if(netMapStrength.contains(netname) - && netMapStrength.value(netname) < sigStrength) { - netMapStrength.remove(netname); - map.remove(netname); - } - netMapStrength.insert(netname, sigStrength); - map.insert(netname,netPath); - } - } - } - QConnmanServiceInterface *serv; - serv = new QConnmanServiceInterface(servPath); - if(map.contains(serv->getName())) { - return map.value(serv->getName()); - } - return QString(); -} - -void QConnmanEngine::propertyChangedContext(const QString &/*path*/,const QString &item, const QDBusVariant &value) +void QConnmanEngine::propertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) { QMutexLocker locker(&mutex); if(item == "Services") { @@ -413,14 +387,17 @@ void QConnmanEngine::propertyChangedContext(const QString &/*path*/,const QStrin } } } + if(item == "State") { +// qDebug() << value.variant(); + } } void QConnmanEngine::servicePropertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) { -// qWarning() << __FUNCTION__ << path << item << value.variant(); QMutexLocker locker(&mutex); if(item == "State") { configurationChange(QString::number(qHash(path))); + if(value.variant().toString() == "failure") { QConnmanServiceInterface serv(path); emit connectionError(QString::number(qHash(path)), ConnectError); @@ -439,8 +416,17 @@ void QConnmanEngine::devicePropertyChangedContext(const QString &devpath,const Q if(item == "Networks") { QDBusArgument arg = qvariant_cast(value.variant()); QStringList remainingNetworks = qdbus_cast(arg); - QConnmanDeviceInterface device(devpath); - QStringList oldnetworks = knownNetworks[device.getType()]; + QString devicetype; + QMapIterator i(deviceMap); + while(i.hasNext()) { + i.next(); + if(i.value().contains(devpath)) { + devicetype = i.key(); + } + } + + + QStringList oldnetworks = knownNetworks[devicetype]; if(remainingNetworks.count() > oldnetworks.count()) { foreach(const QString netPath, remainingNetworks) { @@ -450,14 +436,14 @@ void QConnmanEngine::devicePropertyChangedContext(const QString &devpath,const Q } } else { foreach(const QString netPath, oldnetworks) { - QString servicePath = getServiceForNetwork(netPath); + QString servicePath = serviceNetworks.key(netPath); if(!remainingNetworks.contains(netPath)) { if(servicePath.isEmpty()) { removeConfiguration(QString::number(qHash(netPath))); } else { removeConfiguration(QString::number(qHash(servicePath))); } - knownNetworks[device.getType()].removeAll(netPath); + knownNetworks[devicetype].removeAll(netPath); } } } @@ -471,14 +457,18 @@ void QConnmanEngine::technologyPropertyChangedContext(const QString & path, cons QStringList list = qdbus_cast(arg); } if(item == "State") { + if(value.variant().toString() == "available") { QConnmanTechnologyInterface tech(connmanManager->getPathForTechnology(path)); foreach(const QString devPath, tech.getDevices()) { - QConnmanDeviceInterface *dev; - dev = new QConnmanDeviceInterface(devPath,this); - connect(dev,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(devicePropertyChangedContext(QString,QString,QDBusVariant))); - deviceMap.insert(path,QStringList() << devPath); + + if(!deviceMap.value(path).contains(devPath)) { + QConnmanDeviceInterface *dev; + dev = new QConnmanDeviceInterface(devPath,this); + connect(dev,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(devicePropertyChangedContext(QString,QString,QDBusVariant))); + deviceMap.insert(path,QStringList() << devPath); + } } } if(value.variant().toString() == "offline") { @@ -571,6 +561,20 @@ void QConnmanEngine::removeConfiguration(const QString &id) QMutexLocker locker(&mutex); if (accessPointConfigurations.contains(id)) { + + QString service = serviceFromId(id); + QConnmanServiceInterface serv(service); + + disconnect(&serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); + + QString netPath = serviceNetworks.value(service); + serviceNetworks.remove(service); + + QConnmanServiceInterface network(netPath); + disconnect(&network,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(networkPropertyChangedContext(QString,QString, QDBusVariant))); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); locker.unlock(); emit configurationRemoved(ptr); @@ -584,20 +588,21 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath) QMutexLocker locker(&mutex); QConnmanServiceInterface *serv; serv = new QConnmanServiceInterface(servicePath); - const QString netPath = getNetworkForService(servicePath); + const QString netPath = serviceNetworks.value(servicePath); QConnmanNetworkInterface *network; network = new QConnmanNetworkInterface(netPath, this); + serviceNetworks.insert(servicePath,netPath); + const QString id = QString::number(qHash(servicePath)); if (!accessPointConfigurations.contains(id)) { + QConnmanDeviceInterface device(netPath.section("/",0,5),this); knownNetworks[device.getType()]<< netPath; -// knownNetworks << servicePath; connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); QString networkName = serv->getName(); @@ -626,6 +631,8 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath) QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ptr->id, ptr); foundConfigurations.append(cpPriv); + configInterfaces[cpPriv->id] = device.getInterface(); + locker.unlock(); emit configurationAdded(ptr); @@ -650,11 +657,12 @@ void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) id = QString::number(qHash(networkPath)); } else { id = QString::number(qHash(servicePath)); - serv = new QConnmanServiceInterface(servicePath,this); - connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); + serv = new QConnmanServiceInterface(servicePath,this); + connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); } knownNetworks[device.getType()]<< networkPath; + serviceNetworks.insert(servicePath,networkPath); if (!accessPointConfigurations.contains(id)) { connect(network,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), @@ -707,6 +715,8 @@ void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ptr->id, ptr); foundConfigurations.append(cpPriv); + configInterfaces[cpPriv->id] = device.getInterface(); + locker.unlock(); emit configurationAdded(ptr); locker.relock(); diff --git a/src/plugins/bearer/connman/qconnmanengine.h b/src/plugins/bearer/connman/qconnmanengine.h index b5f1488..0f6dc1c 100644 --- a/src/plugins/bearer/connman/qconnmanengine.h +++ b/src/plugins/bearer/connman/qconnmanengine.h @@ -120,7 +120,6 @@ private: void getNetworkListing(); QString getServiceForNetwork(const QString &network); - QString getNetworkForService(const QString &network); QString serviceFromId(const QString &id); QString networkFromId(const QString &id); @@ -134,11 +133,12 @@ private: QDateTime activeTime; - QMap technologies; - // QStringList knownNetworks; + QMap technologies; // techpath, tech interface + QMap configInterfaces; // id, interface name + QMap knownNetworks; //device path, net paths list + QMap deviceMap; //tech path, device path + QMap serviceNetworks; //service, network - QMap knownNetworks; - QMap deviceMap; protected: bool requiresPolling() const; -- cgit v0.12 From 5a6d8c40791da2e8751965d05ae2d5ef69bed301 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 30 Jun 2010 12:20:14 +1000 Subject: make sure ap's are removed when the device is removed --- src/plugins/bearer/connman/qconnmanengine.cpp | 24 ++++++++---- .../bearer/connman/qconnmanservice_linux.cpp | 44 +++++++++++++++++++--- .../bearer/connman/qconnmanservice_linux_p.h | 34 +++++++++-------- 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/src/plugins/bearer/connman/qconnmanengine.cpp b/src/plugins/bearer/connman/qconnmanengine.cpp index bdff815..8775623 100644 --- a/src/plugins/bearer/connman/qconnmanengine.cpp +++ b/src/plugins/bearer/connman/qconnmanengine.cpp @@ -250,7 +250,7 @@ QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) QConnmanServiceInterface serv(service); QString servState = serv.getState(); - if(serv.isFavorite() && servState == "idle" || servState == "failure") { + if(serv.isFavorite() && (servState == "idle" || servState == "failure")) { return QNetworkSession::Disconnected; } @@ -285,6 +285,7 @@ quint64 QConnmanEngine::bytesWritten(const QString &id) in >> result; tx.close(); } + return result; } @@ -347,6 +348,9 @@ QString QConnmanEngine::getServiceForNetwork(const QString &netPath) void QConnmanEngine::propertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) { + Q_UNUSED(path); +// qDebug() << __FUNCTION__ << path << item << value.variant(); + QMutexLocker locker(&mutex); if(item == "Services") { QDBusArgument arg = qvariant_cast(value.variant()); @@ -421,11 +425,10 @@ void QConnmanEngine::devicePropertyChangedContext(const QString &devpath,const Q while(i.hasNext()) { i.next(); if(i.value().contains(devpath)) { - devicetype = i.key(); + devicetype = i.key().section("/",-1); } } - QStringList oldnetworks = knownNetworks[devicetype]; if(remainingNetworks.count() > oldnetworks.count()) { @@ -593,14 +596,16 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath) QConnmanNetworkInterface *network; network = new QConnmanNetworkInterface(netPath, this); - serviceNetworks.insert(servicePath,netPath); const QString id = QString::number(qHash(servicePath)); if (!accessPointConfigurations.contains(id)) { - QConnmanDeviceInterface device(netPath.section("/",0,5),this); - knownNetworks[device.getType()]<< netPath; + + serviceNetworks.insert(servicePath,netPath); + + knownNetworks[device.getType()].append(netPath); + connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); @@ -661,10 +666,13 @@ void QConnmanEngine::addNetworkConfiguration(const QString &networkPath) connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(servicePropertyChangedContext(QString,QString, QDBusVariant))); } - knownNetworks[device.getType()]<< networkPath; - serviceNetworks.insert(servicePath,networkPath); if (!accessPointConfigurations.contains(id)) { + + knownNetworks[device.getType()].append(networkPath); + + serviceNetworks.insert(servicePath,networkPath); + connect(network,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), this,SLOT(networkPropertyChangedContext(QString,QString, QDBusVariant))); diff --git a/src/plugins/bearer/connman/qconnmanservice_linux.cpp b/src/plugins/bearer/connman/qconnmanservice_linux.cpp index ca76ffd..b20e7c1 100644 --- a/src/plugins/bearer/connman/qconnmanservice_linux.cpp +++ b/src/plugins/bearer/connman/qconnmanservice_linux.cpp @@ -208,17 +208,29 @@ void QConnmanManagerInterface::unregisterAgent(QDBusObjectPath /*path*/) { } -void QConnmanManagerInterface::registerCounter(QDBusObjectPath /*path*/, quint32 /*interval*/) -{ +void QConnmanManagerInterface::registerCounter(const QString &path, quint32 interval) +{ QDBusReply > reply = this->call(QLatin1String("RegisterCounter"), + QVariant::fromValue(path), + QVariant::fromValue(interval)); + bool ok = true; + if(reply.error().type() == QDBusError::InvalidArgs) { + qWarning() << reply.error().message(); + } } -void QConnmanManagerInterface::unregisterCounter(QDBusObjectPath /*path*/) -{ +void QConnmanManagerInterface::unregisterCounter(const QString &path) +{ QDBusReply > reply = this->call(QLatin1String("UnregisterCounter"), + QVariant::fromValue(path)); + bool ok = true; + if(reply.error().type() == QDBusError::InvalidArgs) { + qWarning() << reply.error().message(); + } } QString QConnmanManagerInterface::requestSession(const QString &bearerName) { - QDBusReply > reply = this->call(QLatin1String("RequestSession"), QVariant::fromValue(bearerName)); + QDBusReply > reply = this->call(QLatin1String("RequestSession"), + QVariant::fromValue(bearerName)); return QString(); } @@ -863,7 +875,29 @@ void QConnmanAgentInterface::cancel() ///////////////////////////////////////// +QConnmanCounterInterface::QConnmanCounterInterface(const QString &dbusPathName,QObject *parent) + : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_COUNTER_INTERFACE, + QDBusConnection::systemBus(), parent) +{ +} + +QConnmanCounterInterface::~QConnmanCounterInterface() +{ +} + +quint32 QConnmanCounterInterface::getReceivedByteCount() +{ +return 0; +} + +quint32 QConnmanCounterInterface::getTransmittedByteCount() +{ +return 0; +} +///////////////////////////////////////// QConnmanDeviceInterface::QConnmanDeviceInterface(const QString &dbusPathName,QObject *parent) : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), dbusPathName, diff --git a/src/plugins/bearer/connman/qconnmanservice_linux_p.h b/src/plugins/bearer/connman/qconnmanservice_linux_p.h index 9475296..35e3f3d 100644 --- a/src/plugins/bearer/connman/qconnmanservice_linux_p.h +++ b/src/plugins/bearer/connman/qconnmanservice_linux_p.h @@ -115,8 +115,8 @@ public: QDBusObjectPath connectService(QVariantMap &map); void registerAgent(QDBusObjectPath &path); void unregisterAgent(QDBusObjectPath path); - void registerCounter(QDBusObjectPath path, quint32 interval); - void unregisterCounter(QDBusObjectPath path); + void registerCounter(const QString &path, quint32 interval); + void unregisterCounter(const QString &path); QString requestSession(const QString &bearerName); void releaseSession(); @@ -307,20 +307,24 @@ protected: void disconnectNotify(const char *signal); }; -//class QConnmanCounterInterfacePrivate; -//class QConnmanCounterInterface : public QDBusAbstractInterface -//{ -// Q_OBJECT -// -//public: -// -// QConnmanCounterInterface(QObject *parent = 0); -// ~QConnmanCounterInterface(); -// +class QConnmanCounterInterfacePrivate; +class QConnmanCounterInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + QConnmanCounterInterface(const QString &dbusPathName, QObject *parent = 0); + ~QConnmanCounterInterface(); + // void release(); -//private: -// QConnmanCounterInterfacePrivate *d; -//}; + QString getInterface(); + quint32 getReceivedByteCount(); + quint32 getTransmittedByteCount(); + +private: + QConnmanCounterInterfacePrivate *d; +}; class QConnmanDeviceInterface : public QDBusAbstractInterface { -- cgit v0.12 From 4c100e6f1ddecff46e5b1e46a481b62c275bc30d Mon Sep 17 00:00:00 2001 From: Roland Wolf Date: Wed, 26 May 2010 16:53:41 +0200 Subject: dummy commit to check permissions --- src/testfile.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/testfile.txt diff --git a/src/testfile.txt b/src/testfile.txt new file mode 100644 index 0000000..e69de29 -- cgit v0.12 From 09f3e7adf39ef93a9181486680fb6575b4d56de5 Mon Sep 17 00:00:00 2001 From: Michael D Scull Date: Wed, 26 May 2010 17:30:14 +0200 Subject: Michaels first commit --- doc/src/frameworks-technologies/modelview.qdoc | 840 +++++++++++++++++++++++++ doc/src/images/clock.png | Bin 0 -> 16514 bytes doc/src/images/columnview.png | Bin 0 -> 11717 bytes doc/src/images/combobox.png | Bin 0 -> 5022 bytes doc/src/images/dummy_tree.png | Bin 0 -> 20189 bytes doc/src/images/edit.png | Bin 0 -> 19636 bytes doc/src/images/example_model.png | Bin 0 -> 16577 bytes doc/src/images/header.png | Bin 0 -> 30302 bytes doc/src/images/lineedit.png | Bin 0 -> 2613 bytes doc/src/images/list_table_tree.png | Bin 0 -> 85530 bytes doc/src/images/listview.png | Bin 0 -> 9695 bytes doc/src/images/lotto.png | Bin 0 -> 17015 bytes doc/src/images/modelview.png | Bin 0 -> 2887 bytes doc/src/images/path.png | Bin 0 -> 31015 bytes doc/src/images/qcompleter.png | Bin 0 -> 17017 bytes doc/src/images/readonlytable.png | Bin 0 -> 28971 bytes doc/src/images/readonlytable_role.png | Bin 0 -> 27467 bytes doc/src/images/selection2.png | Bin 0 -> 23784 bytes doc/src/images/standardwidget.png | Bin 0 -> 1466 bytes doc/src/images/tableview.png | Bin 0 -> 10102 bytes doc/src/images/tree.png | Bin 0 -> 27074 bytes doc/src/images/tree_2.png | Bin 0 -> 14084 bytes doc/src/images/tree_2_with_algorithm.png | Bin 0 -> 16921 bytes doc/src/images/tree_city.png | Bin 0 -> 30398 bytes doc/src/images/treeview.png | Bin 0 -> 17173 bytes doc/src/images/widgetmapper.png | Bin 0 -> 20145 bytes 26 files changed, 840 insertions(+) create mode 100755 doc/src/frameworks-technologies/modelview.qdoc create mode 100755 doc/src/images/clock.png create mode 100755 doc/src/images/columnview.png create mode 100755 doc/src/images/combobox.png create mode 100755 doc/src/images/dummy_tree.png create mode 100755 doc/src/images/edit.png create mode 100755 doc/src/images/example_model.png create mode 100755 doc/src/images/header.png create mode 100755 doc/src/images/lineedit.png create mode 100755 doc/src/images/list_table_tree.png create mode 100755 doc/src/images/listview.png create mode 100755 doc/src/images/lotto.png create mode 100755 doc/src/images/modelview.png create mode 100755 doc/src/images/path.png create mode 100755 doc/src/images/qcompleter.png create mode 100755 doc/src/images/readonlytable.png create mode 100755 doc/src/images/readonlytable_role.png create mode 100755 doc/src/images/selection2.png create mode 100755 doc/src/images/standardwidget.png create mode 100755 doc/src/images/tableview.png create mode 100755 doc/src/images/tree.png create mode 100755 doc/src/images/tree_2.png create mode 100755 doc/src/images/tree_2_with_algorithm.png create mode 100755 doc/src/images/tree_city.png create mode 100755 doc/src/images/treeview.png create mode 100755 doc/src/images/widgetmapper.png diff --git a/doc/src/frameworks-technologies/modelview.qdoc b/doc/src/frameworks-technologies/modelview.qdoc new file mode 100755 index 0000000..7729cd2 --- /dev/null +++ b/doc/src/frameworks-technologies/modelview.qdoc @@ -0,0 +1,840 @@ +/*! + + \contentspage{modelview.html}{Crash Course in Model/View Programming} + \page modelview.html + +\title Crash Course in Model/View Programming +Contents: +\tableofcontents + +\section1 1 Introduction +Model/View is a technology used to separate data from views in widgets that handle data sets. Standard Widgets are not designed for separating data from views and this is why Qt 4 has two different types of widgets. Both types of widgets look the same, but they interact with data differently. + \table + \row + \o Standard widgets use data that is part of the widget. + \o \image standardwidget.png + \row + \o View classes operate on external data (the model) + \o \image modelview.png + \endtable +\section2 1.1 Standard widgets +Let's have a closer look at a standard table widget. A table widget is a 2D array of the data elements that the user can change. The table widget can be integrated into a program flow by reading and writing the data elements that the table widget provides. This method is very intuitive and useful in many applications. + +Displaying and editing a database table with a standard table widget can be problematic. Two copies of the data have to be coordinated: one outside the widget; one inside the widget. The developer needs to know where up-to-date data is so the both copies contain the most recent data. The tight coupling of presentation and data makes it harder to write unit tests. + +\section2 1.2 Model/View to the rescue +Model/View stepped up to provide a solution that uses a more versatile architecture. Model/View eliminates the data consistency problems that may occur with standard widgets. Model/View also makes it easier to use more than one view of the same data because one model can be passed on to many views. The most important difference is that model/view widgets do not store data behind the table cells. In fact, they operate directly from your data. Since view classes do not know your data's structure, you need to provide a wrapper to make your data conform to the \l QAbstractItemModel interface. A view uses this interface to read from and write to your data and any class that implements \l QAbstractItemModel is a model. Once the view receives a pointer to a model, it will read and display its content and be its editor. + +\section2 1.3 Overview of the model/view widgets +Here is an overview of the model/view widgets and their corresponding standard widgets. + \table + \header + \o Widget + \o Standard Widget +(a convenience class with data in the widget) + \o Model/View View Class (for use with external data) + \row + \o \image listview.png + \o \l QListWidget + \o \l QListView + \row + \o \image tableview.png + \o \l QTableWidget + \o \l QTableView + \row + \o \image treeview.png + \o \l QTreeWidget + \o \l QTreeView + \row + \o \image columnview.png + \o + \o \l QColumnView shows a tree as a hierarchy of lists + \row + \o \image combobox.png + \o {2, 1} \l QComboBox can work as both a view class and also as a traditional widget + \endtable +\section2 1.4 Having adapters between forms and models can come in handy. +We often prefer editing data stored in tables (e.g. in database tables) in forms rather than in tables. There is no direct model/view counterpart for separating data and views for widgets that operate on one value instead of a dataset, so we need an adapter in order to connect the form to the source of data. + +\l QDataWidgetMapper is a great solution because it maps form widgets to a table row and it makes it very easy to build forms for database tables. \image widgetmapper.png + +Another example of an adapter is \l QCompleter. Qt has QCompleter for providing auto completions in Qt widgets such as \l QComboBox and, as shown below, \l QLineEdit. \l QCompleter uses a model as its data source, so \l QCompleter, in itself, is a very handy adapter. \image qcompleter.png + +\section1 2 A Simple Model/View Application +If you want to develop a model/view application, where should you start? We recommend starting with a simple example and extending it step-by-step. This makes understanding the architecture a lot easier. Trying to understand the model/view architecture in detail before invoking the IDE has proven to be less convenient for many developers. It is substantially easier to start with a simple model/view application that has demo data. Give it a try! Simply replace the data in the examples below with your own. + +Below are 7 very simple and independent applications that show different sides of model/view programming. The source code can be downloaded from @todo___________paste link here_________________________ + +\section2 2.1 A read only table +We start with an application that uses a \l QTableView to show data. We will add editing capabilities later. + +-------------------------------------------------------------main.cpp--------------------- +\code +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} +\endcode + +We have the usual main() function; +-------------------------------------------------------------modelview.h--------------------- +\code +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTableView; //forward declaration + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTableView *tableView; +public: + ModelView(QWidget *parent = 0); + +}; + +#endif // MODELVIEW_H +\endcode + +The application is a \l QMainWindow that holds a \l QTableView. + +-------------------------------------------------------------modelview.cpp--------------------- +\code +#include +#include "modelview.h" +#include "mymodel.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + tableView = new QTableView(this); + setCentralWidget(tableView); + tableView->setModel(new MyModel(this) ); +} + +\endcode + +Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView::}{tableView()} OR \l QTableView::tableView() OR \l QTableView::tableView . \l {QTableView::}{tableView} will invoke the methods of the pointer it has received to find out two things: + \list + \o How many rows and columns should be displayed + \o What content should be printed into each cell. + \endlist + +The model needs some code to respond to this. + +We have a table data set, so let's start with QAbstractTableModel since it is easier to use. +-------------------------------------------------------------mymodel.h--------------------- +\code +#ifndef MYMODEL_H +#define MYMODEL_H + +#include + +class MyModel : public QAbstractTableModel +{ + Q_OBJECT +public: + MyModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; +}; + +#endif // MYMODEL_H +\endcode + +QAbstractTableModel requires the implementation of three abstract methods. + + +-------------------------------------------------------------mymodel.cpp--------------------- +\code +HIER FEHLT mymodel.cpp !!! +\endcode + +The number of rows and columns is set by \c MyModel::rowCount() and \c MyModel::columnCount(). +When the view has to know what the cell 's text is, it calls the \l{QAbstractItemModel::data()}{data()} method. Row and column information is specified with parameter \c index and the role is set to Qt::Display Role. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. + +This small example demonstrates the passive nature of a model. The model does not know when it will be used or which data is needed. It simply provides data each time the view requests it. + +What happens when the model 's data needs to be changed? How does the view know when data changes and needs to be read again? The model has to emit a signal that indicates what range of cells has changed. This will be demonstrated in section 2.3. + +\section2 2.2 Extending the read only example with roles +In addition to controlling what text the view displays, the model also controls the text's appearance. When we slightly change the model, we get the following result: \image readonlytable_role.png + + +In fact, nothing except for the \l{QAbstractItemModel::data()}{data()} method needs to be changed to set fonts, background colour, alignment and a checkbox. Here is the \l{QAbstractItemModel::data()}{data()} method that produces the result shown above: + +\code +HIER FEHLT WAS !!! +\endcode + +Each formatting property will be requested from the model with a separate call to the \l{QAbstractItemModel::data()}{data()} method. The \c role parameter is used to let the model know which property is being requested: + + \table + \header + \o Role (enum Qt::ItemDataRole ) + \o Meaning + \o Type + \row + \o Qt::DisplayRole + \o text + \o QString + \row + \o Qt::FontRole + \o font + \o QFont + \row + \o Qt::BackgroundRole + \o brush for the background of the cell + \o QBrush + \row + \o Qt::TextAlignmentRole + \o text alignment + \o enum Qt::AlignmentFlag + \row + \o {1, 3} Qt::CheckStateRole + \o {1, 3} suppresses checkboxes with QVariant(), sets checkboxes with Qt::Checked or Qt::Unchecked + \o {1, 3} enum Qt::ItemDataRole + + \endtable + +Refer to Qt documentation to learn more about enum Qt::ItemDataRole's capabilities. + + +Now we need to determine how using a seperated model impacts the application's performance, so let's trace how often the view calls the \l{QAbstractItemModel::data()}{data()} method. In order to track how often the view calls the model, we have put a debug statement in the \l{QAbstractItemModel::data()}{data()} method, which logs onto stdio. In our small example, \l{QAbstractItemModel::data()}{data()} will be called 42 times. Each time you hover the cursor over the field, \l{QAbstractItemModel::data()}{data()} will be called again - 7 times for each cell. That's why it is important to make sure that your data is available when \l{QAbstractItemModel::data()}{data()}) is invoked and expensive lookup operations are cached. + +\section2 2.3 A clock inside a table cell +\image clock.png + +We still have a read only table, but this time the content changes every second because we are showing the current time. +\code +QVariant MyModel::data(const QModelIndex &index, int role ) const +{ + QVariant returnVal; + int row = index.row(); + int col = index.column(); + + if(role == Qt::DisplayRole) + + { + if(row == 0 && col == 0 ) + { + returnVal = QTime::currentTime().toString(); + } + } + return returnVal; +} +\endcode + +Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal. +\code +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ +// selectedCell = 0; + timer = new QTimer(this); + timer->setInterval(1000); + connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) ); + timer->start(); +} +\endcode + +Here is the corresponding slot: +\code + +void MyModel::timerHit() +{ + //we identify the top left cell + QModelIndex topLeft = createIndex ( 0,0 ); + //emit a signal to make the view reread identified data + emit dataChanged ( topLeft, topLeft ); +} +\endcode + +We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QAbstractItemModel::setModel()}{setModel()} . + +\section2 2.4 Setting up Headers for Columns and Rows +Headers can be hidden via a view method. +\c tableView->verticalHeader()->hide(); +\image header.png + + +The header content, however , is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: +\code +QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole) + { + if (orientation == Qt::Horizontal) { + switch (section) + { + case 0: + return QString("first"); + case 1: + return QString("second"); + case 2: + return QString("third"); + } + } + } + return QVariant(); +} +\endcode + + +\section2 2.5 The minimal Editing example +In this example, we are going to build an application that automatically populates a window title with content by repeating values entered into table cells. + +The model decides whether editing capabilities are available . We only have to modify the model in order for the available editing capabilities to be enabled. This is done by reimplementing the following virtual methods: \l{QAbstractItemModel::setData()}{setData()} and \l{QAbstractItemModel::flags()}{flags()}. +\code +#ifndef MYMODEL_H +#define MYMODEL_H + +#include +#include + +class MyModel : public QAbstractTableModel +{ + Q_OBJECT +public: + MyModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); + Qt::ItemFlags flags ( const QModelIndex & index ) const ; +private: + QStringList m_gridData; //holds text entered into QTableView + int modelIndexToOffset(const QModelIndex & index) const; +signals: + void editCompleted(const QString &); +}; + +#endif // MYMODEL_H +\endcode + +We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title. +\code +#include "mymodel.h" + +const int COLS= 3; +const int ROWS= 2; + +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ + //gridData needs to have 6 element, one for each table cell + m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ; +} +\endcode + +In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table) +\code +HIER FEHLT WAS!!! +\endcode + +\l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole. +\code +HIER FEHLT WAS!!! +\endcode + +Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read. + +\section1 3 Intermediate Topics +\section2 3.1 TreeView +You can convert the example above into an application with a tree view. Simply replace QTableView with QTreeView, which results in a read/write tree. No changes have to be made to the model. The tree won't have any hierarchies because there aren't any hierarchies in the model itself. +\image dummy_tree.png + + +QListView, QTableView and QTreeView all use a model abstraction, which is a merged list, table and tree. This makes it possible to use several different types of view classes from the same model. +\image list_table_tree.png + +This is how our example model looks so far: +\image example_model.png + + +We want to, however, present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with QStandardItems, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png +\code +#include +#include +#include +#include "modelview.h" + + +const int ROWS = 2; +const int COLUMNS = 3; + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + treeView = new QTreeView(this); + setCentralWidget(treeView); + standardModel = new QStandardItemModel ; + + QList preparedColumn =prepareColumn("first", "second", "third"); + QStandardItem *item = standardModel->invisibleRootItem(); + // adding a row to the invisible root item produces a root element + item->appendRow(preparedColumn); + + QList secondRow =prepareColumn("111", "222", "333"); + // adding a row to an item starts a subtree + preparedColumn.first()->appendRow(secondRow); + + treeView->setModel( standardModel ); + treeView->expandAll(); +} + +//--------------------------------------------------------------------------- +QList ModelView::prepareColumn(const QString &first, + const QString &second, + const QString &third ) +{ + QList colItems; + colItems << new QStandardItem(first); + colItems << new QStandardItem(second); + colItems << new QStandardItem(third); + return colItems; +} + +\endcode + +We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other QStandardItems. Nodes are collapsed and expanded within the view. + +\section2 3.2 Working with selection +We want to access a selected item's content in order to output it into the window title together with the hierarchy level. +\image selection2.png + + +So let's create a couple of items: +\code +#include +#include +#include +#include "modelview.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + treeView = new QTreeView(this); + setCentralWidget(treeView); + standardModel = new QStandardItemModel ; + QStandardItem *rootNode = standardModel->invisibleRootItem(); + + + //defining a couple of items + QStandardItem *americaItem = new QStandardItem("America"); + QStandardItem *mexicoItem = new QStandardItem("Canada"); + QStandardItem *usaItem = new QStandardItem("USA"); + QStandardItem *bostonItem = new QStandardItem("Boston"); + QStandardItem *europeItem = new QStandardItem("Europe"); + QStandardItem *italyItem = new QStandardItem("Italy"); + QStandardItem *romeItem = new QStandardItem("Rome"); + QStandardItem *veronaItem = new QStandardItem("Verona"); + + //building up the hierarchy + rootNode-> appendRow(americaItem); + rootNode-> appendRow(europeItem); + americaItem-> appendRow(mexicoItem); + americaItem-> appendRow(usaItem); + usaItem-> appendRow(bostonItem); + europeItem-> appendRow(italyItem); + italyItem-> appendRow(romeItem); + italyItem-> appendRow(veronaItem); + + //register the model + treeView->setModel( standardModel ); + treeView->expandAll(); + + //selection changes shall trigger a slot + QItemSelectionModel *selectionModel= treeView->selectionModel(); + connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), + this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & ))); +} +\endcode + +Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal. +\code +HIER FEHLT WAS!!! +\endcode + +We get the model index that corresponds to the selection by calling +\c treeView->selectionModel()->currentIndex() and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed QModelIndex(). This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. + +The selection model (as shown above) can be retrieved, but it can also be set with \c QAbstractItemView::setSelectionModel. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemModel::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemModel::setSelectionModel()}{setSelectionModel()}; +\section2 3.3 Predefined Models +The typical way to use model/view is to wrap specific data to make it usable with view classes. Qt, however, also provides predefined models for common underlying data structures. If one of the available data structures is suitable for your application, a predefined model can be a good choice. + + \table + \row + \o QStringListModel + \o Stores a list of strings + \row + \o QStandardItemModel + \o Stores arbitrary hierarchical items + \row + \o {1, 2} QFileSystemModel +QDirModel (deprecated) + \o {1, 2} Encapsulate the local file system + \row + \o QSqlQueryModel + \o Encapsulate an SQL result set + \row + \o QSqlTableModel + \o Encapsulates an SQL table + \row + \o QSqlRelationalTableModel + \o Encapsulates an SQL table with foreign keys + \row + \o QSortFilterProxyModel + \o Sorts and/or filters another model + + \endtable + +\section2 3.4 Delegates +In all examples so far, data is presented as text or a checkbox in a cell and is edited as text or a checkbox. The component that provides these presentation and editing services is called a “delegate.” We are only just beginning to work with the delegate because the view uses a default delegate. But imagine that we want to have a different editor.(e.g. a slider or a drop down list) Or imagine that we want to present data as graphics. Let's take a look at an example called Stardelegate, ( \l{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html}{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html} ) in which stars are used to show a rating: \image stardelegate.png + +The view has a method that replaces the default delegate and installs a custom delegate. This method is called \l{QAbstractItemModel::setItemDelegate()}{setItemDelegate()}. A new delegate can be written by creating a class that inherits from QStyledItemDelegate. In order to write a delegate that displays stars and has no input capabilities, we only need to overwrite 2 methods. +\code + class StarDelegate : public QStyledItemDelegate + { + Q_OBJECT + public: + StarDelegate(QWidget *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const; + }; + +\endcode + +\l{QAbstractItemModel::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \c index.data(). \c SizeHint specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. + +Writing custom delegates is the right choice if you want to show your data with a custom graphical representation inside the grid of the view class. If you want to leave the grid, you can write a custom view class. + +\section2 3.5 Debugging with ModelTest +The passive nature of models provides new challenges for programmers. Inconsistencies in the model can cause the application to crash. Since the model is hit by numerous calls from the view, it is hard to find out which call has crashed the application and which operation has introduced the problem. + +Qt provides software called ModelTest, which checks models while your programming is running. Every time the model is changed, ModelTest scans the model and reports errors with an assert. This is especially important for tree models, since their hierarchical nature leaves many possibilities for subtle inconsistencies. http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest + +Unlike view classes, ModelTest uses out of range indexes to test the model. This means your application may crash with ModelTest even if it runs perfectly without it. So you also need to handle all of the indexes that are out of range when using ModelTest. + + + + + + + + + +\section2 3.6 Model/View NG + +\image path.png + +Model/View was introduced in Qt 4.0 and is a frequently used technology. Feedback from clients and new development trends have shown, that there is a need to further develop the model/view technology. Therefore a research project at Nokia is looking into ways to go beyond the current implementation. + +One limitation of model/view is that view classes are basically all fixed grids. It is possible, but really hard to make a list view with icons placed on a curve; or cells expanding on mouse over events to show additional information. In order to achieve graphically rich view experiences, Model/View NG will use QGraphicsView to render elements. Nodel/View NG also aims to make model/view programming more intuitive. One way to achieve this is to have separate models for lists, tables and trees. The current model abstraction is complex because it is capable of representing a list, a table or a tree. + +Model/View NG is a research project. You are welcome to checkout the source code, monitor progress and take part in discussions at the following address: \l{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG}{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG} + +\section1 4 Good Sources for Additional Information +\section2 4.1 Books +Model/View programming is covered quite extensively in the documentation of Qt but also in several good books. + \list 1 + \o 1.C++ GUI Programming with Qt 4 / Jasmin Blanchette, Mark Summerfield, Prentice Hall, 2nd edition, ISBN 0-13-235416-0 +also available in German: C++ GUI Programmierung mit Qt 4: Die offizielle Einführung, Addison-Wesley, ISBN 3-827327-29-6 + \o 1.The Book of Qt4, The Art of Building Qt Applications / Daniel Molkentin, Open Source Press ISBN 1-59327-147-6 +Translated from: Qt 4, Einführung in die Applikationsentwicklung, Open Source Press, ISBN 3-937514-12-0 + \o 1.Foundations of Qt Development / Johan Thelin, Apress, ISBN 1-59059-831-8 + \endlist + + +The following list provides an overview of example programs contained in the books above. Some of them make very good templates for developing similar applications. + + \table + \header + \o example name + \o view class used + \o model used + \o aspects touched + \o + \row + \o Team Leaders + \o QListview + \o QStringListModel + \o + \o Book 1, Chapter 10, Figure 10.6 + \row + \o Directory Viewer + \o QTreeView + \o QDirModel + \o + \o Book 1, Chapter 10, Figure 10.7 + \row + \o Color Names + \o QListView + \o QSortFilterProxyModel +applied to QStringListModel + \o + \o Book 1, Chapter 10, Figure 10.8 + \row + \o Currencies + \o QTableView + \o custom model based on +QAbstractTableModel + \o read only + \o Book 1, Chapter 10, Figure 10.10 + \row + \o Cities + \o QTableView + \o custom model based on +QAbstractTableModel + \o read / write + \o Book 1, Chapter 10, Figure 10.12 + \row + \o Boolean Parser + \o QTreeView + \o custom model based on +QAbstractItemModel + \o read only + \o Book 1, Chapter 10, Figure 10.14 + \row + \o Track Editor + \o {2, 1} QTableWidget + \o custom delegate providing a custom editor + \o Book 1, Chapter 10, Figure 10.15 + + \row + \o Four directory views + \o QListView +QTableView +QTreeView + \o QDirModel + \o demonstrates the use of multiple views + \o Book2, Chapter 8.2 + \row + \o Address Book + \o QListView +QTableView +QTreeView + \o custom model based on +QAbstractTableModel + \o read / write + \o Book2, Chapter 8.4 + \row + \o Address Book with sorting + \o + \o QProxyModel + \o introducing sort and filter capabilities + \o Book2, Chapter 8.5 + \row + \o Address Book +with checkboxes + \o + \o + \o introducing checkboxes +in model/view + \o Book2, Chapter 8.6 + \row + \o Address Book +with transposed grid + \o + \o custom proxy Model based on QAbstractProxyModel + \o introducing a custom model + \o Book2, Chapter 8.7 + \row + \o Address Book +with drag and drop + \o + \o + \o introducing drag and drop support + \o Book2, Chapter 8.8 + \row + \o Address Book with custom editor + \o + \o + \o introducing custom delegates + \o Book2, Chapter 8.9 + \row + \o Views + \o QListView +QTableView +QTreeView + \o QStandardItemModel + \o read only + \o Book 3, Chapter 5, figure 5-3 + \row + \o Bardelegate + \o QTableView + \o + \o custom delegate for presentation based on QAbstractItemDelegate + \o Book 3, Chapter 5, figure 5-5 + \row + \o Editdelegate + \o QTableView + \o + \o custom delegate for editing based on QAbstractItemDelegate + \o Book 3, Chapter 5, figure 5-6 + \row + \o Singleitemview + \o custom view based on +QAbstractItemView + \o + \o custom view + \o Book 3, +Chapter 5, +figure 5-7 + \row + \o listmodel + \o QTableView + \o custom Model based on +QAbstractTableModel + \o read only + \o Book 3, +Chapter 5, +Figure 5-8 + \row + \o treemodel + \o QTreeView + \o custom Model based on +QAbstractItemModel + \o read only + \o Book 3, +Chapter 5, +Figure 5-10 + \row + \o edit integers + \o QListView + \o custom Model based on +QAbstractListModel + \o read / write + \o Book 3, +Chapter 5, +Listing 5-37, Figure 5-11 + \row + \o sorting + \o QTableView + \o QSortFilterProxyModel +applied to QStringListModel + \o demonstrates sorting + \o Book 3, Chapter 5, Figure 5-12 + + \endtable + + +\section2 4.2 Qt documentation +Qt 4.6 comes with 17 examples and 2 Demonstrations for model/view. The examples can be found here: \l{http://doc.qt.nokia.com/4.6/examples-itemviews.html}{http://doc.qt.nokia.com/4.6/examples-itemviews.html} + \table + \header + \o example name + \o view class used + \o model used + \o aspects touched + \row + \o Address Book + \o QTableView + \o QTableModel +QSortFilterProxyModel + \o usage of QSortFilterProxyModel to generate different subsets from one data pool + \row + \o Basic Sort/Filter Model + \o QTreeView + \o QStandardItemModel +QSortFilterProxyModel + \o + \row + \o Chart + \o custom view + \o QStandardItemModel + \o designing custom views that cooperate with selection models + \row + \o Color Editor Factory + \o {2, 1} QTableWidget + \o enhancing the standard delegate with a new custom editor to choose colours + \row + \o Combo Widget Mapper + \o QDataWidgetMapper to map QLineEdit, QTextEdit and QComboBox + \o QStandardItemModel + \o shows how a QComboBox can serve as a view class + \row + \o Custom Sort/Filter Model + \o QTreeView + \o QStandardItemModel +QSortFilterProxyModel + \o subclass QSortFilterProxyModel +for advanced sorting and filtering + \row + \o Dir View + \o QTreeView + \o QDirModel + \o very small example to demonstrate how to assign a model to a view + \row + \o Editable Tree Model + \o QTreeView + \o custom tree model + \o comprehensive example for working with trees, demonstrates editing cells and tree structure with an underlying custom model + \row + \o Fetch More + \o QListView + \o custom list model + \o dynamically changing model + \row + \o Frozen Column + \o QTableView + \o QStandardItemModel + \o + \row + \o Pixelator + \o QTableView + \o custom table model + \o implementation of a custom delegate + \row + \o Puzzle + \o QListView + \o custom list model + \o model/view with drag and drop + \row + \o Simple DOM Model + \o QTreeView + \o custom tree model + \o read only example for a custom tree model + \row + \o Simple Tree Model + \o QTreeView + \o custom tree model + \o read only example for a custom tree model + \row + \o Simple Widget Mapper + \o QDataWidgetMapper to map QLineEdit, QTextEdit and QSpinBox + \o QStandardItemModel + \o basic QDataWidgetMapper usage + \row + \o Spin Box Delegate + \o QTableView + \o QStandardItemModel + \o custom delegate that uses a spin box as a cell editor + \row + \o Star Delegate + \o {2, 1} QTableWidget + \o comprehensive custom delegate example. + \endtable + +Demonstrations are similar to examples except that no walk-through is provided for the code lines. Demonstrations are also sometimes more feature rich. + \l{http://doc.qt.nokia.com/4.6/demos.html}{http://doc.qt.nokia.com/4.6/demos.html} + \list + \o The \bold Interview demonstration shows the same model and selection being shared between three different views. + \o Demonstration \bold Spreadsheet demonstrates the use of a table view as a spreadsheet, using custom delegates to render each item according to the type of data it contains. + \endlist + +A reference documentation for model/view technology is also available. \l{http://doc.qt.nokia.com/4.6/model-view-programming.html}{http://doc.qt.nokia.com/4.6/model-view-programming.html} + +*/ \ No newline at end of file diff --git a/doc/src/images/clock.png b/doc/src/images/clock.png new file mode 100755 index 0000000..c7f6a1b Binary files /dev/null and b/doc/src/images/clock.png differ diff --git a/doc/src/images/columnview.png b/doc/src/images/columnview.png new file mode 100755 index 0000000..2fb972e Binary files /dev/null and b/doc/src/images/columnview.png differ diff --git a/doc/src/images/combobox.png b/doc/src/images/combobox.png new file mode 100755 index 0000000..d172b41 Binary files /dev/null and b/doc/src/images/combobox.png differ diff --git a/doc/src/images/dummy_tree.png b/doc/src/images/dummy_tree.png new file mode 100755 index 0000000..7373ea6 Binary files /dev/null and b/doc/src/images/dummy_tree.png differ diff --git a/doc/src/images/edit.png b/doc/src/images/edit.png new file mode 100755 index 0000000..161b06f Binary files /dev/null and b/doc/src/images/edit.png differ diff --git a/doc/src/images/example_model.png b/doc/src/images/example_model.png new file mode 100755 index 0000000..4261261 Binary files /dev/null and b/doc/src/images/example_model.png differ diff --git a/doc/src/images/header.png b/doc/src/images/header.png new file mode 100755 index 0000000..2597635 Binary files /dev/null and b/doc/src/images/header.png differ diff --git a/doc/src/images/lineedit.png b/doc/src/images/lineedit.png new file mode 100755 index 0000000..83d1c47 Binary files /dev/null and b/doc/src/images/lineedit.png differ diff --git a/doc/src/images/list_table_tree.png b/doc/src/images/list_table_tree.png new file mode 100755 index 0000000..b2daf1f Binary files /dev/null and b/doc/src/images/list_table_tree.png differ diff --git a/doc/src/images/listview.png b/doc/src/images/listview.png new file mode 100755 index 0000000..fa49c52 Binary files /dev/null and b/doc/src/images/listview.png differ diff --git a/doc/src/images/lotto.png b/doc/src/images/lotto.png new file mode 100755 index 0000000..dd751cf Binary files /dev/null and b/doc/src/images/lotto.png differ diff --git a/doc/src/images/modelview.png b/doc/src/images/modelview.png new file mode 100755 index 0000000..7b042af Binary files /dev/null and b/doc/src/images/modelview.png differ diff --git a/doc/src/images/path.png b/doc/src/images/path.png new file mode 100755 index 0000000..73107ff Binary files /dev/null and b/doc/src/images/path.png differ diff --git a/doc/src/images/qcompleter.png b/doc/src/images/qcompleter.png new file mode 100755 index 0000000..d25caac Binary files /dev/null and b/doc/src/images/qcompleter.png differ diff --git a/doc/src/images/readonlytable.png b/doc/src/images/readonlytable.png new file mode 100755 index 0000000..90bcba4 Binary files /dev/null and b/doc/src/images/readonlytable.png differ diff --git a/doc/src/images/readonlytable_role.png b/doc/src/images/readonlytable_role.png new file mode 100755 index 0000000..7d2d416 Binary files /dev/null and b/doc/src/images/readonlytable_role.png differ diff --git a/doc/src/images/selection2.png b/doc/src/images/selection2.png new file mode 100755 index 0000000..66c757f Binary files /dev/null and b/doc/src/images/selection2.png differ diff --git a/doc/src/images/standardwidget.png b/doc/src/images/standardwidget.png new file mode 100755 index 0000000..3ccccf1 Binary files /dev/null and b/doc/src/images/standardwidget.png differ diff --git a/doc/src/images/tableview.png b/doc/src/images/tableview.png new file mode 100755 index 0000000..8be1b6c Binary files /dev/null and b/doc/src/images/tableview.png differ diff --git a/doc/src/images/tree.png b/doc/src/images/tree.png new file mode 100755 index 0000000..3f046c9 Binary files /dev/null and b/doc/src/images/tree.png differ diff --git a/doc/src/images/tree_2.png b/doc/src/images/tree_2.png new file mode 100755 index 0000000..6ee1f4a Binary files /dev/null and b/doc/src/images/tree_2.png differ diff --git a/doc/src/images/tree_2_with_algorithm.png b/doc/src/images/tree_2_with_algorithm.png new file mode 100755 index 0000000..ecf9101 Binary files /dev/null and b/doc/src/images/tree_2_with_algorithm.png differ diff --git a/doc/src/images/tree_city.png b/doc/src/images/tree_city.png new file mode 100755 index 0000000..57f03d9 Binary files /dev/null and b/doc/src/images/tree_city.png differ diff --git a/doc/src/images/treeview.png b/doc/src/images/treeview.png new file mode 100755 index 0000000..af31fe9 Binary files /dev/null and b/doc/src/images/treeview.png differ diff --git a/doc/src/images/widgetmapper.png b/doc/src/images/widgetmapper.png new file mode 100755 index 0000000..9627088 Binary files /dev/null and b/doc/src/images/widgetmapper.png differ -- cgit v0.12 From 4df3fb13821e13ecf581d87f2d224b2f1b964609 Mon Sep 17 00:00:00 2001 From: Roland Wolf Date: Thu, 27 May 2010 10:37:48 +0200 Subject: clean up previous test commit --- src/testfile.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/testfile.txt diff --git a/src/testfile.txt b/src/testfile.txt deleted file mode 100644 index e69de29..0000000 -- cgit v0.12 From f574700f920ae5d5bda25ba217d6face9f3d3902 Mon Sep 17 00:00:00 2001 From: Michael D Scull Date: Thu, 27 May 2010 15:12:58 +0200 Subject: Rolands ModelView Source --- .../tutorials/modelview/1_readonly/1_readonly.pro | 10 +++ examples/tutorials/modelview/1_readonly/main.cpp | 10 +++ .../tutorials/modelview/1_readonly/modelview.cpp | 12 ++++ .../tutorials/modelview/1_readonly/modelview.h | 18 ++++++ .../tutorials/modelview/1_readonly/mymodel.cpp | 30 +++++++++ examples/tutorials/modelview/1_readonly/mymodel.h | 16 +++++ .../modelview/2_formatting/2_formatting.pro | 10 +++ examples/tutorials/modelview/2_formatting/main.cpp | 10 +++ .../tutorials/modelview/2_formatting/modelview.cpp | 12 ++++ .../tutorials/modelview/2_formatting/modelview.h | 17 +++++ .../tutorials/modelview/2_formatting/mymodel.cpp | 73 ++++++++++++++++++++++ .../tutorials/modelview/2_formatting/mymodel.h | 16 +++++ .../modelview/3_changingmodel/3_changingmodel.pro | 10 +++ .../tutorials/modelview/3_changingmodel/main.cpp | 10 +++ .../modelview/3_changingmodel/modelview.cpp | 12 ++++ .../modelview/3_changingmodel/modelview.h | 17 +++++ .../modelview/3_changingmodel/mymodel.cpp | 53 ++++++++++++++++ .../tutorials/modelview/3_changingmodel/mymodel.h | 23 +++++++ .../tutorials/modelview/4_headers/4_headers.pro | 10 +++ examples/tutorials/modelview/4_headers/main.cpp | 10 +++ .../tutorials/modelview/4_headers/modelview.cpp | 14 +++++ examples/tutorials/modelview/4_headers/modelview.h | 18 ++++++ examples/tutorials/modelview/4_headers/mymodel.cpp | 50 +++++++++++++++ examples/tutorials/modelview/4_headers/mymodel.h | 17 +++++ examples/tutorials/modelview/5_edit/5_edit.pro | 10 +++ examples/tutorials/modelview/5_edit/main.cpp | 10 +++ examples/tutorials/modelview/5_edit/modelview.cpp | 20 ++++++ examples/tutorials/modelview/5_edit/modelview.h | 19 ++++++ examples/tutorials/modelview/5_edit/mymodel.cpp | 58 +++++++++++++++++ examples/tutorials/modelview/5_edit/mymodel.h | 24 +++++++ .../tutorials/modelview/6_treeview/6_treeview.pro | 5 ++ examples/tutorials/modelview/6_treeview/main.cpp | 10 +++ .../tutorials/modelview/6_treeview/modelview.cpp | 40 ++++++++++++ .../tutorials/modelview/6_treeview/modelview.h | 24 +++++++ .../modelview/7_selections/7_selections.pro | 5 ++ examples/tutorials/modelview/7_selections/main.cpp | 10 +++ .../tutorials/modelview/7_selections/modelview.cpp | 63 +++++++++++++++++++ .../tutorials/modelview/7_selections/modelview.h | 23 +++++++ examples/tutorials/modelview/qmake.pro | 10 +++ 39 files changed, 809 insertions(+) create mode 100755 examples/tutorials/modelview/1_readonly/1_readonly.pro create mode 100755 examples/tutorials/modelview/1_readonly/main.cpp create mode 100755 examples/tutorials/modelview/1_readonly/modelview.cpp create mode 100755 examples/tutorials/modelview/1_readonly/modelview.h create mode 100755 examples/tutorials/modelview/1_readonly/mymodel.cpp create mode 100755 examples/tutorials/modelview/1_readonly/mymodel.h create mode 100755 examples/tutorials/modelview/2_formatting/2_formatting.pro create mode 100755 examples/tutorials/modelview/2_formatting/main.cpp create mode 100755 examples/tutorials/modelview/2_formatting/modelview.cpp create mode 100755 examples/tutorials/modelview/2_formatting/modelview.h create mode 100755 examples/tutorials/modelview/2_formatting/mymodel.cpp create mode 100755 examples/tutorials/modelview/2_formatting/mymodel.h create mode 100755 examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro create mode 100755 examples/tutorials/modelview/3_changingmodel/main.cpp create mode 100755 examples/tutorials/modelview/3_changingmodel/modelview.cpp create mode 100755 examples/tutorials/modelview/3_changingmodel/modelview.h create mode 100755 examples/tutorials/modelview/3_changingmodel/mymodel.cpp create mode 100755 examples/tutorials/modelview/3_changingmodel/mymodel.h create mode 100755 examples/tutorials/modelview/4_headers/4_headers.pro create mode 100755 examples/tutorials/modelview/4_headers/main.cpp create mode 100755 examples/tutorials/modelview/4_headers/modelview.cpp create mode 100755 examples/tutorials/modelview/4_headers/modelview.h create mode 100755 examples/tutorials/modelview/4_headers/mymodel.cpp create mode 100755 examples/tutorials/modelview/4_headers/mymodel.h create mode 100755 examples/tutorials/modelview/5_edit/5_edit.pro create mode 100755 examples/tutorials/modelview/5_edit/main.cpp create mode 100755 examples/tutorials/modelview/5_edit/modelview.cpp create mode 100755 examples/tutorials/modelview/5_edit/modelview.h create mode 100755 examples/tutorials/modelview/5_edit/mymodel.cpp create mode 100755 examples/tutorials/modelview/5_edit/mymodel.h create mode 100755 examples/tutorials/modelview/6_treeview/6_treeview.pro create mode 100755 examples/tutorials/modelview/6_treeview/main.cpp create mode 100755 examples/tutorials/modelview/6_treeview/modelview.cpp create mode 100755 examples/tutorials/modelview/6_treeview/modelview.h create mode 100755 examples/tutorials/modelview/7_selections/7_selections.pro create mode 100755 examples/tutorials/modelview/7_selections/main.cpp create mode 100755 examples/tutorials/modelview/7_selections/modelview.cpp create mode 100755 examples/tutorials/modelview/7_selections/modelview.h create mode 100755 examples/tutorials/modelview/qmake.pro diff --git a/examples/tutorials/modelview/1_readonly/1_readonly.pro b/examples/tutorials/modelview/1_readonly/1_readonly.pro new file mode 100755 index 0000000..1162d5a --- /dev/null +++ b/examples/tutorials/modelview/1_readonly/1_readonly.pro @@ -0,0 +1,10 @@ +TARGET = mv_readonly + +TEMPLATE = app + +SOURCES += main.cpp \ + modelview.cpp \ + mymodel.cpp + +HEADERS += modelview.h \ + mymodel.h diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp new file mode 100755 index 0000000..998503c --- /dev/null +++ b/examples/tutorials/modelview/1_readonly/main.cpp @@ -0,0 +1,10 @@ +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} diff --git a/examples/tutorials/modelview/1_readonly/modelview.cpp b/examples/tutorials/modelview/1_readonly/modelview.cpp new file mode 100755 index 0000000..becd61d --- /dev/null +++ b/examples/tutorials/modelview/1_readonly/modelview.cpp @@ -0,0 +1,12 @@ +#include +#include "modelview.h" +#include "mymodel.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + tableView = new QTableView(this); + setCentralWidget(tableView); + tableView->setModel(new MyModel(this) ); +} + diff --git a/examples/tutorials/modelview/1_readonly/modelview.h b/examples/tutorials/modelview/1_readonly/modelview.h new file mode 100755 index 0000000..f1b63bd --- /dev/null +++ b/examples/tutorials/modelview/1_readonly/modelview.h @@ -0,0 +1,18 @@ +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTableView; //forward declaration + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTableView *tableView; +public: + ModelView(QWidget *parent = 0); + +}; + +#endif // MODELVIEW_H diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp new file mode 100755 index 0000000..ff3e2d2 --- /dev/null +++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp @@ -0,0 +1,30 @@ +#include "mymodel.h" + +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ +} + +//------------------------------------------------------- +int MyModel::rowCount(const QModelIndex & /*parent*/ ) const +{ + return 2; +} + +//------------------------------------------------------- +int MyModel::columnCount(const QModelIndex & /*parent*/ ) const +{ + return 3; +} + +//------------------------------------------------------- +QVariant MyModel::data(const QModelIndex &index, int role ) const +{ + if(role == Qt::DisplayRole) + { + return QString("Row%1, Column%2") + .arg(index.row() + 1) + .arg(index.column() +1); + } + return QVariant(); +} diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h new file mode 100755 index 0000000..01ae6cb --- /dev/null +++ b/examples/tutorials/modelview/1_readonly/mymodel.h @@ -0,0 +1,16 @@ +#ifndef MYMODEL_H +#define MYMODEL_H + +#include + +class MyModel : public QAbstractTableModel +{ + Q_OBJECT +public: + MyModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; +}; + +#endif // MYMODEL_H diff --git a/examples/tutorials/modelview/2_formatting/2_formatting.pro b/examples/tutorials/modelview/2_formatting/2_formatting.pro new file mode 100755 index 0000000..7e70d81 --- /dev/null +++ b/examples/tutorials/modelview/2_formatting/2_formatting.pro @@ -0,0 +1,10 @@ +TARGET = mv_formatting + +TEMPLATE = app + +SOURCES += main.cpp \ + modelview.cpp \ + mymodel.cpp + +HEADERS += modelview.h \ + mymodel.h diff --git a/examples/tutorials/modelview/2_formatting/main.cpp b/examples/tutorials/modelview/2_formatting/main.cpp new file mode 100755 index 0000000..998503c --- /dev/null +++ b/examples/tutorials/modelview/2_formatting/main.cpp @@ -0,0 +1,10 @@ +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} diff --git a/examples/tutorials/modelview/2_formatting/modelview.cpp b/examples/tutorials/modelview/2_formatting/modelview.cpp new file mode 100755 index 0000000..becd61d --- /dev/null +++ b/examples/tutorials/modelview/2_formatting/modelview.cpp @@ -0,0 +1,12 @@ +#include +#include "modelview.h" +#include "mymodel.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + tableView = new QTableView(this); + setCentralWidget(tableView); + tableView->setModel(new MyModel(this) ); +} + diff --git a/examples/tutorials/modelview/2_formatting/modelview.h b/examples/tutorials/modelview/2_formatting/modelview.h new file mode 100755 index 0000000..98bee38 --- /dev/null +++ b/examples/tutorials/modelview/2_formatting/modelview.h @@ -0,0 +1,17 @@ +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTableView; //forward declaration + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTableView *tableView; +public: + ModelView(QWidget *parent = 0); +}; + +#endif // MODELVIEW_H diff --git a/examples/tutorials/modelview/2_formatting/mymodel.cpp b/examples/tutorials/modelview/2_formatting/mymodel.cpp new file mode 100755 index 0000000..48b1134 --- /dev/null +++ b/examples/tutorials/modelview/2_formatting/mymodel.cpp @@ -0,0 +1,73 @@ +#include +#include +#include "mymodel.h" +#include + +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ +} + +//------------------------------------------------------- +int MyModel::rowCount(const QModelIndex & /*parent */ ) const +{ + return 2; +} + +//------------------------------------------------------- +int MyModel::columnCount(const QModelIndex & /*parent */ ) const +{ + return 3; +} + +//------------------------------------------------------- +QVariant MyModel::data(const QModelIndex &index, int role ) const +{ + int row = index.row(); + int col = index.column(); + // generate a log message when this method gets called + qDebug() << QString("row %1, col%2, role %3") + .arg(row).arg(col).arg(role); + + switch(role){ + case Qt::DisplayRole: + if(row == 0 && col == 1 )return QString("<--left"); + if(row == 1 && col == 1 )return QString("right-->"); + + return QString("Row%1, Column%2") + .arg(row + 1) + .arg(col +1); + break; + case Qt::FontRole: + if(row == 0 && col ==0 ) //change font only for cell(0,0) + { + QFont boldFont; + boldFont.setBold(true); + return boldFont; + } + break; + case Qt::BackgroundRole: + + if(row == 1 && col ==2 ) //change background only for cell(1,2) + { + QBrush redBackground(QColor(Qt::red)); + return redBackground; + } + break; + case Qt::TextAlignmentRole: + + if(row == 1 && col ==1 ) //change text alignment only for cell(1,1) + { + return Qt::AlignRight + Qt::AlignVCenter; + } + break; + case Qt::CheckStateRole: + + if(row == 1 && col ==0 ) //add a checkbox to cell(1,0) + { + return Qt::Checked; + } + } + return QVariant(); +} + diff --git a/examples/tutorials/modelview/2_formatting/mymodel.h b/examples/tutorials/modelview/2_formatting/mymodel.h new file mode 100755 index 0000000..01ae6cb --- /dev/null +++ b/examples/tutorials/modelview/2_formatting/mymodel.h @@ -0,0 +1,16 @@ +#ifndef MYMODEL_H +#define MYMODEL_H + +#include + +class MyModel : public QAbstractTableModel +{ + Q_OBJECT +public: + MyModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; +}; + +#endif // MYMODEL_H diff --git a/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro new file mode 100755 index 0000000..d61ee4c --- /dev/null +++ b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro @@ -0,0 +1,10 @@ +TARGET = mv_changingmodel + +TEMPLATE = app + +SOURCES += main.cpp \ + modelview.cpp \ + mymodel.cpp + +HEADERS += modelview.h \ + mymodel.h diff --git a/examples/tutorials/modelview/3_changingmodel/main.cpp b/examples/tutorials/modelview/3_changingmodel/main.cpp new file mode 100755 index 0000000..998503c --- /dev/null +++ b/examples/tutorials/modelview/3_changingmodel/main.cpp @@ -0,0 +1,10 @@ +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} diff --git a/examples/tutorials/modelview/3_changingmodel/modelview.cpp b/examples/tutorials/modelview/3_changingmodel/modelview.cpp new file mode 100755 index 0000000..becd61d --- /dev/null +++ b/examples/tutorials/modelview/3_changingmodel/modelview.cpp @@ -0,0 +1,12 @@ +#include +#include "modelview.h" +#include "mymodel.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + tableView = new QTableView(this); + setCentralWidget(tableView); + tableView->setModel(new MyModel(this) ); +} + diff --git a/examples/tutorials/modelview/3_changingmodel/modelview.h b/examples/tutorials/modelview/3_changingmodel/modelview.h new file mode 100755 index 0000000..98bee38 --- /dev/null +++ b/examples/tutorials/modelview/3_changingmodel/modelview.h @@ -0,0 +1,17 @@ +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTableView; //forward declaration + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTableView *tableView; +public: + ModelView(QWidget *parent = 0); +}; + +#endif // MODELVIEW_H diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp new file mode 100755 index 0000000..d594175 --- /dev/null +++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include "mymodel.h" + + +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ +// selectedCell = 0; + timer = new QTimer(this); + timer->setInterval(1000); + connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) ); + timer->start(); +} + +//------------------------------------------------------- +int MyModel::rowCount(const QModelIndex & /*parent */ ) const +{ + return 2; +} + +//------------------------------------------------------- +int MyModel::columnCount(const QModelIndex & /*parent */ ) const +{ + return 3; +} + +//------------------------------------------------------- +QVariant MyModel::data(const QModelIndex &index, int role ) const +{ + int row = index.row(); + int col = index.column(); + + if(role == Qt::DisplayRole) + { + if(row == 0 && col == 0 ) + { + return QTime::currentTime().toString(); + } + } + return QVariant(); +} + +//------------------------------------------------------- +void MyModel::timerHit() +{ + //we identify the top left cell + QModelIndex topLeft = createIndex ( 0,0 ); + //emit a signal to make the view reread identified data + emit dataChanged ( topLeft, topLeft ); +} + diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.h b/examples/tutorials/modelview/3_changingmodel/mymodel.h new file mode 100755 index 0000000..9cc023b --- /dev/null +++ b/examples/tutorials/modelview/3_changingmodel/mymodel.h @@ -0,0 +1,23 @@ +#ifndef MYMODEL_H +#define MYMODEL_H + +#include + +class QTimer; // forward declaration + +class MyModel : public QAbstractTableModel +{ + Q_OBJECT +public: + MyModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QTimer *timer; +private: + int selectedCell; +private slots: + void timerHit(); +}; + +#endif // MYMODEL_H diff --git a/examples/tutorials/modelview/4_headers/4_headers.pro b/examples/tutorials/modelview/4_headers/4_headers.pro new file mode 100755 index 0000000..d6f8d23 --- /dev/null +++ b/examples/tutorials/modelview/4_headers/4_headers.pro @@ -0,0 +1,10 @@ +TARGET = mv_headers + +TEMPLATE = app + +SOURCES += main.cpp \ + modelview.cpp \ + mymodel.cpp + +HEADERS += modelview.h \ + mymodel.h diff --git a/examples/tutorials/modelview/4_headers/main.cpp b/examples/tutorials/modelview/4_headers/main.cpp new file mode 100755 index 0000000..998503c --- /dev/null +++ b/examples/tutorials/modelview/4_headers/main.cpp @@ -0,0 +1,10 @@ +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} diff --git a/examples/tutorials/modelview/4_headers/modelview.cpp b/examples/tutorials/modelview/4_headers/modelview.cpp new file mode 100755 index 0000000..39394da --- /dev/null +++ b/examples/tutorials/modelview/4_headers/modelview.cpp @@ -0,0 +1,14 @@ +#include +#include +#include "modelview.h" +#include "mymodel.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + tableView = new QTableView(this); + setCentralWidget(tableView); + tableView->setModel(new MyModel(this) ); + tableView->verticalHeader()->hide(); +} + diff --git a/examples/tutorials/modelview/4_headers/modelview.h b/examples/tutorials/modelview/4_headers/modelview.h new file mode 100755 index 0000000..f1b63bd --- /dev/null +++ b/examples/tutorials/modelview/4_headers/modelview.h @@ -0,0 +1,18 @@ +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTableView; //forward declaration + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTableView *tableView; +public: + ModelView(QWidget *parent = 0); + +}; + +#endif // MODELVIEW_H diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp new file mode 100755 index 0000000..a032fe5 --- /dev/null +++ b/examples/tutorials/modelview/4_headers/mymodel.cpp @@ -0,0 +1,50 @@ +#include "mymodel.h" + +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ +} + +//------------------------------------------------------- +int MyModel::rowCount(const QModelIndex & /*parent*/ ) const +{ + return 2; +} + +//------------------------------------------------------- +int MyModel::columnCount(const QModelIndex & /*parent*/ ) const +{ + return 3; +} + +//------------------------------------------------------- +QVariant MyModel::data(const QModelIndex &index, int role ) const +{ + if(role == Qt::DisplayRole) + { + return QString("Row%1, Column%2") + .arg(index.row() + 1) + .arg(index.column() +1); + } + return QVariant(); +} + + +QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole) + { + if (orientation == Qt::Horizontal) { + switch (section) + { + case 0: + return QString("first"); + case 1: + return QString("second"); + case 2: + return QString("third"); + } + } + } + return QVariant(); +} diff --git a/examples/tutorials/modelview/4_headers/mymodel.h b/examples/tutorials/modelview/4_headers/mymodel.h new file mode 100755 index 0000000..327ca10 --- /dev/null +++ b/examples/tutorials/modelview/4_headers/mymodel.h @@ -0,0 +1,17 @@ +#ifndef MYMODEL_H +#define MYMODEL_H + +#include + +class MyModel : public QAbstractTableModel +{ + Q_OBJECT +public: + MyModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; +}; + +#endif // MYMODEL_H diff --git a/examples/tutorials/modelview/5_edit/5_edit.pro b/examples/tutorials/modelview/5_edit/5_edit.pro new file mode 100755 index 0000000..e18c596 --- /dev/null +++ b/examples/tutorials/modelview/5_edit/5_edit.pro @@ -0,0 +1,10 @@ +TARGET = mv_edit + +TEMPLATE = app + +SOURCES += main.cpp \ + modelview.cpp \ + mymodel.cpp + +HEADERS += modelview.h \ + mymodel.h diff --git a/examples/tutorials/modelview/5_edit/main.cpp b/examples/tutorials/modelview/5_edit/main.cpp new file mode 100755 index 0000000..998503c --- /dev/null +++ b/examples/tutorials/modelview/5_edit/main.cpp @@ -0,0 +1,10 @@ +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} diff --git a/examples/tutorials/modelview/5_edit/modelview.cpp b/examples/tutorials/modelview/5_edit/modelview.cpp new file mode 100755 index 0000000..b6e8e34 --- /dev/null +++ b/examples/tutorials/modelview/5_edit/modelview.cpp @@ -0,0 +1,20 @@ +#include +#include "modelview.h" +#include "mymodel.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + tableView = new QTableView(this); + setCentralWidget(tableView); + QAbstractTableModel *myModel = new MyModel(this); + tableView->setModel( myModel ); + + //transfer changes to the model to the window title + connect(myModel, SIGNAL(editCompleted(const QString &) ), this, SLOT(setWindowTitle(const QString &))); +} + +void ModelView::showWindowTitle(const QString & title) +{ +setWindowTitle( title ); +} diff --git a/examples/tutorials/modelview/5_edit/modelview.h b/examples/tutorials/modelview/5_edit/modelview.h new file mode 100755 index 0000000..e1591f9 --- /dev/null +++ b/examples/tutorials/modelview/5_edit/modelview.h @@ -0,0 +1,19 @@ +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTableView; //forward declaration + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTableView *tableView; +public: + ModelView(QWidget *parent = 0); +public slots: + void showWindowTitle(const QString & title); +}; + +#endif // MODELVIEW_H diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp new file mode 100755 index 0000000..c64a6b7 --- /dev/null +++ b/examples/tutorials/modelview/5_edit/mymodel.cpp @@ -0,0 +1,58 @@ +#include "mymodel.h" + +const int COLS= 3; +const int ROWS= 2; + +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ + //gridData needs to have 6 element, one for each table cell + m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ; +} + +//------------------------------------------------------- +int MyModel::rowCount(const QModelIndex & /*parent*/ ) const +{ + return ROWS; +} + +//------------------------------------------------------- +int MyModel::columnCount(const QModelIndex & /*parent*/ ) const +{ + return COLS; +} + +//------------------------------------------------------- +QVariant MyModel::data(const QModelIndex &index, int role ) const +{ + if(role == Qt::DisplayRole) + { + return m_gridData[modelIndexToOffset(index)]; + } + return QVariant(); +} + +//----------------------------------------------------------------- +bool MyModel::setData ( const QModelIndex & index, const QVariant & value, int role ) +{ + if(role == Qt::EditRole) + { + m_gridData[modelIndexToOffset(index)] = value.toString(); + emit editCompleted(m_gridData.join(" | ") ); + } + return true; +} + +//----------------------------------------------------------------- +Qt::ItemFlags MyModel::flags ( const QModelIndex & /*index*/ ) const +{ + return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ; +} + +//----------------------------------------------------------------- +//convert row and column information to array offset +int MyModel::modelIndexToOffset(const QModelIndex & index) const +{ + return index.row()*COLS + index.column(); +} + diff --git a/examples/tutorials/modelview/5_edit/mymodel.h b/examples/tutorials/modelview/5_edit/mymodel.h new file mode 100755 index 0000000..f8fac77 --- /dev/null +++ b/examples/tutorials/modelview/5_edit/mymodel.h @@ -0,0 +1,24 @@ +#ifndef MYMODEL_H +#define MYMODEL_H + +#include +#include + +class MyModel : public QAbstractTableModel +{ + Q_OBJECT +public: + MyModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); + Qt::ItemFlags flags ( const QModelIndex & index ) const ; +private: + QStringList m_gridData; //holds text entered into QTableView + int modelIndexToOffset(const QModelIndex & index) const; +signals: + void editCompleted(const QString &); +}; + +#endif // MYMODEL_H diff --git a/examples/tutorials/modelview/6_treeview/6_treeview.pro b/examples/tutorials/modelview/6_treeview/6_treeview.pro new file mode 100755 index 0000000..6d078be --- /dev/null +++ b/examples/tutorials/modelview/6_treeview/6_treeview.pro @@ -0,0 +1,5 @@ +TARGET = mv_tree +TEMPLATE = app +SOURCES += main.cpp \ + modelview.cpp +HEADERS += modelview.h diff --git a/examples/tutorials/modelview/6_treeview/main.cpp b/examples/tutorials/modelview/6_treeview/main.cpp new file mode 100755 index 0000000..998503c --- /dev/null +++ b/examples/tutorials/modelview/6_treeview/main.cpp @@ -0,0 +1,10 @@ +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} diff --git a/examples/tutorials/modelview/6_treeview/modelview.cpp b/examples/tutorials/modelview/6_treeview/modelview.cpp new file mode 100755 index 0000000..a5488f7 --- /dev/null +++ b/examples/tutorials/modelview/6_treeview/modelview.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include "modelview.h" + + +const int ROWS = 2; +const int COLUMNS = 3; + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + treeView = new QTreeView(this); + setCentralWidget(treeView); + standardModel = new QStandardItemModel ; + + QList preparedColumn =prepareColumn("first", "second", "third"); + QStandardItem *item = standardModel->invisibleRootItem(); + // adding a row to the invisible root item produces a root element + item->appendRow(preparedColumn); + + QList secondRow =prepareColumn("111", "222", "333"); + // adding a row to an item starts a subtree + preparedColumn.first()->appendRow(secondRow); + + treeView->setModel( standardModel ); + treeView->expandAll(); +} + +//--------------------------------------------------------------------------- +QList ModelView::prepareColumn(const QString &first, + const QString &second, + const QString &third ) +{ + QList colItems; + colItems << new QStandardItem(first); + colItems << new QStandardItem(second); + colItems << new QStandardItem(third); + return colItems; +} diff --git a/examples/tutorials/modelview/6_treeview/modelview.h b/examples/tutorials/modelview/6_treeview/modelview.h new file mode 100755 index 0000000..1ab23ea --- /dev/null +++ b/examples/tutorials/modelview/6_treeview/modelview.h @@ -0,0 +1,24 @@ +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTreeView; //forward declaration +class QStandardItemModel; +class QStandardItem; + + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTreeView *treeView; + QStandardItemModel *standardModel; + QList prepareColumn(const QString &first, + const QString &second, + const QString &third ); +public: + ModelView(QWidget *parent = 0); +}; + +#endif // MODELVIEW_H diff --git a/examples/tutorials/modelview/7_selections/7_selections.pro b/examples/tutorials/modelview/7_selections/7_selections.pro new file mode 100755 index 0000000..952641c6 --- /dev/null +++ b/examples/tutorials/modelview/7_selections/7_selections.pro @@ -0,0 +1,5 @@ +TARGET = mv_selections +TEMPLATE = app +SOURCES += main.cpp \ + modelview.cpp +HEADERS += modelview.h diff --git a/examples/tutorials/modelview/7_selections/main.cpp b/examples/tutorials/modelview/7_selections/main.cpp new file mode 100755 index 0000000..998503c --- /dev/null +++ b/examples/tutorials/modelview/7_selections/main.cpp @@ -0,0 +1,10 @@ +#include +#include "modelview.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ModelView w; + w.show(); + return a.exec(); +} diff --git a/examples/tutorials/modelview/7_selections/modelview.cpp b/examples/tutorials/modelview/7_selections/modelview.cpp new file mode 100755 index 0000000..49c5bb8 --- /dev/null +++ b/examples/tutorials/modelview/7_selections/modelview.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include "modelview.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + treeView = new QTreeView(this); + setCentralWidget(treeView); + standardModel = new QStandardItemModel ; + QStandardItem *rootNode = standardModel->invisibleRootItem(); + + + //defining a couple of items + QStandardItem *americaItem = new QStandardItem("America"); + QStandardItem *mexicoItem = new QStandardItem("Canada"); + QStandardItem *usaItem = new QStandardItem("USA"); + QStandardItem *bostonItem = new QStandardItem("Boston"); + QStandardItem *europeItem = new QStandardItem("Europe"); + QStandardItem *italyItem = new QStandardItem("Italy"); + QStandardItem *romeItem = new QStandardItem("Rome"); + QStandardItem *veronaItem = new QStandardItem("Verona"); + + //building up the hierarchy + rootNode-> appendRow(americaItem); + rootNode-> appendRow(europeItem); + americaItem-> appendRow(mexicoItem); + americaItem-> appendRow(usaItem); + usaItem-> appendRow(bostonItem); + europeItem-> appendRow(italyItem); + italyItem-> appendRow(romeItem); + italyItem-> appendRow(veronaItem); + + //register the model + treeView->setModel( standardModel ); + treeView->expandAll(); + + //selection changes shall trigger a slot + QItemSelectionModel *selectionModel= treeView->selectionModel(); + connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), + this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & ))); +} + +//------------------------------------------------------------------------------------ +void ModelView::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/) +{ + const QModelIndex index = treeView->selectionModel()->currentIndex(); + QString selectedText = index.data(Qt::DisplayRole).toString(); + int hierarchyLevel=1; + QModelIndex seekRoot = index; + while(seekRoot.parent() != QModelIndex() ) + { + seekRoot = seekRoot.parent(); + hierarchyLevel++; + } + QString showString = QString("%1, Level %2").arg(selectedText) + .arg(hierarchyLevel); + setWindowTitle(showString); +} + + + diff --git a/examples/tutorials/modelview/7_selections/modelview.h b/examples/tutorials/modelview/7_selections/modelview.h new file mode 100755 index 0000000..0e638a9 --- /dev/null +++ b/examples/tutorials/modelview/7_selections/modelview.h @@ -0,0 +1,23 @@ +#ifndef MODELVIEW_H +#define MODELVIEW_H + +#include + +class QTreeView; //forward declaration +class QStandardItemModel; +class QItemSelection; + + +class ModelView : public QMainWindow +{ + Q_OBJECT +private: + QTreeView *treeView; + QStandardItemModel *standardModel; +private slots: + void selectionChangedSlot(const QItemSelection & newSelection, const QItemSelection & oldSelection); +public: + ModelView(QWidget *parent = 0); +}; + +#endif // MODELVIEW_H diff --git a/examples/tutorials/modelview/qmake.pro b/examples/tutorials/modelview/qmake.pro new file mode 100755 index 0000000..7f684ba --- /dev/null +++ b/examples/tutorials/modelview/qmake.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs + +SUBDIRS = 1_readonly \ + 2_formatting \ + 3_changingmodel \ + 4_headers \ + 5_edit \ + 6_treeview \ + 7_selections + -- cgit v0.12 From cdc354e3e777b6de28710c05b83567fa3ad63658 Mon Sep 17 00:00:00 2001 From: Michael D Scull Date: Tue, 22 Jun 2010 11:56:24 +0200 Subject: new version of modelview.qdoc with snippets --- doc/src/frameworks-technologies/modelview.qdoc | 168 +++++-------------------- 1 file changed, 29 insertions(+), 139 deletions(-) diff --git a/doc/src/frameworks-technologies/modelview.qdoc b/doc/src/frameworks-technologies/modelview.qdoc index 7729cd2..5f9969b 100755 --- a/doc/src/frameworks-technologies/modelview.qdoc +++ b/doc/src/frameworks-technologies/modelview.qdoc @@ -69,59 +69,16 @@ Below are 7 very simple and independent applications that show different sides o We start with an application that uses a \l QTableView to show data. We will add editing capabilities later. -------------------------------------------------------------main.cpp--------------------- -\code -#include -#include "modelview.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - ModelView w; - w.show(); - return a.exec(); -} -\endcode + \snippet examples/tutorials/modelview/1_readonly/main.cpp We have the usual main() function; -------------------------------------------------------------modelview.h--------------------- -\code -#ifndef MODELVIEW_H -#define MODELVIEW_H - -#include - -class QTableView; //forward declaration - -class ModelView : public QMainWindow -{ - Q_OBJECT -private: - QTableView *tableView; -public: - ModelView(QWidget *parent = 0); - -}; - -#endif // MODELVIEW_H -\endcode + \snippet examples/tutorials/modelview/1_readonly/modelview.h The application is a \l QMainWindow that holds a \l QTableView. -------------------------------------------------------------modelview.cpp--------------------- -\code -#include -#include "modelview.h" -#include "mymodel.h" - -ModelView::ModelView(QWidget *parent) - : QMainWindow(parent) -{ - tableView = new QTableView(this); - setCentralWidget(tableView); - tableView->setModel(new MyModel(this) ); -} - -\endcode + \snippet examples/tutorials/modelview/1_readonly/modelview.cpp Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView::}{tableView()} OR \l QTableView::tableView() OR \l QTableView::tableView . \l {QTableView::}{tableView} will invoke the methods of the pointer it has received to find out two things: \list @@ -133,32 +90,13 @@ The model needs some code to respond to this. We have a table data set, so let's start with QAbstractTableModel since it is easier to use. -------------------------------------------------------------mymodel.h--------------------- -\code -#ifndef MYMODEL_H -#define MYMODEL_H - -#include - -class MyModel : public QAbstractTableModel -{ - Q_OBJECT -public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const ; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; -}; - -#endif // MYMODEL_H -\endcode + \snippet examples/tutorials/modelview/1_readonly/mymodel.h QAbstractTableModel requires the implementation of three abstract methods. -------------------------------------------------------------mymodel.cpp--------------------- -\code -HIER FEHLT mymodel.cpp !!! -\endcode + \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp The number of rows and columns is set by \c MyModel::rowCount() and \c MyModel::columnCount(). When the view has to know what the cell 's text is, it calls the \l{QAbstractItemModel::data()}{data()} method. Row and column information is specified with parameter \c index and the role is set to Qt::Display Role. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. @@ -173,9 +111,8 @@ In addition to controlling what text the view displays, the model also controls In fact, nothing except for the \l{QAbstractItemModel::data()}{data()} method needs to be changed to set fonts, background colour, alignment and a checkbox. Here is the \l{QAbstractItemModel::data()}{data()} method that produces the result shown above: -\code -HIER FEHLT WAS !!! -\endcode +-------------------------------------------------------------mymodel.cpp--------------------- + \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp Each formatting property will be requested from the model with a separate call to the \l{QAbstractItemModel::data()}{data()} method. The \c role parameter is used to let the model know which property is being requested: @@ -216,6 +153,8 @@ Now we need to determine how using a seperated model impacts the application's p \image clock.png We still have a read only table, but this time the content changes every second because we are showing the current time. + +!!!!!I CAN'T FIND THIS FILE!!!!! \code QVariant MyModel::data(const QModelIndex &index, int role ) const { @@ -236,6 +175,8 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const \endcode Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal. + +?????(include section from 3_changingmodel/mymodel.cpp)????? \code MyModel::MyModel(QObject *parent) :QAbstractTableModel(parent) @@ -249,6 +190,8 @@ MyModel::MyModel(QObject *parent) \endcode Here is the corresponding slot: + +?????(include section from 3_changingmodel/mymodel.cpp)????? \code void MyModel::timerHit() @@ -269,6 +212,9 @@ Headers can be hidden via a view method. The header content, however , is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: + + +?????(include section from 4_headers/mymodel.cpp)????? \code QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const { @@ -295,34 +241,12 @@ QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) In this example, we are going to build an application that automatically populates a window title with content by repeating values entered into table cells. The model decides whether editing capabilities are available . We only have to modify the model in order for the available editing capabilities to be enabled. This is done by reimplementing the following virtual methods: \l{QAbstractItemModel::setData()}{setData()} and \l{QAbstractItemModel::flags()}{flags()}. -\code -#ifndef MYMODEL_H -#define MYMODEL_H - -#include -#include - -class MyModel : public QAbstractTableModel -{ - Q_OBJECT -public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const ; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); - Qt::ItemFlags flags ( const QModelIndex & index ) const ; -private: - QStringList m_gridData; //holds text entered into QTableView - int modelIndexToOffset(const QModelIndex & index) const; -signals: - void editCompleted(const QString &); -}; - -#endif // MYMODEL_H -\endcode +-------------------------------------------------------------mymodel.h--------------------- + \snippet examples/tutorials/modelview/5_edit/mymodel.h We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title. + +?????(include section from 5_edit/mymodel.cpp)????? \code #include "mymodel.h" @@ -338,11 +262,13 @@ MyModel::MyModel(QObject *parent) \endcode In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table) +?????(include section from 5_edit/mymodel.cpp)????? \code HIER FEHLT WAS!!! \endcode \l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole. +?????(include section from 5_edit/mymodel.cpp)????? \code HIER FEHLT WAS!!! \endcode @@ -363,49 +289,8 @@ This is how our example model looks so far: We want to, however, present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with QStandardItems, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png -\code -#include -#include -#include -#include "modelview.h" - - -const int ROWS = 2; -const int COLUMNS = 3; - -ModelView::ModelView(QWidget *parent) - : QMainWindow(parent) -{ - treeView = new QTreeView(this); - setCentralWidget(treeView); - standardModel = new QStandardItemModel ; - - QList preparedColumn =prepareColumn("first", "second", "third"); - QStandardItem *item = standardModel->invisibleRootItem(); - // adding a row to the invisible root item produces a root element - item->appendRow(preparedColumn); - - QList secondRow =prepareColumn("111", "222", "333"); - // adding a row to an item starts a subtree - preparedColumn.first()->appendRow(secondRow); - - treeView->setModel( standardModel ); - treeView->expandAll(); -} - -//--------------------------------------------------------------------------- -QList ModelView::prepareColumn(const QString &first, - const QString &second, - const QString &third ) -{ - QList colItems; - colItems << new QStandardItem(first); - colItems << new QStandardItem(second); - colItems << new QStandardItem(third); - return colItems; -} - -\endcode +-------------------------------------------------------------modelview.cpp--------------------- + \snippet examples/tutorials/modelview/6_treeview/modelview.cpp We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other QStandardItems. Nodes are collapsed and expanded within the view. @@ -415,6 +300,7 @@ We want to access a selected item's content in order to output it into the windo So let's create a couple of items: +?????(include section from 7_selections/modelview.cpp)????? \code #include #include @@ -462,6 +348,8 @@ ModelView::ModelView(QWidget *parent) \endcode Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal. + +?????(include section from 7_selections/modelview.cpp)????? \code HIER FEHLT WAS!!! \endcode @@ -503,6 +391,8 @@ QDirModel (deprecated) In all examples so far, data is presented as text or a checkbox in a cell and is edited as text or a checkbox. The component that provides these presentation and editing services is called a “delegate.” We are only just beginning to work with the delegate because the view uses a default delegate. But imagine that we want to have a different editor.(e.g. a slider or a drop down list) Or imagine that we want to present data as graphics. Let's take a look at an example called Stardelegate, ( \l{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html}{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html} ) in which stars are used to show a rating: \image stardelegate.png The view has a method that replaces the default delegate and installs a custom delegate. This method is called \l{QAbstractItemModel::setItemDelegate()}{setItemDelegate()}. A new delegate can be written by creating a class that inherits from QStyledItemDelegate. In order to write a delegate that displays stars and has no input capabilities, we only need to overwrite 2 methods. + +!!!!!I CAN'T FIND THIS FILE!!!!! \code class StarDelegate : public QStyledItemDelegate { -- cgit v0.12 From 6de484f195366b560e10f95b04d2f0e7303a2b63 Mon Sep 17 00:00:00 2001 From: Roland Wolf Date: Tue, 22 Jun 2010 14:26:05 +0200 Subject: integrating modelview tutorial in the build system, first attempt --- doc/src/frameworks-technologies/modelview.qdoc | 730 ------------------------ doc/src/tutorials/modelview.qdoc | 732 +++++++++++++++++++++++++ examples/tutorials/modelview/modelview.pro | 10 + examples/tutorials/modelview/qmake.pro | 10 - examples/tutorials/tutorials.pro | 4 +- 5 files changed, 745 insertions(+), 741 deletions(-) delete mode 100755 doc/src/frameworks-technologies/modelview.qdoc create mode 100755 doc/src/tutorials/modelview.qdoc create mode 100755 examples/tutorials/modelview/modelview.pro delete mode 100755 examples/tutorials/modelview/qmake.pro diff --git a/doc/src/frameworks-technologies/modelview.qdoc b/doc/src/frameworks-technologies/modelview.qdoc deleted file mode 100755 index 5f9969b..0000000 --- a/doc/src/frameworks-technologies/modelview.qdoc +++ /dev/null @@ -1,730 +0,0 @@ -/*! - - \contentspage{modelview.html}{Crash Course in Model/View Programming} - \page modelview.html - -\title Crash Course in Model/View Programming -Contents: -\tableofcontents - -\section1 1 Introduction -Model/View is a technology used to separate data from views in widgets that handle data sets. Standard Widgets are not designed for separating data from views and this is why Qt 4 has two different types of widgets. Both types of widgets look the same, but they interact with data differently. - \table - \row - \o Standard widgets use data that is part of the widget. - \o \image standardwidget.png - \row - \o View classes operate on external data (the model) - \o \image modelview.png - \endtable -\section2 1.1 Standard widgets -Let's have a closer look at a standard table widget. A table widget is a 2D array of the data elements that the user can change. The table widget can be integrated into a program flow by reading and writing the data elements that the table widget provides. This method is very intuitive and useful in many applications. - -Displaying and editing a database table with a standard table widget can be problematic. Two copies of the data have to be coordinated: one outside the widget; one inside the widget. The developer needs to know where up-to-date data is so the both copies contain the most recent data. The tight coupling of presentation and data makes it harder to write unit tests. - -\section2 1.2 Model/View to the rescue -Model/View stepped up to provide a solution that uses a more versatile architecture. Model/View eliminates the data consistency problems that may occur with standard widgets. Model/View also makes it easier to use more than one view of the same data because one model can be passed on to many views. The most important difference is that model/view widgets do not store data behind the table cells. In fact, they operate directly from your data. Since view classes do not know your data's structure, you need to provide a wrapper to make your data conform to the \l QAbstractItemModel interface. A view uses this interface to read from and write to your data and any class that implements \l QAbstractItemModel is a model. Once the view receives a pointer to a model, it will read and display its content and be its editor. - -\section2 1.3 Overview of the model/view widgets -Here is an overview of the model/view widgets and their corresponding standard widgets. - \table - \header - \o Widget - \o Standard Widget -(a convenience class with data in the widget) - \o Model/View View Class (for use with external data) - \row - \o \image listview.png - \o \l QListWidget - \o \l QListView - \row - \o \image tableview.png - \o \l QTableWidget - \o \l QTableView - \row - \o \image treeview.png - \o \l QTreeWidget - \o \l QTreeView - \row - \o \image columnview.png - \o - \o \l QColumnView shows a tree as a hierarchy of lists - \row - \o \image combobox.png - \o {2, 1} \l QComboBox can work as both a view class and also as a traditional widget - \endtable -\section2 1.4 Having adapters between forms and models can come in handy. -We often prefer editing data stored in tables (e.g. in database tables) in forms rather than in tables. There is no direct model/view counterpart for separating data and views for widgets that operate on one value instead of a dataset, so we need an adapter in order to connect the form to the source of data. - -\l QDataWidgetMapper is a great solution because it maps form widgets to a table row and it makes it very easy to build forms for database tables. \image widgetmapper.png - -Another example of an adapter is \l QCompleter. Qt has QCompleter for providing auto completions in Qt widgets such as \l QComboBox and, as shown below, \l QLineEdit. \l QCompleter uses a model as its data source, so \l QCompleter, in itself, is a very handy adapter. \image qcompleter.png - -\section1 2 A Simple Model/View Application -If you want to develop a model/view application, where should you start? We recommend starting with a simple example and extending it step-by-step. This makes understanding the architecture a lot easier. Trying to understand the model/view architecture in detail before invoking the IDE has proven to be less convenient for many developers. It is substantially easier to start with a simple model/view application that has demo data. Give it a try! Simply replace the data in the examples below with your own. - -Below are 7 very simple and independent applications that show different sides of model/view programming. The source code can be downloaded from @todo___________paste link here_________________________ - -\section2 2.1 A read only table -We start with an application that uses a \l QTableView to show data. We will add editing capabilities later. - --------------------------------------------------------------main.cpp--------------------- - \snippet examples/tutorials/modelview/1_readonly/main.cpp - -We have the usual main() function; --------------------------------------------------------------modelview.h--------------------- - \snippet examples/tutorials/modelview/1_readonly/modelview.h - -The application is a \l QMainWindow that holds a \l QTableView. - --------------------------------------------------------------modelview.cpp--------------------- - \snippet examples/tutorials/modelview/1_readonly/modelview.cpp - -Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView::}{tableView()} OR \l QTableView::tableView() OR \l QTableView::tableView . \l {QTableView::}{tableView} will invoke the methods of the pointer it has received to find out two things: - \list - \o How many rows and columns should be displayed - \o What content should be printed into each cell. - \endlist - -The model needs some code to respond to this. - -We have a table data set, so let's start with QAbstractTableModel since it is easier to use. --------------------------------------------------------------mymodel.h--------------------- - \snippet examples/tutorials/modelview/1_readonly/mymodel.h - -QAbstractTableModel requires the implementation of three abstract methods. - - --------------------------------------------------------------mymodel.cpp--------------------- - \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp - -The number of rows and columns is set by \c MyModel::rowCount() and \c MyModel::columnCount(). -When the view has to know what the cell 's text is, it calls the \l{QAbstractItemModel::data()}{data()} method. Row and column information is specified with parameter \c index and the role is set to Qt::Display Role. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. - -This small example demonstrates the passive nature of a model. The model does not know when it will be used or which data is needed. It simply provides data each time the view requests it. - -What happens when the model 's data needs to be changed? How does the view know when data changes and needs to be read again? The model has to emit a signal that indicates what range of cells has changed. This will be demonstrated in section 2.3. - -\section2 2.2 Extending the read only example with roles -In addition to controlling what text the view displays, the model also controls the text's appearance. When we slightly change the model, we get the following result: \image readonlytable_role.png - - -In fact, nothing except for the \l{QAbstractItemModel::data()}{data()} method needs to be changed to set fonts, background colour, alignment and a checkbox. Here is the \l{QAbstractItemModel::data()}{data()} method that produces the result shown above: - --------------------------------------------------------------mymodel.cpp--------------------- - \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp - -Each formatting property will be requested from the model with a separate call to the \l{QAbstractItemModel::data()}{data()} method. The \c role parameter is used to let the model know which property is being requested: - - \table - \header - \o Role (enum Qt::ItemDataRole ) - \o Meaning - \o Type - \row - \o Qt::DisplayRole - \o text - \o QString - \row - \o Qt::FontRole - \o font - \o QFont - \row - \o Qt::BackgroundRole - \o brush for the background of the cell - \o QBrush - \row - \o Qt::TextAlignmentRole - \o text alignment - \o enum Qt::AlignmentFlag - \row - \o {1, 3} Qt::CheckStateRole - \o {1, 3} suppresses checkboxes with QVariant(), sets checkboxes with Qt::Checked or Qt::Unchecked - \o {1, 3} enum Qt::ItemDataRole - - \endtable - -Refer to Qt documentation to learn more about enum Qt::ItemDataRole's capabilities. - - -Now we need to determine how using a seperated model impacts the application's performance, so let's trace how often the view calls the \l{QAbstractItemModel::data()}{data()} method. In order to track how often the view calls the model, we have put a debug statement in the \l{QAbstractItemModel::data()}{data()} method, which logs onto stdio. In our small example, \l{QAbstractItemModel::data()}{data()} will be called 42 times. Each time you hover the cursor over the field, \l{QAbstractItemModel::data()}{data()} will be called again - 7 times for each cell. That's why it is important to make sure that your data is available when \l{QAbstractItemModel::data()}{data()}) is invoked and expensive lookup operations are cached. - -\section2 2.3 A clock inside a table cell -\image clock.png - -We still have a read only table, but this time the content changes every second because we are showing the current time. - -!!!!!I CAN'T FIND THIS FILE!!!!! -\code -QVariant MyModel::data(const QModelIndex &index, int role ) const -{ - QVariant returnVal; - int row = index.row(); - int col = index.column(); - - if(role == Qt::DisplayRole) - - { - if(row == 0 && col == 0 ) - { - returnVal = QTime::currentTime().toString(); - } - } - return returnVal; -} -\endcode - -Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal. - -?????(include section from 3_changingmodel/mymodel.cpp)????? -\code -MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) -{ -// selectedCell = 0; - timer = new QTimer(this); - timer->setInterval(1000); - connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) ); - timer->start(); -} -\endcode - -Here is the corresponding slot: - -?????(include section from 3_changingmodel/mymodel.cpp)????? -\code - -void MyModel::timerHit() -{ - //we identify the top left cell - QModelIndex topLeft = createIndex ( 0,0 ); - //emit a signal to make the view reread identified data - emit dataChanged ( topLeft, topLeft ); -} -\endcode - -We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QAbstractItemModel::setModel()}{setModel()} . - -\section2 2.4 Setting up Headers for Columns and Rows -Headers can be hidden via a view method. -\c tableView->verticalHeader()->hide(); -\image header.png - - -The header content, however , is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: - - -?????(include section from 4_headers/mymodel.cpp)????? -\code -QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role == Qt::DisplayRole) - { - if (orientation == Qt::Horizontal) { - switch (section) - { - case 0: - return QString("first"); - case 1: - return QString("second"); - case 2: - return QString("third"); - } - } - } - return QVariant(); -} -\endcode - - -\section2 2.5 The minimal Editing example -In this example, we are going to build an application that automatically populates a window title with content by repeating values entered into table cells. - -The model decides whether editing capabilities are available . We only have to modify the model in order for the available editing capabilities to be enabled. This is done by reimplementing the following virtual methods: \l{QAbstractItemModel::setData()}{setData()} and \l{QAbstractItemModel::flags()}{flags()}. --------------------------------------------------------------mymodel.h--------------------- - \snippet examples/tutorials/modelview/5_edit/mymodel.h - -We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title. - -?????(include section from 5_edit/mymodel.cpp)????? -\code -#include "mymodel.h" - -const int COLS= 3; -const int ROWS= 2; - -MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) -{ - //gridData needs to have 6 element, one for each table cell - m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ; -} -\endcode - -In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table) -?????(include section from 5_edit/mymodel.cpp)????? -\code -HIER FEHLT WAS!!! -\endcode - -\l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole. -?????(include section from 5_edit/mymodel.cpp)????? -\code -HIER FEHLT WAS!!! -\endcode - -Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read. - -\section1 3 Intermediate Topics -\section2 3.1 TreeView -You can convert the example above into an application with a tree view. Simply replace QTableView with QTreeView, which results in a read/write tree. No changes have to be made to the model. The tree won't have any hierarchies because there aren't any hierarchies in the model itself. -\image dummy_tree.png - - -QListView, QTableView and QTreeView all use a model abstraction, which is a merged list, table and tree. This makes it possible to use several different types of view classes from the same model. -\image list_table_tree.png - -This is how our example model looks so far: -\image example_model.png - - -We want to, however, present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with QStandardItems, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png --------------------------------------------------------------modelview.cpp--------------------- - \snippet examples/tutorials/modelview/6_treeview/modelview.cpp - -We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other QStandardItems. Nodes are collapsed and expanded within the view. - -\section2 3.2 Working with selection -We want to access a selected item's content in order to output it into the window title together with the hierarchy level. -\image selection2.png - - -So let's create a couple of items: -?????(include section from 7_selections/modelview.cpp)????? -\code -#include -#include -#include -#include "modelview.h" - -ModelView::ModelView(QWidget *parent) - : QMainWindow(parent) -{ - treeView = new QTreeView(this); - setCentralWidget(treeView); - standardModel = new QStandardItemModel ; - QStandardItem *rootNode = standardModel->invisibleRootItem(); - - - //defining a couple of items - QStandardItem *americaItem = new QStandardItem("America"); - QStandardItem *mexicoItem = new QStandardItem("Canada"); - QStandardItem *usaItem = new QStandardItem("USA"); - QStandardItem *bostonItem = new QStandardItem("Boston"); - QStandardItem *europeItem = new QStandardItem("Europe"); - QStandardItem *italyItem = new QStandardItem("Italy"); - QStandardItem *romeItem = new QStandardItem("Rome"); - QStandardItem *veronaItem = new QStandardItem("Verona"); - - //building up the hierarchy - rootNode-> appendRow(americaItem); - rootNode-> appendRow(europeItem); - americaItem-> appendRow(mexicoItem); - americaItem-> appendRow(usaItem); - usaItem-> appendRow(bostonItem); - europeItem-> appendRow(italyItem); - italyItem-> appendRow(romeItem); - italyItem-> appendRow(veronaItem); - - //register the model - treeView->setModel( standardModel ); - treeView->expandAll(); - - //selection changes shall trigger a slot - QItemSelectionModel *selectionModel= treeView->selectionModel(); - connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), - this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & ))); -} -\endcode - -Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal. - -?????(include section from 7_selections/modelview.cpp)????? -\code -HIER FEHLT WAS!!! -\endcode - -We get the model index that corresponds to the selection by calling -\c treeView->selectionModel()->currentIndex() and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed QModelIndex(). This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. - -The selection model (as shown above) can be retrieved, but it can also be set with \c QAbstractItemView::setSelectionModel. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemModel::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemModel::setSelectionModel()}{setSelectionModel()}; -\section2 3.3 Predefined Models -The typical way to use model/view is to wrap specific data to make it usable with view classes. Qt, however, also provides predefined models for common underlying data structures. If one of the available data structures is suitable for your application, a predefined model can be a good choice. - - \table - \row - \o QStringListModel - \o Stores a list of strings - \row - \o QStandardItemModel - \o Stores arbitrary hierarchical items - \row - \o {1, 2} QFileSystemModel -QDirModel (deprecated) - \o {1, 2} Encapsulate the local file system - \row - \o QSqlQueryModel - \o Encapsulate an SQL result set - \row - \o QSqlTableModel - \o Encapsulates an SQL table - \row - \o QSqlRelationalTableModel - \o Encapsulates an SQL table with foreign keys - \row - \o QSortFilterProxyModel - \o Sorts and/or filters another model - - \endtable - -\section2 3.4 Delegates -In all examples so far, data is presented as text or a checkbox in a cell and is edited as text or a checkbox. The component that provides these presentation and editing services is called a “delegate.” We are only just beginning to work with the delegate because the view uses a default delegate. But imagine that we want to have a different editor.(e.g. a slider or a drop down list) Or imagine that we want to present data as graphics. Let's take a look at an example called Stardelegate, ( \l{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html}{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html} ) in which stars are used to show a rating: \image stardelegate.png - -The view has a method that replaces the default delegate and installs a custom delegate. This method is called \l{QAbstractItemModel::setItemDelegate()}{setItemDelegate()}. A new delegate can be written by creating a class that inherits from QStyledItemDelegate. In order to write a delegate that displays stars and has no input capabilities, we only need to overwrite 2 methods. - -!!!!!I CAN'T FIND THIS FILE!!!!! -\code - class StarDelegate : public QStyledItemDelegate - { - Q_OBJECT - public: - StarDelegate(QWidget *parent = 0); - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const; - }; - -\endcode - -\l{QAbstractItemModel::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \c index.data(). \c SizeHint specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. - -Writing custom delegates is the right choice if you want to show your data with a custom graphical representation inside the grid of the view class. If you want to leave the grid, you can write a custom view class. - -\section2 3.5 Debugging with ModelTest -The passive nature of models provides new challenges for programmers. Inconsistencies in the model can cause the application to crash. Since the model is hit by numerous calls from the view, it is hard to find out which call has crashed the application and which operation has introduced the problem. - -Qt provides software called ModelTest, which checks models while your programming is running. Every time the model is changed, ModelTest scans the model and reports errors with an assert. This is especially important for tree models, since their hierarchical nature leaves many possibilities for subtle inconsistencies. http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest - -Unlike view classes, ModelTest uses out of range indexes to test the model. This means your application may crash with ModelTest even if it runs perfectly without it. So you also need to handle all of the indexes that are out of range when using ModelTest. - - - - - - - - - -\section2 3.6 Model/View NG - -\image path.png - -Model/View was introduced in Qt 4.0 and is a frequently used technology. Feedback from clients and new development trends have shown, that there is a need to further develop the model/view technology. Therefore a research project at Nokia is looking into ways to go beyond the current implementation. - -One limitation of model/view is that view classes are basically all fixed grids. It is possible, but really hard to make a list view with icons placed on a curve; or cells expanding on mouse over events to show additional information. In order to achieve graphically rich view experiences, Model/View NG will use QGraphicsView to render elements. Nodel/View NG also aims to make model/view programming more intuitive. One way to achieve this is to have separate models for lists, tables and trees. The current model abstraction is complex because it is capable of representing a list, a table or a tree. - -Model/View NG is a research project. You are welcome to checkout the source code, monitor progress and take part in discussions at the following address: \l{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG}{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG} - -\section1 4 Good Sources for Additional Information -\section2 4.1 Books -Model/View programming is covered quite extensively in the documentation of Qt but also in several good books. - \list 1 - \o 1.C++ GUI Programming with Qt 4 / Jasmin Blanchette, Mark Summerfield, Prentice Hall, 2nd edition, ISBN 0-13-235416-0 -also available in German: C++ GUI Programmierung mit Qt 4: Die offizielle Einführung, Addison-Wesley, ISBN 3-827327-29-6 - \o 1.The Book of Qt4, The Art of Building Qt Applications / Daniel Molkentin, Open Source Press ISBN 1-59327-147-6 -Translated from: Qt 4, Einführung in die Applikationsentwicklung, Open Source Press, ISBN 3-937514-12-0 - \o 1.Foundations of Qt Development / Johan Thelin, Apress, ISBN 1-59059-831-8 - \endlist - - -The following list provides an overview of example programs contained in the books above. Some of them make very good templates for developing similar applications. - - \table - \header - \o example name - \o view class used - \o model used - \o aspects touched - \o - \row - \o Team Leaders - \o QListview - \o QStringListModel - \o - \o Book 1, Chapter 10, Figure 10.6 - \row - \o Directory Viewer - \o QTreeView - \o QDirModel - \o - \o Book 1, Chapter 10, Figure 10.7 - \row - \o Color Names - \o QListView - \o QSortFilterProxyModel -applied to QStringListModel - \o - \o Book 1, Chapter 10, Figure 10.8 - \row - \o Currencies - \o QTableView - \o custom model based on -QAbstractTableModel - \o read only - \o Book 1, Chapter 10, Figure 10.10 - \row - \o Cities - \o QTableView - \o custom model based on -QAbstractTableModel - \o read / write - \o Book 1, Chapter 10, Figure 10.12 - \row - \o Boolean Parser - \o QTreeView - \o custom model based on -QAbstractItemModel - \o read only - \o Book 1, Chapter 10, Figure 10.14 - \row - \o Track Editor - \o {2, 1} QTableWidget - \o custom delegate providing a custom editor - \o Book 1, Chapter 10, Figure 10.15 - - \row - \o Four directory views - \o QListView -QTableView -QTreeView - \o QDirModel - \o demonstrates the use of multiple views - \o Book2, Chapter 8.2 - \row - \o Address Book - \o QListView -QTableView -QTreeView - \o custom model based on -QAbstractTableModel - \o read / write - \o Book2, Chapter 8.4 - \row - \o Address Book with sorting - \o - \o QProxyModel - \o introducing sort and filter capabilities - \o Book2, Chapter 8.5 - \row - \o Address Book -with checkboxes - \o - \o - \o introducing checkboxes -in model/view - \o Book2, Chapter 8.6 - \row - \o Address Book -with transposed grid - \o - \o custom proxy Model based on QAbstractProxyModel - \o introducing a custom model - \o Book2, Chapter 8.7 - \row - \o Address Book -with drag and drop - \o - \o - \o introducing drag and drop support - \o Book2, Chapter 8.8 - \row - \o Address Book with custom editor - \o - \o - \o introducing custom delegates - \o Book2, Chapter 8.9 - \row - \o Views - \o QListView -QTableView -QTreeView - \o QStandardItemModel - \o read only - \o Book 3, Chapter 5, figure 5-3 - \row - \o Bardelegate - \o QTableView - \o - \o custom delegate for presentation based on QAbstractItemDelegate - \o Book 3, Chapter 5, figure 5-5 - \row - \o Editdelegate - \o QTableView - \o - \o custom delegate for editing based on QAbstractItemDelegate - \o Book 3, Chapter 5, figure 5-6 - \row - \o Singleitemview - \o custom view based on -QAbstractItemView - \o - \o custom view - \o Book 3, -Chapter 5, -figure 5-7 - \row - \o listmodel - \o QTableView - \o custom Model based on -QAbstractTableModel - \o read only - \o Book 3, -Chapter 5, -Figure 5-8 - \row - \o treemodel - \o QTreeView - \o custom Model based on -QAbstractItemModel - \o read only - \o Book 3, -Chapter 5, -Figure 5-10 - \row - \o edit integers - \o QListView - \o custom Model based on -QAbstractListModel - \o read / write - \o Book 3, -Chapter 5, -Listing 5-37, Figure 5-11 - \row - \o sorting - \o QTableView - \o QSortFilterProxyModel -applied to QStringListModel - \o demonstrates sorting - \o Book 3, Chapter 5, Figure 5-12 - - \endtable - - -\section2 4.2 Qt documentation -Qt 4.6 comes with 17 examples and 2 Demonstrations for model/view. The examples can be found here: \l{http://doc.qt.nokia.com/4.6/examples-itemviews.html}{http://doc.qt.nokia.com/4.6/examples-itemviews.html} - \table - \header - \o example name - \o view class used - \o model used - \o aspects touched - \row - \o Address Book - \o QTableView - \o QTableModel -QSortFilterProxyModel - \o usage of QSortFilterProxyModel to generate different subsets from one data pool - \row - \o Basic Sort/Filter Model - \o QTreeView - \o QStandardItemModel -QSortFilterProxyModel - \o - \row - \o Chart - \o custom view - \o QStandardItemModel - \o designing custom views that cooperate with selection models - \row - \o Color Editor Factory - \o {2, 1} QTableWidget - \o enhancing the standard delegate with a new custom editor to choose colours - \row - \o Combo Widget Mapper - \o QDataWidgetMapper to map QLineEdit, QTextEdit and QComboBox - \o QStandardItemModel - \o shows how a QComboBox can serve as a view class - \row - \o Custom Sort/Filter Model - \o QTreeView - \o QStandardItemModel -QSortFilterProxyModel - \o subclass QSortFilterProxyModel -for advanced sorting and filtering - \row - \o Dir View - \o QTreeView - \o QDirModel - \o very small example to demonstrate how to assign a model to a view - \row - \o Editable Tree Model - \o QTreeView - \o custom tree model - \o comprehensive example for working with trees, demonstrates editing cells and tree structure with an underlying custom model - \row - \o Fetch More - \o QListView - \o custom list model - \o dynamically changing model - \row - \o Frozen Column - \o QTableView - \o QStandardItemModel - \o - \row - \o Pixelator - \o QTableView - \o custom table model - \o implementation of a custom delegate - \row - \o Puzzle - \o QListView - \o custom list model - \o model/view with drag and drop - \row - \o Simple DOM Model - \o QTreeView - \o custom tree model - \o read only example for a custom tree model - \row - \o Simple Tree Model - \o QTreeView - \o custom tree model - \o read only example for a custom tree model - \row - \o Simple Widget Mapper - \o QDataWidgetMapper to map QLineEdit, QTextEdit and QSpinBox - \o QStandardItemModel - \o basic QDataWidgetMapper usage - \row - \o Spin Box Delegate - \o QTableView - \o QStandardItemModel - \o custom delegate that uses a spin box as a cell editor - \row - \o Star Delegate - \o {2, 1} QTableWidget - \o comprehensive custom delegate example. - \endtable - -Demonstrations are similar to examples except that no walk-through is provided for the code lines. Demonstrations are also sometimes more feature rich. - \l{http://doc.qt.nokia.com/4.6/demos.html}{http://doc.qt.nokia.com/4.6/demos.html} - \list - \o The \bold Interview demonstration shows the same model and selection being shared between three different views. - \o Demonstration \bold Spreadsheet demonstrates the use of a table view as a spreadsheet, using custom delegates to render each item according to the type of data it contains. - \endlist - -A reference documentation for model/view technology is also available. \l{http://doc.qt.nokia.com/4.6/model-view-programming.html}{http://doc.qt.nokia.com/4.6/model-view-programming.html} - -*/ \ No newline at end of file diff --git a/doc/src/tutorials/modelview.qdoc b/doc/src/tutorials/modelview.qdoc new file mode 100755 index 0000000..1be4b46 --- /dev/null +++ b/doc/src/tutorials/modelview.qdoc @@ -0,0 +1,732 @@ +/*! + + \page modelview.html + \startpage {index.html}{Qt Reference Documentation} + \contentspage Tutorials + \contentspage{modelview.html}{Crash Course in Model/View Programming} + +\title Crash Course in Model/View Programming +Contents: +\tableofcontents + +\section1 1 Introduction +Model/View is a technology used to separate data from views in widgets that handle data sets. Standard Widgets are not designed for separating data from views and this is why Qt 4 has two different types of widgets. Both types of widgets look the same, but they interact with data differently. + \table + \row + \o Standard widgets use data that is part of the widget. + \o \image standardwidget.png + \row + \o View classes operate on external data (the model) + \o \image modelview.png + \endtable +\section2 1.1 Standard widgets +Let's have a closer look at a standard table widget. A table widget is a 2D array of the data elements that the user can change. The table widget can be integrated into a program flow by reading and writing the data elements that the table widget provides. This method is very intuitive and useful in many applications. + +Displaying and editing a database table with a standard table widget can be problematic. Two copies of the data have to be coordinated: one outside the widget; one inside the widget. The developer needs to know where up-to-date data is so the both copies contain the most recent data. The tight coupling of presentation and data makes it harder to write unit tests. + +\section2 1.2 Model/View to the rescue +Model/View stepped up to provide a solution that uses a more versatile architecture. Model/View eliminates the data consistency problems that may occur with standard widgets. Model/View also makes it easier to use more than one view of the same data because one model can be passed on to many views. The most important difference is that model/view widgets do not store data behind the table cells. In fact, they operate directly from your data. Since view classes do not know your data's structure, you need to provide a wrapper to make your data conform to the \l QAbstractItemModel interface. A view uses this interface to read from and write to your data and any class that implements \l QAbstractItemModel is a model. Once the view receives a pointer to a model, it will read and display its content and be its editor. + +\section2 1.3 Overview of the model/view widgets +Here is an overview of the model/view widgets and their corresponding standard widgets. + \table + \header + \o Widget + \o Standard Widget +(a convenience class with data in the widget) + \o Model/View View Class (for use with external data) + \row + \o \image listview.png + \o \l QListWidget + \o \l QListView + \row + \o \image tableview.png + \o \l QTableWidget + \o \l QTableView + \row + \o \image treeview.png + \o \l QTreeWidget + \o \l QTreeView + \row + \o \image columnview.png + \o + \o \l QColumnView shows a tree as a hierarchy of lists + \row + \o \image combobox.png + \o {2, 1} \l QComboBox can work as both a view class and also as a traditional widget + \endtable +\section2 1.4 Having adapters between forms and models can come in handy. +We often prefer editing data stored in tables (e.g. in database tables) in forms rather than in tables. There is no direct model/view counterpart for separating data and views for widgets that operate on one value instead of a dataset, so we need an adapter in order to connect the form to the source of data. + +\l QDataWidgetMapper is a great solution because it maps form widgets to a table row and it makes it very easy to build forms for database tables. \image widgetmapper.png + +Another example of an adapter is \l QCompleter. Qt has QCompleter for providing auto completions in Qt widgets such as \l QComboBox and, as shown below, \l QLineEdit. \l QCompleter uses a model as its data source, so \l QCompleter, in itself, is a very handy adapter. \image qcompleter.png + +\section1 2 A Simple Model/View Application +If you want to develop a model/view application, where should you start? We recommend starting with a simple example and extending it step-by-step. This makes understanding the architecture a lot easier. Trying to understand the model/view architecture in detail before invoking the IDE has proven to be less convenient for many developers. It is substantially easier to start with a simple model/view application that has demo data. Give it a try! Simply replace the data in the examples below with your own. + +Below are 7 very simple and independent applications that show different sides of model/view programming. The source code can be downloaded from @todo___________paste link here_________________________ + +\section2 2.1 A read only table +We start with an application that uses a \l QTableView to show data. We will add editing capabilities later. + +-------------------------------------------------------------main.cpp--------------------- + \snippet examples/tutorials/modelview/1_readonly/main.cpp + +We have the usual main() function; +-------------------------------------------------------------modelview.h--------------------- + \snippet examples/tutorials/modelview/1_readonly/modelview.h + +The application is a \l QMainWindow that holds a \l QTableView. + +-------------------------------------------------------------modelview.cpp--------------------- + \snippet examples/tutorials/modelview/1_readonly/modelview.cpp + +Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView::}{tableView()} OR \l QTableView::tableView() OR \l QTableView::tableView . \l {QTableView::}{tableView} will invoke the methods of the pointer it has received to find out two things: + \list + \o How many rows and columns should be displayed + \o What content should be printed into each cell. + \endlist + +The model needs some code to respond to this. + +We have a table data set, so let's start with QAbstractTableModel since it is easier to use. +-------------------------------------------------------------mymodel.h--------------------- + \snippet examples/tutorials/modelview/1_readonly/mymodel.h + +QAbstractTableModel requires the implementation of three abstract methods. + + +-------------------------------------------------------------mymodel.cpp--------------------- + \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp + +The number of rows and columns is set by \c MyModel::rowCount() and \c MyModel::columnCount(). +When the view has to know what the cell 's text is, it calls the \l{QAbstractItemModel::data()}{data()} method. Row and column information is specified with parameter \c index and the role is set to Qt::Display Role. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. + +This small example demonstrates the passive nature of a model. The model does not know when it will be used or which data is needed. It simply provides data each time the view requests it. + +What happens when the model 's data needs to be changed? How does the view know when data changes and needs to be read again? The model has to emit a signal that indicates what range of cells has changed. This will be demonstrated in section 2.3. + +\section2 2.2 Extending the read only example with roles +In addition to controlling what text the view displays, the model also controls the text's appearance. When we slightly change the model, we get the following result: \image readonlytable_role.png + + +In fact, nothing except for the \l{QAbstractItemModel::data()}{data()} method needs to be changed to set fonts, background colour, alignment and a checkbox. Here is the \l{QAbstractItemModel::data()}{data()} method that produces the result shown above: + +-------------------------------------------------------------mymodel.cpp--------------------- + \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp + +Each formatting property will be requested from the model with a separate call to the \l{QAbstractItemModel::data()}{data()} method. The \c role parameter is used to let the model know which property is being requested: + + \table + \header + \o Role (enum Qt::ItemDataRole ) + \o Meaning + \o Type + \row + \o Qt::DisplayRole + \o text + \o QString + \row + \o Qt::FontRole + \o font + \o QFont + \row + \o Qt::BackgroundRole + \o brush for the background of the cell + \o QBrush + \row + \o Qt::TextAlignmentRole + \o text alignment + \o enum Qt::AlignmentFlag + \row + \o {1, 3} Qt::CheckStateRole + \o {1, 3} suppresses checkboxes with QVariant(), sets checkboxes with Qt::Checked or Qt::Unchecked + \o {1, 3} enum Qt::ItemDataRole + + \endtable + +Refer to Qt documentation to learn more about enum Qt::ItemDataRole's capabilities. + + +Now we need to determine how using a seperated model impacts the application's performance, so let's trace how often the view calls the \l{QAbstractItemModel::data()}{data()} method. In order to track how often the view calls the model, we have put a debug statement in the \l{QAbstractItemModel::data()}{data()} method, which logs onto stdio. In our small example, \l{QAbstractItemModel::data()}{data()} will be called 42 times. Each time you hover the cursor over the field, \l{QAbstractItemModel::data()}{data()} will be called again - 7 times for each cell. That's why it is important to make sure that your data is available when \l{QAbstractItemModel::data()}{data()}) is invoked and expensive lookup operations are cached. + +\section2 2.3 A clock inside a table cell +\image clock.png + +We still have a read only table, but this time the content changes every second because we are showing the current time. + +!!!!!I CAN'T FIND THIS FILE!!!!! +\code +QVariant MyModel::data(const QModelIndex &index, int role ) const +{ + QVariant returnVal; + int row = index.row(); + int col = index.column(); + + if(role == Qt::DisplayRole) + + { + if(row == 0 && col == 0 ) + { + returnVal = QTime::currentTime().toString(); + } + } + return returnVal; +} +\endcode + +Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal. + +?????(include section from 3_changingmodel/mymodel.cpp)????? +\code +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ +// selectedCell = 0; + timer = new QTimer(this); + timer->setInterval(1000); + connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) ); + timer->start(); +} +\endcode + +Here is the corresponding slot: + +?????(include section from 3_changingmodel/mymodel.cpp)????? +\code + +void MyModel::timerHit() +{ + //we identify the top left cell + QModelIndex topLeft = createIndex ( 0,0 ); + //emit a signal to make the view reread identified data + emit dataChanged ( topLeft, topLeft ); +} +\endcode + +We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QAbstractItemModel::setModel()}{setModel()} . + +\section2 2.4 Setting up Headers for Columns and Rows +Headers can be hidden via a view method. +\c tableView->verticalHeader()->hide(); +\image header.png + + +The header content, however , is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: + + +?????(include section from 4_headers/mymodel.cpp)????? +\code +QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole) + { + if (orientation == Qt::Horizontal) { + switch (section) + { + case 0: + return QString("first"); + case 1: + return QString("second"); + case 2: + return QString("third"); + } + } + } + return QVariant(); +} +\endcode + + +\section2 2.5 The minimal Editing example +In this example, we are going to build an application that automatically populates a window title with content by repeating values entered into table cells. + +The model decides whether editing capabilities are available . We only have to modify the model in order for the available editing capabilities to be enabled. This is done by reimplementing the following virtual methods: \l{QAbstractItemModel::setData()}{setData()} and \l{QAbstractItemModel::flags()}{flags()}. +-------------------------------------------------------------mymodel.h--------------------- + \snippet examples/tutorials/modelview/5_edit/mymodel.h + +We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title. + +?????(include section from 5_edit/mymodel.cpp)????? +\code +#include "mymodel.h" + +const int COLS= 3; +const int ROWS= 2; + +MyModel::MyModel(QObject *parent) + :QAbstractTableModel(parent) +{ + //gridData needs to have 6 element, one for each table cell + m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ; +} +\endcode + +In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table) +?????(include section from 5_edit/mymodel.cpp)????? +\code +HIER FEHLT WAS!!! +\endcode + +\l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole. +?????(include section from 5_edit/mymodel.cpp)????? +\code +HIER FEHLT WAS!!! +\endcode + +Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read. + +\section1 3 Intermediate Topics +\section2 3.1 TreeView +You can convert the example above into an application with a tree view. Simply replace QTableView with QTreeView, which results in a read/write tree. No changes have to be made to the model. The tree won't have any hierarchies because there aren't any hierarchies in the model itself. +\image dummy_tree.png + + +QListView, QTableView and QTreeView all use a model abstraction, which is a merged list, table and tree. This makes it possible to use several different types of view classes from the same model. +\image list_table_tree.png + +This is how our example model looks so far: +\image example_model.png + + +We want to, however, present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with QStandardItems, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png +-------------------------------------------------------------modelview.cpp--------------------- + \snippet examples/tutorials/modelview/6_treeview/modelview.cpp + +We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other QStandardItems. Nodes are collapsed and expanded within the view. + +\section2 3.2 Working with selection +We want to access a selected item's content in order to output it into the window title together with the hierarchy level. +\image selection2.png + + +So let's create a couple of items: +?????(include section from 7_selections/modelview.cpp)????? +\code +#include +#include +#include +#include "modelview.h" + +ModelView::ModelView(QWidget *parent) + : QMainWindow(parent) +{ + treeView = new QTreeView(this); + setCentralWidget(treeView); + standardModel = new QStandardItemModel ; + QStandardItem *rootNode = standardModel->invisibleRootItem(); + + + //defining a couple of items + QStandardItem *americaItem = new QStandardItem("America"); + QStandardItem *mexicoItem = new QStandardItem("Canada"); + QStandardItem *usaItem = new QStandardItem("USA"); + QStandardItem *bostonItem = new QStandardItem("Boston"); + QStandardItem *europeItem = new QStandardItem("Europe"); + QStandardItem *italyItem = new QStandardItem("Italy"); + QStandardItem *romeItem = new QStandardItem("Rome"); + QStandardItem *veronaItem = new QStandardItem("Verona"); + + //building up the hierarchy + rootNode-> appendRow(americaItem); + rootNode-> appendRow(europeItem); + americaItem-> appendRow(mexicoItem); + americaItem-> appendRow(usaItem); + usaItem-> appendRow(bostonItem); + europeItem-> appendRow(italyItem); + italyItem-> appendRow(romeItem); + italyItem-> appendRow(veronaItem); + + //register the model + treeView->setModel( standardModel ); + treeView->expandAll(); + + //selection changes shall trigger a slot + QItemSelectionModel *selectionModel= treeView->selectionModel(); + connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), + this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & ))); +} +\endcode + +Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal. + +?????(include section from 7_selections/modelview.cpp)????? +\code +HIER FEHLT WAS!!! +\endcode + +We get the model index that corresponds to the selection by calling +\c treeView->selectionModel()->currentIndex() and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed QModelIndex(). This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. + +The selection model (as shown above) can be retrieved, but it can also be set with \c QAbstractItemView::setSelectionModel. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemModel::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemModel::setSelectionModel()}{setSelectionModel()}; +\section2 3.3 Predefined Models +The typical way to use model/view is to wrap specific data to make it usable with view classes. Qt, however, also provides predefined models for common underlying data structures. If one of the available data structures is suitable for your application, a predefined model can be a good choice. + + \table + \row + \o QStringListModel + \o Stores a list of strings + \row + \o QStandardItemModel + \o Stores arbitrary hierarchical items + \row + \o {1, 2} QFileSystemModel +QDirModel (deprecated) + \o {1, 2} Encapsulate the local file system + \row + \o QSqlQueryModel + \o Encapsulate an SQL result set + \row + \o QSqlTableModel + \o Encapsulates an SQL table + \row + \o QSqlRelationalTableModel + \o Encapsulates an SQL table with foreign keys + \row + \o QSortFilterProxyModel + \o Sorts and/or filters another model + + \endtable + +\section2 3.4 Delegates +In all examples so far, data is presented as text or a checkbox in a cell and is edited as text or a checkbox. The component that provides these presentation and editing services is called a “delegate.” We are only just beginning to work with the delegate because the view uses a default delegate. But imagine that we want to have a different editor.(e.g. a slider or a drop down list) Or imagine that we want to present data as graphics. Let's take a look at an example called Stardelegate, ( \l{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html}{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html} ) in which stars are used to show a rating: \image stardelegate.png + +The view has a method that replaces the default delegate and installs a custom delegate. This method is called \l{QAbstractItemModel::setItemDelegate()}{setItemDelegate()}. A new delegate can be written by creating a class that inherits from QStyledItemDelegate. In order to write a delegate that displays stars and has no input capabilities, we only need to overwrite 2 methods. + +!!!!!I CAN'T FIND THIS FILE!!!!! +\code + class StarDelegate : public QStyledItemDelegate + { + Q_OBJECT + public: + StarDelegate(QWidget *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const; + }; + +\endcode + +\l{QAbstractItemModel::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \c index.data(). \c SizeHint specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. + +Writing custom delegates is the right choice if you want to show your data with a custom graphical representation inside the grid of the view class. If you want to leave the grid, you can write a custom view class. + +\section2 3.5 Debugging with ModelTest +The passive nature of models provides new challenges for programmers. Inconsistencies in the model can cause the application to crash. Since the model is hit by numerous calls from the view, it is hard to find out which call has crashed the application and which operation has introduced the problem. + +Qt provides software called ModelTest, which checks models while your programming is running. Every time the model is changed, ModelTest scans the model and reports errors with an assert. This is especially important for tree models, since their hierarchical nature leaves many possibilities for subtle inconsistencies. http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest + +Unlike view classes, ModelTest uses out of range indexes to test the model. This means your application may crash with ModelTest even if it runs perfectly without it. So you also need to handle all of the indexes that are out of range when using ModelTest. + + + + + + + + + +\section2 3.6 Model/View NG + +\image path.png + +Model/View was introduced in Qt 4.0 and is a frequently used technology. Feedback from clients and new development trends have shown, that there is a need to further develop the model/view technology. Therefore a research project at Nokia is looking into ways to go beyond the current implementation. + +One limitation of model/view is that view classes are basically all fixed grids. It is possible, but really hard to make a list view with icons placed on a curve; or cells expanding on mouse over events to show additional information. In order to achieve graphically rich view experiences, Model/View NG will use QGraphicsView to render elements. Nodel/View NG also aims to make model/view programming more intuitive. One way to achieve this is to have separate models for lists, tables and trees. The current model abstraction is complex because it is capable of representing a list, a table or a tree. + +Model/View NG is a research project. You are welcome to checkout the source code, monitor progress and take part in discussions at the following address: \l{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG}{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG} + +\section1 4 Good Sources for Additional Information +\section2 4.1 Books +Model/View programming is covered quite extensively in the documentation of Qt but also in several good books. + \list 1 + \o 1.C++ GUI Programming with Qt 4 / Jasmin Blanchette, Mark Summerfield, Prentice Hall, 2nd edition, ISBN 0-13-235416-0 +also available in German: C++ GUI Programmierung mit Qt 4: Die offizielle Einführung, Addison-Wesley, ISBN 3-827327-29-6 + \o 1.The Book of Qt4, The Art of Building Qt Applications / Daniel Molkentin, Open Source Press ISBN 1-59327-147-6 +Translated from: Qt 4, Einführung in die Applikationsentwicklung, Open Source Press, ISBN 3-937514-12-0 + \o 1.Foundations of Qt Development / Johan Thelin, Apress, ISBN 1-59059-831-8 + \endlist + + +The following list provides an overview of example programs contained in the books above. Some of them make very good templates for developing similar applications. + + \table + \header + \o example name + \o view class used + \o model used + \o aspects touched + \o + \row + \o Team Leaders + \o QListview + \o QStringListModel + \o + \o Book 1, Chapter 10, Figure 10.6 + \row + \o Directory Viewer + \o QTreeView + \o QDirModel + \o + \o Book 1, Chapter 10, Figure 10.7 + \row + \o Color Names + \o QListView + \o QSortFilterProxyModel +applied to QStringListModel + \o + \o Book 1, Chapter 10, Figure 10.8 + \row + \o Currencies + \o QTableView + \o custom model based on +QAbstractTableModel + \o read only + \o Book 1, Chapter 10, Figure 10.10 + \row + \o Cities + \o QTableView + \o custom model based on +QAbstractTableModel + \o read / write + \o Book 1, Chapter 10, Figure 10.12 + \row + \o Boolean Parser + \o QTreeView + \o custom model based on +QAbstractItemModel + \o read only + \o Book 1, Chapter 10, Figure 10.14 + \row + \o Track Editor + \o {2, 1} QTableWidget + \o custom delegate providing a custom editor + \o Book 1, Chapter 10, Figure 10.15 + + \row + \o Four directory views + \o QListView +QTableView +QTreeView + \o QDirModel + \o demonstrates the use of multiple views + \o Book2, Chapter 8.2 + \row + \o Address Book + \o QListView +QTableView +QTreeView + \o custom model based on +QAbstractTableModel + \o read / write + \o Book2, Chapter 8.4 + \row + \o Address Book with sorting + \o + \o QProxyModel + \o introducing sort and filter capabilities + \o Book2, Chapter 8.5 + \row + \o Address Book +with checkboxes + \o + \o + \o introducing checkboxes +in model/view + \o Book2, Chapter 8.6 + \row + \o Address Book +with transposed grid + \o + \o custom proxy Model based on QAbstractProxyModel + \o introducing a custom model + \o Book2, Chapter 8.7 + \row + \o Address Book +with drag and drop + \o + \o + \o introducing drag and drop support + \o Book2, Chapter 8.8 + \row + \o Address Book with custom editor + \o + \o + \o introducing custom delegates + \o Book2, Chapter 8.9 + \row + \o Views + \o QListView +QTableView +QTreeView + \o QStandardItemModel + \o read only + \o Book 3, Chapter 5, figure 5-3 + \row + \o Bardelegate + \o QTableView + \o + \o custom delegate for presentation based on QAbstractItemDelegate + \o Book 3, Chapter 5, figure 5-5 + \row + \o Editdelegate + \o QTableView + \o + \o custom delegate for editing based on QAbstractItemDelegate + \o Book 3, Chapter 5, figure 5-6 + \row + \o Singleitemview + \o custom view based on +QAbstractItemView + \o + \o custom view + \o Book 3, +Chapter 5, +figure 5-7 + \row + \o listmodel + \o QTableView + \o custom Model based on +QAbstractTableModel + \o read only + \o Book 3, +Chapter 5, +Figure 5-8 + \row + \o treemodel + \o QTreeView + \o custom Model based on +QAbstractItemModel + \o read only + \o Book 3, +Chapter 5, +Figure 5-10 + \row + \o edit integers + \o QListView + \o custom Model based on +QAbstractListModel + \o read / write + \o Book 3, +Chapter 5, +Listing 5-37, Figure 5-11 + \row + \o sorting + \o QTableView + \o QSortFilterProxyModel +applied to QStringListModel + \o demonstrates sorting + \o Book 3, Chapter 5, Figure 5-12 + + \endtable + + +\section2 4.2 Qt documentation +Qt 4.6 comes with 17 examples and 2 Demonstrations for model/view. The examples can be found here: \l{http://doc.qt.nokia.com/4.6/examples-itemviews.html}{http://doc.qt.nokia.com/4.6/examples-itemviews.html} + \table + \header + \o example name + \o view class used + \o model used + \o aspects touched + \row + \o Address Book + \o QTableView + \o QTableModel +QSortFilterProxyModel + \o usage of QSortFilterProxyModel to generate different subsets from one data pool + \row + \o Basic Sort/Filter Model + \o QTreeView + \o QStandardItemModel +QSortFilterProxyModel + \o + \row + \o Chart + \o custom view + \o QStandardItemModel + \o designing custom views that cooperate with selection models + \row + \o Color Editor Factory + \o {2, 1} QTableWidget + \o enhancing the standard delegate with a new custom editor to choose colours + \row + \o Combo Widget Mapper + \o QDataWidgetMapper to map QLineEdit, QTextEdit and QComboBox + \o QStandardItemModel + \o shows how a QComboBox can serve as a view class + \row + \o Custom Sort/Filter Model + \o QTreeView + \o QStandardItemModel +QSortFilterProxyModel + \o subclass QSortFilterProxyModel +for advanced sorting and filtering + \row + \o Dir View + \o QTreeView + \o QDirModel + \o very small example to demonstrate how to assign a model to a view + \row + \o Editable Tree Model + \o QTreeView + \o custom tree model + \o comprehensive example for working with trees, demonstrates editing cells and tree structure with an underlying custom model + \row + \o Fetch More + \o QListView + \o custom list model + \o dynamically changing model + \row + \o Frozen Column + \o QTableView + \o QStandardItemModel + \o + \row + \o Pixelator + \o QTableView + \o custom table model + \o implementation of a custom delegate + \row + \o Puzzle + \o QListView + \o custom list model + \o model/view with drag and drop + \row + \o Simple DOM Model + \o QTreeView + \o custom tree model + \o read only example for a custom tree model + \row + \o Simple Tree Model + \o QTreeView + \o custom tree model + \o read only example for a custom tree model + \row + \o Simple Widget Mapper + \o QDataWidgetMapper to map QLineEdit, QTextEdit and QSpinBox + \o QStandardItemModel + \o basic QDataWidgetMapper usage + \row + \o Spin Box Delegate + \o QTableView + \o QStandardItemModel + \o custom delegate that uses a spin box as a cell editor + \row + \o Star Delegate + \o {2, 1} QTableWidget + \o comprehensive custom delegate example. + \endtable + +Demonstrations are similar to examples except that no walk-through is provided for the code lines. Demonstrations are also sometimes more feature rich. + \l{http://doc.qt.nokia.com/4.6/demos.html}{http://doc.qt.nokia.com/4.6/demos.html} + \list + \o The \bold Interview demonstration shows the same model and selection being shared between three different views. + \o Demonstration \bold Spreadsheet demonstrates the use of a table view as a spreadsheet, using custom delegates to render each item according to the type of data it contains. + \endlist + +A reference documentation for model/view technology is also available. \l{http://doc.qt.nokia.com/4.6/model-view-programming.html}{http://doc.qt.nokia.com/4.6/model-view-programming.html} + +*/ \ No newline at end of file diff --git a/examples/tutorials/modelview/modelview.pro b/examples/tutorials/modelview/modelview.pro new file mode 100755 index 0000000..7f684ba --- /dev/null +++ b/examples/tutorials/modelview/modelview.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs + +SUBDIRS = 1_readonly \ + 2_formatting \ + 3_changingmodel \ + 4_headers \ + 5_edit \ + 6_treeview \ + 7_selections + diff --git a/examples/tutorials/modelview/qmake.pro b/examples/tutorials/modelview/qmake.pro deleted file mode 100755 index 7f684ba..0000000 --- a/examples/tutorials/modelview/qmake.pro +++ /dev/null @@ -1,10 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = 1_readonly \ - 2_formatting \ - 3_changingmodel \ - 4_headers \ - 5_edit \ - 6_treeview \ - 7_selections - diff --git a/examples/tutorials/tutorials.pro b/examples/tutorials/tutorials.pro index 949fdf6..34723c2 100644 --- a/examples/tutorials/tutorials.pro +++ b/examples/tutorials/tutorials.pro @@ -1,6 +1,8 @@ TEMPLATE = subdirs SUBDIRS = \ - addressbook + addressbook \ + modelview + # install sources.files = README *.pro -- cgit v0.12 From ca10c2c5a8190cac9c2ae0526f2e250add09d6f2 Mon Sep 17 00:00:00 2001 From: Michael D Scull Date: Wed, 23 Jun 2010 17:19:49 +0200 Subject: correction of snippet tags --- doc/src/tutorials/modelview.qdoc | 41 ++++++--------------- examples/tutorials/modelview/._.DS_Store | Bin 0 -> 4096 bytes examples/tutorials/modelview/1_readonly/main.cpp | 2 + .../tutorials/modelview/1_readonly/modelview.cpp | 3 +- .../tutorials/modelview/1_readonly/modelview.h | 3 ++ .../tutorials/modelview/1_readonly/mymodel.cpp | 2 + examples/tutorials/modelview/1_readonly/mymodel.h | 2 + .../tutorials/modelview/2_formatting/mymodel.cpp | 3 +- .../modelview/3_changingmodel/mymodel.cpp | 7 ++-- examples/tutorials/modelview/4_headers/mymodel.cpp | 3 +- examples/tutorials/modelview/5_edit/mymodel.cpp | 8 +++- examples/tutorials/modelview/5_edit/mymodel.h | 2 + .../tutorials/modelview/6_treeview/modelview.cpp | 2 + .../tutorials/modelview/7_selections/modelview.cpp | 6 ++- examples/tutorials/modelview/qmake.pro | 10 +++++ 15 files changed, 57 insertions(+), 37 deletions(-) create mode 100755 examples/tutorials/modelview/._.DS_Store create mode 100755 examples/tutorials/modelview/qmake.pro diff --git a/doc/src/tutorials/modelview.qdoc b/doc/src/tutorials/modelview.qdoc index 1be4b46..3c73a80 100755 --- a/doc/src/tutorials/modelview.qdoc +++ b/doc/src/tutorials/modelview.qdoc @@ -1,9 +1,7 @@ /*! - \page modelview.html - \startpage {index.html}{Qt Reference Documentation} - \contentspage Tutorials \contentspage{modelview.html}{Crash Course in Model/View Programming} + \page modelview.html \title Crash Course in Model/View Programming Contents: @@ -71,16 +69,16 @@ Below are 7 very simple and independent applications that show different sides o We start with an application that uses a \l QTableView to show data. We will add editing capabilities later. -------------------------------------------------------------main.cpp--------------------- - \snippet examples/tutorials/modelview/1_readonly/main.cpp + \snippet examples/tutorials/modelview/1_readonly/main.cpp Quoting ModelView Tutorial We have the usual main() function; -------------------------------------------------------------modelview.h--------------------- - \snippet examples/tutorials/modelview/1_readonly/modelview.h + \snippet examples/tutorials/modelview/1_readonly/modelview.h Quoting ModelView Tutorial The application is a \l QMainWindow that holds a \l QTableView. -------------------------------------------------------------modelview.cpp--------------------- - \snippet examples/tutorials/modelview/1_readonly/modelview.cpp + \snippet examples/tutorials/modelview/1_readonly/modelview.cpp Quoting ModelView Tutorial Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView::}{tableView()} OR \l QTableView::tableView() OR \l QTableView::tableView . \l {QTableView::}{tableView} will invoke the methods of the pointer it has received to find out two things: \list @@ -92,13 +90,13 @@ The model needs some code to respond to this. We have a table data set, so let's start with QAbstractTableModel since it is easier to use. -------------------------------------------------------------mymodel.h--------------------- - \snippet examples/tutorials/modelview/1_readonly/mymodel.h + \snippet examples/tutorials/modelview/1_readonly/mymodel.h Quoting ModelView Tutorial QAbstractTableModel requires the implementation of three abstract methods. -------------------------------------------------------------mymodel.cpp--------------------- - \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp + \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp Quoting ModelView Tutorial The number of rows and columns is set by \c MyModel::rowCount() and \c MyModel::columnCount(). When the view has to know what the cell 's text is, it calls the \l{QAbstractItemModel::data()}{data()} method. Row and column information is specified with parameter \c index and the role is set to Qt::Display Role. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. @@ -114,7 +112,7 @@ In addition to controlling what text the view displays, the model also controls In fact, nothing except for the \l{QAbstractItemModel::data()}{data()} method needs to be changed to set fonts, background colour, alignment and a checkbox. Here is the \l{QAbstractItemModel::data()}{data()} method that produces the result shown above: -------------------------------------------------------------mymodel.cpp--------------------- - \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp + \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp Quoting ModelView Tutorial Each formatting property will be requested from the model with a separate call to the \l{QAbstractItemModel::data()}{data()} method. The \c role parameter is used to let the model know which property is being requested: @@ -178,7 +176,6 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal. -?????(include section from 3_changingmodel/mymodel.cpp)????? \code MyModel::MyModel(QObject *parent) :QAbstractTableModel(parent) @@ -193,7 +190,6 @@ MyModel::MyModel(QObject *parent) Here is the corresponding slot: -?????(include section from 3_changingmodel/mymodel.cpp)????? \code void MyModel::timerHit() @@ -215,8 +211,6 @@ Headers can be hidden via a view method. The header content, however , is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: - -?????(include section from 4_headers/mymodel.cpp)????? \code QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const { @@ -244,11 +238,10 @@ In this example, we are going to build an application that automatically populat The model decides whether editing capabilities are available . We only have to modify the model in order for the available editing capabilities to be enabled. This is done by reimplementing the following virtual methods: \l{QAbstractItemModel::setData()}{setData()} and \l{QAbstractItemModel::flags()}{flags()}. -------------------------------------------------------------mymodel.h--------------------- - \snippet examples/tutorials/modelview/5_edit/mymodel.h + \snippet examples/tutorials/modelview/5_edit/mymodel.h Quoting ModelView Tutorial We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title. -?????(include section from 5_edit/mymodel.cpp)????? \code #include "mymodel.h" @@ -264,16 +257,10 @@ MyModel::MyModel(QObject *parent) \endcode In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table) -?????(include section from 5_edit/mymodel.cpp)????? -\code -HIER FEHLT WAS!!! -\endcode + \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_e \l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole. -?????(include section from 5_edit/mymodel.cpp)????? -\code -HIER FEHLT WAS!!! -\endcode + \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_f Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read. @@ -292,7 +279,7 @@ This is how our example model looks so far: We want to, however, present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with QStandardItems, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png -------------------------------------------------------------modelview.cpp--------------------- - \snippet examples/tutorials/modelview/6_treeview/modelview.cpp + \snippet examples/tutorials/modelview/6_treeview/modelview.cpp Quoting ModelView Tutorial We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other QStandardItems. Nodes are collapsed and expanded within the view. @@ -302,7 +289,6 @@ We want to access a selected item's content in order to output it into the windo So let's create a couple of items: -?????(include section from 7_selections/modelview.cpp)????? \code #include #include @@ -351,10 +337,7 @@ ModelView::ModelView(QWidget *parent) Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal. -?????(include section from 7_selections/modelview.cpp)????? -\code -HIER FEHLT WAS!!! -\endcode + \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_b We get the model index that corresponds to the selection by calling \c treeView->selectionModel()->currentIndex() and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed QModelIndex(). This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. diff --git a/examples/tutorials/modelview/._.DS_Store b/examples/tutorials/modelview/._.DS_Store new file mode 100755 index 0000000..338bd7b Binary files /dev/null and b/examples/tutorials/modelview/._.DS_Store differ diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp index 998503c..bdf740c 100755 --- a/examples/tutorials/modelview/1_readonly/main.cpp +++ b/examples/tutorials/modelview/1_readonly/main.cpp @@ -1,3 +1,4 @@ +//! [Quoting ModelView Tutorial] #include #include "modelview.h" @@ -8,3 +9,4 @@ int main(int argc, char *argv[]) w.show(); return a.exec(); } +//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/1_readonly/modelview.cpp b/examples/tutorials/modelview/1_readonly/modelview.cpp index becd61d..14311f9 100755 --- a/examples/tutorials/modelview/1_readonly/modelview.cpp +++ b/examples/tutorials/modelview/1_readonly/modelview.cpp @@ -1,3 +1,4 @@ +//! [Quoting ModelView Tutorial] #include #include "modelview.h" #include "mymodel.h" @@ -9,4 +10,4 @@ ModelView::ModelView(QWidget *parent) setCentralWidget(tableView); tableView->setModel(new MyModel(this) ); } - +//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/1_readonly/modelview.h b/examples/tutorials/modelview/1_readonly/modelview.h index f1b63bd..93b6b90 100755 --- a/examples/tutorials/modelview/1_readonly/modelview.h +++ b/examples/tutorials/modelview/1_readonly/modelview.h @@ -1,6 +1,8 @@ +//! [Quoting ModelView Tutorial] #ifndef MODELVIEW_H #define MODELVIEW_H + #include class QTableView; //forward declaration @@ -16,3 +18,4 @@ public: }; #endif // MODELVIEW_H +//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp index ff3e2d2..3386907 100755 --- a/examples/tutorials/modelview/1_readonly/mymodel.cpp +++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp @@ -1,3 +1,4 @@ +//! [Quoting ModelView Tutorial] #include "mymodel.h" MyModel::MyModel(QObject *parent) @@ -28,3 +29,4 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const } return QVariant(); } +//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h index 01ae6cb..aac1bf0 100755 --- a/examples/tutorials/modelview/1_readonly/mymodel.h +++ b/examples/tutorials/modelview/1_readonly/mymodel.h @@ -1,3 +1,4 @@ +//! [Quoting ModelView Tutorial] #ifndef MYMODEL_H #define MYMODEL_H @@ -14,3 +15,4 @@ public: }; #endif // MYMODEL_H +//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/2_formatting/mymodel.cpp b/examples/tutorials/modelview/2_formatting/mymodel.cpp index 48b1134..916dabc 100755 --- a/examples/tutorials/modelview/2_formatting/mymodel.cpp +++ b/examples/tutorials/modelview/2_formatting/mymodel.cpp @@ -3,6 +3,7 @@ #include "mymodel.h" #include +//! [Quoting ModelView Tutorial] MyModel::MyModel(QObject *parent) :QAbstractTableModel(parent) { @@ -70,4 +71,4 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const } return QVariant(); } - +//! [Quoting ModelView Tutorial] diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp index d594175..fa7f566 100755 --- a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp +++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -3,7 +3,7 @@ #include #include "mymodel.h" - +//! [quoting mymodel_a] MyModel::MyModel(QObject *parent) :QAbstractTableModel(parent) { @@ -13,7 +13,7 @@ MyModel::MyModel(QObject *parent) connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) ); timer->start(); } - +//! [quoting mymodel_a] //------------------------------------------------------- int MyModel::rowCount(const QModelIndex & /*parent */ ) const { @@ -43,6 +43,7 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const } //------------------------------------------------------- +//! [quoting mymodel_b ] void MyModel::timerHit() { //we identify the top left cell @@ -50,4 +51,4 @@ void MyModel::timerHit() //emit a signal to make the view reread identified data emit dataChanged ( topLeft, topLeft ); } - +//! [quoting mymodel_b ] diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp index a032fe5..7891c80 100755 --- a/examples/tutorials/modelview/4_headers/mymodel.cpp +++ b/examples/tutorials/modelview/4_headers/mymodel.cpp @@ -29,7 +29,7 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const return QVariant(); } - +//! [quoting mymodel_c] QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole) @@ -48,3 +48,4 @@ QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) } return QVariant(); } +//! [quoting mymodel_c] \ No newline at end of file diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp index c64a6b7..ef45bc3 100755 --- a/examples/tutorials/modelview/5_edit/mymodel.cpp +++ b/examples/tutorials/modelview/5_edit/mymodel.cpp @@ -1,3 +1,4 @@ +//! [quoting mymodel_d] #include "mymodel.h" const int COLS= 3; @@ -9,7 +10,9 @@ MyModel::MyModel(QObject *parent) //gridData needs to have 6 element, one for each table cell m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ; } +//! [quoting mymodel_d] +//! [quoting mymodel_e] //------------------------------------------------------- int MyModel::rowCount(const QModelIndex & /*parent*/ ) const { @@ -31,8 +34,11 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const } return QVariant(); } +//! [quoting mymodel_e] //----------------------------------------------------------------- + +//! [quoting mymodel_f] bool MyModel::setData ( const QModelIndex & index, const QVariant & value, int role ) { if(role == Qt::EditRole) @@ -55,4 +61,4 @@ int MyModel::modelIndexToOffset(const QModelIndex & index) const { return index.row()*COLS + index.column(); } - +//! [quoting mymodel_f] diff --git a/examples/tutorials/modelview/5_edit/mymodel.h b/examples/tutorials/modelview/5_edit/mymodel.h index f8fac77..1612fa0 100755 --- a/examples/tutorials/modelview/5_edit/mymodel.h +++ b/examples/tutorials/modelview/5_edit/mymodel.h @@ -1,3 +1,4 @@ +//! [Quoting ModelView Tutorial] #ifndef MYMODEL_H #define MYMODEL_H @@ -22,3 +23,4 @@ signals: }; #endif // MYMODEL_H +//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/6_treeview/modelview.cpp b/examples/tutorials/modelview/6_treeview/modelview.cpp index a5488f7..b5b4d06 100755 --- a/examples/tutorials/modelview/6_treeview/modelview.cpp +++ b/examples/tutorials/modelview/6_treeview/modelview.cpp @@ -1,3 +1,4 @@ +//! [Quoting ModelView Tutorial] #include #include #include @@ -38,3 +39,4 @@ QList ModelView::prepareColumn(const QString &first, colItems << new QStandardItem(third); return colItems; } +//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/7_selections/modelview.cpp b/examples/tutorials/modelview/7_selections/modelview.cpp index 49c5bb8..eac6df9 100755 --- a/examples/tutorials/modelview/7_selections/modelview.cpp +++ b/examples/tutorials/modelview/7_selections/modelview.cpp @@ -1,3 +1,4 @@ +//! [quoting modelview_a] #include #include #include @@ -41,8 +42,11 @@ ModelView::ModelView(QWidget *parent) connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & ))); } +//! [quoting modelview_a] //------------------------------------------------------------------------------------ + +//! [quoting modelview_b] void ModelView::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/) { const QModelIndex index = treeView->selectionModel()->currentIndex(); @@ -58,6 +62,6 @@ void ModelView::selectionChangedSlot(const QItemSelection & /*newSelection*/, co .arg(hierarchyLevel); setWindowTitle(showString); } - +//! [quoting modelview_b] diff --git a/examples/tutorials/modelview/qmake.pro b/examples/tutorials/modelview/qmake.pro new file mode 100755 index 0000000..7f684ba --- /dev/null +++ b/examples/tutorials/modelview/qmake.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs + +SUBDIRS = 1_readonly \ + 2_formatting \ + 3_changingmodel \ + 4_headers \ + 5_edit \ + 6_treeview \ + 7_selections + -- cgit v0.12 From 798433c9046281a8739eb6b313c7dd0fc7b5e3b1 Mon Sep 17 00:00:00 2001 From: Michael D Scull Date: Mon, 28 Jun 2010 12:49:05 +0200 Subject: I've cleaned up the qdoc file a bit. --- doc/src/tutorials/modelview.qdoc | 213 +++++++-------------- .../modelview/3_changingmodel/mymodel.cpp | 3 +- 2 files changed, 70 insertions(+), 146 deletions(-) diff --git a/doc/src/tutorials/modelview.qdoc b/doc/src/tutorials/modelview.qdoc index 3c73a80..c9caf17 100755 --- a/doc/src/tutorials/modelview.qdoc +++ b/doc/src/tutorials/modelview.qdoc @@ -56,9 +56,13 @@ Here is an overview of the model/view widgets and their corresponding standard w \section2 1.4 Having adapters between forms and models can come in handy. We often prefer editing data stored in tables (e.g. in database tables) in forms rather than in tables. There is no direct model/view counterpart for separating data and views for widgets that operate on one value instead of a dataset, so we need an adapter in order to connect the form to the source of data. -\l QDataWidgetMapper is a great solution because it maps form widgets to a table row and it makes it very easy to build forms for database tables. \image widgetmapper.png -Another example of an adapter is \l QCompleter. Qt has QCompleter for providing auto completions in Qt widgets such as \l QComboBox and, as shown below, \l QLineEdit. \l QCompleter uses a model as its data source, so \l QCompleter, in itself, is a very handy adapter. \image qcompleter.png +\l QDataWidgetMapper is a great solution because it maps form widgets to a table row and it makes it very easy to build forms for database tables. +\image widgetmapper.png + + +Another example of an adapter is \l QCompleter. Qt has QCompleter for providing auto completions in Qt widgets such as \l QComboBox and, as shown below, \l QLineEdit. \l QCompleter uses a model as its data source, so \l QCompleter, in itself, is a very handy adapter. +\image qcompleter.png \section1 2 A Simple Model/View Application If you want to develop a model/view application, where should you start? We recommend starting with a simple example and extending it step-by-step. This makes understanding the architecture a lot easier. Trying to understand the model/view architecture in detail before invoking the IDE has proven to be less convenient for many developers. It is substantially easier to start with a simple model/view application that has demo data. Give it a try! Simply replace the data in the examples below with your own. @@ -71,7 +75,7 @@ We start with an application that uses a \l QTableView to show data. We will add -------------------------------------------------------------main.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/main.cpp Quoting ModelView Tutorial -We have the usual main() function; +We have the usual \l {tutorials/modelview/1_readonly/main.cpp}{main()} function; -------------------------------------------------------------modelview.h--------------------- \snippet examples/tutorials/modelview/1_readonly/modelview.h Quoting ModelView Tutorial @@ -80,7 +84,7 @@ The application is a \l QMainWindow that holds a \l QTableView. -------------------------------------------------------------modelview.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/modelview.cpp Quoting ModelView Tutorial -Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView::}{tableView()} OR \l QTableView::tableView() OR \l QTableView::tableView . \l {QTableView::}{tableView} will invoke the methods of the pointer it has received to find out two things: +Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView}{tableView()}. \l {QTableView}{tableView} will invoke the methods of the pointer it has received to find out two things: \list \o How many rows and columns should be displayed \o What content should be printed into each cell. @@ -154,54 +158,17 @@ Now we need to determine how using a seperated model impacts the application's p We still have a read only table, but this time the content changes every second because we are showing the current time. -!!!!!I CAN'T FIND THIS FILE!!!!! -\code -QVariant MyModel::data(const QModelIndex &index, int role ) const -{ - QVariant returnVal; - int row = index.row(); - int col = index.column(); - - if(role == Qt::DisplayRole) - - { - if(row == 0 && col == 0 ) - { - returnVal = QTime::currentTime().toString(); - } - } - return returnVal; -} -\endcode + \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_QVariant Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal. -\code -MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) -{ -// selectedCell = 0; - timer = new QTimer(this); - timer->setInterval(1000); - connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) ); - timer->start(); -} -\endcode + \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_a Here is the corresponding slot: -\code + \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_b -void MyModel::timerHit() -{ - //we identify the top left cell - QModelIndex topLeft = createIndex ( 0,0 ); - //emit a signal to make the view reread identified data - emit dataChanged ( topLeft, topLeft ); -} -\endcode - -We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QAbstractItemModel::setModel()}{setModel()} . +We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QTableView::setModel}{setModel()} . \section2 2.4 Setting up Headers for Columns and Rows Headers can be hidden via a view method. @@ -209,28 +176,9 @@ Headers can be hidden via a view method. \image header.png -The header content, however , is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: +The header content, however, is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: -\code -QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role == Qt::DisplayRole) - { - if (orientation == Qt::Horizontal) { - switch (section) - { - case 0: - return QString("first"); - case 1: - return QString("second"); - case 2: - return QString("third"); - } - } - } - return QVariant(); -} -\endcode + \snippet examples/tutorials/modelview/4_headers/mymodel.cpp quoting mymodel_c \section2 2.5 The minimal Editing example @@ -242,19 +190,7 @@ The model decides whether editing capabilities are available . We only have to m We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title. -\code -#include "mymodel.h" - -const int COLS= 3; -const int ROWS= 2; - -MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) -{ - //gridData needs to have 6 element, one for each table cell - m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ; -} -\endcode + \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_d In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table) \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_e @@ -266,6 +202,7 @@ Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags() \section1 3 Intermediate Topics \section2 3.1 TreeView + You can convert the example above into an application with a tree view. Simply replace QTableView with QTreeView, which results in a read/write tree. No changes have to be made to the model. The tree won't have any hierarchies because there aren't any hierarchies in the model itself. \image dummy_tree.png @@ -273,76 +210,33 @@ You can convert the example above into an application with a tree view. Simply r QListView, QTableView and QTreeView all use a model abstraction, which is a merged list, table and tree. This makes it possible to use several different types of view classes from the same model. \image list_table_tree.png + This is how our example model looks so far: \image example_model.png -We want to, however, present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with QStandardItems, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png +We want to present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with \l{QStandardItem}{QStandardItems}, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png -------------------------------------------------------------modelview.cpp--------------------- \snippet examples/tutorials/modelview/6_treeview/modelview.cpp Quoting ModelView Tutorial -We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other QStandardItems. Nodes are collapsed and expanded within the view. +We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other \l{QStandardItem}{QStandardItems}. Nodes are collapsed and expanded within the view. \section2 3.2 Working with selection + + We want to access a selected item's content in order to output it into the window title together with the hierarchy level. \image selection2.png - So let's create a couple of items: -\code -#include -#include -#include -#include "modelview.h" - -ModelView::ModelView(QWidget *parent) - : QMainWindow(parent) -{ - treeView = new QTreeView(this); - setCentralWidget(treeView); - standardModel = new QStandardItemModel ; - QStandardItem *rootNode = standardModel->invisibleRootItem(); - - - //defining a couple of items - QStandardItem *americaItem = new QStandardItem("America"); - QStandardItem *mexicoItem = new QStandardItem("Canada"); - QStandardItem *usaItem = new QStandardItem("USA"); - QStandardItem *bostonItem = new QStandardItem("Boston"); - QStandardItem *europeItem = new QStandardItem("Europe"); - QStandardItem *italyItem = new QStandardItem("Italy"); - QStandardItem *romeItem = new QStandardItem("Rome"); - QStandardItem *veronaItem = new QStandardItem("Verona"); - - //building up the hierarchy - rootNode-> appendRow(americaItem); - rootNode-> appendRow(europeItem); - americaItem-> appendRow(mexicoItem); - americaItem-> appendRow(usaItem); - usaItem-> appendRow(bostonItem); - europeItem-> appendRow(italyItem); - italyItem-> appendRow(romeItem); - italyItem-> appendRow(veronaItem); - - //register the model - treeView->setModel( standardModel ); - treeView->expandAll(); - - //selection changes shall trigger a slot - QItemSelectionModel *selectionModel= treeView->selectionModel(); - connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), - this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & ))); -} -\endcode - + \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_a Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal. \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_b We get the model index that corresponds to the selection by calling -\c treeView->selectionModel()->currentIndex() and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed QModelIndex(). This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. +\l{QItemSelectionModel::currentIndex()}{treeView->selectionModel()->currentIndex()} and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed \l{QModelIndex}{QModelIndex()}. This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. -The selection model (as shown above) can be retrieved, but it can also be set with \c QAbstractItemView::setSelectionModel. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemModel::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemModel::setSelectionModel()}{setSelectionModel()}; +The selection model (as shown above) can be retrieved, but it can also be set with \l{QAbstractItemView}{QAbstractItemView::setSelectionModel}. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemModel::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemModel::setSelectionModel()}{setSelectionModel()}; \section2 3.3 Predefined Models The typical way to use model/view is to wrap specific data to make it usable with view classes. Qt, however, also provides predefined models for common underlying data structures. If one of the available data structures is suitable for your application, a predefined model can be a good choice. @@ -354,9 +248,12 @@ The typical way to use model/view is to wrap specific data to make it usable wit \o QStandardItemModel \o Stores arbitrary hierarchical items \row - \o {1, 2} QFileSystemModel -QDirModel (deprecated) - \o {1, 2} Encapsulate the local file system + \o QFileSystemModel + \raw HTML +
+ \endraw + QDirModel (deprecated) + \o Encapsulate the local file system \row \o QSqlQueryModel \o Encapsulate an SQL result set @@ -375,9 +272,8 @@ QDirModel (deprecated) \section2 3.4 Delegates In all examples so far, data is presented as text or a checkbox in a cell and is edited as text or a checkbox. The component that provides these presentation and editing services is called a “delegate.” We are only just beginning to work with the delegate because the view uses a default delegate. But imagine that we want to have a different editor.(e.g. a slider or a drop down list) Or imagine that we want to present data as graphics. Let's take a look at an example called Stardelegate, ( \l{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html}{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html} ) in which stars are used to show a rating: \image stardelegate.png -The view has a method that replaces the default delegate and installs a custom delegate. This method is called \l{QAbstractItemModel::setItemDelegate()}{setItemDelegate()}. A new delegate can be written by creating a class that inherits from QStyledItemDelegate. In order to write a delegate that displays stars and has no input capabilities, we only need to overwrite 2 methods. +The view has a method that replaces the default delegate and installs a custom delegate. This method is called \l{QAbstractItemView::setItemDelegate()}{setItemDelegate()}. A new delegate can be written by creating a class that inherits from QStyledItemDelegate. In order to write a delegate that displays stars and has no input capabilities, we only need to overwrite 2 methods. -!!!!!I CAN'T FIND THIS FILE!!!!! \code class StarDelegate : public QStyledItemDelegate { @@ -392,20 +288,22 @@ The view has a method that replaces the default delegate and installs a custom d \endcode -\l{QAbstractItemModel::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \c index.data(). \c SizeHint specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. +\l{QStyledItemDelegate::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \l{QModelIndex::data()}{index.data()}. \l{QStyledItemDelegate::SizeHint}{SizeHint} specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. Writing custom delegates is the right choice if you want to show your data with a custom graphical representation inside the grid of the view class. If you want to leave the grid, you can write a custom view class. \section2 3.5 Debugging with ModelTest The passive nature of models provides new challenges for programmers. Inconsistencies in the model can cause the application to crash. Since the model is hit by numerous calls from the view, it is hard to find out which call has crashed the application and which operation has introduced the problem. -Qt provides software called ModelTest, which checks models while your programming is running. Every time the model is changed, ModelTest scans the model and reports errors with an assert. This is especially important for tree models, since their hierarchical nature leaves many possibilities for subtle inconsistencies. http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest +Qt provides software called ModelTest, which checks models while your programming is running. Every time the model is changed, ModelTest scans the model and reports errors with an assert. This is especially important for tree models, since their hierarchical nature leaves many possibilities for subtle inconsistencies. \l http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest Unlike view classes, ModelTest uses out of range indexes to test the model. This means your application may crash with ModelTest even if it runs perfectly without it. So you also need to handle all of the indexes that are out of range when using ModelTest. - +\raw HTML +
+\endraw @@ -413,25 +311,50 @@ Unlike view classes, ModelTest uses out of range indexes to test the model. Thi \section2 3.6 Model/View NG -\image path.png +\raw HTML + +
+\endraw -Model/View was introduced in Qt 4.0 and is a frequently used technology. Feedback from clients and new development trends have shown, that there is a need to further develop the model/view technology. Therefore a research project at Nokia is looking into ways to go beyond the current implementation. +\raw HTML + +\endraw +Model/View was introduced in Qt 4.0 and is a frequently used technology. Feedback from clients and new development trends have shown, that there is a need to further develop the model/view technology. Therefore a research project at Nokia is looking into ways to go beyond the current implementation. +\raw HTML +
+\endraw One limitation of model/view is that view classes are basically all fixed grids. It is possible, but really hard to make a list view with icons placed on a curve; or cells expanding on mouse over events to show additional information. In order to achieve graphically rich view experiences, Model/View NG will use QGraphicsView to render elements. Nodel/View NG also aims to make model/view programming more intuitive. One way to achieve this is to have separate models for lists, tables and trees. The current model abstraction is complex because it is capable of representing a list, a table or a tree. - +\raw HTML +
+\endraw Model/View NG is a research project. You are welcome to checkout the source code, monitor progress and take part in discussions at the following address: \l{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG}{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG} +\raw HTML +
+\endraw + +\inlineimage path.png + +\raw HTML +
+\endraw +\raw HTML +
+\endraw \section1 4 Good Sources for Additional Information \section2 4.1 Books Model/View programming is covered quite extensively in the documentation of Qt but also in several good books. \list 1 - \o 1.C++ GUI Programming with Qt 4 / Jasmin Blanchette, Mark Summerfield, Prentice Hall, 2nd edition, ISBN 0-13-235416-0 + \o C++ GUI Programming with Qt 4 / Jasmin Blanchette, Mark Summerfield, Prentice Hall, 2nd edition, ISBN 0-13-235416-0 also available in German: C++ GUI Programmierung mit Qt 4: Die offizielle Einführung, Addison-Wesley, ISBN 3-827327-29-6 - \o 1.The Book of Qt4, The Art of Building Qt Applications / Daniel Molkentin, Open Source Press ISBN 1-59327-147-6 + \o The Book of Qt4, The Art of Building Qt Applications / Daniel Molkentin, Open Source Press ISBN 1-59327-147-6 Translated from: Qt 4, Einführung in die Applikationsentwicklung, Open Source Press, ISBN 3-937514-12-0 - \o 1.Foundations of Qt Development / Johan Thelin, Apress, ISBN 1-59059-831-8 + \o Foundations of Qt Development / Johan Thelin, Apress, ISBN 1-59059-831-8 \endlist - +\raw HTML +
+\endraw The following list provides an overview of example programs contained in the books above. Some of them make very good templates for developing similar applications. diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp index fa7f566..8943003 100755 --- a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp +++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -27,6 +27,7 @@ int MyModel::columnCount(const QModelIndex & /*parent */ ) const } //------------------------------------------------------- +//! [quoting mymodel_QVariant ] QVariant MyModel::data(const QModelIndex &index, int role ) const { int row = index.row(); @@ -41,7 +42,7 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const } return QVariant(); } - +//! [quoting mymodel_QVariant ] //------------------------------------------------------- //! [quoting mymodel_b ] void MyModel::timerHit() -- cgit v0.12 From 269b910f08f54333834c3a4d91b250b185a53863 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Mon, 28 Jun 2010 15:52:45 +0200 Subject: Doc: Added the standard three clause BSD license header. Reviewed-by: Trust Me --- examples/tutorials/modelview/1_readonly/main.cpp | 42 +++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp index bdf740c..ad11f38 100755 --- a/examples/tutorials/modelview/1_readonly/main.cpp +++ b/examples/tutorials/modelview/1_readonly/main.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [Quoting ModelView Tutorial] #include #include "modelview.h" @@ -9,4 +49,4 @@ int main(int argc, char *argv[]) w.show(); return a.exec(); } -//! [Quoting ModelView Tutorial] \ No newline at end of file +//! [Quoting ModelView Tutorial] -- cgit v0.12 From 5938c706524fa9a7de531847bedae19a97fa130b Mon Sep 17 00:00:00 2001 From: Michael D Scull Date: Thu, 1 Jul 2010 10:32:05 +0200 Subject: replaced image, license headers, more links in modelview.qdoc file --- doc/src/images/columnview.png | Bin 11717 -> 3480 bytes doc/src/tutorials/modelview.qdoc | 30 ++++++++-------- .../tutorials/modelview/1_readonly/1_readonly.pro | 40 +++++++++++++++++++++ .../tutorials/modelview/1_readonly/modelview.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/1_readonly/modelview.h | 40 +++++++++++++++++++++ .../tutorials/modelview/1_readonly/mymodel.cpp | 40 +++++++++++++++++++++ examples/tutorials/modelview/1_readonly/mymodel.h | 40 +++++++++++++++++++++ .../modelview/2_formatting/2_formatting.pro | 40 +++++++++++++++++++++ examples/tutorials/modelview/2_formatting/main.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/2_formatting/modelview.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/2_formatting/modelview.h | 40 +++++++++++++++++++++ .../tutorials/modelview/2_formatting/mymodel.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/2_formatting/mymodel.h | 40 +++++++++++++++++++++ .../modelview/3_changingmodel/3_changingmodel.pro | 40 +++++++++++++++++++++ .../tutorials/modelview/3_changingmodel/main.cpp | 40 +++++++++++++++++++++ .../modelview/3_changingmodel/modelview.cpp | 40 +++++++++++++++++++++ .../modelview/3_changingmodel/modelview.h | 40 +++++++++++++++++++++ .../modelview/3_changingmodel/mymodel.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/3_changingmodel/mymodel.h | 40 +++++++++++++++++++++ .../tutorials/modelview/4_headers/4_headers.pro | 40 +++++++++++++++++++++ examples/tutorials/modelview/4_headers/main.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/4_headers/modelview.cpp | 40 +++++++++++++++++++++ examples/tutorials/modelview/4_headers/modelview.h | 40 +++++++++++++++++++++ examples/tutorials/modelview/4_headers/mymodel.cpp | 40 +++++++++++++++++++++ examples/tutorials/modelview/4_headers/mymodel.h | 40 +++++++++++++++++++++ examples/tutorials/modelview/5_edit/5_edit.pro | 40 +++++++++++++++++++++ examples/tutorials/modelview/5_edit/main.cpp | 40 +++++++++++++++++++++ examples/tutorials/modelview/5_edit/modelview.cpp | 40 +++++++++++++++++++++ examples/tutorials/modelview/5_edit/modelview.h | 40 +++++++++++++++++++++ examples/tutorials/modelview/5_edit/mymodel.cpp | 40 +++++++++++++++++++++ examples/tutorials/modelview/5_edit/mymodel.h | 40 +++++++++++++++++++++ .../tutorials/modelview/6_treeview/6_treeview.pro | 40 +++++++++++++++++++++ examples/tutorials/modelview/6_treeview/main.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/6_treeview/modelview.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/6_treeview/modelview.h | 40 +++++++++++++++++++++ .../modelview/7_selections/7_selections.pro | 40 +++++++++++++++++++++ examples/tutorials/modelview/7_selections/main.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/7_selections/modelview.cpp | 40 +++++++++++++++++++++ .../tutorials/modelview/7_selections/modelview.h | 40 +++++++++++++++++++++ 39 files changed, 1495 insertions(+), 15 deletions(-) mode change 100755 => 100644 doc/src/images/columnview.png diff --git a/doc/src/images/columnview.png b/doc/src/images/columnview.png old mode 100755 new mode 100644 index 2fb972e..127b795 Binary files a/doc/src/images/columnview.png and b/doc/src/images/columnview.png differ diff --git a/doc/src/tutorials/modelview.qdoc b/doc/src/tutorials/modelview.qdoc index c9caf17..67908b9 100755 --- a/doc/src/tutorials/modelview.qdoc +++ b/doc/src/tutorials/modelview.qdoc @@ -3,7 +3,7 @@ \contentspage{modelview.html}{Crash Course in Model/View Programming} \page modelview.html -\title Crash Course in Model/View Programming +\title An Introduction to Model/View Programming Contents: \tableofcontents @@ -84,7 +84,7 @@ The application is a \l QMainWindow that holds a \l QTableView. -------------------------------------------------------------modelview.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/modelview.cpp Quoting ModelView Tutorial -Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView}{tableView()}. \l {QTableView}{tableView} will invoke the methods of the pointer it has received to find out two things: +Here is the interesting part: We use \l{QTableView::setModel()}{tableView->setModel(new MyModel(this) );} to instantiate the Model and pass its pointer to \l {QTableView}{tableView()}. \l {QTableView}{tableView} will invoke the methods of the pointer it has received to find out two things: \list \o How many rows and columns should be displayed \o What content should be printed into each cell. @@ -102,8 +102,8 @@ QAbstractTableModel requires the implementation of three abstract methods. -------------------------------------------------------------mymodel.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp Quoting ModelView Tutorial -The number of rows and columns is set by \c MyModel::rowCount() and \c MyModel::columnCount(). -When the view has to know what the cell 's text is, it calls the \l{QAbstractItemModel::data()}{data()} method. Row and column information is specified with parameter \c index and the role is set to Qt::Display Role. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. +The number of rows and columns is set by \l{QAbstractItemModel::rowCount()}{MyModel::rowCount()} and \l{QAbstractItemModel::columnCount()}{MyModel::columnCount()}. +When the view has to know what the cell 's text is, it calls the method. Row and column information is specified with parameter \c index and the role is set to \l{Qt::ItemDataRole}{Qt::DisplayRole}. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. This small example demonstrates the passive nature of a model. The model does not know when it will be used or which data is needed. It simply provides data each time the view requests it. @@ -126,7 +126,7 @@ Each formatting property will be requested from the model with a separate call t \o Meaning \o Type \row - \o Qt::DisplayRole + \o \l{Qt::ItemDataRole}{Qt::DisplayRole} \o text \o QString \row @@ -143,15 +143,15 @@ Each formatting property will be requested from the model with a separate call t \o enum Qt::AlignmentFlag \row \o {1, 3} Qt::CheckStateRole - \o {1, 3} suppresses checkboxes with QVariant(), sets checkboxes with Qt::Checked or Qt::Unchecked - \o {1, 3} enum Qt::ItemDataRole + \o {1, 3} suppresses checkboxes with \l{QVariant}{QVariant()}, sets checkboxes with Qt::Checked or Qt::Unchecked + \o {1, 3} \l{Qt::ItemDataRole}{enum Qt::ItemDataRole} \endtable Refer to Qt documentation to learn more about enum Qt::ItemDataRole's capabilities. -Now we need to determine how using a seperated model impacts the application's performance, so let's trace how often the view calls the \l{QAbstractItemModel::data()}{data()} method. In order to track how often the view calls the model, we have put a debug statement in the \l{QAbstractItemModel::data()}{data()} method, which logs onto stdio. In our small example, \l{QAbstractItemModel::data()}{data()} will be called 42 times. Each time you hover the cursor over the field, \l{QAbstractItemModel::data()}{data()} will be called again - 7 times for each cell. That's why it is important to make sure that your data is available when \l{QAbstractItemModel::data()}{data()}) is invoked and expensive lookup operations are cached. +Now we need to determine how using a seperated model impacts the application's performance, so let's trace how often the view calls the \l{QAbstractItemModel::data()}{data()} method. In order to track how often the view calls the model, we have put a debug statement in the \l{QAbstractItemModel::data()}{data()} method, which logs onto stdio. In our small example, \l{QAbstractItemModel::data()}{data()} will be called 42 times. Each time you hover the cursor over the field, \l{QAbstractItemModel::data()}{data()} will be called again - 7 times for each cell. That's why it is important to make sure that your data is available when \l{QAbstractItemModel::data()}{data()} is invoked and expensive lookup operations are cached. \section2 2.3 A clock inside a table cell \image clock.png @@ -168,7 +168,7 @@ Here is the corresponding slot: \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_b -We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QTableView::setModel}{setModel()} . +We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QTableView::setModel()}{setModel()}. \section2 2.4 Setting up Headers for Columns and Rows Headers can be hidden via a view method. @@ -219,7 +219,7 @@ We want to present a real tree. We have wrapped our data in the examples above i -------------------------------------------------------------modelview.cpp--------------------- \snippet examples/tutorials/modelview/6_treeview/modelview.cpp Quoting ModelView Tutorial -We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other \l{QStandardItem}{QStandardItems}. Nodes are collapsed and expanded within the view. +We simply instantiate a QStandardItemModel and add a couple of \l{QStandardItem}{QStandardItems} to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other \l{QStandardItem}{QStandardItems}. Nodes are collapsed and expanded within the view. \section2 3.2 Working with selection @@ -229,14 +229,14 @@ We want to access a selected item's content in order to output it into the windo So let's create a couple of items: \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_a -Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal. +Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemView::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemView::selectionChanged()}{selectionChanged()} signal. \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_b We get the model index that corresponds to the selection by calling \l{QItemSelectionModel::currentIndex()}{treeView->selectionModel()->currentIndex()} and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed \l{QModelIndex}{QModelIndex()}. This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. -The selection model (as shown above) can be retrieved, but it can also be set with \l{QAbstractItemView}{QAbstractItemView::setSelectionModel}. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemModel::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemModel::setSelectionModel()}{setSelectionModel()}; +The selection model (as shown above) can be retrieved, but it can also be set with \l{QAbstractItemView}{QAbstractItemView::setSelectionModel}. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemView::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemView::setSelectionModel()}{setSelectionModel()}; \section2 3.3 Predefined Models The typical way to use model/view is to wrap specific data to make it usable with view classes. Qt, however, also provides predefined models for common underlying data structures. If one of the available data structures is suitable for your application, a predefined model can be a good choice. @@ -252,7 +252,7 @@ The typical way to use model/view is to wrap specific data to make it usable wit \raw HTML
\endraw - QDirModel (deprecated) + QDirModel \o Encapsulate the local file system \row \o QSqlQueryModel @@ -288,7 +288,7 @@ The view has a method that replaces the default delegate and installs a custom d \endcode -\l{QStyledItemDelegate::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \l{QModelIndex::data()}{index.data()}. \l{QStyledItemDelegate::SizeHint}{SizeHint} specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. +\l{QStyledItemDelegate::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \l{QModelIndex::data()}{index.data()}. \l{QGraphicsLayoutItem::sizeHint()}{sizeHint} specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. Writing custom delegates is the right choice if you want to show your data with a custom graphical representation inside the grid of the view class. If you want to leave the grid, you can write a custom view class. @@ -540,7 +540,7 @@ Qt 4.6 comes with 17 examples and 2 Demonstrations for model/view. The examples \row \o Address Book \o QTableView - \o QTableModel + \o QAbstractTableModel QSortFilterProxyModel \o usage of QSortFilterProxyModel to generate different subsets from one data pool \row diff --git a/examples/tutorials/modelview/1_readonly/1_readonly.pro b/examples/tutorials/modelview/1_readonly/1_readonly.pro index 1162d5a..8528cde 100755 --- a/examples/tutorials/modelview/1_readonly/1_readonly.pro +++ b/examples/tutorials/modelview/1_readonly/1_readonly.pro @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + TARGET = mv_readonly TEMPLATE = app diff --git a/examples/tutorials/modelview/1_readonly/modelview.cpp b/examples/tutorials/modelview/1_readonly/modelview.cpp index 14311f9..027be56 100755 --- a/examples/tutorials/modelview/1_readonly/modelview.cpp +++ b/examples/tutorials/modelview/1_readonly/modelview.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [Quoting ModelView Tutorial] #include #include "modelview.h" diff --git a/examples/tutorials/modelview/1_readonly/modelview.h b/examples/tutorials/modelview/1_readonly/modelview.h index 93b6b90..d0f96cd 100755 --- a/examples/tutorials/modelview/1_readonly/modelview.h +++ b/examples/tutorials/modelview/1_readonly/modelview.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [Quoting ModelView Tutorial] #ifndef MODELVIEW_H #define MODELVIEW_H diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp index 3386907..c441720 100755 --- a/examples/tutorials/modelview/1_readonly/mymodel.cpp +++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [Quoting ModelView Tutorial] #include "mymodel.h" diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h index aac1bf0..c0ddf4ac6 100755 --- a/examples/tutorials/modelview/1_readonly/mymodel.h +++ b/examples/tutorials/modelview/1_readonly/mymodel.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [Quoting ModelView Tutorial] #ifndef MYMODEL_H #define MYMODEL_H diff --git a/examples/tutorials/modelview/2_formatting/2_formatting.pro b/examples/tutorials/modelview/2_formatting/2_formatting.pro index 7e70d81..cdf72bf 100755 --- a/examples/tutorials/modelview/2_formatting/2_formatting.pro +++ b/examples/tutorials/modelview/2_formatting/2_formatting.pro @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + TARGET = mv_formatting TEMPLATE = app diff --git a/examples/tutorials/modelview/2_formatting/main.cpp b/examples/tutorials/modelview/2_formatting/main.cpp index 998503c..7be212e 100755 --- a/examples/tutorials/modelview/2_formatting/main.cpp +++ b/examples/tutorials/modelview/2_formatting/main.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" diff --git a/examples/tutorials/modelview/2_formatting/modelview.cpp b/examples/tutorials/modelview/2_formatting/modelview.cpp index becd61d..2b05d4c 100755 --- a/examples/tutorials/modelview/2_formatting/modelview.cpp +++ b/examples/tutorials/modelview/2_formatting/modelview.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" #include "mymodel.h" diff --git a/examples/tutorials/modelview/2_formatting/modelview.h b/examples/tutorials/modelview/2_formatting/modelview.h index 98bee38..7291487 100755 --- a/examples/tutorials/modelview/2_formatting/modelview.h +++ b/examples/tutorials/modelview/2_formatting/modelview.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MODELVIEW_H #define MODELVIEW_H diff --git a/examples/tutorials/modelview/2_formatting/mymodel.cpp b/examples/tutorials/modelview/2_formatting/mymodel.cpp index 916dabc..e9e68de 100755 --- a/examples/tutorials/modelview/2_formatting/mymodel.cpp +++ b/examples/tutorials/modelview/2_formatting/mymodel.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include #include "mymodel.h" diff --git a/examples/tutorials/modelview/2_formatting/mymodel.h b/examples/tutorials/modelview/2_formatting/mymodel.h index 01ae6cb..4dc405a 100755 --- a/examples/tutorials/modelview/2_formatting/mymodel.h +++ b/examples/tutorials/modelview/2_formatting/mymodel.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MYMODEL_H #define MYMODEL_H diff --git a/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro index d61ee4c..8b217cb 100755 --- a/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro +++ b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + TARGET = mv_changingmodel TEMPLATE = app diff --git a/examples/tutorials/modelview/3_changingmodel/main.cpp b/examples/tutorials/modelview/3_changingmodel/main.cpp index 998503c..7be212e 100755 --- a/examples/tutorials/modelview/3_changingmodel/main.cpp +++ b/examples/tutorials/modelview/3_changingmodel/main.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" diff --git a/examples/tutorials/modelview/3_changingmodel/modelview.cpp b/examples/tutorials/modelview/3_changingmodel/modelview.cpp index becd61d..2b05d4c 100755 --- a/examples/tutorials/modelview/3_changingmodel/modelview.cpp +++ b/examples/tutorials/modelview/3_changingmodel/modelview.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" #include "mymodel.h" diff --git a/examples/tutorials/modelview/3_changingmodel/modelview.h b/examples/tutorials/modelview/3_changingmodel/modelview.h index 98bee38..7291487 100755 --- a/examples/tutorials/modelview/3_changingmodel/modelview.h +++ b/examples/tutorials/modelview/3_changingmodel/modelview.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MODELVIEW_H #define MODELVIEW_H diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp index 8943003..d806945 100755 --- a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp +++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include #include diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.h b/examples/tutorials/modelview/3_changingmodel/mymodel.h index 9cc023b..47b026e 100755 --- a/examples/tutorials/modelview/3_changingmodel/mymodel.h +++ b/examples/tutorials/modelview/3_changingmodel/mymodel.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MYMODEL_H #define MYMODEL_H diff --git a/examples/tutorials/modelview/4_headers/4_headers.pro b/examples/tutorials/modelview/4_headers/4_headers.pro index d6f8d23..13b0b1d 100755 --- a/examples/tutorials/modelview/4_headers/4_headers.pro +++ b/examples/tutorials/modelview/4_headers/4_headers.pro @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + TARGET = mv_headers TEMPLATE = app diff --git a/examples/tutorials/modelview/4_headers/main.cpp b/examples/tutorials/modelview/4_headers/main.cpp index 998503c..7be212e 100755 --- a/examples/tutorials/modelview/4_headers/main.cpp +++ b/examples/tutorials/modelview/4_headers/main.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" diff --git a/examples/tutorials/modelview/4_headers/modelview.cpp b/examples/tutorials/modelview/4_headers/modelview.cpp index 39394da..f661ab5 100755 --- a/examples/tutorials/modelview/4_headers/modelview.cpp +++ b/examples/tutorials/modelview/4_headers/modelview.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include #include "modelview.h" diff --git a/examples/tutorials/modelview/4_headers/modelview.h b/examples/tutorials/modelview/4_headers/modelview.h index f1b63bd..7669e35 100755 --- a/examples/tutorials/modelview/4_headers/modelview.h +++ b/examples/tutorials/modelview/4_headers/modelview.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MODELVIEW_H #define MODELVIEW_H diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp index 7891c80..94fde34 100755 --- a/examples/tutorials/modelview/4_headers/mymodel.cpp +++ b/examples/tutorials/modelview/4_headers/mymodel.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "mymodel.h" MyModel::MyModel(QObject *parent) diff --git a/examples/tutorials/modelview/4_headers/mymodel.h b/examples/tutorials/modelview/4_headers/mymodel.h index 327ca10..ada3169 100755 --- a/examples/tutorials/modelview/4_headers/mymodel.h +++ b/examples/tutorials/modelview/4_headers/mymodel.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MYMODEL_H #define MYMODEL_H diff --git a/examples/tutorials/modelview/5_edit/5_edit.pro b/examples/tutorials/modelview/5_edit/5_edit.pro index e18c596..d0a2571 100755 --- a/examples/tutorials/modelview/5_edit/5_edit.pro +++ b/examples/tutorials/modelview/5_edit/5_edit.pro @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + TARGET = mv_edit TEMPLATE = app diff --git a/examples/tutorials/modelview/5_edit/main.cpp b/examples/tutorials/modelview/5_edit/main.cpp index 998503c..7be212e 100755 --- a/examples/tutorials/modelview/5_edit/main.cpp +++ b/examples/tutorials/modelview/5_edit/main.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" diff --git a/examples/tutorials/modelview/5_edit/modelview.cpp b/examples/tutorials/modelview/5_edit/modelview.cpp index b6e8e34..d8853c9 100755 --- a/examples/tutorials/modelview/5_edit/modelview.cpp +++ b/examples/tutorials/modelview/5_edit/modelview.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" #include "mymodel.h" diff --git a/examples/tutorials/modelview/5_edit/modelview.h b/examples/tutorials/modelview/5_edit/modelview.h index e1591f9..97c840c 100755 --- a/examples/tutorials/modelview/5_edit/modelview.h +++ b/examples/tutorials/modelview/5_edit/modelview.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MODELVIEW_H #define MODELVIEW_H diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp index ef45bc3..6007da1 100755 --- a/examples/tutorials/modelview/5_edit/mymodel.cpp +++ b/examples/tutorials/modelview/5_edit/mymodel.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [quoting mymodel_d] #include "mymodel.h" diff --git a/examples/tutorials/modelview/5_edit/mymodel.h b/examples/tutorials/modelview/5_edit/mymodel.h index 1612fa0..54f2b30 100755 --- a/examples/tutorials/modelview/5_edit/mymodel.h +++ b/examples/tutorials/modelview/5_edit/mymodel.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [Quoting ModelView Tutorial] #ifndef MYMODEL_H #define MYMODEL_H diff --git a/examples/tutorials/modelview/6_treeview/6_treeview.pro b/examples/tutorials/modelview/6_treeview/6_treeview.pro index 6d078be..fa27c3a 100755 --- a/examples/tutorials/modelview/6_treeview/6_treeview.pro +++ b/examples/tutorials/modelview/6_treeview/6_treeview.pro @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + TARGET = mv_tree TEMPLATE = app SOURCES += main.cpp \ diff --git a/examples/tutorials/modelview/6_treeview/main.cpp b/examples/tutorials/modelview/6_treeview/main.cpp index 998503c..7be212e 100755 --- a/examples/tutorials/modelview/6_treeview/main.cpp +++ b/examples/tutorials/modelview/6_treeview/main.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" diff --git a/examples/tutorials/modelview/6_treeview/modelview.cpp b/examples/tutorials/modelview/6_treeview/modelview.cpp index b5b4d06..a25e4e9 100755 --- a/examples/tutorials/modelview/6_treeview/modelview.cpp +++ b/examples/tutorials/modelview/6_treeview/modelview.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [Quoting ModelView Tutorial] #include #include diff --git a/examples/tutorials/modelview/6_treeview/modelview.h b/examples/tutorials/modelview/6_treeview/modelview.h index 1ab23ea..2329e89 100755 --- a/examples/tutorials/modelview/6_treeview/modelview.h +++ b/examples/tutorials/modelview/6_treeview/modelview.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MODELVIEW_H #define MODELVIEW_H diff --git a/examples/tutorials/modelview/7_selections/7_selections.pro b/examples/tutorials/modelview/7_selections/7_selections.pro index 952641c6..671dc24 100755 --- a/examples/tutorials/modelview/7_selections/7_selections.pro +++ b/examples/tutorials/modelview/7_selections/7_selections.pro @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + TARGET = mv_selections TEMPLATE = app SOURCES += main.cpp \ diff --git a/examples/tutorials/modelview/7_selections/main.cpp b/examples/tutorials/modelview/7_selections/main.cpp index 998503c..7be212e 100755 --- a/examples/tutorials/modelview/7_selections/main.cpp +++ b/examples/tutorials/modelview/7_selections/main.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include "modelview.h" diff --git a/examples/tutorials/modelview/7_selections/modelview.cpp b/examples/tutorials/modelview/7_selections/modelview.cpp index eac6df9..2ef980d 100755 --- a/examples/tutorials/modelview/7_selections/modelview.cpp +++ b/examples/tutorials/modelview/7_selections/modelview.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + //! [quoting modelview_a] #include #include diff --git a/examples/tutorials/modelview/7_selections/modelview.h b/examples/tutorials/modelview/7_selections/modelview.h index 0e638a9..5229ac3 100755 --- a/examples/tutorials/modelview/7_selections/modelview.h +++ b/examples/tutorials/modelview/7_selections/modelview.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MODELVIEW_H #define MODELVIEW_H -- cgit v0.12 From b7bf2ab2d0aa9e3bf073126f0e15c71e39567fcc Mon Sep 17 00:00:00 2001 From: Michael D Scull Date: Fri, 2 Jul 2010 18:10:13 +0200 Subject: new image for tutorial.qdoc --- doc/src/getting-started/tutorials.qdoc | 12 ++++ doc/src/images/treeview_sml.png | Bin 0 -> 17419 bytes doc/src/tutorials/modelview.qdoc | 115 ++++++++++++++++++++++++++++++--- 3 files changed, 118 insertions(+), 9 deletions(-) create mode 100755 doc/src/images/treeview_sml.png diff --git a/doc/src/getting-started/tutorials.qdoc b/doc/src/getting-started/tutorials.qdoc index 6e1cee8..0a83170 100644 --- a/doc/src/getting-started/tutorials.qdoc +++ b/doc/src/getting-started/tutorials.qdoc @@ -71,6 +71,18 @@ A guided tour through the translations process, explaining the tools provided for developers, translators and release managers. + + \row + \o{2,1} \l{modelview.html}{\bold{ModelView}} + \o{2,1} + + \row + \o \image treeview_sml.png ModelView + \o This tutorial gives an introduction to ModelView programming using the Qt cross-platform framework + + \o + \o + \row \o{2,1} \l{QTestLib Tutorial}{\bold QTestLib} \o{2,1} \l{qmake Tutorial}{\bold qmake} diff --git a/doc/src/images/treeview_sml.png b/doc/src/images/treeview_sml.png new file mode 100755 index 0000000..fb6de1d Binary files /dev/null and b/doc/src/images/treeview_sml.png differ diff --git a/doc/src/tutorials/modelview.qdoc b/doc/src/tutorials/modelview.qdoc index 67908b9..bc03f44 100755 --- a/doc/src/tutorials/modelview.qdoc +++ b/doc/src/tutorials/modelview.qdoc @@ -1,12 +1,63 @@ /*! - - \contentspage{modelview.html}{Crash Course in Model/View Programming} \page modelview.html -\title An Introduction to Model/View Programming -Contents: -\tableofcontents + \startpage {index.html}{Qt Reference Documentation} + \contentspage {modelview-index.html}{ModelView Contents} + \nextpage {modelview-part1.html}{Introduction} + \title ModelView Contents Page + \brief An introduction to ModelView programming + + This tutorial gives an introduction to ModelView programming using the Qt + cross-platform framework. + + \image treeview.png + + \omit + It doesn't cover everything; the emphasis is on teaching the programming + philosophy of ModelView programming, and Qt's features are introduced as needed. + Some commonly used features are never used in this tutorial. + \endomit + + In the process, we will learn about some basic technologies provided by Qt, + such as: + + \list + \o The difference between standard and modelview widgets + \o Adapters betweeen forms and models + \o Developing a simple Model/View application + \o Intermediate topics such as: + \list + \o Tree views + \o Selection + \o Predefined models + \o Delegates + \o Debugging with model test + \endlist + \endlist + + If you are completely new to Qt, please read \l{How to Learn Qt} if you + have not already done so. + + The tutorial's source code is located in Qt's \c examples/tutorials/modelview + directory. + + \list 1 + \o \l{modelview-part1.html}{Introduction} + \o \l{modelview-part2.html}{Developing a simple ModelView application} + \o \l{modelview-part3.html}{Intermediate Topics} + \o \l{modelview-part4.html}{Good Sources for Additional Information} + \endlist + +*/ + +/*! + \page modelview-part1.html + \title An Introduction to Model/View Programming + + \raw HTML +
+ \endraw \section1 1 Introduction Model/View is a technology used to separate data from views in widgets that handle data sets. Standard Widgets are not designed for separating data from views and this is why Qt 4 has two different types of widgets. Both types of widgets look the same, but they interact with data differently. \table @@ -64,6 +115,27 @@ We often prefer editing data stored in tables (e.g. in database tables) in forms Another example of an adapter is \l QCompleter. Qt has QCompleter for providing auto completions in Qt widgets such as \l QComboBox and, as shown below, \l QLineEdit. \l QCompleter uses a model as its data source, so \l QCompleter, in itself, is a very handy adapter. \image qcompleter.png + +*/ + +/*! + + + \page modelview-part2-main-cpp.html + \title main.cpp + \quotefile tutorials/modelview/1_readonly/main.cpp + + +*/ + +/*! + \page modelview-part2.html + \title ModelView Chapter 2 - A Simple Model/View Application + + \raw HTML +
+ \endraw + \section1 2 A Simple Model/View Application If you want to develop a model/view application, where should you start? We recommend starting with a simple example and extending it step-by-step. This makes understanding the architecture a lot easier. Trying to understand the model/view architecture in detail before invoking the IDE has proven to be less convenient for many developers. It is substantially easier to start with a simple model/view application that has demo data. Give it a try! Simply replace the data in the examples below with your own. @@ -75,7 +147,7 @@ We start with an application that uses a \l QTableView to show data. We will add -------------------------------------------------------------main.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/main.cpp Quoting ModelView Tutorial -We have the usual \l {tutorials/modelview/1_readonly/main.cpp}{main()} function; +We have the usual \l {modelview-part2-main-cpp.html}{main()} function; -------------------------------------------------------------modelview.h--------------------- \snippet examples/tutorials/modelview/1_readonly/modelview.h Quoting ModelView Tutorial @@ -148,7 +220,7 @@ Each formatting property will be requested from the model with a separate call t \endtable -Refer to Qt documentation to learn more about enum Qt::ItemDataRole's capabilities. +Refer to Qt documentation to learn more about enum Qt::ItemDataRole's capabilities. Now we need to determine how using a seperated model impacts the application's performance, so let's trace how often the view calls the \l{QAbstractItemModel::data()}{data()} method. In order to track how often the view calls the model, we have put a debug statement in the \l{QAbstractItemModel::data()}{data()} method, which logs onto stdio. In our small example, \l{QAbstractItemModel::data()}{data()} will be called 42 times. Each time you hover the cursor over the field, \l{QAbstractItemModel::data()}{data()} will be called again - 7 times for each cell. That's why it is important to make sure that your data is available when \l{QAbstractItemModel::data()}{data()} is invoked and expensive lookup operations are cached. @@ -198,9 +270,20 @@ In the constructor, we fill \c QStringList gridData with 6 items. (one item for \l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole. \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_f -Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read. +Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | \c Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read. + +*/ +/*! + \page modelview-part3.html + \title ModelView Chapter 3 - Intermediate Topics + \raw HTML +
+ \endraw \section1 3 Intermediate Topics + \raw HTML +
+ \endraw \section2 3.1 TreeView You can convert the example above into an application with a tree view. Simply replace QTableView with QTreeView, which results in a read/write tree. No changes have to be made to the model. The tree won't have any hierarchies because there aren't any hierarchies in the model itself. @@ -288,7 +371,7 @@ The view has a method that replaces the default delegate and installs a custom d \endcode -\l{QStyledItemDelegate::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \l{QModelIndex::data()}{index.data()}. \l{QGraphicsLayoutItem::sizeHint()}{sizeHint} specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. +\l{QStyledItemDelegate::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \l{QModelIndex::data()}{index.data()}. \l{QAbstractItemDelegate::sizeHint()}{sizeHint} specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. Writing custom delegates is the right choice if you want to show your data with a custom graphical representation inside the grid of the view class. If you want to leave the grid, you can write a custom view class. @@ -342,7 +425,21 @@ Model/View NG is a research project. You are welcome to checkout the source code \raw HTML
\endraw + +*/ + +/*! + \page modelview-part4.html + + \title ModelView Chapter 4 - Good Sources for Additional Information + + \raw HTML +
+ \endraw \section1 4 Good Sources for Additional Information +\raw HTML +
+\endraw \section2 4.1 Books Model/View programming is covered quite extensively in the documentation of Qt but also in several good books. \list 1 -- cgit v0.12 From aba1572d588396d3c9e29192ae86047b5b10070a Mon Sep 17 00:00:00 2001 From: David Boddie Date: Thu, 8 Jul 2010 20:58:46 +0200 Subject: Doc: Fixed incorrect QML property type. Reviewed-by: Trust Me --- src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp b/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp index 0342c9f..9dcba60 100644 --- a/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp +++ b/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp @@ -612,7 +612,7 @@ QAction* QDeclarativeWebView::stopAction() const #endif // QT_NO_ACTION /*! - \qmlproperty real WebView::title + \qmlproperty string WebView::title This property holds the title of the web page currently viewed By default, this property contains an empty string. -- cgit v0.12 From 3e326e54856b1fce33ab2c005de2a46af6a4ea0f Mon Sep 17 00:00:00 2001 From: David Boddie Date: Fri, 9 Jul 2010 13:59:56 +0200 Subject: Doc: Removed accidentally committed file. Reviewed-by: Trust Me --- examples/tutorials/modelview/._.DS_Store | Bin 4096 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 examples/tutorials/modelview/._.DS_Store diff --git a/examples/tutorials/modelview/._.DS_Store b/examples/tutorials/modelview/._.DS_Store deleted file mode 100755 index 338bd7b..0000000 Binary files a/examples/tutorials/modelview/._.DS_Store and /dev/null differ -- cgit v0.12 From 5608f5c35dd3f4470f51436ead9a7048d561affa Mon Sep 17 00:00:00 2001 From: David Boddie Date: Tue, 13 Jul 2010 17:04:31 +0200 Subject: Doc: Reviewed Michael's model/view tutorial and overview document. Reviewed-by: Trust Me --- doc/src/tutorials/modelview.qdoc | 791 +++++++++++++-------- examples/tutorials/modelview/1_readonly/main.cpp | 1 + .../tutorials/modelview/1_readonly/modelview.cpp | 5 +- .../tutorials/modelview/1_readonly/modelview.h | 6 +- .../tutorials/modelview/1_readonly/mymodel.cpp | 14 +- examples/tutorials/modelview/1_readonly/mymodel.h | 5 +- .../tutorials/modelview/2_formatting/modelview.cpp | 2 +- .../tutorials/modelview/2_formatting/mymodel.cpp | 22 +- .../modelview/3_changingmodel/modelview.cpp | 2 +- .../modelview/3_changingmodel/mymodel.cpp | 16 +- .../tutorials/modelview/4_headers/modelview.cpp | 2 +- examples/tutorials/modelview/4_headers/mymodel.cpp | 10 +- examples/tutorials/modelview/5_edit/modelview.cpp | 6 +- examples/tutorials/modelview/5_edit/mymodel.cpp | 21 +- examples/tutorials/modelview/5_edit/mymodel.h | 9 +- .../tutorials/modelview/6_treeview/modelview.cpp | 8 +- .../tutorials/modelview/6_treeview/modelview.h | 2 +- .../tutorials/modelview/7_selections/modelview.cpp | 8 +- examples/tutorials/modelview/qmake.pro | 10 - 19 files changed, 564 insertions(+), 376 deletions(-) delete mode 100755 examples/tutorials/modelview/qmake.pro diff --git a/doc/src/tutorials/modelview.qdoc b/doc/src/tutorials/modelview.qdoc index bc03f44..98096a0 100755 --- a/doc/src/tutorials/modelview.qdoc +++ b/doc/src/tutorials/modelview.qdoc @@ -1,10 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in a +** written agreement between you and Nokia. +** +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of this +** file. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + /*! \page modelview.html \startpage {index.html}{Qt Reference Documentation} - \contentspage {modelview-index.html}{ModelView Contents} \nextpage {modelview-part1.html}{Introduction} - \title ModelView Contents Page + + \title Model/View Contents \brief An introduction to ModelView programming This tutorial gives an introduction to ModelView programming using the Qt @@ -14,17 +41,17 @@ \omit It doesn't cover everything; the emphasis is on teaching the programming - philosophy of ModelView programming, and Qt's features are introduced as needed. - Some commonly used features are never used in this tutorial. + philosophy of Model/View programming, and Qt's features are introduced as + needed. Some commonly used features are never used in this tutorial. \endomit In the process, we will learn about some basic technologies provided by Qt, such as: \list - \o The difference between standard and modelview widgets + \o The difference between standard and model/view widgets \o Adapters betweeen forms and models - \o Developing a simple Model/View application + \o Developing a simple model/view application \o Intermediate topics such as: \list \o Tree views @@ -43,9 +70,9 @@ \list 1 \o \l{modelview-part1.html}{Introduction} - \o \l{modelview-part2.html}{Developing a simple ModelView application} + \o \l{modelview-part2.html}{Developing a Simple Model/View Application} \o \l{modelview-part3.html}{Intermediate Topics} - \o \l{modelview-part4.html}{Good Sources for Additional Information} + \o \l{modelview-part4.html}{Good Sources of Additional Information} \endlist @@ -53,13 +80,18 @@ /*! \page modelview-part1.html + \contentspage {modelview-index.html}{Model/View Contents} + \previouspage {modelview-index.html}{Model/View Contents} + \nextpage {modelview-part2.html}{Developing a Simple Model/View Application} \title An Introduction to Model/View Programming - \raw HTML -
- \endraw -\section1 1 Introduction -Model/View is a technology used to separate data from views in widgets that handle data sets. Standard Widgets are not designed for separating data from views and this is why Qt 4 has two different types of widgets. Both types of widgets look the same, but they interact with data differently. + \section1 1. Introduction + + Model/View is a technology used to separate data from views in widgets that + handle data sets. Standard widgets are not designed for separating data + from views and this is why Qt 4 has two different types of widgets. Both + types of widgets look the same, but they interact with data differently. + \table \row \o Standard widgets use data that is part of the widget. @@ -68,129 +100,193 @@ Model/View is a technology used to separate data from views in widgets that hand \o View classes operate on external data (the model) \o \image modelview.png \endtable -\section2 1.1 Standard widgets -Let's have a closer look at a standard table widget. A table widget is a 2D array of the data elements that the user can change. The table widget can be integrated into a program flow by reading and writing the data elements that the table widget provides. This method is very intuitive and useful in many applications. -Displaying and editing a database table with a standard table widget can be problematic. Two copies of the data have to be coordinated: one outside the widget; one inside the widget. The developer needs to know where up-to-date data is so the both copies contain the most recent data. The tight coupling of presentation and data makes it harder to write unit tests. + \section2 1.1 Standard Widgets + + Let's have a closer look at a standard table widget. A table widget is a 2D + array of the data elements that the user can change. The table widget can + be integrated into a program flow by reading and writing the data elements + that the table widget provides. This method is very intuitive and useful in + many applications. + + Displaying and editing a database table with a standard table widget can be + problematic. Two copies of the data have to be coordinated: one outside the + widget; one inside the widget. The developer needs to know where up-to-date + data is so the both copies contain the most recent data. The tight coupling + of presentation and data makes it harder to write unit tests. + + \section2 1.2 Model/View to the Rescue + + Model/view stepped up to provide a solution that uses a more versatile + architecture. Model/view eliminates the data consistency problems that may + occur with standard widgets. Model/view also makes it easier to use more + than one view of the same data because one model can be passed on to many + views. The most important difference is that model/view widgets do not + store data behind the table cells. In fact, they operate directly from your + data. Since view classes do not know your data's structure, you need to + provide a wrapper to make your data conform to the QAbstractItemModel + interface. A view uses this interface to read from and write to your data + and any class that implements QAbstractItemModel is a model. Once the view + receives a pointer to a model, it will read and display its content and be + its editor. + + \section2 1.3 Overview of the Model/View Widgets -\section2 1.2 Model/View to the rescue -Model/View stepped up to provide a solution that uses a more versatile architecture. Model/View eliminates the data consistency problems that may occur with standard widgets. Model/View also makes it easier to use more than one view of the same data because one model can be passed on to many views. The most important difference is that model/view widgets do not store data behind the table cells. In fact, they operate directly from your data. Since view classes do not know your data's structure, you need to provide a wrapper to make your data conform to the \l QAbstractItemModel interface. A view uses this interface to read from and write to your data and any class that implements \l QAbstractItemModel is a model. Once the view receives a pointer to a model, it will read and display its content and be its editor. + Here is an overview of the model/view widgets and their corresponding + standard widgets. -\section2 1.3 Overview of the model/view widgets -Here is an overview of the model/view widgets and their corresponding standard widgets. \table \header \o Widget - \o Standard Widget -(a convenience class with data in the widget) + \o Standard Widget (a convenience class with data in + the widget) \o Model/View View Class (for use with external data) \row - \o \image listview.png + \o \inlineimage listview.png \o \l QListWidget \o \l QListView \row - \o \image tableview.png + \o \inlineimage tableview.png \o \l QTableWidget \o \l QTableView \row - \o \image treeview.png + \o \inlineimage treeview.png \o \l QTreeWidget \o \l QTreeView \row - \o \image columnview.png - \o + \o \inlineimage columnview.png + \o \o \l QColumnView shows a tree as a hierarchy of lists \row - \o \image combobox.png - \o {2, 1} \l QComboBox can work as both a view class and also as a traditional widget + \o \inlineimage combobox.png + \o {2, 1} \l QComboBox can work as both a view class and also + as a traditional widget \endtable -\section2 1.4 Having adapters between forms and models can come in handy. -We often prefer editing data stored in tables (e.g. in database tables) in forms rather than in tables. There is no direct model/view counterpart for separating data and views for widgets that operate on one value instead of a dataset, so we need an adapter in order to connect the form to the source of data. + \section2 1.4 Using Adapters between Forms and Models -\l QDataWidgetMapper is a great solution because it maps form widgets to a table row and it makes it very easy to build forms for database tables. -\image widgetmapper.png + Having adapters between forms and models can come in handy. + We often prefer editing data stored in tables (e.g. in database tables) in + forms rather than in tables. There is no direct model/view counterpart for + separating data and views for widgets that operate on one value instead of + a dataset, so we need an adapter in order to connect the form to the source + of data. -Another example of an adapter is \l QCompleter. Qt has QCompleter for providing auto completions in Qt widgets such as \l QComboBox and, as shown below, \l QLineEdit. \l QCompleter uses a model as its data source, so \l QCompleter, in itself, is a very handy adapter. -\image qcompleter.png + \l QDataWidgetMapper is a great solution because it maps form widgets to a + table row and it makes it very easy to build forms for database tables. + \image widgetmapper.png + Another example of an adapter is QCompleter. Qt has QCompleter for + providing auto-completions in Qt widgets such as QComboBox and, as shown + below, QLineEdit. QCompleter uses a model as its data source, so QCompleter, + in itself, is a very handy adapter. + + \image qcompleter.png */ /*! - - \page modelview-part2-main-cpp.html \title main.cpp \quotefile tutorials/modelview/1_readonly/main.cpp - - */ /*! \page modelview-part2.html - \title ModelView Chapter 2 - A Simple Model/View Application - - \raw HTML -
- \endraw - -\section1 2 A Simple Model/View Application -If you want to develop a model/view application, where should you start? We recommend starting with a simple example and extending it step-by-step. This makes understanding the architecture a lot easier. Trying to understand the model/view architecture in detail before invoking the IDE has proven to be less convenient for many developers. It is substantially easier to start with a simple model/view application that has demo data. Give it a try! Simply replace the data in the examples below with your own. + \contentspage {modelview-index.html}{Model/View Contents} + \previouspage {modelview-part1.html}{Introduction} + \nextpage {modelview-part3.html}{Intermediate Topics} + \title Model/View Chapter 2 - A Simple Model/View Application + + \section1 2. A Simple Model/View Application + + If you want to develop a model/view application, where should you start? We + recommend starting with a simple example and extending it step-by-step. + This makes understanding the architecture a lot easier. Trying to + understand the model/view architecture in detail before invoking the IDE + has proven to be less convenient for many developers. It is substantially + easier to start with a simple model/view application that has demo data. + Give it a try! Simply replace the data in the examples below with your own. + + Below are 7 very simple and independent applications that show different + sides of model/view programming. The source code can be found inside the + \c{examples/tutorials/modelview} directory. -Below are 7 very simple and independent applications that show different sides of model/view programming. The source code can be downloaded from @todo___________paste link here_________________________ + \section2 2.1 A Read Only Table -\section2 2.1 A read only table -We start with an application that uses a \l QTableView to show data. We will add editing capabilities later. + We start with an application that uses a QTableView to show data. We will + add editing capabilities later. --------------------------------------------------------------main.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/main.cpp Quoting ModelView Tutorial -We have the usual \l {modelview-part2-main-cpp.html}{main()} function; --------------------------------------------------------------modelview.h--------------------- + We have the usual \l {modelview-part2-main-cpp.html}{main()} function: + \snippet examples/tutorials/modelview/1_readonly/modelview.h Quoting ModelView Tutorial -The application is a \l QMainWindow that holds a \l QTableView. + The application is a \l QMainWindow that holds a \l QTableView. --------------------------------------------------------------modelview.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/modelview.cpp Quoting ModelView Tutorial -Here is the interesting part: We use \l{QTableView::setModel()}{tableView->setModel(new MyModel(this) );} to instantiate the Model and pass its pointer to \l {QTableView}{tableView()}. \l {QTableView}{tableView} will invoke the methods of the pointer it has received to find out two things: + Here is the interesting part: We use + \l{QTableView::setModel()}{tableView->setModel(new MyModel(this));} to + instantiate the Model and pass its pointer to \l {QTableView}{tableView()}. + \l{QTableView}{tableView} will invoke the methods of the pointer it has + received to find out two things: + \list \o How many rows and columns should be displayed \o What content should be printed into each cell. \endlist -The model needs some code to respond to this. + The model needs some code to respond to this. -We have a table data set, so let's start with QAbstractTableModel since it is easier to use. --------------------------------------------------------------mymodel.h--------------------- - \snippet examples/tutorials/modelview/1_readonly/mymodel.h Quoting ModelView Tutorial + We have a table data set, so let's start with QAbstractTableModel since it + is easier to use. -QAbstractTableModel requires the implementation of three abstract methods. + \snippet examples/tutorials/modelview/1_readonly/mymodel.h Quoting ModelView Tutorial + QAbstractTableModel requires the implementation of three abstract methods. --------------------------------------------------------------mymodel.cpp--------------------- \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp Quoting ModelView Tutorial -The number of rows and columns is set by \l{QAbstractItemModel::rowCount()}{MyModel::rowCount()} and \l{QAbstractItemModel::columnCount()}{MyModel::columnCount()}. -When the view has to know what the cell 's text is, it calls the method. Row and column information is specified with parameter \c index and the role is set to \l{Qt::ItemDataRole}{Qt::DisplayRole}. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations. - -This small example demonstrates the passive nature of a model. The model does not know when it will be used or which data is needed. It simply provides data each time the view requests it. - -What happens when the model 's data needs to be changed? How does the view know when data changes and needs to be read again? The model has to emit a signal that indicates what range of cells has changed. This will be demonstrated in section 2.3. + The number of rows and columns is set by + \l{QAbstractItemModel::rowCount()}{MyModel::rowCount()} and + \l{QAbstractItemModel::columnCount()}{MyModel::columnCount()}. + When the view has to know what the cell's text is, it calls the method. + Row and column information is specified with parameter \c index and the + role is set to \l{Qt::ItemDataRole}{Qt::DisplayRole}. Other roles are + covered in the next section. In our example, the data that should be + displayed is generated. In a real application, \c MyModel would have a + member called \c MyData, which serves as the target for all reading and + writing operations. + + This small example demonstrates the passive nature of a model. The model + does not know when it will be used or which data is needed. It simply + provides data each time the view requests it. + + What happens when the model 's data needs to be changed? How does the view + know when data changes and needs to be read again? The model has to emit a + signal that indicates what range of cells has changed. This will be + demonstrated in section 2.3. + + \section2 2.2 Extending the Read Only Example with Roles + + In addition to controlling what text the view displays, the model also + controls the text's appearance. When we slightly change the model, we get + the following result: \image readonlytable_role.png + + In fact, nothing except for the \l{QAbstractItemModel::}{data()} + method needs to be changed to set fonts, background colour, alignment and a + checkbox. + Here is the \l{QAbstractItemModel::data()}{data()} method that produces the + result shown above: -\section2 2.2 Extending the read only example with roles -In addition to controlling what text the view displays, the model also controls the text's appearance. When we slightly change the model, we get the following result: \image readonlytable_role.png - - -In fact, nothing except for the \l{QAbstractItemModel::data()}{data()} method needs to be changed to set fonts, background colour, alignment and a checkbox. Here is the \l{QAbstractItemModel::data()}{data()} method that produces the result shown above: - --------------------------------------------------------------mymodel.cpp--------------------- \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp Quoting ModelView Tutorial -Each formatting property will be requested from the model with a separate call to the \l{QAbstractItemModel::data()}{data()} method. The \c role parameter is used to let the model know which property is being requested: + Each formatting property will be requested from the model with a separate + call to the \l{QAbstractItemModel::data()}{data()} method. The \c role + parameter is used to let the model know which property is being requested: \table \header @@ -214,114 +310,194 @@ Each formatting property will be requested from the model with a separate call t \o text alignment \o enum Qt::AlignmentFlag \row - \o {1, 3} Qt::CheckStateRole - \o {1, 3} suppresses checkboxes with \l{QVariant}{QVariant()}, sets checkboxes with Qt::Checked or Qt::Unchecked - \o {1, 3} \l{Qt::ItemDataRole}{enum Qt::ItemDataRole} - + \o {1, 3} Qt::CheckStateRole + \o {1, 3} suppresses checkboxes with \l{QVariant}{QVariant()}, + sets checkboxes with Qt::Checked or Qt::Unchecked + \o {1, 3} \l{Qt::ItemDataRole}{enum Qt::ItemDataRole} \endtable -Refer to Qt documentation to learn more about enum Qt::ItemDataRole's capabilities. + Refer to the Qt namespace documentation to learn more about the + Qt::ItemDataRole enum's capabilities. + Now we need to determine how using a seperated model impacts the + application's performance, so let's trace how often the view calls the + \l{QAbstractItemModel::}{data()} method. In order to track how often + the view calls the model, we have put a debug statement in the + \l{QAbstractItemModel::}{data()} method, which logs onto stdio. In + our small example, \l{QAbstractItemModel::}{data()} will be called 42 + times. + Each time you hover the cursor over the field, + \l{QAbstractItemModel::}{data()} will be called again \mdash 7 times for + each cell. That's why it is important to make sure that your data is + available when \l{QAbstractItemModel::}{data()} is invoked and expensive + lookup operations are cached. -Now we need to determine how using a seperated model impacts the application's performance, so let's trace how often the view calls the \l{QAbstractItemModel::data()}{data()} method. In order to track how often the view calls the model, we have put a debug statement in the \l{QAbstractItemModel::data()}{data()} method, which logs onto stdio. In our small example, \l{QAbstractItemModel::data()}{data()} will be called 42 times. Each time you hover the cursor over the field, \l{QAbstractItemModel::data()}{data()} will be called again - 7 times for each cell. That's why it is important to make sure that your data is available when \l{QAbstractItemModel::data()}{data()} is invoked and expensive lookup operations are cached. + \section2 2.3 A Clock inside a Table Cell -\section2 2.3 A clock inside a table cell -\image clock.png + \image clock.png -We still have a read only table, but this time the content changes every second because we are showing the current time. + We still have a read only table, but this time the content changes every + second because we are showing the current time. \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_QVariant -Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal. + Something is missing to make the clock tick. We need to tell the view every + second that the time has changed and that it needs to be read again. We do + this with a timer. In the constructor, we set its interval to 1 second and + connect its timeout signal. \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_a -Here is the corresponding slot: + Here is the corresponding slot: \snippet examples/tutorials/modelview/3_changingmodel/mymodel.cpp quoting mymodel_b -We ask the view to read the data in the top left cell again by emitting the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal. Note that we did not explicitly connect the \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal to the view. This happened automatically when we called \l{QTableView::setModel()}{setModel()}. + We ask the view to read the data in the top left cell again by emitting the + \l{QAbstractItemModel::}{dataChanged()} signal. Note that we did not + explicitly connect the \l{QAbstractItemModel::}{dataChanged()} signal to + the view. This happened automatically when we called + \l{QTableView::}{setModel()}. -\section2 2.4 Setting up Headers for Columns and Rows -Headers can be hidden via a view method. -\c tableView->verticalHeader()->hide(); -\image header.png + \section2 2.4 Setting up Headers for Columns and Rows + Headers can be hidden via a view method: \c{tableView->verticalHeader()->hide();} + \image header.png -The header content, however, is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method: + The header content, however, is set via the model, so we reimplement the + \l{QAbstractItemModel::headerData()}{headerData()} method: \snippet examples/tutorials/modelview/4_headers/mymodel.cpp quoting mymodel_c -\section2 2.5 The minimal Editing example -In this example, we are going to build an application that automatically populates a window title with content by repeating values entered into table cells. + \section2 2.5 The Minimal Editing Example + + In this example, we are going to build an application that automatically + populates a window title with content by repeating values entered into + table cells. + + The model decides whether editing capabilities are available . We only have + to modify the model in order for the available editing capabilities to be + enabled. This is done by reimplementing the following virtual methods: + \l{QAbstractItemModel::}{setData()} and \l{QAbstractItemModel::}{flags()}. -The model decides whether editing capabilities are available . We only have to modify the model in order for the available editing capabilities to be enabled. This is done by reimplementing the following virtual methods: \l{QAbstractItemModel::setData()}{setData()} and \l{QAbstractItemModel::flags()}{flags()}. --------------------------------------------------------------mymodel.h--------------------- \snippet examples/tutorials/modelview/5_edit/mymodel.h Quoting ModelView Tutorial -We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title. + We use \c QStringList m_gridData to store our data. This makes + \c m_gridData the core of MyModel. The rest of \c MyModel acts like a + wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We + have also introduced the \c editCompleted() signal, + which makes it possible to transfer the modified text to the window title. \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_d -In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table) + In the constructor, we fill \c QStringList gridData with 6 items (one item + for every field in the table): + \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_e -\l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole. - \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_f + \l{QAbstractItemModel::setData()}{setData()} will be called each time the + user edits a cell. The \c index parameter tells us which field has been + edited and \c value provides the result of the editing process. The role + will always be set to \c Qt::EditRole because our cells only contain text. + If a checkbox were present and user permissions are set to allow the + checkbox to be selected, calls would also be made with the role set to + \c Qt::CheckStateRole. -Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | \c Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read. + \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_f + Various properties of a cell can be adjusted with + \l{QAbstractItemModel::flags()}{flags()}. Returning + \c Qt::ItemIsEditable | \c Qt::ItemIsEnabled is enough to show an editor + that a cell has been selected. If editing one cell modifies more data than + the data in that particular cell, the model must emit a + \l{QAbstractItemModel::}{dataChanged()} signal in order for the data that + has been changed to be read. */ /*! \page modelview-part3.html - \title ModelView Chapter 3 - Intermediate Topics - \raw HTML -
- \endraw -\section1 3 Intermediate Topics - \raw HTML -
- \endraw -\section2 3.1 TreeView + \contentspage {modelview-index.html}{Model/View Contents} + \previouspage {modelview-part2.html}{Developing a Simple Model/View Application} + \nextpage {modelview-part4.html}{Good Sources of Additional Information} + \title Model/View Chapter 3 - Intermediate Topics + + \section1 3. Intermediate Topics + + \section2 3.1 TreeView -You can convert the example above into an application with a tree view. Simply replace QTableView with QTreeView, which results in a read/write tree. No changes have to be made to the model. The tree won't have any hierarchies because there aren't any hierarchies in the model itself. -\image dummy_tree.png + You can convert the example above into an application with a tree view. + Simply replace QTableView with QTreeView, which results in a read/write + tree. No changes have to be made to the model. The tree won't have any + hierarchies because there aren't any hierarchies in the model itself. + \image dummy_tree.png -QListView, QTableView and QTreeView all use a model abstraction, which is a merged list, table and tree. This makes it possible to use several different types of view classes from the same model. -\image list_table_tree.png + QListView, QTableView and QTreeView all use a model abstraction, which is a + merged list, table and tree. This makes it possible to use several different + types of view classes from the same model. + \image list_table_tree.png -This is how our example model looks so far: -\image example_model.png + This is how our example model looks so far: + \image example_model.png -We want to present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with \l{QStandardItem}{QStandardItems}, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png --------------------------------------------------------------modelview.cpp--------------------- + We want to present a real tree. We have wrapped our data in the examples + above in order to make a model. This time we use QStandardItemModel, which + is a container for hierarchical data that also implements + QAbstractItemModel. To show a tree, QStandardItemModel must be populated + with \l{QStandardItem}{QStandardItems}, which are able to hold all the + standard properties of items like text, fonts, checkboxes or brushes. + \image tree_2_with_algorithm.png + \snippet examples/tutorials/modelview/6_treeview/modelview.cpp Quoting ModelView Tutorial -We simply instantiate a QStandardItemModel and add a couple of \l{QStandardItem}{QStandardItems} to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other \l{QStandardItem}{QStandardItems}. Nodes are collapsed and expanded within the view. + We simply instantiate a QStandardItemModel and add a couple of + \l{QStandardItem}{QStandardItems} to the constructor. We can then make a + hierarchical data structure because a QStandardItem can hold other + \l{QStandardItem}{QStandardItems}. Nodes are collapsed and expanded within + the view. -\section2 3.2 Working with selection + \section2 3.2 Working with Selections + We want to access a selected item's content in order to output it into the + window title together with the hierarchy level. + \image selection2.png -We want to access a selected item's content in order to output it into the window title together with the hierarchy level. -\image selection2.png + So let's create a couple of items: -So let's create a couple of items: \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_a -Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemView::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemView::selectionChanged()}{selectionChanged()} signal. - \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_b + Views manage selections within a separate selection model, which can be + retrieved with the \l{QAbstractItemView::}{selectionModel()} + method. We retrieve the selection Model in order to connect a slot to its + \l{QAbstractItemView::}{selectionChanged()} signal. -We get the model index that corresponds to the selection by calling -\l{QItemSelectionModel::currentIndex()}{treeView->selectionModel()->currentIndex()} and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed \l{QModelIndex}{QModelIndex()}. This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration. + \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_b -The selection model (as shown above) can be retrieved, but it can also be set with \l{QAbstractItemView}{QAbstractItemView::setSelectionModel}. This is how it's possible to have 3 view classes with synchronised selections because only one instance of a selection model is used. The instance of a selection model is retrieved from the first view class with \l{QAbstractItemView::selectionModel()}{selectionModel()} and the result is assigned to the second and third view class with \l{QAbstractItemView::setSelectionModel()}{setSelectionModel()}; -\section2 3.3 Predefined Models -The typical way to use model/view is to wrap specific data to make it usable with view classes. Qt, however, also provides predefined models for common underlying data structures. If one of the available data structures is suitable for your application, a predefined model can be a good choice. + We get the model index that corresponds to the selection by calling + \l{QItemSelectionModel::currentIndex()}{treeView->selectionModel()->currentIndex()} + and we get the the field's string by using the model index. Then we just + calculate the item's \c hierarchyLevel. Top level items do not have + parents and the \l{QAbstractItemModel::}{parent()} method will return a + default constructed \l{QModelIndex}{QModelIndex()}. This is why we use the + \l{QAbstractItemModel::}{parent()} method to iterate to the top level while + counting the steps performed during iteration. + + The selection model (as shown above) can be retrieved, but it can also be + set with \l{QAbstractItemView}{QAbstractItemView::setSelectionModel}. This + is how it's possible to have 3 view classes with synchronised selections + because only one instance of a selection model is used. The instance of a + selection model is retrieved from the first view class with + \l{QAbstractItemView::}{selectionModel()} and the result is assigned to the + second and third view class with \l{QAbstractItemView::}{setSelectionModel()}. + + \section2 3.3 Predefined Models + + The typical way to use model/view is to wrap specific data to make it + usable with view classes. Qt, however, also provides predefined models for + common underlying data structures. If one of the available data structures + is suitable for your application, a predefined model can be a good choice. \table \row @@ -331,11 +507,8 @@ The typical way to use model/view is to wrap specific data to make it usable wit \o QStandardItemModel \o Stores arbitrary hierarchical items \row - \o QFileSystemModel - \raw HTML -
- \endraw - QDirModel + \o QFileSystemModel\br + QDirModel \o Encapsulate the local file system \row \o QSqlQueryModel @@ -352,108 +525,144 @@ The typical way to use model/view is to wrap specific data to make it usable wit \endtable -\section2 3.4 Delegates -In all examples so far, data is presented as text or a checkbox in a cell and is edited as text or a checkbox. The component that provides these presentation and editing services is called a “delegate.” We are only just beginning to work with the delegate because the view uses a default delegate. But imagine that we want to have a different editor.(e.g. a slider or a drop down list) Or imagine that we want to present data as graphics. Let's take a look at an example called Stardelegate, ( \l{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html}{http://qt.nokia.com/doc/4.6/itemviews-stardelegate.html} ) in which stars are used to show a rating: \image stardelegate.png - -The view has a method that replaces the default delegate and installs a custom delegate. This method is called \l{QAbstractItemView::setItemDelegate()}{setItemDelegate()}. A new delegate can be written by creating a class that inherits from QStyledItemDelegate. In order to write a delegate that displays stars and has no input capabilities, we only need to overwrite 2 methods. - -\code - class StarDelegate : public QStyledItemDelegate - { - Q_OBJECT - public: - StarDelegate(QWidget *parent = 0); - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, + \section2 3.4 Delegates + + In all examples so far, data is presented as text or a checkbox in a cell + and is edited as text or a checkbox. The component that provides these + presentation and editing services is called a \e delegate. We are only just + beginning to work with the delegate because the view uses a default + delegate. But imagine that we want to have a different editor.(e.g. a + slider or a drop down list) Or imagine that we want to present data as + graphics. Let's take a look at an example called + \l{Star Delegate Example}{Star Delegate}, in which stars are used to show + a rating: + \image stardelegate.png + + The view has a method that replaces the default delegate and installs a + custom delegate. This method is called + \l{QAbstractItemView::}{setItemDelegate()}. A new delegate can be written + by creating a class that inherits from QStyledItemDelegate. In order to + write a delegate that displays stars and has no input capabilities, we only + need to overwrite 2 methods. + + \code + class StarDelegate : public QStyledItemDelegate + { + Q_OBJECT + public: + StarDelegate(QWidget *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - }; - -\endcode - -\l{QStyledItemDelegate::paint()}{paint()} draws stars depending on the content of the underlying data. The data can be looked up with parameter \l{QModelIndex::data()}{index.data()}. \l{QAbstractItemDelegate::sizeHint()}{sizeHint} specifies the stars dimensions so the the cell will provide enough height and width to accommodate the stars. + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const; + }; + \endcode -Writing custom delegates is the right choice if you want to show your data with a custom graphical representation inside the grid of the view class. If you want to leave the grid, you can write a custom view class. + \l{QStyledItemDelegate::}{paint()} draws stars depending on the content + of the underlying data. The data can be looked up with parameter + \l{QModelIndex::data()}{index.data()}. + \l{QAbstractItemDelegate::}{sizeHint()} specifies each star's dimensions + so the the cell will provide enough height and width to accommodate the + stars. -\section2 3.5 Debugging with ModelTest -The passive nature of models provides new challenges for programmers. Inconsistencies in the model can cause the application to crash. Since the model is hit by numerous calls from the view, it is hard to find out which call has crashed the application and which operation has introduced the problem. + Writing custom delegates is the right choice if you want to show your data + with a custom graphical representation inside the grid of the view class. + If you want to leave the grid, you can write a custom view class. -Qt provides software called ModelTest, which checks models while your programming is running. Every time the model is changed, ModelTest scans the model and reports errors with an assert. This is especially important for tree models, since their hierarchical nature leaves many possibilities for subtle inconsistencies. \l http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest + \section2 3.5 Debugging with ModelTest -Unlike view classes, ModelTest uses out of range indexes to test the model. This means your application may crash with ModelTest even if it runs perfectly without it. So you also need to handle all of the indexes that are out of range when using ModelTest. + The passive nature of models provides new challenges for programmers. + Inconsistencies in the model can cause the application to crash. Since the + model is hit by numerous calls from the view, it is hard to find out which + call has crashed the application and which operation has introduced the + problem. + Qt provides software called + \l{http://labs.qt.nokia.com/page/Projects/Itemview/Modeltest}{ModelTest}, + which checks models while your programming is running. Every time the model + is changed, ModelTest scans the model and reports errors with an assert. + This is especially important for tree models, since their hierarchical + nature leaves many possibilities for subtle inconsistencies. - -\raw HTML -
-\endraw + Unlike view classes, ModelTest uses out of range indexes to test the model. + This means your application may crash with ModelTest even if it runs + perfectly without it. So you also need to handle all of the indexes that + are out of range when using ModelTest. + \section2 3.6 Model/View NG + \raw HTML + +
+ \endraw + \raw HTML + + \endraw -\section2 3.6 Model/View NG + Model/View was introduced in Qt 4.0 and is a frequently used technology. + Feedback from developers and new development trends have shown that there + is a need to further develop the model/view technology. Therefore a + research project originated at Nokia is looking into ways to go beyond the + current implementation. + + One limitation of model/view is that view classes are basically all fixed + grids. It is possible, but really hard to make a list view with icons + placed on a curve; or cells expanding on mouse over events to show + additional information. + In order to achieve graphically rich view experiences, Model/View NG will + use QGraphicsView to render elements. Nodel/View NG also aims to make + model/view programming more intuitive. One way to achieve this is to have + separate models for lists, tables and trees. The current model abstraction + is complex because it is capable of representing a list, a table or a tree. + + Model/View NG is a research project. You are welcome to checkout the source + code, monitor progress and take part in discussions at the following + address: \l{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG} -\raw HTML - -
-\endraw + \raw HTML + + \endraw -\raw HTML - -\endraw + \inlineimage path.png -Model/View was introduced in Qt 4.0 and is a frequently used technology. Feedback from clients and new development trends have shown, that there is a need to further develop the model/view technology. Therefore a research project at Nokia is looking into ways to go beyond the current implementation. -\raw HTML -
-\endraw -One limitation of model/view is that view classes are basically all fixed grids. It is possible, but really hard to make a list view with icons placed on a curve; or cells expanding on mouse over events to show additional information. In order to achieve graphically rich view experiences, Model/View NG will use QGraphicsView to render elements. Nodel/View NG also aims to make model/view programming more intuitive. One way to achieve this is to have separate models for lists, tables and trees. The current model abstraction is complex because it is capable of representing a list, a table or a tree. -\raw HTML -
-\endraw -Model/View NG is a research project. You are welcome to checkout the source code, monitor progress and take part in discussions at the following address: \l{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG}{http://labs.qt.nokia.com/page/Projects/Itemview/ItemviewsNG} + \raw HTML +
+ \endraw +*/ -\raw HTML -
-\endraw +/*! + \page modelview-part4.html + \contentspage {modelview-index.html}{Model/View Contents} + \previouspage {modelview-part3.html}{Intermediate Topics} + \title Model/View Chapter 4 - Good Sources of Additional Information -\inlineimage path.png + \section1 4. Good Sources of Additional Information -\raw HTML -
-\endraw -\raw HTML -
-\endraw + \section2 4.1 Books -*/ + Model/View programming is covered quite extensively in the documentation of + Qt but also in several good books. -/*! - \page modelview-part4.html - - \title ModelView Chapter 4 - Good Sources for Additional Information - - \raw HTML -
- \endraw -\section1 4 Good Sources for Additional Information -\raw HTML -
-\endraw -\section2 4.1 Books -Model/View programming is covered quite extensively in the documentation of Qt but also in several good books. \list 1 - \o C++ GUI Programming with Qt 4 / Jasmin Blanchette, Mark Summerfield, Prentice Hall, 2nd edition, ISBN 0-13-235416-0 -also available in German: C++ GUI Programmierung mit Qt 4: Die offizielle Einführung, Addison-Wesley, ISBN 3-827327-29-6 - \o The Book of Qt4, The Art of Building Qt Applications / Daniel Molkentin, Open Source Press ISBN 1-59327-147-6 -Translated from: Qt 4, Einführung in die Applikationsentwicklung, Open Source Press, ISBN 3-937514-12-0 - \o Foundations of Qt Development / Johan Thelin, Apress, ISBN 1-59059-831-8 + \o \bold{C++ GUI Programming with Qt 4} / Jasmin Blanchette, Mark Summerfield, + \e{Prentice Hall, 2nd edition}, ISBN 0-13-235416-0. Also available in + German: C++ GUI Programmierung mit Qt 4: Die offizielle Einführung, + \e{Addison-Wesley}, ISBN 3-827327-29-6 + \o \bold{The Book of Qt4, The Art of Building Qt Applications} / Daniel Molkentin, + \e{Open Source Press}, ISBN 1-59327-147-6. + Translated from \bold{Qt 4, Einführung in die Applikationsentwicklung}, + \e{Open Source Press}, ISBN 3-937514-12-0. + \o \bold{Foundations of Qt Development} / Johan Thelin, \e{Apress}, ISBN 1-59059-831-8. \endlist -\raw HTML -
-\endraw -The following list provides an overview of example programs contained in the books above. Some of them make very good templates for developing similar applications. + More information about these books is available on the + \l{Books about Qt Programming}{Qt Web site}. + + The following list provides an overview of example programs contained in the + books above. Some of them make very good templates for developing similar + applications. \table \header @@ -461,45 +670,45 @@ The following list provides an overview of example programs contained in the boo \o view class used \o model used \o aspects touched - \o + \o \row \o Team Leaders \o QListview \o QStringListModel - \o + \o \o Book 1, Chapter 10, Figure 10.6 \row \o Directory Viewer \o QTreeView \o QDirModel - \o + \o \o Book 1, Chapter 10, Figure 10.7 \row \o Color Names \o QListView \o QSortFilterProxyModel -applied to QStringListModel - \o + applied to QStringListModel + \o \o Book 1, Chapter 10, Figure 10.8 \row \o Currencies \o QTableView \o custom model based on -QAbstractTableModel + QAbstractTableModel \o read only \o Book 1, Chapter 10, Figure 10.10 \row \o Cities \o QTableView \o custom model based on -QAbstractTableModel + QAbstractTableModel \o read / write \o Book 1, Chapter 10, Figure 10.12 \row \o Boolean Parser \o QTreeView \o custom model based on -QAbstractItemModel + QAbstractItemModel \o read only \o Book 1, Chapter 10, Figure 10.14 \row @@ -511,141 +720,129 @@ QAbstractItemModel \row \o Four directory views \o QListView -QTableView -QTreeView + QTableView + QTreeView \o QDirModel \o demonstrates the use of multiple views \o Book2, Chapter 8.2 \row \o Address Book \o QListView -QTableView -QTreeView + QTableView + QTreeView \o custom model based on -QAbstractTableModel + QAbstractTableModel \o read / write \o Book2, Chapter 8.4 \row \o Address Book with sorting - \o + \o \o QProxyModel \o introducing sort and filter capabilities \o Book2, Chapter 8.5 \row - \o Address Book -with checkboxes - \o - \o - \o introducing checkboxes -in model/view + \o Address Book + with checkboxes + \o + \o + \o introducing checkboxes in model/view \o Book2, Chapter 8.6 \row - \o Address Book -with transposed grid - \o + \o Address Book with transposed grid + \o \o custom proxy Model based on QAbstractProxyModel \o introducing a custom model \o Book2, Chapter 8.7 \row - \o Address Book -with drag and drop - \o - \o + \o Address Book with drag and drop + \o + \o \o introducing drag and drop support \o Book2, Chapter 8.8 \row \o Address Book with custom editor - \o - \o + \o + \o \o introducing custom delegates \o Book2, Chapter 8.9 \row \o Views \o QListView -QTableView -QTreeView + QTableView + QTreeView \o QStandardItemModel \o read only \o Book 3, Chapter 5, figure 5-3 \row \o Bardelegate \o QTableView - \o + \o \o custom delegate for presentation based on QAbstractItemDelegate \o Book 3, Chapter 5, figure 5-5 \row \o Editdelegate \o QTableView - \o + \o \o custom delegate for editing based on QAbstractItemDelegate \o Book 3, Chapter 5, figure 5-6 \row \o Singleitemview - \o custom view based on -QAbstractItemView - \o + \o custom view based on QAbstractItemView + \o \o custom view \o Book 3, -Chapter 5, -figure 5-7 + Chapter 5, + figure 5-7 \row \o listmodel \o QTableView - \o custom Model based on -QAbstractTableModel + \o custom Model based on QAbstractTableModel \o read only - \o Book 3, -Chapter 5, -Figure 5-8 + \o Book 3, Chapter 5, Figure 5-8 \row \o treemodel \o QTreeView - \o custom Model based on -QAbstractItemModel + \o custom Model based on QAbstractItemModel \o read only - \o Book 3, -Chapter 5, -Figure 5-10 + \o Book 3, Chapter 5, Figure 5-10 \row \o edit integers \o QListView - \o custom Model based on -QAbstractListModel + \o custom Model based on QAbstractListModel \o read / write - \o Book 3, -Chapter 5, -Listing 5-37, Figure 5-11 + \o Book 3, Chapter 5, Listing 5-37, Figure 5-11 \row \o sorting \o QTableView - \o QSortFilterProxyModel -applied to QStringListModel + \o QSortFilterProxyModel applied to QStringListModel \o demonstrates sorting \o Book 3, Chapter 5, Figure 5-12 - \endtable -\section2 4.2 Qt documentation -Qt 4.6 comes with 17 examples and 2 Demonstrations for model/view. The examples can be found here: \l{http://doc.qt.nokia.com/4.6/examples-itemviews.html}{http://doc.qt.nokia.com/4.6/examples-itemviews.html} + \section2 4.2 Qt Documentation + + Qt 4.7 comes with 17 examples and 2 Demonstrations for model/view. + The examples can be found here: \l{Item Views Examples} \table \header - \o example name - \o view class used - \o model used - \o aspects touched + \o Example name + \o View class used + \o Model used + \o Aspects touched \row \o Address Book \o QTableView \o QAbstractTableModel -QSortFilterProxyModel - \o usage of QSortFilterProxyModel to generate different subsets from one data pool + QSortFilterProxyModel + \o usage of QSortFilterProxyModel to generate different + subsets from one data pool \row \o Basic Sort/Filter Model \o QTreeView \o QStandardItemModel -QSortFilterProxyModel - \o + QSortFilterProxyModel + \o \row \o Chart \o custom view @@ -664,9 +861,8 @@ QSortFilterProxyModel \o Custom Sort/Filter Model \o QTreeView \o QStandardItemModel -QSortFilterProxyModel - \o subclass QSortFilterProxyModel -for advanced sorting and filtering + QSortFilterProxyModel + \o subclass QSortFilterProxyModel for advanced sorting and filtering \row \o Dir View \o QTreeView @@ -676,17 +872,19 @@ for advanced sorting and filtering \o Editable Tree Model \o QTreeView \o custom tree model - \o comprehensive example for working with trees, demonstrates editing cells and tree structure with an underlying custom model + \o comprehensive example for working with trees, demonstrates + editing cells and tree structure with an underlying custom + model \row \o Fetch More \o QListView \o custom list model - \o dynamically changing model + \o dynamically changing model \row \o Frozen Column \o QTableView \o QStandardItemModel - \o + \o \row \o Pixelator \o QTableView @@ -723,13 +921,18 @@ for advanced sorting and filtering \o comprehensive custom delegate example. \endtable -Demonstrations are similar to examples except that no walk-through is provided for the code lines. Demonstrations are also sometimes more feature rich. - \l{http://doc.qt.nokia.com/4.6/demos.html}{http://doc.qt.nokia.com/4.6/demos.html} + \l{Qt Demonstrations}{Demonstrations} are similar to examples except + that no walkthrough is provided for the code. Demonstrations are also + sometimes more feature rich. + \list - \o The \bold Interview demonstration shows the same model and selection being shared between three different views. - \o Demonstration \bold Spreadsheet demonstrates the use of a table view as a spreadsheet, using custom delegates to render each item according to the type of data it contains. + \o The \bold Interview demonstration shows the same model and + selection being shared between three different views. + \o Demonstration \bold Spreadsheet demonstrates the use of a + table view as a spreadsheet, using custom delegates to render + each item according to the type of data it contains. \endlist -A reference documentation for model/view technology is also available. \l{http://doc.qt.nokia.com/4.6/model-view-programming.html}{http://doc.qt.nokia.com/4.6/model-view-programming.html} - -*/ \ No newline at end of file + A \l{Model/View Programming}{reference document} for model/view technology + is also available. +*/ diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp index ad11f38..fb4726a 100755 --- a/examples/tutorials/modelview/1_readonly/main.cpp +++ b/examples/tutorials/modelview/1_readonly/main.cpp @@ -39,6 +39,7 @@ ****************************************************************************/ //! [Quoting ModelView Tutorial] +// main.cpp #include #include "modelview.h" diff --git a/examples/tutorials/modelview/1_readonly/modelview.cpp b/examples/tutorials/modelview/1_readonly/modelview.cpp index 027be56..91a97bf 100755 --- a/examples/tutorials/modelview/1_readonly/modelview.cpp +++ b/examples/tutorials/modelview/1_readonly/modelview.cpp @@ -39,6 +39,7 @@ ****************************************************************************/ //! [Quoting ModelView Tutorial] +// modelview.cpp #include #include "modelview.h" #include "mymodel.h" @@ -48,6 +49,6 @@ ModelView::ModelView(QWidget *parent) { tableView = new QTableView(this); setCentralWidget(tableView); - tableView->setModel(new MyModel(this) ); + tableView->setModel(new MyModel(this)); } -//! [Quoting ModelView Tutorial] \ No newline at end of file +//! [Quoting ModelView Tutorial] diff --git a/examples/tutorials/modelview/1_readonly/modelview.h b/examples/tutorials/modelview/1_readonly/modelview.h index d0f96cd..9307083 100755 --- a/examples/tutorials/modelview/1_readonly/modelview.h +++ b/examples/tutorials/modelview/1_readonly/modelview.h @@ -38,11 +38,11 @@ ** ****************************************************************************/ -//! [Quoting ModelView Tutorial] #ifndef MODELVIEW_H #define MODELVIEW_H - +//! [Quoting ModelView Tutorial] +// modelview.h #include class QTableView; //forward declaration @@ -56,6 +56,6 @@ public: ModelView(QWidget *parent = 0); }; +//! [Quoting ModelView Tutorial] #endif // MODELVIEW_H -//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp index c441720..394605a 100755 --- a/examples/tutorials/modelview/1_readonly/mymodel.cpp +++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp @@ -39,6 +39,7 @@ ****************************************************************************/ //! [Quoting ModelView Tutorial] +// mymodel.cpp #include "mymodel.h" MyModel::MyModel(QObject *parent) @@ -46,22 +47,19 @@ MyModel::MyModel(QObject *parent) { } -//------------------------------------------------------- -int MyModel::rowCount(const QModelIndex & /*parent*/ ) const +int MyModel::rowCount(const QModelIndex & /*parent*/) const { return 2; } -//------------------------------------------------------- -int MyModel::columnCount(const QModelIndex & /*parent*/ ) const +int MyModel::columnCount(const QModelIndex & /*parent*/) const { return 3; } -//------------------------------------------------------- -QVariant MyModel::data(const QModelIndex &index, int role ) const +QVariant MyModel::data(const QModelIndex &index, int role) const { - if(role == Qt::DisplayRole) + if (role == Qt::DisplayRole) { return QString("Row%1, Column%2") .arg(index.row() + 1) @@ -69,4 +67,4 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const } return QVariant(); } -//! [Quoting ModelView Tutorial] \ No newline at end of file +//! [Quoting ModelView Tutorial] diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h index c0ddf4ac6..6065f6e 100755 --- a/examples/tutorials/modelview/1_readonly/mymodel.h +++ b/examples/tutorials/modelview/1_readonly/mymodel.h @@ -38,10 +38,11 @@ ** ****************************************************************************/ -//! [Quoting ModelView Tutorial] #ifndef MYMODEL_H #define MYMODEL_H +//! [Quoting ModelView Tutorial] +// mymodel.h #include class MyModel : public QAbstractTableModel @@ -53,6 +54,6 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; }; +//! [Quoting ModelView Tutorial] #endif // MYMODEL_H -//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/2_formatting/modelview.cpp b/examples/tutorials/modelview/2_formatting/modelview.cpp index 2b05d4c..9a5ce64 100755 --- a/examples/tutorials/modelview/2_formatting/modelview.cpp +++ b/examples/tutorials/modelview/2_formatting/modelview.cpp @@ -47,6 +47,6 @@ ModelView::ModelView(QWidget *parent) { tableView = new QTableView(this); setCentralWidget(tableView); - tableView->setModel(new MyModel(this) ); + tableView->setModel(new MyModel(this)); } diff --git a/examples/tutorials/modelview/2_formatting/mymodel.cpp b/examples/tutorials/modelview/2_formatting/mymodel.cpp index e9e68de..e34e014 100755 --- a/examples/tutorials/modelview/2_formatting/mymodel.cpp +++ b/examples/tutorials/modelview/2_formatting/mymodel.cpp @@ -44,25 +44,23 @@ #include //! [Quoting ModelView Tutorial] +// mymodel.cpp MyModel::MyModel(QObject *parent) :QAbstractTableModel(parent) { } -//------------------------------------------------------- -int MyModel::rowCount(const QModelIndex & /*parent */ ) const +int MyModel::rowCount(const QModelIndex & /*parent */) const { return 2; } -//------------------------------------------------------- -int MyModel::columnCount(const QModelIndex & /*parent */ ) const +int MyModel::columnCount(const QModelIndex & /*parent */) const { return 3; } -//------------------------------------------------------- -QVariant MyModel::data(const QModelIndex &index, int role ) const +QVariant MyModel::data(const QModelIndex &index, int role) const { int row = index.row(); int col = index.column(); @@ -72,15 +70,15 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const switch(role){ case Qt::DisplayRole: - if(row == 0 && col == 1 )return QString("<--left"); - if(row == 1 && col == 1 )return QString("right-->"); + if (row == 0 && col == 1) return QString("<--left"); + if (row == 1 && col == 1) return QString("right-->"); return QString("Row%1, Column%2") .arg(row + 1) .arg(col +1); break; case Qt::FontRole: - if(row == 0 && col ==0 ) //change font only for cell(0,0) + if (row == 0 && col == 0) //change font only for cell(0,0) { QFont boldFont; boldFont.setBold(true); @@ -89,7 +87,7 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const break; case Qt::BackgroundRole: - if(row == 1 && col ==2 ) //change background only for cell(1,2) + if (row == 1 && col == 2) //change background only for cell(1,2) { QBrush redBackground(QColor(Qt::red)); return redBackground; @@ -97,14 +95,14 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const break; case Qt::TextAlignmentRole: - if(row == 1 && col ==1 ) //change text alignment only for cell(1,1) + if (row == 1 && col == 1) //change text alignment only for cell(1,1) { return Qt::AlignRight + Qt::AlignVCenter; } break; case Qt::CheckStateRole: - if(row == 1 && col ==0 ) //add a checkbox to cell(1,0) + if (row == 1 && col == 0) //add a checkbox to cell(1,0) { return Qt::Checked; } diff --git a/examples/tutorials/modelview/3_changingmodel/modelview.cpp b/examples/tutorials/modelview/3_changingmodel/modelview.cpp index 2b05d4c..9a5ce64 100755 --- a/examples/tutorials/modelview/3_changingmodel/modelview.cpp +++ b/examples/tutorials/modelview/3_changingmodel/modelview.cpp @@ -47,6 +47,6 @@ ModelView::ModelView(QWidget *parent) { tableView = new QTableView(this); setCentralWidget(tableView); - tableView->setModel(new MyModel(this) ); + tableView->setModel(new MyModel(this)); } diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp index d806945..42915b0 100755 --- a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp +++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -50,32 +50,32 @@ MyModel::MyModel(QObject *parent) // selectedCell = 0; timer = new QTimer(this); timer->setInterval(1000); - connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) ); + connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit())); timer->start(); } //! [quoting mymodel_a] //------------------------------------------------------- -int MyModel::rowCount(const QModelIndex & /*parent */ ) const +int MyModel::rowCount(const QModelIndex & /*parent */) const { return 2; } //------------------------------------------------------- -int MyModel::columnCount(const QModelIndex & /*parent */ ) const +int MyModel::columnCount(const QModelIndex & /*parent */) const { return 3; } //------------------------------------------------------- //! [quoting mymodel_QVariant ] -QVariant MyModel::data(const QModelIndex &index, int role ) const +QVariant MyModel::data(const QModelIndex &index, int role) const { int row = index.row(); int col = index.column(); - if(role == Qt::DisplayRole) + if (role == Qt::DisplayRole) { - if(row == 0 && col == 0 ) + if (row == 0 && col == 0) { return QTime::currentTime().toString(); } @@ -88,8 +88,8 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const void MyModel::timerHit() { //we identify the top left cell - QModelIndex topLeft = createIndex ( 0,0 ); + QModelIndex topLeft = createIndex(0,0); //emit a signal to make the view reread identified data - emit dataChanged ( topLeft, topLeft ); + emit dataChanged(topLeft, topLeft); } //! [quoting mymodel_b ] diff --git a/examples/tutorials/modelview/4_headers/modelview.cpp b/examples/tutorials/modelview/4_headers/modelview.cpp index f661ab5..449dbbc 100755 --- a/examples/tutorials/modelview/4_headers/modelview.cpp +++ b/examples/tutorials/modelview/4_headers/modelview.cpp @@ -48,7 +48,7 @@ ModelView::ModelView(QWidget *parent) { tableView = new QTableView(this); setCentralWidget(tableView); - tableView->setModel(new MyModel(this) ); + tableView->setModel(new MyModel(this)); tableView->verticalHeader()->hide(); } diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp index 94fde34..e6f977d 100755 --- a/examples/tutorials/modelview/4_headers/mymodel.cpp +++ b/examples/tutorials/modelview/4_headers/mymodel.cpp @@ -46,21 +46,21 @@ MyModel::MyModel(QObject *parent) } //------------------------------------------------------- -int MyModel::rowCount(const QModelIndex & /*parent*/ ) const +int MyModel::rowCount(const QModelIndex & /*parent*/) const { return 2; } //------------------------------------------------------- -int MyModel::columnCount(const QModelIndex & /*parent*/ ) const +int MyModel::columnCount(const QModelIndex & /*parent*/) const { return 3; } //------------------------------------------------------- -QVariant MyModel::data(const QModelIndex &index, int role ) const +QVariant MyModel::data(const QModelIndex &index, int role) const { - if(role == Qt::DisplayRole) + if (role == Qt::DisplayRole) { return QString("Row%1, Column%2") .arg(index.row() + 1) @@ -88,4 +88,4 @@ QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) } return QVariant(); } -//! [quoting mymodel_c] \ No newline at end of file +//! [quoting mymodel_c] diff --git a/examples/tutorials/modelview/5_edit/modelview.cpp b/examples/tutorials/modelview/5_edit/modelview.cpp index d8853c9..a6c6ef5 100755 --- a/examples/tutorials/modelview/5_edit/modelview.cpp +++ b/examples/tutorials/modelview/5_edit/modelview.cpp @@ -48,13 +48,13 @@ ModelView::ModelView(QWidget *parent) tableView = new QTableView(this); setCentralWidget(tableView); QAbstractTableModel *myModel = new MyModel(this); - tableView->setModel( myModel ); + tableView->setModel(myModel); //transfer changes to the model to the window title - connect(myModel, SIGNAL(editCompleted(const QString &) ), this, SLOT(setWindowTitle(const QString &))); + connect(myModel, SIGNAL(editCompleted(const QString &)), this, SLOT(setWindowTitle(const QString &))); } void ModelView::showWindowTitle(const QString & title) { -setWindowTitle( title ); +setWindowTitle(title); } diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp index 6007da1..67181ca 100755 --- a/examples/tutorials/modelview/5_edit/mymodel.cpp +++ b/examples/tutorials/modelview/5_edit/mymodel.cpp @@ -53,22 +53,19 @@ MyModel::MyModel(QObject *parent) //! [quoting mymodel_d] //! [quoting mymodel_e] -//------------------------------------------------------- -int MyModel::rowCount(const QModelIndex & /*parent*/ ) const +int MyModel::rowCount(const QModelIndex & /*parent*/) const { return ROWS; } -//------------------------------------------------------- -int MyModel::columnCount(const QModelIndex & /*parent*/ ) const +int MyModel::columnCount(const QModelIndex & /*parent*/) const { return COLS; } -//------------------------------------------------------- -QVariant MyModel::data(const QModelIndex &index, int role ) const +QVariant MyModel::data(const QModelIndex &index, int role) const { - if(role == Qt::DisplayRole) + if (role == Qt::DisplayRole) { return m_gridData[modelIndexToOffset(index)]; } @@ -79,23 +76,21 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const //----------------------------------------------------------------- //! [quoting mymodel_f] -bool MyModel::setData ( const QModelIndex & index, const QVariant & value, int role ) +bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role) { - if(role == Qt::EditRole) + if (role == Qt::EditRole) { m_gridData[modelIndexToOffset(index)] = value.toString(); - emit editCompleted(m_gridData.join(" | ") ); + emit editCompleted(m_gridData.join(" | ")); } return true; } -//----------------------------------------------------------------- -Qt::ItemFlags MyModel::flags ( const QModelIndex & /*index*/ ) const +Qt::ItemFlags MyModel::flags(const QModelIndex & /*index*/) const { return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ; } -//----------------------------------------------------------------- //convert row and column information to array offset int MyModel::modelIndexToOffset(const QModelIndex & index) const { diff --git a/examples/tutorials/modelview/5_edit/mymodel.h b/examples/tutorials/modelview/5_edit/mymodel.h index 54f2b30..0d2a1b8 100755 --- a/examples/tutorials/modelview/5_edit/mymodel.h +++ b/examples/tutorials/modelview/5_edit/mymodel.h @@ -38,10 +38,11 @@ ** ****************************************************************************/ -//! [Quoting ModelView Tutorial] #ifndef MYMODEL_H #define MYMODEL_H +//! [Quoting ModelView Tutorial] +// mymodel.h #include #include @@ -53,14 +54,14 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const ; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); - Qt::ItemFlags flags ( const QModelIndex & index ) const ; + bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex & index) const ; private: QStringList m_gridData; //holds text entered into QTableView int modelIndexToOffset(const QModelIndex & index) const; signals: void editCompleted(const QString &); }; +//! [Quoting ModelView Tutorial] #endif // MYMODEL_H -//! [Quoting ModelView Tutorial] \ No newline at end of file diff --git a/examples/tutorials/modelview/6_treeview/modelview.cpp b/examples/tutorials/modelview/6_treeview/modelview.cpp index a25e4e9..772dbdd 100755 --- a/examples/tutorials/modelview/6_treeview/modelview.cpp +++ b/examples/tutorials/modelview/6_treeview/modelview.cpp @@ -39,6 +39,7 @@ ****************************************************************************/ //! [Quoting ModelView Tutorial] +// modelview.cpp #include #include #include @@ -64,14 +65,13 @@ ModelView::ModelView(QWidget *parent) // adding a row to an item starts a subtree preparedColumn.first()->appendRow(secondRow); - treeView->setModel( standardModel ); + treeView->setModel(standardModel); treeView->expandAll(); } -//--------------------------------------------------------------------------- QList ModelView::prepareColumn(const QString &first, const QString &second, - const QString &third ) + const QString &third) { QList colItems; colItems << new QStandardItem(first); @@ -79,4 +79,4 @@ QList ModelView::prepareColumn(const QString &first, colItems << new QStandardItem(third); return colItems; } -//! [Quoting ModelView Tutorial] \ No newline at end of file +//! [Quoting ModelView Tutorial] diff --git a/examples/tutorials/modelview/6_treeview/modelview.h b/examples/tutorials/modelview/6_treeview/modelview.h index 2329e89..a47111c 100755 --- a/examples/tutorials/modelview/6_treeview/modelview.h +++ b/examples/tutorials/modelview/6_treeview/modelview.h @@ -56,7 +56,7 @@ private: QStandardItemModel *standardModel; QList prepareColumn(const QString &first, const QString &second, - const QString &third ); + const QString &third); public: ModelView(QWidget *parent = 0); }; diff --git a/examples/tutorials/modelview/7_selections/modelview.cpp b/examples/tutorials/modelview/7_selections/modelview.cpp index 2ef980d..3b373c6 100755 --- a/examples/tutorials/modelview/7_selections/modelview.cpp +++ b/examples/tutorials/modelview/7_selections/modelview.cpp @@ -74,13 +74,13 @@ ModelView::ModelView(QWidget *parent) italyItem-> appendRow(veronaItem); //register the model - treeView->setModel( standardModel ); + treeView->setModel(standardModel); treeView->expandAll(); //selection changes shall trigger a slot QItemSelectionModel *selectionModel= treeView->selectionModel(); - connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), - this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & ))); + connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)), + this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &))); } //! [quoting modelview_a] @@ -93,7 +93,7 @@ void ModelView::selectionChangedSlot(const QItemSelection & /*newSelection*/, co QString selectedText = index.data(Qt::DisplayRole).toString(); int hierarchyLevel=1; QModelIndex seekRoot = index; - while(seekRoot.parent() != QModelIndex() ) + while(seekRoot.parent() != QModelIndex()) { seekRoot = seekRoot.parent(); hierarchyLevel++; diff --git a/examples/tutorials/modelview/qmake.pro b/examples/tutorials/modelview/qmake.pro deleted file mode 100755 index 7f684ba..0000000 --- a/examples/tutorials/modelview/qmake.pro +++ /dev/null @@ -1,10 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = 1_readonly \ - 2_formatting \ - 3_changingmodel \ - 4_headers \ - 5_edit \ - 6_treeview \ - 7_selections - -- cgit v0.12 From bca7646d81d8c580820cf5f6e52122da6d984c6b Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 16 Jul 2010 09:34:51 +0200 Subject: Network Proxy Query: Fix memleak on OS X Task-number: QTBUG-12106 --- src/network/kernel/qnetworkproxy_mac.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/network/kernel/qnetworkproxy_mac.cpp b/src/network/kernel/qnetworkproxy_mac.cpp index 1e22212..4139a7e 100644 --- a/src/network/kernel/qnetworkproxy_mac.cpp +++ b/src/network/kernel/qnetworkproxy_mac.cpp @@ -157,8 +157,10 @@ QList macQueryInternal(const QNetworkProxyQuery &query) return result; // failed } - if (isHostExcluded(dict, query.peerHostName())) + if (isHostExcluded(dict, query.peerHostName())) { + CFRelease(dict); return result; // no proxy for this host + } // is there a PAC enabled? If so, use it first. CFNumberRef pacEnabled; @@ -222,6 +224,7 @@ QList macQueryInternal(const QNetworkProxyQuery &query) result << https; } + CFRelease(dict); return result; } -- cgit v0.12 From 70ffe96013dcf7b4be11d1fbe850b9bbcf37c741 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 16 Jul 2010 10:40:55 +0200 Subject: Added LatinAmericaAndTheCaribbean country to the doc. Task-number: QTBUG-12063 Reviewed-by: trustme --- src/corelib/tools/qlocale.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index a51ee81..6b1de5e 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -2096,6 +2096,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l) \value Serbia \value SaintBarthelemy \value SaintMartin + \value LatinAmericaAndTheCaribbean \omitvalue LastCountry \sa country() -- cgit v0.12 From 4942890f85e5fa74bf8c37cf7f53f6f3eaf40596 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Mon, 31 May 2010 11:03:24 +0200 Subject: Revert the change in applicationShouldTerminate(). It used to fix an issue during logout but it seems to be fine now. Related issue: QTBUG-6296 Task-number: QTBUG-10993 Reviewed-by: Morten Sorvig --- src/gui/kernel/qcocoaapplicationdelegate_mac.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm index 5dcf613..7a9dc70 100644 --- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm +++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm @@ -196,7 +196,6 @@ static void cleanupCocoaApplicationDelegate() qAppInstance()->quit(); startedQuit = false; } - return NSTerminateNow; } if (qtPrivate->threadData->eventLoops.size() == 0) { -- cgit v0.12 From 790417ac69cd4fa780d6e298567908fc3d7ef6d0 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Fri, 16 Jul 2010 15:33:59 +0200 Subject: Doc: Fixed whitespace issues. Reviewed-by: Trust Me --- examples/itemviews/addressbook/addresswidget.cpp | 2 +- examples/itemviews/addressbook/tablemodel.cpp | 48 ++++++++++++------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/itemviews/addressbook/addresswidget.cpp b/examples/itemviews/addressbook/addresswidget.cpp index e226643..22dfae3 100644 --- a/examples/itemviews/addressbook/addresswidget.cpp +++ b/examples/itemviews/addressbook/addresswidget.cpp @@ -230,7 +230,7 @@ void AddressWidget::writeToFile(QString fileName) return; } - QList< QPair > pairs = table->getList(); + QList< QPair > pairs = table->getList(); QDataStream out(&file); out << pairs; } diff --git a/examples/itemviews/addressbook/tablemodel.cpp b/examples/itemviews/addressbook/tablemodel.cpp index 603c926..e9a08f0 100644 --- a/examples/itemviews/addressbook/tablemodel.cpp +++ b/examples/itemviews/addressbook/tablemodel.cpp @@ -72,13 +72,13 @@ QVariant TableModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); - + if (index.row() >= listOfPairs.size() || index.row() < 0) return QVariant(); - + if (role == Qt::DisplayRole) { QPair pair = listOfPairs.at(index.row()); - + if (index.column() == 0) return pair.first; else if (index.column() == 1) @@ -93,15 +93,15 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation, int ro { if (role != Qt::DisplayRole) return QVariant(); - + if (orientation == Qt::Horizontal) { switch (section) { case 0: return tr("Name"); - + case 1: return tr("Address"); - + default: return QVariant(); } @@ -115,7 +115,7 @@ bool TableModel::insertRows(int position, int rows, const QModelIndex &index) { Q_UNUSED(index); beginInsertRows(QModelIndex(), position, position+rows-1); - + for (int row=0; row < rows; row++) { QPair pair(" ", " "); listOfPairs.insert(position, pair); @@ -129,9 +129,9 @@ bool TableModel::insertRows(int position, int rows, const QModelIndex &index) //! [5] bool TableModel::removeRows(int position, int rows, const QModelIndex &index) { - Q_UNUSED(index); + Q_UNUSED(index); beginRemoveRows(QModelIndex(), position, position+rows-1); - + for (int row=0; row < rows; ++row) { listOfPairs.removeAt(position); } @@ -144,25 +144,25 @@ bool TableModel::removeRows(int position, int rows, const QModelIndex &index) //! [6] bool TableModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (index.isValid() && role == Qt::EditRole) { - int row = index.row(); - - QPair p = listOfPairs.value(row); - - if (index.column() == 0) - p.first = value.toString(); - else if (index.column() == 1) - p.second = value.toString(); + if (index.isValid() && role == Qt::EditRole) { + int row = index.row(); + + QPair p = listOfPairs.value(row); + + if (index.column() == 0) + p.first = value.toString(); + else if (index.column() == 1) + p.second = value.toString(); else return false; - + listOfPairs.replace(row, p); - emit(dataChanged(index, index)); - + emit(dataChanged(index, index)); + return true; - } + } - return false; + return false; } //! [6] @@ -171,7 +171,7 @@ Qt::ItemFlags TableModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::ItemIsEnabled; - + return QAbstractTableModel::flags(index) | Qt::ItemIsEditable; } //! [7] -- cgit v0.12 From 3db1408bb63ada82fb9d5adb4c082e5525d46ab0 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Fri, 16 Jul 2010 15:36:27 +0200 Subject: Doc: Whitespace fixes. Reviewed-by: Trust Me --- doc/src/index.qdoc | 32 ++++++++--------- tools/qdoc3/test/qt.qdocconf | 82 ++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/doc/src/index.qdoc b/doc/src/index.qdoc index 42fd4fc..ca7fef5 100644 --- a/doc/src/index.qdoc +++ b/doc/src/index.qdoc @@ -56,29 +56,29 @@ @@ -103,7 +103,7 @@ - + \endraw */ diff --git a/tools/qdoc3/test/qt.qdocconf b/tools/qdoc3/test/qt.qdocconf index d132771..e4ed1bc 100644 --- a/tools/qdoc3/test/qt.qdocconf +++ b/tools/qdoc3/test/qt.qdocconf @@ -9,7 +9,7 @@ versionsym = version = %VERSION% description = Qt Reference Documentation url = http://qt.nokia.com/doc/4.7 -online = true +online = true sourceencoding = UTF-8 outputencoding = UTF-8 @@ -26,46 +26,46 @@ qhp.Qt.indexRoot = # Files not referenced in any qdoc file (last four are needed by qtdemo) # See also extraimages.HTML qhp.Qt.extraFiles = index.html \ - images/bg_l.png \ - images/bg_l_blank.png \ - images/bg_ll_blank.png \ - images/bg_ul_blank.png \ - images/header_bg.png \ + images/bg_l.png \ + images/bg_l_blank.png \ + images/bg_ll_blank.png \ + images/bg_ul_blank.png \ + images/header_bg.png \ images/bg_r.png \ - images/box_bg.png \ - images/breadcrumb.png \ - images/bullet_gt.png \ - images/bullet_dn.png \ - images/bullet_sq.png \ - images/bullet_up.png \ - images/arrow_down.png \ - images/feedbackground.png \ - images/horBar.png \ - images/page.png \ - images/page_bg.png \ - images/sprites-combined.png \ - images/spinner.gif \ - images/stylesheet-coffee-plastique.png \ - images/taskmenuextension-example.png \ - images/coloreditorfactoryimage.png \ - images/dynamiclayouts-example.png \ - scripts/functions.js \ - scripts/jquery.js \ - scripts/shBrushCpp.js \ - scripts/shCore.js \ - scripts/shLegacy.js \ - scripts/narrow.js \ - scripts/superfish.js \ - style/shCore.css \ - style/shThemeDefault.css \ - style/narrow.css \ - style/superfish.css \ - style/superfish_skin.css \ - style/OfflineStyle.css \ - style/style_ie6.css \ - style/style_ie7.css \ - style/style_ie8.css \ - style/style.css + images/box_bg.png \ + images/breadcrumb.png \ + images/bullet_gt.png \ + images/bullet_dn.png \ + images/bullet_sq.png \ + images/bullet_up.png \ + images/arrow_down.png \ + images/feedbackground.png \ + images/horBar.png \ + images/page.png \ + images/page_bg.png \ + images/sprites-combined.png \ + images/spinner.gif \ + images/stylesheet-coffee-plastique.png \ + images/taskmenuextension-example.png \ + images/coloreditorfactoryimage.png \ + images/dynamiclayouts-example.png \ + scripts/functions.js \ + scripts/jquery.js \ + scripts/shBrushCpp.js \ + scripts/shCore.js \ + scripts/shLegacy.js \ + scripts/narrow.js \ + scripts/superfish.js \ + style/shCore.css \ + style/shThemeDefault.css \ + style/narrow.css \ + style/superfish.css \ + style/superfish_skin.css \ + style/OfflineStyle.css \ + style/style_ie6.css \ + style/style_ie7.css \ + style/style_ie8.css \ + style/style.css qhp.Qt.filterAttributes = qt 4.7.0 qtrefdoc qhp.Qt.customFilters.Qt.name = Qt 4.7.0 @@ -146,7 +146,7 @@ exampledirs = $QTDIR/doc/src \ imagedirs = $QTDIR/doc/src/images \ $QTDIR/examples \ $QTDIR/doc/src/declarative/pics \ - $QTDIR/doc/src/template/images + $QTDIR/doc/src/template/images outputdir = $QTDIR/doc/html tagfile = $QTDIR/doc/html/qt.tags base = file:$QTDIR/doc/html -- cgit v0.12 From eef1d13743baddf41bd135d98fc2ad12944b8477 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Fri, 16 Jul 2010 16:09:20 +0200 Subject: Doc: Excluded the QML documentation from the Qt-only set. Reviewed-by: Trust Me --- tools/qdoc3/test/qt-api-only.qdocconf | 7 +++++++ tools/qdoc3/test/qt-api-only_ja_JP.qdocconf | 7 +++++++ tools/qdoc3/test/qt-api-only_zh_CN.qdocconf | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/tools/qdoc3/test/qt-api-only.qdocconf b/tools/qdoc3/test/qt-api-only.qdocconf index 10b7be5..bf6c0dc 100644 --- a/tools/qdoc3/test/qt-api-only.qdocconf +++ b/tools/qdoc3/test/qt-api-only.qdocconf @@ -25,6 +25,13 @@ qhp.Qt.excluded += $QT_SOURCE_TREE/doc/src/development/assistant-manual.qdoc \ $QT_SOURCE_TREE/doc/src/examples/trollprint.qdoc \ $QT_SOURCE_TREE/doc/src/development/qmake-manual.qdoc +# Remove the QML documentation from the Qt-only documentation. + +excludedirs += $QT_SOURCE_TREE/src/declarative \ + $QT_SOURCE_TREE/src/imports \ + $QT_SOURCE_TREE/src/3rdparty/webkit/WebKit/qt/declarative \ + $QT_SOURCE_TREE/doc/src/declarative + outputdir = $QT_BUILD_TREE/doc-build/html-qt tagfile = $QT_BUILD_TREE/doc-build/html-qt/qt.tags base = file:$QT_BUILD_TREE/doc-build/html-qt diff --git a/tools/qdoc3/test/qt-api-only_ja_JP.qdocconf b/tools/qdoc3/test/qt-api-only_ja_JP.qdocconf index aa3ab01..70e0235 100644 --- a/tools/qdoc3/test/qt-api-only_ja_JP.qdocconf +++ b/tools/qdoc3/test/qt-api-only_ja_JP.qdocconf @@ -25,6 +25,13 @@ qhp.Qt.excluded += $QT_SOURCE_TREE/doc/src/development/assistant-manual.qdoc \ $QT_SOURCE_TREE/doc/src/examples/trollprint.qdoc \ $QT_SOURCE_TREE/doc/src/development/qmake-manual.qdoc +# Remove the QML documentation from the Qt-only documentation. + +excludedirs += $QT_SOURCE_TREE/src/declarative \ + $QT_SOURCE_TREE/src/imports \ + $QT_SOURCE_TREE/src/3rdparty/webkit/WebKit/qt/declarative \ + $QT_SOURCE_TREE/doc/src/declarative + outputdir = $QT_BUILD_TREE/doc-build/html-qt_ja_JP tagfile = $QT_BUILD_TREE/doc-build/html-qt_ja_JP/qt.tags base = file:$QT_BUILD_TREE/doc-build/html-qt_ja_JP diff --git a/tools/qdoc3/test/qt-api-only_zh_CN.qdocconf b/tools/qdoc3/test/qt-api-only_zh_CN.qdocconf index c722ee8..d6bf410 100644 --- a/tools/qdoc3/test/qt-api-only_zh_CN.qdocconf +++ b/tools/qdoc3/test/qt-api-only_zh_CN.qdocconf @@ -25,6 +25,13 @@ qhp.Qt.excluded += $QT_SOURCE_TREE/doc/src/development/assistant-manual.qdoc \ $QT_SOURCE_TREE/doc/src/examples/trollprint.qdoc \ $QT_SOURCE_TREE/doc/src/development/qmake-manual.qdoc +# Remove the QML documentation from the Qt-only documentation. + +excludedirs += $QT_SOURCE_TREE/src/declarative \ + $QT_SOURCE_TREE/src/imports \ + $QT_SOURCE_TREE/src/3rdparty/webkit/WebKit/qt/declarative \ + $QT_SOURCE_TREE/doc/src/declarative + outputdir = $QT_BUILD_TREE/doc-build/html-qt_zh_CN tagfile = $QT_BUILD_TREE/doc-build/html-qt_zh_CN/qt.tags base = file:$QT_BUILD_TREE/doc-build/html-qt_zh_CN -- cgit v0.12 From f231bd03007484d239cb5456db9e20a1f9ab7a63 Mon Sep 17 00:00:00 2001 From: Petri Latvala Date: Wed, 7 Jul 2010 16:30:14 +0300 Subject: Link to the unsinstalled libraries first. Task-number: QT-3371 Reviewed-by: Harald Fernengel --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 62e0863..fb544bd 100755 --- a/configure +++ b/configure @@ -7746,7 +7746,7 @@ EOF # Ensure we can link to uninistalled libraries if [ "$XPLATFORM_MINGW" != "yes" ] && linkerSupportsFlag -rpath-link "$outpath/lib"; then - echo "QMAKE_LFLAGS += -Wl,-rpath-link,\$\$QT_BUILD_TREE/lib" >> "$CACHEFILE.tmp" + echo "QMAKE_LFLAGS = -Wl,-rpath-link,\$\$QT_BUILD_TREE/lib \$\$QMAKE_LFLAGS" >> "$CACHEFILE.tmp" fi if [ -n "$QT_CFLAGS_PSQL" ]; then -- cgit v0.12 From ab4dde176cfa314522964e5e5fbf9f2d388f8fdf Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 29 Jun 2010 09:29:29 +0300 Subject: Do not crash if addrinfo signal does not contain ip address information. Fixes: NB#176643 - Segmentation fault occurs while using networking Reviewed-by: Adrian Constantin --- src/plugins/bearer/icd/qnetworksession_impl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/bearer/icd/qnetworksession_impl.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp index e375b4f..aeac620 100644 --- a/src/plugins/bearer/icd/qnetworksession_impl.cpp +++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp @@ -620,6 +620,9 @@ static QString get_network_interface() return iface; } + if (addr_results.first().ip_info.isEmpty()) + return QString(); + const char *address = addr_results.first().ip_info.first().address.toAscii().constData(); struct in_addr addr; if (inet_aton(address, &addr) == 0) { -- cgit v0.12 From bba06aacb84b5ae9fc286345e721cab639db35c8 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Fri, 16 Jul 2010 18:20:49 +0200 Subject: Doc: Added license documentation for 3rd party code and data. Task-number: QT-3585 Pre-approved-by: Legal Reviewed-by: Trust Me --- doc/src/legal/3rdparty.qdoc | 234 +++++++++++++++++++++++++++++++++++++++++--- doc/src/legal/licenses.qdoc | 49 +++++++++- 2 files changed, 267 insertions(+), 16 deletions(-) diff --git a/doc/src/legal/3rdparty.qdoc b/doc/src/legal/3rdparty.qdoc index 110dac7..e7133e3 100644 --- a/doc/src/legal/3rdparty.qdoc +++ b/doc/src/legal/3rdparty.qdoc @@ -194,16 +194,16 @@ \hr copyright (C) 1999 by Willem van Schaik - + version 1.0 - 1999.10.15 - First version. - + Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. This software is provided "as is" without express or implied warranty. - + \hr Copyright (c) 1998-2001 Greg Roelofs. All rights reserved. @@ -293,7 +293,7 @@ Copyright (c) 1987, 1993, 1994\br The Regents of the University of California. All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\br @@ -305,7 +305,7 @@ 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -336,7 +336,7 @@ Copyright (C) 2004, Andrey Kiselev \br Copyright (c( 1996 USAF Phillips Laboratory\br Additions (c) Richard Nolde 2006-2009 - + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that (i) the above copyright notices and this permission notice appear in @@ -344,11 +344,11 @@ Sam Leffler and Silicon Graphics may not be used in any advertising or publicity relating to the software without the specific, prior written permission of Sam Leffler and Silicon Graphics. - + THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - + IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, @@ -360,11 +360,11 @@ Copyright (c) 1985, 1986 The Regents of the University of California.\br All rights reserved. - + This code is derived from software contributed to Berkeley by James A. Woods, derived from original work by Spencer Thomas and Joseph Orost. - + Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, @@ -381,7 +381,7 @@ Copyright (c) 1996-1997 Sam Leffler\br Copyright (c) 1996 Pixar - + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that (i) the above copyright notices and this permission notice appear in @@ -389,11 +389,11 @@ Pixar, Sam Leffler and Silicon Graphics may not be used in any advertising or publicity relating to the software without the specific, prior written permission of Pixar, Sam Leffler and Silicon Graphics. - + THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - + IN NO EVENT SHALL PIXAR, SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, @@ -423,8 +423,6 @@ \section1 JavaScriptCore - \hr - Copyright (c) 1991, 2000, 2001 by Lucent Technologies.\br Copyright (C) 2002, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. @@ -441,6 +439,60 @@ See \c src/3rdparty/webkit/JavaScriptCore/wtf/dtoa.cpp for license details. + \hr + + Copyright (C) 2009 Company 100, Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met:\br + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer.\br + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + \hr + + Copyright (C) 2009 Apple Inc. All rights reserved.\br + Copyright (C) 2009 University of Szeged\br + All rights reserved.\br + Copyright (C) 2010 MIPS Technologies, Inc. All rights reserved.\br + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met:\br + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer.\br + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY MIPS TECHNOLOGIES, INC. ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MIPS TECHNOLOGIES, INC. OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + \section1 Pixman (\c pixman) version 0.17.11 \e{pixman is a library that provides low-level pixel manipulation @@ -479,4 +531,156 @@ See \c src/3rdparty/pixman/pixman-arm-neon-asm.h and \c src/3rdparty/pixman/pixman-arm-neon-asm.S + + \section1 WebCore (WebKit) + + Copyright (C) 2009 Ericsson AB\br + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer.\br + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution.\br + 3. Neither the name of Ericsson nor the names of its contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + \hr + + Copyright (C) 2004, Apple Computer, Inc. and The Mozilla Foundation.\br + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer.\br + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.\br + 3. Neither the names of Apple Computer, Inc. ("Apple") or The Mozilla + Foundation ("Mozilla") nor the names of their contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE, MOZILLA OR + THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + \hr + + Copyright (C) 2009 Igalia S.L.\br + Copyright (C) 2009 Antonio Gomes \br + Copyright (C) 2008 Christian Dywan \br + Copyright (C) 2007 Nicholas Shanks \br + Copyright (C) 2006 Charles Samuels \br + Copyright (C) 2009 Dominik Röttsches \br + Copyright (C) 2009 Brent Fulgham\br + Copyright (C) 2009 Girish Ramakrishnan \br + Copyright (C) 2006 Alexander Kellett \br + Copyright (C) 2009 Cameron McCormack \br + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met:\br + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer.\br + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + \hr + + Copyright (C) 2007, 2008 Apple Inc. All rights reserved.\br + Copyright (C) IBM Corp. 2009 All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer.\br + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.\br + 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + its contributors may be used to endorse or promote products derived + from this software without specific prior written permission.\br + + THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + \hr + + Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.\br + Copyright (C) 2010 François Sausset (sausset@gmail.com). All rights reserved\br + Copyright (C) 2007 Marius Renn All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met:\br + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer.\br + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ diff --git a/doc/src/legal/licenses.qdoc b/doc/src/legal/licenses.qdoc index 96d5d29..a04a256 100644 --- a/doc/src/legal/licenses.qdoc +++ b/doc/src/legal/licenses.qdoc @@ -328,7 +328,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + \list \o Parts of WebKit used by the QtWebKit module \endlist @@ -716,6 +716,53 @@ \list \o Parts of WebKit used by the QtWebKit module \endlist + + \hr + + Copyright (c) 1991-2009 Unicode, Inc. All rights reserved. + Distributed under the Terms of Use in + http://www.unicode.org/copyright.html. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of the Unicode data files and any associated + documentation (the "Data Files") or Unicode software and any + associated documentation (the "Software") to deal in the Data + Files or Software without restriction, including without + limitation the rights to use, copy, modify, merge, publish, + distribute, and/or sell copies of the Data Files or Software, + and to permit persons to whom the Data Files or Software are + furnished to do so, provided that (a) the above copyright + notice(s) and this permission notice appear with all copies + of the Data Files or Software, (b) both the above copyright + notice(s) and this permission notice appear in associated + documentation, and (c) there is clear notice in each modified + Data File or in the Software as well as in the documentation + associated with the Data File(s) or Software that the data or + software has been modified. + + THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT + WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED + IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING + FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA FILES + OR SOFTWARE. + + Except as contained in this notice, the name of a copyright + holder shall not be used in advertising or otherwise to promote + the sale, use or other dealings in these Data Files or Software + without prior written authorization of the copyright holder. + + \list + \o Included in \c{util/unicode/data}, + \c{tests/auto/qtextboundaryfinder/data} and + \c{tests/auto/qchar} + \o Parts of the \l makeqpf tool + \endlist */ /*! -- cgit v0.12