diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc index 2ca6e9746d151fc3bae71429a43aa01cdc4292fc..f7f40121632f266e6ec346e3a1f0fc4196c700e9 100644 --- a/doc/addressbook-sdk.qdoc +++ b/doc/addressbook-sdk.qdoc @@ -575,6 +575,15 @@ \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: @@ -586,6 +595,26 @@ \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. + + + */ /*! diff --git a/doc/examples/addressbook-sdk/part3/addressbook.h b/doc/examples/addressbook-sdk/part3/addressbook.h index dd18d85512e32bd4b294795834a5dfd4b0afc62c..7d42d0c05314ac7f9ef307b04b26409796254667 100644 --- a/doc/examples/addressbook-sdk/part3/addressbook.h +++ b/doc/examples/addressbook-sdk/part3/addressbook.h @@ -1,4 +1,3 @@ -//! [class definition] #ifndef ADDRESSBOOK_H #define ADDRESSBOOK_H @@ -50,4 +49,3 @@ private: }; #endif // ADDRESSBOOK_H -//! [class definition] diff --git a/doc/examples/addressbook-sdk/part4/addressbook.cpp b/doc/examples/addressbook-sdk/part4/addressbook.cpp index e14c86f426038ab2e49afa1e2d362ea663dcdadf..7dda52ce0fcefb88319192c78a405bf8dd177dd4 100644 --- a/doc/examples/addressbook-sdk/part4/addressbook.cpp +++ b/doc/examples/addressbook-sdk/part4/addressbook.cpp @@ -31,7 +31,15 @@ AddressBook::AddressBook(QWidget *parent) previousButton = new QPushButton; previousButton = ui->previousButton; - nextButton->setEnabled(false); + previousButton->setEnabled(false); + + editButton = new QPushButton; + editButton = ui->editButton; + editButton->setEnabled(false); + + removeButton = new QPushButton; + removeButton = ui->removeButton; + removeButton->setEnabled(false); connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); diff --git a/doc/examples/addressbook-sdk/part4/addressbook.h b/doc/examples/addressbook-sdk/part4/addressbook.h index 7bc76f45f739b939a40f2275a24f86dcf1d58fbf..467932c264072da0f64d6da0523790660154fb4c 100644 --- a/doc/examples/addressbook-sdk/part4/addressbook.h +++ b/doc/examples/addressbook-sdk/part4/addressbook.h @@ -1,4 +1,3 @@ -//! [class definition] #ifndef ADDRESSBOOK_H #define ADDRESSBOOK_H @@ -39,20 +38,27 @@ public slots: private: Ui::AddressBook *ui; +//! [updateInterface] + void updateInterface(Mode mode); +//! [updateInterface] QPushButton *addButton; QPushButton *submitButton; QPushButton *cancelButton; +//! [members] + QPushButton *editButton; + QPushButton *removeButton; //! [members] QPushButton *nextButton; QPushButton *previousButton; -//! [members] QLineEdit *nameLine; QTextEdit *addressText; QMap<QString, QString> contacts; QString oldName; QString oldAddress; +//! [current mode] + Mode currentMode; +//! [current mode] }; #endif // ADDRESSBOOK_H -//! [class definition] diff --git a/doc/examples/addressbook-sdk/part4/addressbook.ui b/doc/examples/addressbook-sdk/part4/addressbook.ui index ee9bbe4d65b79a3468f18dea86c43e4fee4403ec..44b4940ac98914be478b5264c2553db07da226ec 100644 --- a/doc/examples/addressbook-sdk/part4/addressbook.ui +++ b/doc/examples/addressbook-sdk/part4/addressbook.ui @@ -6,104 +6,112 @@ <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/> diff --git a/doc/images/addressbook-tutorial-part4-drop-in-gridlayout.png b/doc/images/addressbook-tutorial-part4-drop-in-gridlayout.png new file mode 100644 index 0000000000000000000000000000000000000000..1969294ba14f383a75360ab0b2ecf5e4a365dca9 Binary files /dev/null and b/doc/images/addressbook-tutorial-part4-drop-in-gridlayout.png differ