Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
f1dfb3c6
Commit
f1dfb3c6
authored
Jul 22, 2009
by
dt
Browse files
Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline
parents
2ece459a
dee87d4e
Changes
120
Expand all
Hide whitespace changes
Inline
Side-by-side
doc/addressbook-sdk.qdoc
View file @
f1dfb3c6
...
...
@@ -714,8 +714,8 @@
of buttons.
When the user clicks on the \gui Find button, it is useful to display a
dialog
that can
prompt the user for a contact's name. Qt provides QDialog,
which
we subclass in this chapter, to implement a FindDialog class.
dialog prompt
ing
the user for a contact's name. Qt provides QDialog,
which
we subclass in this chapter, to implement a FindDialog class.
\section1 Designing The FindDialog
...
...
@@ -737,24 +737,17 @@
\section1 Implementing The FindDialog Class
Let's look at \c{FindDialog}'s header file. Here, we need to provide
private members for the class so that we can access the widgets freely
throughout the class.
Let's look at \c{FindDialog}'s header file. We define a public function,
\c findText(), to be used by classes that instantiate \c FindDialog. This
function allows the these classes to obtain the search string entered by
the user. A public slot, \c findClicked(), is also defined to handle the
search string when the user clicks the \gui Find button.
\snippet examples/addressbook-sdk/part5/finddialog.h private members
We define a public function, \c getFindText(), to be used by classes that
instantiate \c FindDialog. This function allows the these classes to obtain
the search string entered by the user. A public slot, \c findClicked(), is
also defined to handle the search string when the user clicks the \gui Find
button.
\snippet examples/addressbook-sdk/part5/finddialog.h getFindText
\snippet examples/addressbook-sdk/part5/finddialog.h findText
\dots
\snippet examples/addressbook-sdk/part5/finddialog.h findClicked
Now, lets look at our constructor in the \c{finddialog.cpp} file. Here, we
set up the private variables, \c lineEdit, \c findButton, and \c findText.
Now, lets look at our constructor in the \c{finddialog.cpp} file.
\snippet examples/addressbook-sdk/part5/finddialog.cpp constructor
...
...
doc/examples/addressbook-sdk/part5/addressbook.cpp
View file @
f1dfb3c6
...
...
@@ -6,64 +6,31 @@ AddressBook::AddressBook(QWidget *parent)
{
ui
->
setupUi
(
this
);
nameLine
=
new
QLineEdit
;
nameLine
=
ui
->
nameLine
;
nameLine
->
setReadOnly
(
true
);
addressText
=
new
QTextEdit
;
addressText
=
ui
->
addressText
;
addressText
->
setReadOnly
(
true
);
addButton
=
new
QPushButton
;
addButton
=
ui
->
addButton
;
submitButton
=
new
QPushButton
;
submitButton
=
ui
->
submitButton
;
submitButton
->
hide
();
cancelButton
=
new
QPushButton
;
cancelButton
=
ui
->
cancelButton
;
cancelButton
->
hide
();
nextButton
=
new
QPushButton
;
nextButton
=
ui
->
nextButton
;
nextButton
->
setEnabled
(
false
);
previousButton
=
new
QPushButton
;
previousButton
=
ui
->
previousButton
;
previousButton
->
setEnabled
(
false
);
editButton
=
new
QPushButton
;
editButton
=
ui
->
editButton
;
editButton
->
setEnabled
(
false
);
removeButton
=
new
QPushButton
;
removeButton
=
ui
->
removeButton
;
removeButton
->
setEnabled
(
false
);
//! [private members]
findButton
=
new
QPushButton
;
findButton
=
ui
->
findButton
;
dialog
=
new
FindDialog
;
//! [private members]
connect
(
addButton
,
SIGNAL
(
clicked
()),
this
,
ui
->
nameLine
->
setReadOnly
(
true
);
ui
->
addressText
->
setReadOnly
(
true
);
ui
->
submitButton
->
hide
();
ui
->
cancelButton
->
hide
();
ui
->
nextButton
->
setEnabled
(
false
);
ui
->
previousButton
->
setEnabled
(
false
);
ui
->
editButton
->
setEnabled
(
false
);
ui
->
removeButton
->
setEnabled
(
false
);
connect
(
ui
->
addButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
addContact
()));
connect
(
submitButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
submitButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
submitContact
()));
connect
(
cancelButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
cancelButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
cancel
()));
connect
(
nextButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
nextButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
next
()));
connect
(
previousButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
previousButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
previous
()));
connect
(
editButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
editButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
editContact
()));
connect
(
removeButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
removeButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
removeContact
()));
//! [signal slot]
connect
(
findButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
findButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
findContact
()));
//! [signal slot]
...
...
@@ -77,23 +44,25 @@ AddressBook::~AddressBook()
void
AddressBook
::
addContact
()
{
oldName
=
nameLine
->
text
();
oldAddress
=
addressText
->
toPlainText
();
oldName
=
ui
->
nameLine
->
text
();
oldAddress
=
ui
->
addressText
->
toPlainText
();
nameLine
->
clear
();
addressText
->
clear
();
ui
->
nameLine
->
clear
();
ui
->
addressText
->
clear
();
updateInterface
(
AddingMode
);
}
void
AddressBook
::
submitContact
()
{
QString
name
=
nameLine
->
text
();
QString
address
=
addressText
->
toPlainText
();
QString
name
=
ui
->
nameLine
->
text
();
QString
address
=
ui
->
addressText
->
toPlainText
();
if
(
name
==
""
||
address
==
""
)
{
QMessageBox
::
information
(
this
,
tr
(
"Empty Field"
),
tr
(
"Please enter a name and address."
));
updateInterface
(
NavigationMode
);
return
;
}
if
(
currentMode
==
AddingMode
)
{
...
...
@@ -130,15 +99,15 @@ void AddressBook::submitContact()
void
AddressBook
::
cancel
()
{
nameLine
->
setText
(
oldName
);
nameLine
->
setReadOnly
(
true
);
ui
->
nameLine
->
setText
(
oldName
);
ui
->
nameLine
->
setReadOnly
(
true
);
updateInterface
(
NavigationMode
);
}
void
AddressBook
::
next
()
{
QString
name
=
nameLine
->
text
();
QString
name
=
ui
->
nameLine
->
text
();
QMap
<
QString
,
QString
>::
iterator
i
=
contacts
.
find
(
name
);
if
(
i
!=
contacts
.
end
())
...
...
@@ -146,18 +115,18 @@ void AddressBook::next()
if
(
i
==
contacts
.
end
())
i
=
contacts
.
begin
();
nameLine
->
setText
(
i
.
key
());
addressText
->
setText
(
i
.
value
());
ui
->
nameLine
->
setText
(
i
.
key
());
ui
->
addressText
->
setText
(
i
.
value
());
}
void
AddressBook
::
previous
()
{
QString
name
=
nameLine
->
text
();
QString
name
=
ui
->
nameLine
->
text
();
QMap
<
QString
,
QString
>::
iterator
i
=
contacts
.
find
(
name
);
if
(
i
==
contacts
.
end
())
{
nameLine
->
clear
();
addressText
->
clear
();
ui
->
nameLine
->
clear
();
ui
->
addressText
->
clear
();
return
;
}
...
...
@@ -165,22 +134,22 @@ void AddressBook::previous()
i
=
contacts
.
end
();
i
--
;
nameLine
->
setText
(
i
.
key
());
addressText
->
setText
(
i
.
value
());
ui
->
nameLine
->
setText
(
i
.
key
());
ui
->
addressText
->
setText
(
i
.
value
());
}
void
AddressBook
::
editContact
()
{
oldName
=
nameLine
->
text
();
oldAddress
=
addressText
->
toPlainText
();
oldName
=
ui
->
nameLine
->
text
();
oldAddress
=
ui
->
addressText
->
toPlainText
();
updateInterface
(
EditingMode
);
}
void
AddressBook
::
removeContact
()
{
QString
name
=
nameLine
->
text
();
QString
address
=
addressText
->
toPlainText
();
QString
name
=
ui
->
nameLine
->
text
();
QString
address
=
ui
->
addressText
->
toPlainText
();
if
(
contacts
.
contains
(
name
))
{
int
button
=
QMessageBox
::
question
(
this
,
...
...
@@ -209,43 +178,43 @@ void AddressBook::updateInterface(Mode mode)
case
AddingMode
:
case
EditingMode
:
nameLine
->
setReadOnly
(
false
);
nameLine
->
setFocus
(
Qt
::
OtherFocusReason
);
addressText
->
setReadOnly
(
false
);
ui
->
nameLine
->
setReadOnly
(
false
);
ui
->
nameLine
->
setFocus
(
Qt
::
OtherFocusReason
);
ui
->
addressText
->
setReadOnly
(
false
);
addButton
->
setEnabled
(
false
);
editButton
->
setEnabled
(
false
);
removeButton
->
setEnabled
(
false
);
ui
->
addButton
->
setEnabled
(
false
);
ui
->
editButton
->
setEnabled
(
false
);
ui
->
removeButton
->
setEnabled
(
false
);
nextButton
->
setEnabled
(
false
);
previousButton
->
setEnabled
(
false
);
ui
->
nextButton
->
setEnabled
(
false
);
ui
->
previousButton
->
setEnabled
(
false
);
submitButton
->
show
();
cancelButton
->
show
();
ui
->
submitButton
->
show
();
ui
->
cancelButton
->
show
();
break
;
case
NavigationMode
:
if
(
contacts
.
isEmpty
())
{
nameLine
->
clear
();
addressText
->
clear
();
ui
->
nameLine
->
clear
();
ui
->
addressText
->
clear
();
}
nameLine
->
setReadOnly
(
true
);
addressText
->
setReadOnly
(
true
);
addButton
->
setEnabled
(
true
);
ui
->
nameLine
->
setReadOnly
(
true
);
ui
->
addressText
->
setReadOnly
(
true
);
ui
->
addButton
->
setEnabled
(
true
);
int
number
=
contacts
.
size
();
editButton
->
setEnabled
(
number
>=
1
);
removeButton
->
setEnabled
(
number
>=
1
);
ui
->
editButton
->
setEnabled
(
number
>=
1
);
ui
->
removeButton
->
setEnabled
(
number
>=
1
);
//! [enable]
findButton
->
setEnabled
(
number
>
2
);
ui
->
findButton
->
setEnabled
(
number
>
2
);
//! [enable]
nextButton
->
setEnabled
(
number
>
1
);
previousButton
->
setEnabled
(
number
>
1
);
ui
->
nextButton
->
setEnabled
(
number
>
1
);
ui
->
previousButton
->
setEnabled
(
number
>
1
);
submitButton
->
hide
();
cancelButton
->
hide
();
ui
->
submitButton
->
hide
();
ui
->
cancelButton
->
hide
();
break
;
}
}
...
...
@@ -253,14 +222,14 @@ void AddressBook::updateInterface(Mode mode)
//! [findContact]
void
AddressBook
::
findContact
()
{
dialog
->
show
()
;
FindDialog
dialog
;
if
(
dialog
->
exec
()
==
QDialog
::
Accepted
)
{
QString
contactName
=
dialog
->
getF
indText
();
if
(
dialog
.
exec
()
==
QDialog
::
Accepted
)
{
QString
contactName
=
dialog
.
f
indText
();
if
(
contacts
.
contains
(
contactName
))
{
nameLine
->
setText
(
contactName
);
addressText
->
setText
(
contacts
.
value
(
contactName
));
ui
->
nameLine
->
setText
(
contactName
);
ui
->
addressText
->
setText
(
contacts
.
value
(
contactName
));
}
else
{
QMessageBox
::
information
(
this
,
tr
(
"Contact Not Found"
),
tr
(
"Sorry,
\"
%1
\"
is not in your address book."
).
arg
(
contactName
));
...
...
doc/examples/addressbook-sdk/part5/addressbook.h
View file @
f1dfb3c6
...
...
@@ -2,10 +2,8 @@
#define ADDRESSBOOK_H
#include
<QtGui/QWidget>
#include
<QtGui/QPushButton>
#include
<QtGui/QLineEdit>
#include
<QtGui/QTextEdit>
#include
<QtGui/QMessageBox>
#include
<QtCore/QMap>
//! [include]
#include
"finddialog.h"
//! [include]
...
...
@@ -38,28 +36,12 @@ public slots:
private:
Ui
::
AddressBook
*
ui
;
void
updateInterface
(
Mode
mode
);
QPushButton
*
addButton
;
QPushButton
*
submitButton
;
QPushButton
*
cancelButton
;
QPushButton
*
editButton
;
QPushButton
*
removeButton
;
QPushButton
*
nextButton
;
QPushButton
*
previousButton
;
//! [private members]
QPushButton
*
findButton
;
//! [private members]
QLineEdit
*
nameLine
;
QTextEdit
*
addressText
;
QMap
<
QString
,
QString
>
contacts
;
QString
oldName
;
QString
oldAddress
;
Mode
currentMode
;
//! [dialog]
FindDialog
*
dialog
;
//! [dialog]
};
#endif // ADDRESSBOOK_H
doc/examples/addressbook-sdk/part5/finddialog.cpp
View file @
f1dfb3c6
...
...
@@ -8,15 +8,8 @@ FindDialog::FindDialog(QWidget *parent) :
m_ui
(
new
Ui
::
FindDialog
)
{
m_ui
->
setupUi
(
this
);
lineEdit
=
new
QLineEdit
;
lineEdit
=
m_ui
->
lineEdit
;
findButton
=
new
QPushButton
;
findButton
=
m_ui
->
findButton
;
findText
=
""
;
connect
(
findButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
findClicked
()));
connect
(
m_ui
->
findButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
findClicked
()));
setWindowTitle
(
tr
(
"Find a Contact"
));
}
...
...
@@ -30,23 +23,21 @@ FindDialog::~FindDialog()
//! [findClicked]
void
FindDialog
::
findClicked
()
{
QString
text
=
lineEdit
->
text
();
QString
text
=
m_ui
->
lineEdit
->
text
();
if
(
text
.
isEmpty
())
{
QMessageBox
::
information
(
this
,
tr
(
"Empty Field"
),
tr
(
"Please enter a name."
));
re
turn
;
re
ject
()
;
}
else
{
findText
=
text
;
lineEdit
->
clear
();
hide
();
accept
();
}
}
//! [findClicked]
//! [
getF
indText]
QString
FindDialog
::
getF
indText
()
//! [
f
indText]
QString
FindDialog
::
f
indText
()
{
return
findT
ext
;
return
m_ui
->
lineEdit
->
t
ext
()
;
}
//! [
getF
indText]
//! [
f
indText]
doc/examples/addressbook-sdk/part5/finddialog.h
View file @
f1dfb3c6
...
...
@@ -14,9 +14,9 @@ class FindDialog : public QDialog {
public:
FindDialog
(
QWidget
*
parent
=
0
);
~
FindDialog
();
//! [
getF
indText]
QString
getF
indText
();
//! [
getF
indText]
//! [
f
indText]
QString
f
indText
();
//! [
f
indText]
//! [findClicked]
public
slots
:
...
...
@@ -26,9 +26,6 @@ public slots:
//! [private members]
private:
Ui
::
FindDialog
*
m_ui
;
QPushButton
*
findButton
;
QLineEdit
*
lineEdit
;
QString
findText
;
//! [private members]
};
...
...
doc/examples/addressbook-sdk/part6/addressbook.cpp
View file @
f1dfb3c6
...
...
@@ -6,69 +6,30 @@ AddressBook::AddressBook(QWidget *parent)
{
ui
->
setupUi
(
this
);
nameLine
=
new
QLineEdit
;
nameLine
=
ui
->
nameLine
;
nameLine
->
setReadOnly
(
true
);
addressText
=
new
QTextEdit
;
addressText
=
ui
->
addressText
;
addressText
->
setReadOnly
(
true
);
addButton
=
new
QPushButton
;
addButton
=
ui
->
addButton
;
submitButton
=
new
QPushButton
;
submitButton
=
ui
->
submitButton
;
submitButton
->
hide
();
cancelButton
=
new
QPushButton
;
cancelButton
=
ui
->
cancelButton
;
cancelButton
->
hide
();
nextButton
=
new
QPushButton
;
nextButton
=
ui
->
nextButton
;
nextButton
->
setEnabled
(
false
);
previousButton
=
new
QPushButton
;
previousButton
=
ui
->
previousButton
;
previousButton
->
setEnabled
(
false
);
editButton
=
new
QPushButton
;
editButton
=
ui
->
editButton
;
editButton
->
setEnabled
(
false
);
removeButton
=
new
QPushButton
;
removeButton
=
ui
->
removeButton
;
removeButton
->
setEnabled
(
false
);
findButton
=
new
QPushButton
;
findButton
=
ui
->
findButton
;
dialog
=
new
FindDialog
;
//! [private members]
loadButton
=
new
QPushButton
;
loadButton
=
ui
->
loadButton
;
saveButton
=
new
QPushButton
;
saveButton
=
ui
->
saveButton
;
//! [private members]
connect
(
addButton
,
SIGNAL
(
clicked
()),
this
,
ui
->
nameLine
->
setReadOnly
(
true
);
ui
->
addressText
->
setReadOnly
(
true
);
ui
->
submitButton
->
hide
();
ui
->
cancelButton
->
hide
();
ui
->
nextButton
->
setEnabled
(
false
);
ui
->
previousButton
->
setEnabled
(
false
);
ui
->
editButton
->
setEnabled
(
false
);
ui
->
removeButton
->
setEnabled
(
false
);
connect
(
ui
->
addButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
addContact
()));
connect
(
submitButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
submitButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
submitContact
()));
connect
(
cancelButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
cancelButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
cancel
()));
connect
(
nextButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
nextButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
next
()));
connect
(
previousButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
previousButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
previous
()));
connect
(
editButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
editButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
editContact
()));
connect
(
removeButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
removeButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
removeContact
()));
connect
(
findButton
,
SIGNAL
(
clicked
()),
this
,
connect
(
ui
->
findButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
findContact
()));
setWindowTitle
(
tr
(
"Simple Address Book"
));
...
...
@@ -81,23 +42,25 @@ AddressBook::~AddressBook()
void
AddressBook
::
addContact
()
{
oldName
=
nameLine
->
text
();
oldAddress
=
addressText
->
toPlainText
();
oldName
=
ui
->
nameLine
->
text
();
oldAddress
=
ui
->
addressText
->
toPlainText
();
nameLine
->
clear
();
addressText
->
clear
();
ui
->
nameLine
->
clear
();
ui
->
addressText
->
clear
();
updateInterface
(
AddingMode
);
}
void
AddressBook
::
submitContact
()
{
QString
name
=
nameLine
->
text
();
QString
address
=
addressText
->
toPlainText
();
QString
name
=
ui
->
nameLine
->
text
();
QString
address
=
ui
->
addressText
->
toPlainText
();
if
(
name
==
""
||
address
==
""
)
{
QMessageBox
::
information
(
this
,
tr
(
"Empty Field"
),
tr
(
"Please enter a name and address."
));
updateInterface
(
NavigationMode
);
return
;
}
if
(
currentMode
==
AddingMode
)
{
...
...
@@ -134,15 +97,15 @@ void AddressBook::submitContact()
void
AddressBook
::
cancel
()
{
nameLine
->
setText
(
oldName
);
nameLine
->
setReadOnly
(
true
);
ui
->
nameLine
->
setText
(
oldName
);
ui
->
nameLine
->
setReadOnly
(
true
);
updateInterface
(
NavigationMode
);
}
void
AddressBook
::
next
()
{
QString
name
=
nameLine
->
text
();
QString
name
=
ui
->
nameLine
->
text
();
QMap
<
QString
,
QString
>::
iterator
i
=
contacts
.
find
(
name
);
if
(
i
!=
contacts
.
end
())
...
...
@@ -150,18 +113,18 @@ void AddressBook::next()
if
(
i
==
contacts
.
end
())
i
=
contacts
.
begin
();
nameLine
->
setText
(
i
.
key
());
addressText
->
setText
(
i
.
value
());
ui
->
nameLine
->
setText
(
i
.
key
());
ui
->
addressText
->
setText
(
i
.
value
());
}
void
AddressBook
::
previous
()
{
QString
name
=
nameLine
->
text
();
QString
name
=
ui
->
nameLine
->
text
();
QMap
<
QString
,
QString
>::
iterator
i
=
contacts
.
find
(
name
);
if
(
i
==
contacts
.
end
())
{
nameLine
->
clear
();
addressText
->
clear
();
ui
->
nameLine
->
clear
();
ui
->
addressText
->
clear
();
return
;
}
...
...
@@ -169,22 +132,22 @@ void AddressBook::previous()
i
=
contacts
.
end
();
i
--
;
nameLine
->
setText
(
i
.
key
());
addressText
->
setText
(
i
.
value
());
ui
->
nameLine
->
setText
(
i
.
key
());
ui
->
addressText
->
setText
(
i
.
value
());
}
void
AddressBook
::
editContact
()