<!DOCTYPE UI><UI version="3.0" stdsetdef="1">
<class>EditBookForm</class>
<include location="global" impldecl="in declaration">qsqlrecord.h</include>
<include location="global" impldecl="in declaration">qdatabrowser.h</include>
<forward>class QSqlRecord;</forward>
<variable>QMap&lt;QString,int&gt; authorMap;</variable>
<widget class="QDialog">
    <property name="name">
        <cstring>EditBookForm</cstring>
    </property>
    <property name="geometry">
        <rect>
            <x>0</x>
            <y>0</y>
            <width>524</width>
            <height>371</height>
        </rect>
    </property>
    <property name="caption">
        <string>Edit Books</string>
    </property>
    <vbox>
        <property name="name">
            <cstring>unnamed</cstring>
        </property>
        <property name="margin">
            <number>11</number>
        </property>
        <property name="spacing">
            <number>6</number>
        </property>
        <widget class="QDataBrowser">
            <property name="name">
                <cstring>BookDataBrowser</cstring>
            </property>
            <property name="sort">
                <stringlist>
                    <string>title ASC</string>
                </stringlist>
            </property>
            <property name="database" stdset="0">
                <stringlist>
                    <string>(default)</string>
                    <string>book</string>
                </stringlist>
            </property>
            <property name="frameworkCode" stdset="0">
                <bool>true</bool>
            </property>
            <grid>
                <property name="name">
                    <cstring>unnamed</cstring>
                </property>
                <property name="margin">
                    <number>11</number>
                </property>
                <property name="spacing">
                    <number>6</number>
                </property>
                <widget class="QLayoutWidget" row="0" column="0">
                    <property name="name">
                        <cstring>Layout2</cstring>
                    </property>
                    <grid>
                        <property name="name">
                            <cstring>unnamed</cstring>
                        </property>
                        <property name="margin">
                            <number>0</number>
                        </property>
                        <property name="spacing">
                            <number>6</number>
                        </property>
                        <widget class="QLabel" row="1" column="0">
                            <property name="name">
                                <cstring>labelPrice</cstring>
                            </property>
                            <property name="text">
                                <string>Price</string>
                            </property>
                        </widget>
                        <widget class="QLabel" row="0" column="0">
                            <property name="name">
                                <cstring>labelTitle</cstring>
                            </property>
                            <property name="text">
                                <string>Title</string>
                            </property>
                        </widget>
                        <widget class="QLineEdit" row="0" column="1">
                            <property name="name">
                                <cstring>QLineEditTitle</cstring>
                            </property>
                            <property name="database" stdset="0">
                                <stringlist>
                                    <string>(default)</string>
                                    <string>book</string>
                                    <string>title</string>
                                </stringlist>
                            </property>
                        </widget>
                        <widget class="QLineEdit" row="1" column="1">
                            <property name="name">
                                <cstring>QLineEditPrice</cstring>
                            </property>
                            <property name="database" stdset="0">
                                <stringlist>
                                    <string>(default)</string>
                                    <string>book</string>
                                    <string>price</string>
                                </stringlist>
                            </property>
                        </widget>
                    </grid>
                </widget>
                <widget class="QLayoutWidget" row="3" column="0">
                    <property name="name">
                        <cstring>Layout6</cstring>
                    </property>
                    <hbox>
                        <property name="name">
                            <cstring>unnamed</cstring>
                        </property>
                        <property name="margin">
                            <number>0</number>
                        </property>
                        <property name="spacing">
                            <number>6</number>
                        </property>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonInsert</cstring>
                            </property>
                            <property name="text">
                                <string>&amp;Insert</string>
                            </property>
                        </widget>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonUpdate</cstring>
                            </property>
                            <property name="text">
                                <string>&amp;Update</string>
                            </property>
                            <property name="default">
                                <bool>true</bool>
                            </property>
                        </widget>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonDelete</cstring>
                            </property>
                            <property name="text">
                                <string>&amp;Delete</string>
                            </property>
                        </widget>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonClose</cstring>
                            </property>
                            <property name="text">
                                <string>&amp;Close</string>
                            </property>
                        </widget>
                    </hbox>
                </widget>
                <widget class="QLayoutWidget" row="2" column="0">
                    <property name="name">
                        <cstring>Layout3</cstring>
                    </property>
                    <hbox>
                        <property name="name">
                            <cstring>unnamed</cstring>
                        </property>
                        <property name="margin">
                            <number>0</number>
                        </property>
                        <property name="spacing">
                            <number>6</number>
                        </property>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonFirst</cstring>
                            </property>
                            <property name="text">
                                <string>|&lt; &amp;First</string>
                            </property>
                        </widget>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonPrev</cstring>
                            </property>
                            <property name="text">
                                <string>&lt;&lt; &amp;Prev</string>
                            </property>
                        </widget>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonNext</cstring>
                            </property>
                            <property name="text">
                                <string>&amp;Next &gt;&gt;</string>
                            </property>
                        </widget>
                        <widget class="QPushButton">
                            <property name="name">
                                <cstring>PushButtonLast</cstring>
                            </property>
                            <property name="text">
                                <string>&amp;Last &gt;|</string>
                            </property>
                        </widget>
                    </hbox>
                </widget>
                <widget class="QLayoutWidget" row="1" column="0">
                    <property name="name">
                        <cstring>Layout6</cstring>
                    </property>
                    <hbox>
                        <property name="name">
                            <cstring>unnamed</cstring>
                        </property>
                        <property name="margin">
                            <number>0</number>
                        </property>
                        <property name="spacing">
                            <number>6</number>
                        </property>
                        <widget class="QLabel">
                            <property name="name">
                                <cstring>TextLabel1</cstring>
                            </property>
                            <property name="text">
                                <string>Author</string>
                            </property>
                        </widget>
                        <widget class="QComboBox">
                            <property name="name">
                                <cstring>ComboBoxAuthor</cstring>
                            </property>
                            <property name="sizePolicy">
                                <sizepolicy>
                                    <hsizetype>7</hsizetype>
                                    <vsizetype>0</vsizetype>
                                </sizepolicy>
                            </property>
                            <property name="database" stdset="0">
                                <stringlist>
                                    <string>(default)</string>
                                    <string>author_view</string>
                                    <string>name</string>
                                </stringlist>
                            </property>
                        </widget>
                    </hbox>
                </widget>
            </grid>
        </widget>
    </vbox>
