Merge remote-tracking branch 'origin/3.1'

Conflicts:
	qtcreator.pri
	qtcreator.qbs
	src/plugins/qtsupport/qtversionmanager.cpp
	src/shared/qbs

Change-Id: If7a93fb018799fe6ada76e79c24ab5b43dfa6fc2
This commit is contained in:
Eike Ziller
2014-04-02 13:24:34 +02:00
268 changed files with 6338 additions and 7906 deletions

1
dist/changes-3.1.0 vendored
View File

@@ -99,6 +99,7 @@ Version Control Systems
* Added completion in change selection dialog
* Fixed freeze after resolving conflict with cherry-pick or revert
* Added support for local branch selection in the Push to Gerrit dialog
* Removed branch list from "Git Show" header (QTCREATORBUG-11293)
* ClearCase
* Improved performance of indexing dynamic views
* Added warning when editing Derived Objects

View File

@@ -9,9 +9,7 @@
<url>http://www.mycompany.com</url>
//! [2]
//! [3]
<dependencyList>
<dependency name=\"Core\" version=\"$$QTCREATOR_VERSION\"/>
</dependencyList>
$$dependencyList
//! [3]
</plugin>

View File

@@ -1,7 +1,4 @@
#! [1]
TARGET = Example
TEMPLATE = lib
DEFINES += EXAMPLE_LIBRARY
#! [1]
@@ -42,9 +39,25 @@ PROVIDER = MyCompany
#![5]
#! [6]
include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)
include($$QTCREATOR_SOURCES/src/plugins/coreplugin/coreplugin.pri)
###### If the plugin can be depended upon by other plugins, this code needs to be outsourced to
###### <dirname>_dependencies.pri, where <dirname> is the name of the directory containing the
###### plugin's sources.
LIBS += -L$$IDE_PLUGIN_PATH/QtProject
QTC_PLUGIN_NAME = Example
QTC_LIB_DEPENDS += \
# nothing here at this time
QTC_PLUGIN_DEPENDS += \
coreplugin
QTC_PLUGIN_RECOMMENDS += \
# optional plugin dependencies. nothing here at this time
###### End _dependencies.pri contents ######
#! [6]
#![7]
include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)
#![7]

View File

