OSDN Git Service

Doc - more of part 4, including a screenshot and lots of docs
authorKavindra Devi Palaraja <kavindra.palaraja@nokia.com>
Fri, 5 Jun 2009 15:57:47 +0000 (17:57 +0200)
committercon <qtc-committer@nokia.com>
Mon, 8 Jun 2009 08:00:54 +0000 (10:00 +0200)
RevBy:    TrustMe

doc/addressbook-sdk.qdoc
doc/examples/addressbook-sdk/part3/addressbook.h
doc/examples/addressbook-sdk/part4/addressbook.cpp
doc/examples/addressbook-sdk/part4/addressbook.h
doc/examples/addressbook-sdk/part4/addressbook.ui
doc/images/addressbook-tutorial-part4-drop-in-gridlayout.png [new file with mode: 0644]

index 2ca6e97..f7f4012 100644 (file)
 
     \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.
+
+
+
 */
 
 /*!
index dd18d85..7d42d0c 100644 (file)
@@ -1,4 +1,3 @@
-//! [class definition]
 #ifndef ADDRESSBOOK_H
 #define ADDRESSBOOK_H
 
@@ -50,4 +49,3 @@ private:
 };
 
 #endif // ADDRESSBOOK_H
-//! [class definition]
index e14c86f..7dda52c 100644 (file)
@@ -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()));
index 7bc76f4..467932c 100644 (file)
@@ -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]
index ee9bbe4..44b4940 100644 (file)
    <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 (file)
index 0000000..1969294
Binary files /dev/null and b/doc/images/addressbook-tutorial-part4-drop-in-gridlayout.png differ