\section1 Placing Widgets on the Form
+ To edit and remove contacts, we need two push buttons. Drag them and name
+ them accordingly. Their \c objectName properties should be \c editButton
+ and \c removeButton, respectively. The quickest way to place these two
+ buttons into our existing layout, is to simply drag and drop them. Use the
+ screenshot below as a guide:
+
+ \image addressbook-tutorial-part4-drop-in-gridlayout.png
+
+
\section1 The AddressBook Class
We update the header file to contain the \c Mode enum:
\snippet examples/addressbook-sdk/part4/addressbook.h slot definition
+ In order to switch between modes, we introduce the \c updateInterface()
+ function to control the enabling and disabling of all push buttons. We also
+ add two new push buttons, \c editButton and \c removeButton, for the edit
+ and remove functions mentioned earlier.
+
+ \snippet examples/addressbook-sdk/part4/adressbook.h updateInterface
+ \dots
+ \snippet examples/addressbook-sdk/part4/addressbook.h members
+
+ Lastly, we declare \c currentMode to keep track of the enum's current mode.
+
+ \snippet examples/addressbook-sdk/part4/addressbook.h current mode
+
+ Let's begin by implementing the mode-changing features of the address book
+ application. The \c editButton and \c removeButton are extracted and
+ disabled by default, as the address book starts up with zero contacts in
+ memory.
+
+
+
*/
/*!
<rect>
<x>0</x>
<y>0</y>
- <width>600</width>
- <height>400</height>
+ <width>472</width>
+ <height>294</height>
</rect>
</property>
<property name="windowTitle">
<string>AddressBook</string>
</property>
- <widget class="QWidget" name="layoutWidget">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>10</y>
- <width>413</width>
- <height>260</height>
- </rect>
- </property>
- <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>
- </widget>
+ <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/>