@@ -75,7 +75,7 @@ ExtensionSystem::IPlugin::ShutdownFlag ExamplePlugin::aboutToShutdown()
//! [slot implementation]
void ExamplePlugin::triggerAction()
{
QMessageBox::information(Core::ICore::instance()->mainWindow(),
QMessageBox::information(Core::ICore::mainWindow(),
tr("Action triggered"),
tr("This is an action from Example."));
}

View File

@@ -14,6 +14,7 @@ namespace Internal {
class ExamplePlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Example.json")
//! [base class]
public:

View File

@@ -170,11 +170,8 @@
\snippet exampleplugin/example.pro 1
The first section of the .pro file defines the very basic properties of your project,
the name (\c{TARGET}), and that a library should be generated,
since plugins are actually libraries that are dynamically loaded (\c{TEMPLATE = lib}).
The section also lets the compiler pass an \c EXAMPLE_LIBRARY define to the compiled
code, which is used in the \c{example_global.h} header, but is not really of interest
The first section of the .pro file lets the compiler pass an \c EXAMPLE_LIBRARY define to the
compiled code, which is used in the \c{example_global.h} header, but is not really of interest
for now. You should not need to change that section of the .pro file.
\snippet exampleplugin/example.pro 2
@@ -213,14 +210,20 @@
\snippet exampleplugin/example.pro 6
This section includes the necessary parts from the \QC sources and makes your
plugin find the \QC libraries and plugins. The included file
\c{qtcreatorplugin.pri} makes sure that you build a plugin that is suitable
for use in \QC. The file \c{plugins/coreplugin/coreplugin.pri} makes your
plugin dependent on the Core plugin and makes sure that you can access its
public API.
If you want to use or extend functionality from other plugins, you
need to add the corresponding .pri file of the plugin here.
This section defines the name and dependencies of your plugin.
The \c{QTC_PLUGIN_NAME} variable defines the name of your plugin, and the name of the
dynamic library that is created for it. The \c{QTC_LIB_DEPENDS} variable is a list of
library names of the \QC utility libraries that your plugin depends on.
Typical values would be \c{aggregation}, \c{extensionsystem} and \c{utils}.
The \c{QTC_PLUGIN_DEPENDS} variable defines the \QC plugins that your plugin depends on.
Almost all \QC plugins will depend on the \c{coreplugin}. The \c{QTC_PLUGIN_RECOMMENDS}
variable defines the \QC plugins that your plugin optionally depends on. For more information,
see \l{Optional Dependencies}.
\snippet exampleplugin/example.pro 7
The included file \c{qtcreatorplugin.pri} makes sure that you build a plugin that is suitable
for use in \QC, by using the information you gave above.
For more information about qmake, and writing .pro files in general,
see the \l{http://qt-project.org/doc/qt-4.8/qmake-manual.html}{qmake Manual}.
@@ -252,8 +255,8 @@
\snippet exampleplugin/Example.pluginspec.in 3
The last section tells the plugin manager about the dependencies of this
plugin. Most \QC plugins will at least depend on the \c{Core} plugin.
The \c{$$dependencyList} variable is automatically replaced by the dependency information
in \c{QTC_PLUGIN_DEPENDS} and \c{QTC_PLUGIN_RECOMMENDS} from your plugin's .pro file.
\section1 Plugin Class
@@ -274,7 +277,7 @@
\snippet exampleplugin/exampleplugin.h base class
All \QC plugins must be derived from \l{ExtensionSystem::IPlugin} and
are QObjects.
are QObjects. The \c{Q_PLUGIN_METADATA} macro is necessary to create a valid Qt plugin.
\snippet exampleplugin/exampleplugin.h plugin functions

View File

@@ -1,29 +1,42 @@
/****************************************************************************
/**************************************************************************
**
** Copyright (c) 2014 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** You may use this file under the terms of the BSD license as follows:
**
** GNU Free Documentation License
** "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 Digia Plc 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.
**
** 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.
** 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."
**
**
****************************************************************************/
**************************************************************************/
// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtSensors 5.0
@@ -34,6 +47,29 @@ ApplicationWindow {
height: 480
visible: true
Image {
id: bubble
source: "Bluebubble.svg"
smooth: true
property real centerX: mainWindow.width / 2
property real centerY: mainWindow.height / 2
property real bubbleCenter: bubble.width / 2
x: centerX - bubbleCenter
y: centerY - bubbleCenter
Behavior on y {
SmoothedAnimation {
easing.type: Easing.Linear
duration: 100
}
}
Behavior on x {
SmoothedAnimation {
easing.type: Easing.Linear
duration: 100
}
}
}
Accelerometer {
id: accel
dataRate: 100
@@ -67,30 +103,7 @@ ApplicationWindow {
return -(Math.atan(x / Math.sqrt(y * y + z * z)) * 57.2957795);
}
Image {
id: bubble
source: "Bluebubble.svg"
smooth: true
property real centerX: mainWindow.width / 2
property real centerY: mainWindow.height / 2
property real bubbleCenter: bubble.width / 2
x: centerX - bubbleCenter
y: centerY - bubbleCenter
Behavior on y {
SmoothedAnimation {
easing.type: Easing.Linear
duration: 100
}
}
Behavior on x {
SmoothedAnimation {
easing.type: Easing.Linear
duration: 100
}
}
MenuBar {
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
@@ -100,4 +113,3 @@ ApplicationWindow {
}
}
}
}

View File

@@ -1,52 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
//! [class implementation]
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBookClass)
{
ui->setupUi(this);
}
AddressBook::~AddressBook()
{
delete ui;
}
//! [class implementation]

View File

@@ -1,62 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
//! [class definition]
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
namespace Ui
{
class AddressBookClass;
}
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
~AddressBook();
private:
Ui::AddressBookClass *ui;
};
#endif // ADDRESSBOOK_H
//! [class definition]

View File

@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBookClass</class>
<widget class="QWidget" name="AddressBookClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<height>261</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameEdit">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressEdit">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -1,49 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
//! [main function]
#include <QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}
//! [main function]

View File

@@ -1,16 +0,0 @@
#-------------------------------------------------
#
# Project created by QtCreator 2009-03-06T12:30:35
#
#-------------------------------------------------
TARGET = addressbook
TEMPLATE = app
SOURCES += main.cpp\
addressbook.cpp
HEADERS += addressbook.h
FORMS += addressbook.ui

View File

@@ -1,143 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBook)
{
ui->setupUi(this);
//! [setup fields]
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->submitButton->hide();
ui->cancelButton->hide();
//! [setup fields]
//! [signal slot]
connect(ui->addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this,
SLOT(submitContact()));
connect(ui->cancelButton, SIGNAL(clicked()), this,
SLOT(cancel()));
//! [signal slot]
//! [window title]
setWindowTitle(tr("Simple Address Book"));
//! [window title]
}
AddressBook::~AddressBook()
{
delete ui;
}
//! [addContact]
void AddressBook::addContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
ui->nameLine->clear();
ui->addressText->clear();
ui->nameLine->setReadOnly(false);
ui->nameLine->setFocus(Qt::OtherFocusReason);
ui->addressText->setReadOnly(false);
ui->addButton->setEnabled(false);
ui->submitButton->show();
ui->cancelButton->show();
}
//! [addContact]
//! [submitContact part1]
void AddressBook::submitContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (name.isEmpty() || address.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name and address."));
return;
}
//! [submitContact part1]
//! [submitContact part2]
if (!contacts.contains(name)) {
contacts.insert(name, address);
QMessageBox::information(this, tr("Add Successful"),
tr("\"%1\" has been added to your address book.").arg(name));
} else {
QMessageBox::information(this, tr("Add Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
return;
}
//! [submitContact part2]
//! [submitContact part3]
if (contacts.isEmpty()) {
ui->nameLine->clear();
ui->addressText->clear();
}
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
ui->submitButton->hide();
ui->cancelButton->hide();
}
//! [submitContact part3]
//! [cancel]
void AddressBook::cancel()
{
ui->nameLine->setText(oldName);
ui->nameLine->setReadOnly(true);
ui->addressText->setText(oldAddress);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
ui->submitButton->hide();
ui->cancelButton->hide();
}
//! [cancel]

View File

@@ -1,77 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
//! [include]
#include <QWidget>
#include <QMap>
#include <QMessageBox>
//! [include]
namespace Ui
{
class AddressBook;
}
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
~AddressBook();
//! [slot definition]
public slots:
void addContact();
void submitContact();
void cancel();
//! [slot definition]
private:
Ui::AddressBook *ui;
//! [members]
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
//! [members]
};
#endif // ADDRESSBOOK_H

View File

@@ -1,87 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBook</class>
<widget class="QWidget" name="AddressBook">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>463</width>
<height>245</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="addressText"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -1,49 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
//! [main function]
#include <QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}
//! [main function]