</widget>
<connections>
    <connection>
        <sender>PushButtonFirst</sender>
        <signal>clicked()</signal>
        <receiver>BookDataBrowser</receiver>
        <slot>first()</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>firstRecordAvailable( bool )</signal>
        <receiver>PushButtonFirst</receiver>
        <slot>setEnabled(bool)</slot>
    </connection>
    <connection>
        <sender>PushButtonPrev</sender>
        <signal>clicked()</signal>
        <receiver>BookDataBrowser</receiver>
        <slot>prev()</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>prevRecordAvailable( bool )</signal>
        <receiver>PushButtonPrev</receiver>
        <slot>setEnabled(bool)</slot>
    </connection>
    <connection>
        <sender>PushButtonNext</sender>
        <signal>clicked()</signal>
        <receiver>BookDataBrowser</receiver>
        <slot>next()</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>nextRecordAvailable( bool )</signal>
        <receiver>PushButtonNext</receiver>
        <slot>setEnabled(bool)</slot>
    </connection>
    <connection>
        <sender>PushButtonLast</sender>
        <signal>clicked()</signal>
        <receiver>BookDataBrowser</receiver>
        <slot>last()</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>lastRecordAvailable( bool )</signal>
        <receiver>PushButtonLast</receiver>
        <slot>setEnabled(bool)</slot>
    </connection>
    <connection>
        <sender>PushButtonInsert</sender>
        <signal>clicked()</signal>
        <receiver>BookDataBrowser</receiver>
        <slot>insert()</slot>
    </connection>
    <connection>
        <sender>PushButtonUpdate</sender>
        <signal>clicked()</signal>
        <receiver>BookDataBrowser</receiver>
        <slot>update()</slot>
    </connection>
    <connection>
        <sender>PushButtonDelete</sender>
        <signal>clicked()</signal>
        <receiver>BookDataBrowser</receiver>
        <slot>del()</slot>
    </connection>
    <connection>
        <sender>PushButtonClose</sender>
        <signal>clicked()</signal>
        <receiver>EditBookForm</receiver>
        <slot>accept()</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>primeUpdate(QSqlRecord*)</signal>
        <receiver>EditBookForm</receiver>
        <slot>primeUpdateBook(QSqlRecord*)</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>beforeUpdate(QSqlRecord*)</signal>
        <receiver>EditBookForm</receiver>
        <slot>beforeUpdateBook(QSqlRecord*)</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>beforeInsert(QSqlRecord*)</signal>
        <receiver>EditBookForm</receiver>
        <slot>beforeUpdateBook(QSqlRecord*)</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>primeInsert(QSqlRecord*)</signal>
        <receiver>EditBookForm</receiver>
        <slot>primeInsertBook(QSqlRecord*)</slot>
    </connection>
    <connection>
        <sender>BookDataBrowser</sender>
        <signal>primeInsert(QSqlRecord*)</signal>
        <receiver>EditBookForm</receiver>
        <slot>primeInsertBook(QSqlRecord*)</slot>
    </connection>
    <slot access="protected" language="C++" returnType="void">init()</slot>
    <slot access="protected" language="C++" returnType="void">destroy()</slot>
    <slot access="public" language="C++" returnType="void">beforeUpdateBook( QSqlRecord * buffer )</slot>
    <slot access="public" language="C++" returnType="void">mapAuthor( const QString &amp; name, int &amp; id, bool populate )</slot>
    <slot access="public" language="C++" returnType="void">primeInsertBook( QSqlRecord * buffer )</slot>
    <slot access="public" language="C++" returnType="void">primeUpdateBook( QSqlRecord * buffer )</slot>
