source: trunk/examples/sql/overview/custom1/main.cpp

Last change on this file was 202, checked in by rudi, 14 years ago

Added SQL examples

File size: 3.0 KB
Line 
1/****************************************************************************
2** $Id: main.cpp 2051 2007-02-21 10:04:20Z chehrlic $
3**
4** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include "main.h"
12
13
14CustomEdit::CustomEdit( QWidget *parent, const char *name ) :
15 QLineEdit( parent, name )
16{
17 connect( this, SIGNAL(textChanged(const QString &)),
18 this, SLOT(changed(const QString &)) );
19}
20
21
22void CustomEdit::changed( const QString &line )
23{
24 setUpperLine( line );
25}
26
27
28void CustomEdit::setUpperLine( const QString &line )
29{
30 upperLineText = line.upper();
31 setText( upperLineText );
32}
33
34
35QString CustomEdit::upperLine() const
36{
37 return upperLineText;
38}
39
40
41FormDialog::FormDialog()
42{
43 QLabel *forenameLabel = new QLabel( "Forename:", this );
44 CustomEdit *forenameEdit = new CustomEdit( this );
45 QLabel *surnameLabel = new QLabel( "Surname:", this );
46 CustomEdit *surnameEdit = new CustomEdit( this );
47 QLabel *salaryLabel = new QLabel( "Salary:", this );
48 QLineEdit *salaryEdit = new QLineEdit( this );
49 salaryEdit->setAlignment( Qt::AlignRight );
50 QPushButton *saveButton = new QPushButton( "&Save", this );
51 connect( saveButton, SIGNAL(clicked()), this, SLOT(save()) );
52
53 QGridLayout *grid = new QGridLayout( this );
54 grid->addWidget( forenameLabel, 0, 0 );
55 grid->addWidget( forenameEdit, 0, 1 );
56 grid->addWidget( surnameLabel, 1, 0 );
57 grid->addWidget( surnameEdit, 1, 1 );
58 grid->addWidget( salaryLabel, 2, 0 );
59 grid->addWidget( salaryEdit, 2, 1 );
60 grid->addWidget( saveButton, 3, 0 );
61 grid->activate();
62
63 staffCursor = new QSqlCursor( "staff" );
64 staffCursor->setTrimmed( "forename", TRUE );
65 staffCursor->setTrimmed( "surname", TRUE );
66 idIndex = staffCursor->index( "id" );
67 staffCursor->select( idIndex );
68 staffCursor->first();
69
70 propMap = new QSqlPropertyMap;
71 propMap->insert( forenameEdit->className(), "upperLine" );
72
73 sqlForm = new QSqlForm( this );
74 sqlForm->setRecord( staffCursor->primeUpdate() );
75 sqlForm->installPropertyMap( propMap );
76 sqlForm->insert( forenameEdit, "forename" );
77 sqlForm->insert( surnameEdit, "surname" );
78 sqlForm->insert( salaryEdit, "salary" );
79 sqlForm->readFields();
80}
81
82
83FormDialog::~FormDialog()
84{
85 delete staffCursor;
86}
87
88
89void FormDialog::save()
90{
91 sqlForm->writeFields();
92 staffCursor->update();
93 staffCursor->select( idIndex );
94 staffCursor->first();
95}
96
97
98int main( int argc, char *argv[] )
99{
100 QApplication app( argc, argv );
101
102 if ( ! createConnections() )
103 return 1;
104
105 FormDialog *formDialog = new FormDialog();
106 formDialog->show();
107 app.setMainWidget( formDialog );
108
109 return app.exec();
110}
Note: See TracBrowser for help on using the repository browser.