View File

@@ -1,16 +0,0 @@
#-------------------------------------------------
#
# Project created by QtCreator 2009-03-06T12:30:35
#
#-------------------------------------------------
TARGET = addressbook
TEMPLATE = app
SOURCES += main.cpp\
addressbook.cpp
HEADERS += addressbook.h
FORMS += addressbook.ui

View File

@@ -1,190 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBook)
{
ui->setupUi(this);
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton = ui->addButton;
ui->submitButton->hide();
ui->cancelButton->hide();
//! [setup fields]
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
//! [setup fields]
connect(ui->addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this,
SLOT(submitContact()));
connect(ui->cancelButton, SIGNAL(clicked()), this,
SLOT(cancel()));
//! [signal slot]
connect(ui->nextButton, SIGNAL(clicked()), this,
SLOT(next()));
connect(ui->previousButton, SIGNAL(clicked()), this,
SLOT(previous()));
//! [signal slot]
setWindowTitle(tr("Simple Address Book"));
}
AddressBook::~AddressBook()
{
delete ui;
}
void AddressBook::addContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
ui->nameLine->clear();
ui->addressText->clear();
ui->nameLine->setReadOnly(false);
ui->nameLine->setFocus(Qt::OtherFocusReason);
ui->addressText->setReadOnly(false);
ui->addButton->setEnabled(false);
//! [disable navigation]
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
//! [disable navigation]
ui->submitButton->show();
ui->cancelButton->show();
}
void AddressBook::submitContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (name.isEmpty() || address.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name and address."));
return;
}
if (!contacts.contains(name)) {
contacts.insert(name, address);
QMessageBox::information(this, tr("Add Successful"),
tr("\"%1\" has been added to your address book.").arg(name));
} else {
QMessageBox::information(this, tr("Add Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
return;
}
if (contacts.isEmpty()) {
ui->nameLine->clear();
ui->addressText->clear();
}
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
//! [enable navigation]
int number = contacts.size();
ui->nextButton->setEnabled(number > 1);
ui->previousButton->setEnabled(number > 1);
//! [enable navigation]
ui->submitButton->hide();
ui->cancelButton->hide();
}
void AddressBook::cancel()
{
ui->nameLine->setText(oldName);
ui->nameLine->setReadOnly(true);
ui->addressText->setText(oldAddress);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
int number = contacts.size();
ui->nextButton->setEnabled(number > 1);
ui->previousButton->setEnabled(number > 1);
ui->submitButton->hide();
ui->cancelButton->hide();
}
//! [next]
void AddressBook::next()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i != contacts.end())
i++;
if (i == contacts.end())
i = contacts.begin();
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
//! [next]
//! [previous]
void AddressBook::previous()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i == contacts.end()) {
ui->nameLine->clear();
ui->addressText->clear();
return;
}
if (i == contacts.begin())
i = contacts.end();
i--;
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
//! [previous]

View File

@@ -1,74 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
#include <QMessageBox>
#include <QMap>
namespace Ui
{
class AddressBook;
}
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
~AddressBook();
public slots:
void addContact();
void submitContact();
void cancel();
//! [slot definition]
void next();
void previous();
//! [slot definition]
private:
Ui::AddressBook *ui;
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
};
#endif // ADDRESSBOOK_H

View File

@@ -1,105 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBook</class>
<widget class="QWidget" name="AddressBook">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>498</width>
<height>333</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="addressText"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -1,47 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include <QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}

View File

@@ -1,16 +0,0 @@
#-------------------------------------------------
#
# Project created by QtCreator 2009-06-04T13:35:14
#
#-------------------------------------------------
TARGET = part3
TEMPLATE = app
SOURCES += main.cpp\
addressbook.cpp
HEADERS += addressbook.h
FORMS += addressbook.ui

View File

