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
62931997
Commit
62931997
authored
Jul 22, 2009
by
Kavindra Devi Palaraja
Browse files
Doc - More of Part 7
Reviewed-By: TrustMe
parent
08345a27
Changes
4
Hide whitespace changes
Inline
Side-by-side
doc/addressbook-sdk.qdoc
View file @
62931997
...
...
@@ -881,10 +881,13 @@
\gui{Save...} respectively. Ideally, it would be more user-friendly to set
the push buttons' labels to \gui{Load contacts from file} and
\gui{Save contacts to file}. However, due to the size of our push buttons,
we set the labels to \gui{Load...} and \gui{Save...} instead. Fortunately,
Qt Creator's \QD plugin provides a simple way to set tooltips with the
\c toolTip property. To test your tooltip, use \key{Ctrl+Alt+R} and hover
your mouse cursor on the push buttons.
we set the labels to \gui{Load...} and \gui{Save...} instead.
Fortunately, Qt Creator's \QD plugin provides a simple way to set tooltips
with the \c toolTip property. So, we set our buttons' tooltips to
\gui{Load contacts from file} and \gui{Save contacts to file} respectively.
To test your tooltip, use \key{Ctrl+Alt+R} and hover your mouse cursor on
the push buttons.
# screenshot of property editor
...
...
@@ -894,7 +897,7 @@
We declare two public slots, \c saveToFile() and \c loadFromFile().
# code
\snippet examples/addressbook-sdk/part6/addressbook.h slot definition
Now lets look at the \c saveToFile() and \c loadFromFile() functions in
detail.
...
...
@@ -988,7 +991,8 @@
\section1 Placing Widgets on The Form
We add a push button into our layout by dragging and dropping it in, with
\c exportButton as its \c objectName.
\c exportButton as its \c objectName. The \c toolTip property is set to
\gui{Export as vCard}.
# screenshot
...
...
doc/examples/addressbook-sdk/part7/addressbook.cpp
View file @
62931997
...
...
@@ -31,6 +31,8 @@ AddressBook::AddressBook(QWidget *parent)
SLOT
(
removeContact
()));
connect
(
ui
->
findButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
findContact
()));
connect
(
ui
->
exportButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
exportAsVCard
()));
setWindowTitle
(
tr
(
"Simple Address Book"
));
}
...
...
@@ -281,7 +283,7 @@ void AddressBook::loadFromFile()
in
>>
contacts
;
if
(
contacts
.
isEmpty
())
{
QMessage
b
ox
::
information
(
this
,
tr
(
"No contacts in file"
),
QMessage
B
ox
::
information
(
this
,
tr
(
"No contacts in file"
),
tr
(
"The file you are attempting to open contains no contacts."
));
}
else
{
QMap
<
QString
,
QString
>::
iterator
i
=
contacts
.
begin
();
...
...
@@ -292,3 +294,59 @@ void AddressBook::loadFromFile()
updateInterface
(
NavigationMode
);
}
void
AddressBook
::
exportAsVCard
()
{
QString
name
=
ui
->
nameLine
->
text
();
QString
address
=
ui
->
addressText
->
toPlainText
();
QString
firstName
;
QString
lastName
;
QStringList
nameList
;
int
index
=
name
.
indexOf
(
" "
);
if
(
index
!=
-
1
)
{
nameList
=
name
.
split
(
QRegExp
(
"
\\
s+"
),
QString
::
SkipEmptyParts
);
firstName
=
nameList
.
first
();
lastName
=
nameList
.
last
();
}
else
{
firstName
=
name
;
lastName
=
""
;
}
QString
fileName
=
QFileDialog
::
getSaveFileName
(
this
,
tr
(
"Export Coontact"
),
""
,
tr
(
"vCard files (*.vcf);;All Files (*)"
));
if
(
fileName
.
isEmpty
())
return
;
QFile
file
(
fileName
);
if
(
!
file
.
open
(
QIODevice
::
WriteOnly
))
{
QMessageBox
::
information
(
this
,
tr
(
"Unable to open file"
),
file
.
errorString
());
return
;
}
QTextStream
out
(
&
file
);
out
<<
"BEGIN:VCARD"
<<
"
\n
"
;
out
<<
"VERSION:2.1"
<<
"
\n
"
;
out
<<
"N:"
<<
lastName
<<
";"
<<
firstName
<<
"
\n
"
;
if
(
!
nameList
.
isEmpty
())
out
<<
"FN:"
<<
nameList
.
join
(
" "
)
<<
"
\n
"
;
else
out
<<
"FN:"
<<
firstName
<<
"
\n
"
;
address
.
replace
(
";"
,
"
\\
;"
,
Qt
::
CaseInsensitive
);
address
.
replace
(
"
\n
"
,
";"
,
Qt
::
CaseInsensitive
);
address
.
replace
(
","
,
" "
,
Qt
::
CaseInsensitive
);
out
<<
"ADR;HOME:;"
<<
address
<<
"
\n
"
;
out
<<
"END;VCARD"
<<
"
\n
"
;
QMessageBox
::
information
(
this
,
tr
(
"Export Successful"
),
tr
(
"\%1
\"
has been exported as a vCard."
).
arg
(
name
));
}
doc/examples/addressbook-sdk/part7/addressbook.h
View file @
62931997
...
...
@@ -29,10 +29,11 @@ public slots:
void
next
();
void
previous
();
void
findContact
();
//! [slot definition]
void
saveToFile
();
void
loadFromFile
();
//! [slot definition]
void
exportAsVCard
();
//! [slot definition]
private:
Ui
::
AddressBook
*
ui
;
...
...
doc/examples/addressbook-sdk/part7/addressbook.ui
View file @
62931997
...
...
@@ -103,6 +103,16 @@
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"exportButton"
>
<property
name=
"toolTip"
>
<string>
Export as vCard
</string>
</property>
<property
name=
"text"
>
<string>
Export
</string>
</property>
</widget>
</item>
<item>
<spacer
name=
"verticalSpacer"
>
<property
name=
"orientation"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment