diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-10-08 06:09:16 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-10-08 06:09:16 (GMT) |
commit | 05e4f1eaeb3f916bcf845ae0d7e85d283e9ca1bd (patch) | |
tree | 796339a2d7b79eba644ba18b666846d0fb310709 | |
parent | e795864872095d2179a3639403343ade3daf61c7 (diff) | |
download | Qt-05e4f1eaeb3f916bcf845ae0d7e85d283e9ca1bd.zip Qt-05e4f1eaeb3f916bcf845ae0d7e85d283e9ca1bd.tar.gz Qt-05e4f1eaeb3f916bcf845ae0d7e85d283e9ca1bd.tar.bz2 |
Remove redundant support/ files.
-rw-r--r-- | examples/declarative/support/contact.cpp | 81 | ||||
-rw-r--r-- | examples/declarative/support/contact.h | 140 | ||||
-rw-r--r-- | examples/declarative/support/contactmodel.cpp | 158 | ||||
-rw-r--r-- | examples/declarative/support/contactmodel.h | 55 | ||||
-rw-r--r-- | examples/declarative/support/support.pro | 12 |
5 files changed, 0 insertions, 446 deletions
diff --git a/examples/declarative/support/contact.cpp b/examples/declarative/support/contact.cpp deleted file mode 100644 index 9ffeb97..0000000 --- a/examples/declarative/support/contact.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#include "contact.h" - -QML_DEFINE_TYPE(0,0,0,0,Contact,Contact); -Contact::Contact() : QObject(0) -{ - m_firstName = "John"; - m_lastName = "Smith"; - m_portraitFile = "contact.png"; - m_company = "Trollkia"; - m_emails << "smith@trollkia.com" << "john45@gmail.com"; - - m_numbers << new PhoneNumber; - m_numbers << new PhoneNumber; - m_numbers << new PhoneNumber; - - m_numbers.at(0)->setType(PhoneNumber::HomePhone); - m_numbers.at(0)->setNumber("35412451"); - - m_numbers.at(1)->setType(PhoneNumber::BusinessPhone); - m_numbers.at(1)->setNumber("33424994"); - - m_numbers.at(2)->setType(PhoneNumber::MobilePhone); - m_numbers.at(2)->setNumber("0424655137"); - - m_addresses << new Address; - m_addresses << new Address; - m_addresses << new Address; - m_addresses.at(0)->setNumber(13); - m_addresses.at(0)->setStreet("Blackhill Cr"); - m_addresses.at(0)->setCountry("Australia"); - m_addresses.at(1)->setNumber(116); - m_addresses.at(1)->setStreet("Sandankerveien"); - m_addresses.at(1)->setCountry("Norway"); - m_addresses.at(2)->setNumber(92); - m_addresses.at(2)->setStreet("Elizibeth St"); - m_addresses.at(2)->setCountry("Australia"); -} - -void Contact::addNumber(PhoneNumber *newNumber) -{ - m_numbers << newNumber; - emit numbersChanged(); -} - -void Contact::addAddress(Address *newAddress) -{ - m_addresses << newAddress; - emit addressesChanged(); -} - -void Contact::addEmail(QString &newEmail) -{ - - m_emails << newEmail; - emit emailsChanged(); -} - -QML_DEFINE_TYPE(0,0,0,0,Address,Address); -Address::Address() -: _number(0) -{ -} - -QML_DEFINE_TYPE(0,0,0,0,PhoneNumber, PhoneNumber); -PhoneNumber::PhoneNumber() -: _type(HomePhone) -{ -} diff --git a/examples/declarative/support/contact.h b/examples/declarative/support/contact.h deleted file mode 100644 index 7b25869..0000000 --- a/examples/declarative/support/contact.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#ifndef CONTACT_H -#define CONTACT_H - -#include <qml.h> -#include <QtCore> - -class Address : public QObject -{ - Q_OBJECT -public: - Address(); - - Q_PROPERTY(int number READ number WRITE setNumber NOTIFY changed); - Q_PROPERTY(QString street READ street WRITE setStreet NOTIFY changed); - Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY changed); - - int number() const { return _number; } - void setNumber(int n) { _number = n; emit changed(); } - - QString street() const { return _street; } - void setStreet(const QString &s) { _street = s; emit changed(); } - - QString country() const { return _country; } - void setCountry(const QString &c) { _country = c; emit changed(); } - -signals: - void changed(); - -private: - int _number; - QString _street; - QString _country; -}; -QML_DECLARE_TYPE(Address); - -class PhoneNumber : public QObject -{ - Q_OBJECT - Q_ENUMS(PhoneType) -public: - PhoneNumber(); - - enum PhoneType { - HomePhone, - BusinessPhone, - MobilePhone - }; - - Q_PROPERTY(QString number READ number WRITE setNumber NOTIFY changed); - Q_PROPERTY(PhoneType type READ type WRITE setType NOTIFY changed); - - QString number() const { return _number; } - void setNumber(QString n) { _number = n; emit changed(); } - - PhoneType type() const { return _type; } - void setType(PhoneType type) { _type = type; emit changed(); } - -signals: - void changed(); - -private: - QString _number; - PhoneType _type; -}; -QML_DECLARE_TYPE(PhoneNumber); - -class Contact : public QObject -{ - Q_OBJECT -public: - Contact(); - - Q_PROPERTY(QString firstName READ firstName WRITE setFirstName NOTIFY nameChanged); - QString firstName() const { return m_firstName; } - - Q_PROPERTY(QString lastName READ lastName WRITE setLastName NOTIFY nameChanged); - QString lastName() const { return m_lastName; } - - Q_PROPERTY(QString portraitFile READ portraitFile WRITE setPortraitFile NOTIFY portraitChanged); - QString portraitFile() const { return m_portraitFile; } - - Q_PROPERTY(QString company READ company WRITE setCompany NOTIFY companyChanged); - QString company() const { return m_company; } - - Q_PROPERTY(QStringList emails READ emails WRITE setEmails NOTIFY emailsChanged); - QStringList emails() const { return m_emails; } - - Q_PROPERTY(QList<Address *>* addresses READ addresses); - QList<Address *>* addresses() { return &m_addresses; } - - Q_PROPERTY(QList<PhoneNumber *>* numbers READ numbers); - QList<PhoneNumber *>* numbers() { return &m_numbers; } - - - void addEmail(QString&); - void addAddress(Address*); - void addNumber(PhoneNumber*); - -public slots: - void setFirstName(const QString &name) { m_firstName = name; emit nameChanged(); } - void setLastName(const QString &name) { m_lastName = name; emit nameChanged(); } - void setPortraitFile(const QString &portraitFile) { m_portraitFile = portraitFile; emit portraitChanged(); } - void setCompany(const QString &company) { m_company = company; emit companyChanged(); } - void setEmails(const QStringList &emails) { m_emails = emails; emit emailsChanged(); } - -signals: - void nameChanged(); - void portraitChanged(); - void companyChanged(); - void emailsChanged(); - void numbersChanged(); - void addressesChanged(); - -private: - QString m_firstName; - QString m_lastName; - QString m_portraitFile; - - QString m_company; - - QList<Address *> m_addresses; - QList<PhoneNumber *>m_numbers; - QStringList m_emails; -}; -QML_DECLARE_TYPE(Contact); - -#endif diff --git a/examples/declarative/support/contactmodel.cpp b/examples/declarative/support/contactmodel.cpp deleted file mode 100644 index ff71b9c..0000000 --- a/examples/declarative/support/contactmodel.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#include "contactmodel.h" - -ContactModel::ContactModel(QObject *parent) : QListModelInterface(parent) -{ - QFile f("../contacts/contacts.txt"); - f.open(QIODevice::ReadOnly); - QTextStream ts(&f); - QString text = ts.readLine(); - while(!text.isEmpty()) { - Contact *c = new Contact; - QStringList list = text.split(" "); - c->setFirstName(list[0]); - c->setLastName(list[1]); - for (int i = 2; i < list.count(); ++i) - c->addEmail(list[i]); - //contactList.append(c); - insertContact(c); - - text = ts.readLine(); - } - f.close(); -} - -ContactModel::~ContactModel() -{ - while (!contactList.isEmpty()) { - Contact *c = contactList.takeFirst(); - delete c; - } -} - -int ContactModel::count() const -{ - return contactList.count(); -} - -QHash<int,QVariant> ContactModel::data(int index, const QList<int> &roles) const -{ - QHash<int,QVariant> returnHash; - - for (int i = 0; i < roles.size(); ++i) { - int role = roles.at(i); - QVariant info; - switch(role) { - case PortraitRole: - info = "contact.png"; - break; - case FirstNameRole: - info = contactList.at(index)->firstName(); - break; - case LastNameRole: - info = contactList.at(index)->lastName(); - break; - case CompanyRole: - info = contactList.at(index)->company(); - break; - case EmailsRole: - info = contactList.at(index)->emails(); - break; - case AddressesRole: - //returns QVariant BOOL - info = QVariant::fromValue(contactList.at(index)->addresses()); - break; - case NumbersRole: - info = QVariant::fromValue(contactList.at(index)->numbers()); - break; - default: - break; - } - returnHash.insert(role, info); - } - - return returnHash; -} - -QString ContactModel::toString(int role) const -{ - switch(role) { - case PortraitRole: - return "portrait"; - case FirstNameRole: - return "firstName"; - case LastNameRole: - return "lastName"; - case CompanyRole: - return "company"; - case EmailsRole: - return "emails"; - case AddressesRole: - return "addresses"; - case NumbersRole: - return "numbers"; - default: - return ""; - } -} - -QList<int> ContactModel::roles() const -{ - return QList<int>() << PortraitRole << FirstNameRole << LastNameRole << CompanyRole << EmailsRole << AddressesRole << NumbersRole; -} - -void ContactModel::deleteContact(int index) -{ - delete contactList.takeAt(index); - emit itemsRemoved(index, 1); -} - -int ContactModel::insertContact(Contact *contact) -{ - int index = 0; - QString fullName = contact->lastName(); - index = findIndex(fullName); - contactList.insert(index, contact); - emit itemsInserted(index, 1); - return index; -} - - -//search - binary search algorithm lastname only - -int ContactModel::findIndex(QString &searchName) const -{ - int start = 0; - int end = contactList.size()-1; - int middle = 0; - QString middleString; - - while (start <= end) - { - middle = (start+end)/2; - middleString = contactList.at(middle)->lastName(); - if (isAfter(searchName, middleString) < 0) start = middle+1; - else if( isAfter(middleString, searchName) < 0) end = middle-1; - else return middle; - } - return start; -} - -int ContactModel::isAfter(QString &name1, QString &name2) const -{ - //if c1 is after c2 alphabetically, return positive - int compString = QString::compare(name1, name2, Qt::CaseInsensitive); - return -compString; -} diff --git a/examples/declarative/support/contactmodel.h b/examples/declarative/support/contactmodel.h deleted file mode 100644 index e262358..0000000 --- a/examples/declarative/support/contactmodel.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#ifndef _CONTACTMODEL_H_ -#define _CONTACTMODEL_H_ - -#include <qlistmodelinterface.h> -#include "contact.h" - -class ContactModel : public QListModelInterface -{ - Q_OBJECT -public: - ContactModel(QObject *parent = 0); - ~ContactModel(); - - enum Roles { - PortraitRole, - FirstNameRole, - LastNameRole, - CompanyRole, - EmailsRole, - AddressesRole, - NumbersRole - }; - - int count() const; - - QHash<int,QVariant> data(int index, const QList<int> &roles) const; - QList<int> roles() const; - - - QString toString(int role) const; - - void deleteContact(int index); - int insertContact(Contact *contact); - - int isAfter(QString &name1, QString &name2) const; - int findIndex(QString &searchName) const; - -private: - QList<Contact*> contactList; -}; - -#endif diff --git a/examples/declarative/support/support.pro b/examples/declarative/support/support.pro deleted file mode 100644 index 1da1a28..0000000 --- a/examples/declarative/support/support.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = lib -TARGET = QtFxSupport -DEPENDPATH += . -INCLUDEPATH += . -MOC_DIR = .moc -OBJECTS_DIR = .obj -DESTDIR = ../../lib -QT += script declarative - -HEADERS += contact.h contactmodel.h -SOURCES += contact.cpp contactmodel.cpp - |