@@ -1,273 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBook)
{
ui->setupUi(this);
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->submitButton->hide();
ui->cancelButton->hide();
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
//! [extract objects]
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
//! [extract objects]
connect(ui->addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this,
SLOT(submitContact()));
connect(ui->cancelButton, SIGNAL(clicked()), this,
SLOT(cancel()));
connect(ui->nextButton, SIGNAL(clicked()), this,
SLOT(next()));
connect(ui->previousButton, SIGNAL(clicked()), this,
SLOT(previous()));
//! [signal slot]
connect(ui->editButton, SIGNAL(clicked()), this,
SLOT(editContact()));
connect(ui->removeButton, SIGNAL(clicked()), this,
SLOT(removeContact()));
//! [signal slot]
setWindowTitle(tr("Simple Address Book"));
}
AddressBook::~AddressBook()
{
delete ui;
}
//! [addContact]
void AddressBook::addContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
ui->nameLine->clear();
ui->addressText->clear();
updateInterface(AddingMode);
}
//! [addContact]
//! [submitContact part1]
void AddressBook::submitContact()
{
//! [submitContact part1]
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (name.isEmpty() || address.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name and address."));
}
//! [submitContact part2]
if (currentMode == AddingMode) {
if (!contacts.contains(name)) {
contacts.insert(name, address);
QMessageBox::information(this, tr("Add Successful"),
tr("\"%1\" has been added to your address book.").arg(name));
} else {
QMessageBox::information(this, tr("Add Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
return;
}
//! [submitContact part2]
//! [submitContact part3]
} else if (currentMode == EditingMode) {
if (oldName != name) {
if (!contacts.contains(name)) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(oldName));
contacts.remove(oldName);
contacts.insert(name, address);
} else {
QMessageBox::information(this, tr("Edit Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
return;
}
} else if (oldAddress != address) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(name));
contacts[name] = address;
}
}
updateInterface(NavigationMode);
}
//! [submitContact part3]
//! [cancel]
void AddressBook::cancel()
{
ui->nameLine->setText(oldName);
ui->nameLine->setReadOnly(true);
updateInterface(NavigationMode);
}
//! [cancel]
void AddressBook::next()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i != contacts.end())
i++;
if (i == contacts.end())
i = contacts.begin();
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
void AddressBook::previous()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i == contacts.end()) {
ui->nameLine->clear();
ui->addressText->clear();
return;
}
if (i == contacts.begin())
i = contacts.end();
i--;
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
//! [editContact]
void AddressBook::editContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
updateInterface(EditingMode);
}
//! [editContact]
//! [removeContact]
void AddressBook::removeContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (contacts.contains(name)) {
int button = QMessageBox::question(this,
tr("Confirm Remove"),
tr("Are you sure you want to remove \"%1\"?").arg(name),
QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::Yes) {
previous();
contacts.remove(name);
QMessageBox::information(this, tr("Remove Successful"),
tr("\"%1\" has been removed from your address book.").arg(name));
}
}
updateInterface(NavigationMode);
}
//! [removeContact]
//! [updateInterface part1]
void AddressBook::updateInterface(Mode mode)
{
currentMode = mode;
switch (currentMode) {
case AddingMode:
case EditingMode:
ui->nameLine->setReadOnly(false);
ui->nameLine->setFocus(Qt::OtherFocusReason);
ui->addressText->setReadOnly(false);
ui->addButton->setEnabled(false);
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->submitButton->show();
ui->cancelButton->show();
break;
//! [updateInterface part1]
//! [updateInterface part2]
case NavigationMode:
if (contacts.isEmpty()) {
ui->nameLine->clear();
ui->addressText->clear();
}
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
int number = contacts.size();
ui->editButton->setEnabled(number >= 1);
ui->removeButton->setEnabled(number >= 1);
ui->nextButton->setEnabled(number > 1);
ui->previousButton->setEnabled(number >1);
ui->submitButton->hide();
ui->cancelButton->hide();
break;
}
}
//! [updateInterface part2]

View File

@@ -1,87 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
#include <QMessageBox>
#include <QMap>
namespace Ui
{
class AddressBook;
}
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
//! [enum]
enum Mode { NavigationMode, AddingMode, EditingMode };
//! [enum]
~AddressBook();
public slots:
void addContact();
void submitContact();
void cancel();
//! [slot definition]
void editContact();
void removeContact();
//! [slot definition]
void next();
void previous();
private:
Ui::AddressBook *ui;
//! [updateInterface]
void updateInterface(Mode mode);
//! [updateInterface]
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
//! [current mode]
Mode currentMode;
//! [current mode]
};
#endif // ADDRESSBOOK_H

View File

@@ -1,119 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBook</class>
<widget class="QWidget" name="AddressBook">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<height>294</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="addressText"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -1,47 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include <QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}

View File

@@ -1,16 +0,0 @@
#-------------------------------------------------
#
# Project created by QtCreator 2009-06-05T16:03:06
#
#-------------------------------------------------
TARGET = part4
TEMPLATE = app
SOURCES += main.cpp\
addressbook.cpp
HEADERS += addressbook.h
FORMS += addressbook.ui

View File

@@ -1,279 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBook)
{
ui->setupUi(this);
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->submitButton->hide();
ui->cancelButton->hide();
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
connect(ui->addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this,
SLOT(submitContact()));
connect(ui->cancelButton, SIGNAL(clicked()), this,
SLOT(cancel()));
connect(ui->nextButton, SIGNAL(clicked()), this,
SLOT(next()));
connect(ui->previousButton, SIGNAL(clicked()), this,
SLOT(previous()));
connect(ui->editButton, SIGNAL(clicked()), this,
SLOT(editContact()));
connect(ui->removeButton, SIGNAL(clicked()), this,
SLOT(removeContact()));
//! [signal slot]
connect(ui->findButton, SIGNAL(clicked()), this,
SLOT(findContact()));
//! [signal slot]
setWindowTitle(tr("Simple Address Book"));
}
AddressBook::~AddressBook()
{
delete ui;
}
void AddressBook::addContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
ui->nameLine->clear();
ui->addressText->clear();
updateInterface(AddingMode);
}
void AddressBook::submitContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (name.isEmpty() || address.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name and address."));
updateInterface(NavigationMode);
return;
}
if (currentMode == AddingMode) {
if (!contacts.contains(name)) {
contacts.insert(name, address);
QMessageBox::information(this, tr("Add Successful"),
tr("\"%1\" has been added to your address book.").arg(name));
} else {
QMessageBox::information(this, tr("Add Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
}
} else if (currentMode == EditingMode) {
if (oldName != name) {
if (!contacts.contains(name)) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(oldName));
contacts.remove(oldName);
contacts.insert(name, address);
} else {
QMessageBox::information(this, tr("Edit Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
}
} else if (oldAddress != address) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(name));
contacts[name] = address;
}
}
updateInterface(NavigationMode);
}
void AddressBook::cancel()
{
ui->nameLine->setText(oldName);
ui->nameLine->setReadOnly(true);
updateInterface(NavigationMode);
}
void AddressBook::next()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i != contacts.end())
i++;
if (i == contacts.end())
i = contacts.begin();
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
void AddressBook::previous()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i == contacts.end()) {
ui->nameLine->clear();
ui->addressText->clear();
return;
}
if (i == contacts.begin())
i = contacts.end();
i--;
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
void AddressBook::editContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
updateInterface(EditingMode);
}
void AddressBook::removeContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (contacts.contains(name)) {
int button = QMessageBox::question(this,
tr("Confirm Remove"),
tr("Are you sure you want to remove \"%1\"?").arg(name),
QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::Yes) {
previous();
contacts.remove(name);
QMessageBox::information(this, tr("Remove Successful"),
tr("\"%1\" has been removed from your address book.").arg(name));
}
}
updateInterface(NavigationMode);
}
void AddressBook::updateInterface(Mode mode)
{
currentMode = mode;
switch (currentMode) {
case AddingMode:
case EditingMode:
ui->nameLine->setReadOnly(false);
ui->nameLine->setFocus(Qt::OtherFocusReason);
ui->addressText->setReadOnly(false);
ui->addButton->setEnabled(false);
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->submitButton->show();
ui->cancelButton->show();
break;
case NavigationMode:
if (contacts.isEmpty()) {
ui->nameLine->clear();
ui->addressText->clear();
}
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
int number = contacts.size();
ui->editButton->setEnabled(number >= 1);
ui->removeButton->setEnabled(number >= 1);
//! [enable]
ui->findButton->setEnabled(number > 2);
//! [enable]
ui->nextButton->setEnabled(number > 1);
ui->previousButton->setEnabled(number >1);
ui->submitButton->hide();
ui->cancelButton->hide();
break;
}
}
//! [findContact]
void AddressBook::findContact()
{
FindDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
QString contactName = dialog.findText();
if (contacts.contains(contactName)) {
ui->nameLine->setText(contactName);
ui->addressText->setText(contacts.value(contactName));
} else {
QMessageBox::information(this, tr("Contact Not Found"),
tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
return;
}
}
updateInterface(NavigationMode);
}
//! [findContact]