</connections>
<functions>
    <function name="init()" >{
    QSqlQuery query( "SELECT surname, id FROM author ORDER BY surname;" );    
    while ( query.next() ) {
	ComboBoxAuthor-&gt;insertItem( query.value( 0 ).toString() ); 
	int id = query.value( 1 ).toInt();
	mapAuthor( query.value( 0 ).toString(), id, TRUE );
    }
}</function>
    <function name="destroy()" >{
    
}</function>
    <function name="beforeUpdateBook(QSqlRecord*)" >{
    int id;
    mapAuthor( ComboBoxAuthor-&gt;currentText(), id, FALSE );
    buffer-&gt;setValue( "authorid", id );
}</function>
    <function name="mapAuthor(const QString&amp;,int&amp;,bool)" >{
    if ( populate ) 
	authorMap[ name ] = id;
    else
	id = authorMap[ name ];
}</function>
    <function name="primeInsertBook(QSqlRecord*)" >{
    QSqlQuery q;  
    q.exec( "UPDATE sequence SET sequence = sequence + 1 WHERE tablename='book';" );  
    q.exec( "SELECT sequence FROM sequence WHERE tablename='book';" );  
    if ( q.next() ) {  
	buffer-&gt;setValue( "id", q.value( 0 ) );  
    }  
}</function>
    <function name="primeUpdateBook(QSqlRecord*)" >{
    // Who is this book's author?
    QSqlQuery query( "SELECT surname FROM author WHERE id=" +  
	buffer-&gt;value( "authorid" ).toString() + ";" ); 
    QString author = "";    
    if ( query.next() )
	author = query.value( 0 ).toString();
    // Set the ComboBox to the right author
    for ( int i = 0; i &lt; ComboBoxAuthor-&gt;count(); i++ ) {
	if ( ComboBoxAuthor-&gt;text( i ) == author ) {
	    ComboBoxAuthor-&gt;setCurrentItem( i ) ;
	    break;
	}
    }
}</function>
</functions>
<tabstops>
    <tabstop>QLineEditTitle</tabstop>
    <tabstop>QLineEditPrice</tabstop>
    <tabstop>ComboBoxAuthor</tabstop>
    <tabstop>PushButtonFirst</tabstop>
    <tabstop>PushButtonPrev</tabstop>
    <tabstop>PushButtonNext</tabstop>
    <tabstop>PushButtonLast</tabstop>
    <tabstop>PushButtonInsert</tabstop>
    <tabstop>PushButtonUpdate</tabstop>
    <tabstop>PushButtonDelete</tabstop>
    <tabstop>PushButtonClose</tabstop>
</tabstops>
</UI>