View File

@@ -1,84 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
#include <QMessageBox>
#include <QMap>
//! [include]
#include "finddialog.h"
//! [include]
namespace Ui
{
class AddressBook;
}
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
enum Mode { NavigationMode, AddingMode, EditingMode };
~AddressBook();
public slots:
void addContact();
void submitContact();
void cancel();
void editContact();
void removeContact();
void next();
void previous();
//! [slot definition]
void findContact();
//! [slot definition]
private:
Ui::AddressBook *ui;
void updateInterface(Mode mode);
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
Mode currentMode;
};
#endif // ADDRESSBOOK_H

View File

@@ -1,126 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBook</class>
<widget class="QWidget" name="AddressBook">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>253</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="addressText"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -1,80 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include "finddialog.h"
#include "ui_finddialog.h"
#include <QMessageBox>
//! [constructor]
FindDialog::FindDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::FindDialog)
{
m_ui->setupUi(this);
connect(m_ui->findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
setWindowTitle(tr("Find a Contact"));
}
//! [constructor]
FindDialog::~FindDialog()
{
delete m_ui;
}
//! [findClicked]
void FindDialog::findClicked()
{
QString text = m_ui->lineEdit->text();
if (text.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name."));
reject();
} else {
accept();
}
}
//! [findClicked]
//! [findText]
QString FindDialog::findText()
{
return m_ui->lineEdit->text();
}
//! [findText]

View File

@@ -1,69 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <QDialog>
#include <QLineEdit>
#include <QPushButton>
namespace Ui {
class FindDialog;
}
class FindDialog : public QDialog {
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
~FindDialog();
//! [findText]
QString findText();
//! [findText]
//! [findClicked]
public slots:
void findClicked();
//! [findClicked]
//! [private members]
private:
Ui::FindDialog *m_ui;
//! [private members]
};
#endif // FINDDIALOG_H

View File

@@ -1,59 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FindDialog</class>
<widget class="QDialog" name="FindDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>486</width>
<height>65</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Enter the name of a contact:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>findButton</sender>
<signal>clicked()</signal>
<receiver>FindDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>415</x>
<y>42</y>
</hint>
<hint type="destinationlabel">
<x>385</x>
<y>50</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -1,47 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include <QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}

View File

@@ -1,12 +0,0 @@
# -------------------------------------------------
# Project created by QtCreator 2009-06-08T17:25:28
# -------------------------------------------------
TARGET = part5
TEMPLATE = app
SOURCES += main.cpp \
addressbook.cpp \
finddialog.cpp
HEADERS += addressbook.h \
finddialog.h
FORMS += addressbook.ui \
finddialog.ui

View File

@@ -1,351 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include <QFileDialog>
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBook)
{
ui->setupUi(this);
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->submitButton->hide();
ui->cancelButton->hide();
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
connect(ui->addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this,
SLOT(submitContact()));
connect(ui->cancelButton, SIGNAL(clicked()), this,
SLOT(cancel()));
connect(ui->nextButton, SIGNAL(clicked()), this,
SLOT(next()));
connect(ui->previousButton, SIGNAL(clicked()), this,
SLOT(previous()));
connect(ui->editButton, SIGNAL(clicked()), this,
SLOT(editContact()));
connect(ui->removeButton, SIGNAL(clicked()), this,
SLOT(removeContact()));
connect(ui->findButton, SIGNAL(clicked()), this,
SLOT(findContact()));
//! [connectSlots]
connect(ui->loadButton, SIGNAL(clicked()), this,
SLOT(loadFromFile()));
connect(ui->saveButton, SIGNAL(clicked()), this,
SLOT(saveToFile()));
//! [connectSlots]
setWindowTitle(tr("Simple Address Book"));
}
AddressBook::~AddressBook()
{
delete ui;
}
void AddressBook::addContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
ui->nameLine->clear();
ui->addressText->clear();
updateInterface(AddingMode);
}
void AddressBook::submitContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (name.isEmpty() || address.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name and address."));
updateInterface(NavigationMode);
return;
}
if (currentMode == AddingMode) {
if (!contacts.contains(name)) {
contacts.insert(name, address);
QMessageBox::information(this, tr("Add Successful"),
tr("\"%1\" has been added to your address book.").arg(name));
} else {
QMessageBox::information(this, tr("Add Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
}
} else if (currentMode == EditingMode) {
if (oldName != name) {
if (!contacts.contains(name)) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(oldName));
contacts.remove(oldName);
contacts.insert(name, address);
} else {
QMessageBox::information(this, tr("Edit Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
}
} else if (oldAddress != address) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(name));
contacts[name] = address;
}
}
updateInterface(NavigationMode);
}
void AddressBook::cancel()
{
ui->nameLine->setText(oldName);
ui->nameLine->setReadOnly(true);
updateInterface(NavigationMode);
}
void AddressBook::next()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i != contacts.end())
i++;
if (i == contacts.end())
i = contacts.begin();
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
void AddressBook::previous()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i == contacts.end()) {
ui->nameLine->clear();
ui->addressText->clear();
return;
}
if (i == contacts.begin())
i = contacts.end();
i--;
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
void AddressBook::editContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
updateInterface(EditingMode);
}
void AddressBook::removeContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (contacts.contains(name)) {
int button = QMessageBox::question(this,
tr("Confirm Remove"),
tr("Are you sure you want to remove \"%1\"?").arg(name),
QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::Yes) {
previous();
contacts.remove(name);
QMessageBox::information(this, tr("Remove Successful"),
tr("\"%1\" has been removed from your address book.").arg(name));
}
}
updateInterface(NavigationMode);
}
void AddressBook::updateInterface(Mode mode)
{
currentMode = mode;
switch (currentMode) {
case AddingMode:
case EditingMode:
ui->nameLine->setReadOnly(false);
ui->nameLine->setFocus(Qt::OtherFocusReason);
ui->addressText->setReadOnly(false);
ui->addButton->setEnabled(false);
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->submitButton->show();
ui->cancelButton->show();
break;
case NavigationMode:
if (contacts.isEmpty()) {
ui->nameLine->clear();
ui->addressText->clear();
}
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
int number = contacts.size();
ui->editButton->setEnabled(number >= 1);
ui->removeButton->setEnabled(number >= 1);
ui->findButton->setEnabled(number > 2);
ui->nextButton->setEnabled(number > 1);
ui->previousButton->setEnabled(number >1);
ui->submitButton->hide();
ui->cancelButton->hide();
break;
}
}
void AddressBook::findContact()
{
FindDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
QString contactName = dialog.findText();
if (contacts.contains(contactName)) {
ui->nameLine->setText(contactName);
ui->addressText->setText(contacts.value(contactName));
} else {
QMessageBox::information(this, tr("Contact Not Found"),
tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
return;
}
}
updateInterface(NavigationMode);
}
//! [saveToFile part1]
void AddressBook::saveToFile()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Address Book"), "",
tr("Address book (*.abk);; AllFiles (*)"));
//! [saveToFile part1]
//! [saveToFile part2]
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
//! [saveToFile part2]
//! [saveToFile part3]
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_5);
out << contacts;
}
}
//! [saveToFile part3]
//! [loadFromFile part1]
void AddressBook::loadFromFile()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Address Book"), "",
tr("Address Book(*.abk);; All Files(*)"));
//! [loadFromFile part1]
//! [loadFromFile part2]
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_5);
contacts.clear(); // remove all items
in >> contacts;
//! [loadFromFile part2]
//! [loadFromFile part3]
if (contacts.isEmpty()) {
QMessageBox::information(this, tr("No contacts in file"),
tr("The file you are attempting to open contains no contacts."));
} else {
QMap<QString, QString>::iterator i = contacts.begin();
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
}
updateInterface(NavigationMode);
}
//! [loadFromFile part3]

View File

@@ -1,85 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
#include <QMessageBox>
#include <QMap>
#include "finddialog.h"
namespace Ui
{
class AddressBook;
}
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
enum Mode { NavigationMode, AddingMode, EditingMode };
~AddressBook();
public slots:
void addContact();
void submitContact();
void cancel();
void editContact();
void removeContact();
void next();
void previous();
void findContact();
//! [slot definition]
void saveToFile();
void loadFromFile();
//! [slot definition]
private:
Ui::AddressBook *ui;
void updateInterface(Mode mode);
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
Mode currentMode;
FindDialog *dialog;
};
#endif // ADDRESSBOOK_H

View File

@@ -1,146 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBook</class>
<widget class="QWidget" name="AddressBook">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>478</width>
<height>352</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="addressText"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loadButton">
<property name="toolTip">
<string>Load contacts from a file</string>
</property>
<property name="text">
<string>Load...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="toolTip">
<string>Save contacts to a file</string>
</property>
<property name="text">
<string>Save...</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -1,74 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include "finddialog.h"
#include "ui_finddialog.h"
#include <QMessageBox>
FindDialog::FindDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::FindDialog)
{
m_ui->setupUi(this);
connect(m_ui->findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
setWindowTitle(tr("Find a Contact"));
}
FindDialog::~FindDialog()
{
delete m_ui;
}
void FindDialog::findClicked()
{
QString text = m_ui->lineEdit->text();
if (text.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name."));
reject();
} else {
accept();
}
}
QString FindDialog::findText()
{
return m_ui->lineEdit->text();
}

View File

@@ -1,63 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <QDialog>
#include <QLineEdit>
#include <QPushButton>
namespace Ui {
class FindDialog;
}
class FindDialog : public QDialog {
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
~FindDialog();
QString findText();
public slots:
void findClicked();
private:
Ui::FindDialog *m_ui;
};
#endif // FINDDIALOG_H

View File

@@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FindDialog</class>
<widget class="QDialog" name="FindDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>475</width>
<height>71</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Enter the name of a contact:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,47 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include <QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}

View File

@@ -1,12 +0,0 @@
# -------------------------------------------------
# Project created by QtCreator 2009-07-01T16:46:33
# -------------------------------------------------
TARGET = part6
TEMPLATE = app
SOURCES += main.cpp \
addressbook.cpp \
finddialog.cpp
HEADERS += addressbook.h \
finddialog.h
FORMS += addressbook.ui \
finddialog.ui

View File

@@ -1,392 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include <QFileDialog>
#include <QTextStream>
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent), ui(new Ui::AddressBook)
{
ui->setupUi(this);
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->submitButton->hide();
ui->cancelButton->hide();
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
connect(ui->addButton, SIGNAL(clicked()), this,
SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this,
SLOT(submitContact()));
connect(ui->cancelButton, SIGNAL(clicked()), this,
SLOT(cancel()));
connect(ui->nextButton, SIGNAL(clicked()), this,
SLOT(next()));
connect(ui->previousButton, SIGNAL(clicked()), this,
SLOT(previous()));
connect(ui->editButton, SIGNAL(clicked()), this,
SLOT(editContact()));
connect(ui->removeButton, SIGNAL(clicked()), this,
SLOT(removeContact()));
connect(ui->findButton, SIGNAL(clicked()), this,
SLOT(findContact()));
connect(ui->exportButton, SIGNAL(clicked()), this,
SLOT(exportAsVCard()));
setWindowTitle(tr("Simple Address Book"));
}
AddressBook::~AddressBook()
{
delete ui;
}
void AddressBook::addContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
ui->nameLine->clear();
ui->addressText->clear();
updateInterface(AddingMode);
}
void AddressBook::submitContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (name.isEmpty() || address.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name and address."));
updateInterface(NavigationMode);
return;
}
if (currentMode == AddingMode) {
if (!contacts.contains(name)) {
contacts.insert(name, address);
QMessageBox::information(this, tr("Add Successful"),
tr("\"%1\" has been added to your address book.").arg(name));
} else {
QMessageBox::information(this, tr("Add Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
}
} else if (currentMode == EditingMode) {
if (oldName != name) {
if (!contacts.contains(name)) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(oldName));
contacts.remove(oldName);
contacts.insert(name, address);
} else {
QMessageBox::information(this, tr("Edit Unsuccessful"),
tr("Sorry, \"%1\" is already in your address book.").arg(name));
}
} else if (oldAddress != address) {
QMessageBox::information(this, tr("Edit Successful"),
tr("\"%1\" has been edited in your address book.").arg(name));
contacts[name] = address;
}
}
updateInterface(NavigationMode);
}
void AddressBook::cancel()
{
ui->nameLine->setText(oldName);
ui->nameLine->setReadOnly(true);
updateInterface(NavigationMode);
}
void AddressBook::next()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i != contacts.end())
i++;
if (i == contacts.end())
i = contacts.begin();
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
void AddressBook::previous()
{
QString name = ui->nameLine->text();
QMap<QString, QString>::iterator i = contacts.find(name);
if (i == contacts.end()) {
ui->nameLine->clear();
ui->addressText->clear();
return;
}
if (i == contacts.begin())
i = contacts.end();
i--;
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
void AddressBook::editContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
updateInterface(EditingMode);
}
void AddressBook::removeContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if (contacts.contains(name)) {
int button = QMessageBox::question(this,
tr("Confirm Remove"),
tr("Are you sure you want to remove \"%1\"?").arg(name),
QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::Yes) {
previous();
contacts.remove(name);
QMessageBox::information(this, tr("Remove Successful"),
tr("\"%1\" has been removed from your address book.").arg(name));
}
}
updateInterface(NavigationMode);
}
void AddressBook::updateInterface(Mode mode)
{
currentMode = mode;
switch (currentMode) {
case AddingMode:
case EditingMode:
ui->nameLine->setReadOnly(false);
ui->nameLine->setFocus(Qt::OtherFocusReason);
ui->addressText->setReadOnly(false);
ui->addButton->setEnabled(false);
ui->editButton->setEnabled(false);
ui->removeButton->setEnabled(false);
ui->nextButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->submitButton->show();
ui->cancelButton->show();
break;
case NavigationMode:
if (contacts.isEmpty()) {
ui->nameLine->clear();
ui->addressText->clear();
}
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
int number = contacts.size();
ui->editButton->setEnabled(number >= 1);
ui->removeButton->setEnabled(number >= 1);
ui->findButton->setEnabled(number > 2);
ui->nextButton->setEnabled(number > 1);
ui->previousButton->setEnabled(number >1);
ui->submitButton->hide();
ui->cancelButton->hide();
break;
}
}
void AddressBook::findContact()
{
FindDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
QString contactName = dialog.findText();
if (contacts.contains(contactName)) {
ui->nameLine->setText(contactName);
ui->addressText->setText(contacts.value(contactName));
} else {
QMessageBox::information(this, tr("Contact Not Found"),
tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
return;
}
}
updateInterface(NavigationMode);
}
void AddressBook::saveToFile()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Address Book"), "",
tr("Address book (*.abk);; AllFiles (*)"));
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_5);
out << contacts;
}
}
void AddressBook::loadFromFile()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Address Book"), "",
tr("Address Book(*.abk);; All Files(*)"));
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_5);
contacts.empty(); // empty existing contacts
in >> contacts;
if (contacts.isEmpty()) {
QMessageBox::information(this, tr("No contacts in file"),
tr("The file you are attempting to open contains no contacts."));
} else {
QMap<QString, QString>::iterator i = contacts.begin();
ui->nameLine->setText(i.key());
ui->addressText->setText(i.value());
}
}
updateInterface(NavigationMode);
}
void AddressBook::exportAsVCard()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
QString firstName;
QString lastName;
QStringList nameList;
int index = name.indexOf(" ");
if (index != -1) {
nameList = name.split(QRegExp("\\s+"), QString::SkipEmptyParts);
firstName = nameList.first();
lastName = nameList.last();
} else {
firstName = name;
lastName.clear();
}
QString fileName = QFileDialog::getSaveFileName(this,
tr("Export Coontact"), "",
tr("vCard files (*.vcf);;All Files (*)"));
if (fileName.isEmpty())
return;
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QTextStream out(&file);
out << "BEGIN:VCARD" << "\n";
out << "VERSION:2.1" << "\n";
out << "N:" << lastName << ";" << firstName << "\n";
if (!nameList.isEmpty())
out << "FN:" << nameList.join(" ") << "\n";
else
out << "FN:" << firstName << "\n";
address.replace(';', "\\;", Qt::CaseInsensitive);
address.replace('\n', ";", Qt::CaseInsensitive);
address.replace(',', " ", Qt::CaseInsensitive);
out << "ADR;HOME:;" << address << "\n";
out << "END;VCARD" << "\n";
QMessageBox::information(this, tr("Export Successful"),
tr("\"%1\" has been exported as a vCard.").arg(name));
}

View File

@@ -1,86 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
#include <QMessageBox>
#include <QMap>
#include "finddialog.h"
namespace Ui
{
class AddressBook;
}
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
enum Mode { NavigationMode, AddingMode, EditingMode };
~AddressBook();
public slots:
void addContact();
void submitContact();
void cancel();
void editContact();
void removeContact();
void next();
void previous();
void findContact();
void saveToFile();
void loadFromFile();
//! [slot definition]
void exportAsVCard();
//! [slot definition]
private:
Ui::AddressBook *ui;
void updateInterface(Mode mode);
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
Mode currentMode;
FindDialog *dialog;
};
#endif // ADDRESSBOOK_H

View File

@@ -1,156 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBook</class>
<widget class="QWidget" name="AddressBook">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Address:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="addressText"/>
</item>
<item row="1" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="submitButton">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loadButton">
<property name="toolTip">
<string>Load contacts from a file</string>
</property>
<property name="text">
<string>Load...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="toolTip">
<string>Save contacts to a file</string>
</property>
<property name="text">
<string>Save...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportButton">
<property name="toolTip">
<string>Export as vCard</string>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -1,74 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include "finddialog.h"
#include "ui_finddialog.h"
#include <QMessageBox>
FindDialog::FindDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::FindDialog)
{
m_ui->setupUi(this);
connect(m_ui->findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
setWindowTitle(tr("Find a Contact"));
}
FindDialog::~FindDialog()
{
delete m_ui;
}
void FindDialog::findClicked()
{
QString text = m_ui->lineEdit->text();
if (text.isEmpty()) {
QMessageBox::information(this, tr("Empty Field"),
tr("Please enter a name."));
reject();
} else {
accept();
}
}
QString FindDialog::findText()
{
return m_ui->lineEdit->text();
}

View File

@@ -1,63 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <QDialog>
#include <QLineEdit>
#include <QPushButton>
namespace Ui {
class FindDialog;
}
class FindDialog : public QDialog {
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
~FindDialog();
QString findText();
public slots:
void findClicked();
private:
Ui::FindDialog *m_ui;
};
#endif // FINDDIALOG_H

View File

@@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FindDialog</class>
<widget class="QDialog" name="FindDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<height>73</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Enter the name of a contact:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,47 +0,0 @@
/**************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
** 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 Digia Plc 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."
**
**************************************************************************/
#include <QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}

View File

@@ -1,12 +0,0 @@
# -------------------------------------------------
# Project created by QtCreator 2009-07-07T17:10:19
# -------------------------------------------------
TARGET = part7
TEMPLATE = app
SOURCES += main.cpp \
addressbook.cpp \
finddialog.cpp
HEADERS += addressbook.h \
finddialog.h
FORMS += addressbook.ui \
finddialog.ui

View File

@@ -1,19 +0,0 @@
# Add more folders to ship with the application, here
folder_01.source = qml/BatteryStatus
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
CONFIG += mobility
MOBILITY += systeminfo
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()

View File

@@ -1,51 +0,0 @@
/***************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** All rights reserved.
** Contact: http://www.qt-project.org/
**
** This file is part of the documentation of Qt Creator.
**
** 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 Digia Plc 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."
**
****************************************************************************/
#include <QApplication>
#include "qmlapplicationviewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlApplicationViewer viewer;
viewer.setMainQmlFile(QLatin1String("qml/BatteryStatus/main.qml"));
viewer.showExpanded();
return app.exec();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 992 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Some files were not shown because too many files have changed in this diff Show More