Commit bb900dd8 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Merge branch 'master' of

parents fb48a262 d9cabeba
......@@ -362,7 +362,7 @@
\snippet examples/addressbook-sdk/part2/addressbook.cpp window title
\section2 The \c{addContact()} Function
\section2 The \c addContact() Function
In this function, we begin by storing the last displayed contact details
in \c oldName and \c oldAddress. Then we clear these input fields and turn
......@@ -371,7 +371,7 @@
\snippet examples/addressbook-sdk/part2/addressbook.cpp addContact
\section2 The \c{submitContact()} Function
\section2 The \c submitContact() Function
This function can be divided into three parts:
......@@ -404,7 +404,7 @@
\image addressbook-tutorial-part2-add-successful.png
\section2 The \c{cancel()} Function
\section2 The \c cancel() Function
This function restores the last displayed contact details and enables
\c addButton, as well as hides \c submitButton and \c cancelButton.
......@@ -632,7 +632,7 @@
\section2 The \c{editContact()} Function
\section2 The \c editContact() Function
This function stores the contact's old details in \c oldName and
\c oldAddress, before switching the mode to \c EditingMode. In this mode,
......@@ -680,7 +680,7 @@
# image
\section2 The \c{updateInterface()} Function
\section2 The \c updateInterface() Function
We mentioned this function earlier as a means to enable and disable the
push buttons, depending on the current mode. The function updates the
......@@ -911,13 +911,70 @@
Ideally, it would be more user-friendly to set the push buttons' labels to
"Load contacts from a file" and "Save contacts to a file". However, due to
the size of our push buttons, we set the labels to \gui{Load...} and
\gui{Save...}. Fortunately, Qt provides a simple way to set tooltips with
\l{QWidget::}{setToolTip()} and we use it in the following way for our push
\gui{Save...}. Fortunately, Qt Creator's \QD plugin provides a simple way
to set tooltips with the \gui{Property Editor}. Simply fill in your tool
tips in the \gui{toolTip} property. To test your tooltip, use
\key{Ctrl+Alt+R} and hover your mouse cursor on the \gui{Load...} and
\gui{Save...} push buttons.
# code
# screenshot of property editor
Now lets look at the \c saveToFile() and \c loadFromFile() functions in
\section2 The \c saveToFile() Function
To save a contact, we first obtain \c fileName using
QFileDialog::getSaveFileName(). This is a convenience function provided by
QFileDialog, which pops up a modal file dialog and allows the user to enter
a file name or select any existing \c{.abk} file. The \c{.abk} file is our
Address Book extension that we create when we save contacts.
\snippet examples/addressbook-sdk/part6/addressbook.cpp saveToFile part1
The file dialog that pops up is displayed in the screenshto below:
If \c fileName is not empty, we create a QFile object, \c file, with
\c fileName. The QFile object works with QDataStream as QFile is a
Next, we attempt to open the file in \l{QIODevice::}{WriteOnly} mode. If
this is unsuccessful, we display a QMessageBox to inform the user.
\snippet examples/addressbook-sdk/part6/addressbook.cpp saveToFile part2
Otherwise, we instantiate a QDataStream object, \c out, to write the open
file. QDataStream requires that the same version of the stream is used for
reading and writing. We ensure that this is the case by setting the version
used to the version introduced with Qt 4.5 before serializing the data into
\c file.
\snippet examples/addressbook-sdk/part6/addressbook.cpp saveToFile part3
\section2 The \c loadFromFile() Function
To load a contact, we also obtain \c fileName using
QFileDialog::getOpenFileName(). This function, the counterpart to
QFileDialog::getSaveFileName(), also pops up the modal file dialog and
allows the user to enter a file name or select any existing \c{.abk} file
to load it into the address book.
\snippet examples/addressbook-sdk/part6/addressbook.cpp loadFromFile part1
On Windows, for example, this function pops up a native file dialog, as
shown in the following screenshot.
# screenshot
If \c fileName is not empty, again, we use a QFile object, \c file, and
attempt to open it in \l{QIODevice::}{ReadOnly} mode. Similar to our
\snippet examples/addressbook-sdk/part6/addressbook.cpp loadFromFile part2
\snippet examples/addressbook-sdk/part6/addressbook.cpp loadFromFile part3
......@@ -46,6 +46,14 @@ AddressBook::AddressBook(QWidget *parent)
dialog = new FindDialog;
//! [private members]
loadButton = new QPushButton;
loadButton = ui->loadButton;
saveButton = new QPushButton;
saveButton = ui->saveButton;
//! [private members]
connect(addButton, SIGNAL(clicked()), this,
connect(submitButton, SIGNAL(clicked()), this,
......@@ -263,3 +271,73 @@ void AddressBook::findContact()
//! [saveToFile part1]
void AddressBook::saveToFile()
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Address Book"), "",
tr("Address book (*.abk);; AllFiles (*)"));
//! [saveToFile part1]
//! [saveToFile part2]
if (fileName.isEmpty())
else {
QFile file(fileName);
if (! {
QMessageBox::information(this, tr("Unable to open file"),
//! [saveToFile part2]
//! [saveToFile part3]
QDataStream out(&file);
out << contacts;
//! [saveToFile part3]
//! [loadFromFile part1]
void AddressBook::loadFromFile()
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Address Book"), "",
tr("Address Book(*.abk);; All Files(*)"));
//! [loadFromFile part1]
//! [loadFromFile part2]
if (fileName.isEmpty())
else {
QFile file(fileName);
if (! {
QMessageBox::information(this, tr("Unable to open file"),
QDataStream in(&file);
contacts.empty(); // empty existing contacts
in >> contacts;
//! [loadFromFile part2]
//! [loadFromFile part3]
if (contacts.isEmpty()) {
QMessagebox::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();
//! [loadFromFile part3]
......@@ -85,6 +85,9 @@
<widget class="QPushButton" name="loadButton">
<property name="toolTip">
<string>Load contacts from a file</string>
<property name="text">
......@@ -92,6 +95,9 @@
<widget class="QPushButton" name="saveButton">
<property name="toolTip">
<string>Save contacts to a file</string>
<property name="text">
......@@ -91,8 +91,8 @@ const char * const C_NAVIGATION_PANE = "Core.NavigationPane";
const char * const C_PROBLEM_PANE = "Core.ProblemPane";
//default editor kind
const char * const K_DEFAULT_TEXT_EDITOR = "Plain Text Editor";
const char * const K_DEFAULT_BINARY_EDITOR = "Binary Editor";
const char * const K_DEFAULT_TEXT_EDITOR = QT_TRANSLATE_NOOP("OpenWith::Editors", "Plain Text Editor");
const char * const K_DEFAULT_BINARY_EDITOR = QT_TRANSLATE_NOOP("OpenWith::Editors", "Binary Editor");
const char * const UNDO = "QtCreator.Undo";
......@@ -36,7 +36,7 @@ namespace Constants {
const char * const FORMATCODE = "CppEditor.FormatCode";
const char * const M_CONTEXT = "CppEditor.ContextMenu";
const char * const C_CPPEDITOR = "C++ Editor";
const char * const CPPEDITOR_KIND = "C++ Editor";
const char * const CPPEDITOR_KIND = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++ Editor");
const char * const SWITCH_DECLARATION_DEFINITION = "CppEditor.SwitchDeclarationDefinition";
const char * const JUMP_TO_DEFINITION = "CppEditor.JumpToDefinition";
......@@ -372,6 +372,14 @@ protected:
virtual bool visit(TypenameTypeParameterAST *ast)
if (NameAST *nameAst = ast->name)
return true;
virtual bool visit(TemplateTypeParameterAST *ast)
if (ast->name)
......@@ -163,7 +163,7 @@ void FindPlugin::setupMenu()
cmd = am->registerAction(separator, QLatin1String("Find.Sep.Actions"), globalcontext);
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
m_openFindDialog = new QAction(tr("Find Dialog"), this);
m_openFindDialog = new QAction(tr("Find..."), this);
cmd = am->registerAction(m_openFindDialog, QLatin1String("Find.Dialog"), globalcontext);
mfind->addAction(cmd, Constants::G_FIND_FILTERS);
......@@ -1917,7 +1917,7 @@ void ProjectExplorerPlugin::populateOpenWithMenu()
// Add all suitable editors
foreach (Core::IEditorFactory *editorFactory, factories) {
// Add action to open with this very editor factory
QString const actionTitle(editorFactory->kind());
QString const actionTitle = qApp->translate("OpenWith::Editors", editorFactory->kind().toAscii());
QAction * const action = m_openWithMenu->addAction(actionTitle);
// File already open in an editor -> only enable that entry since
......@@ -1934,7 +1934,7 @@ void ProjectExplorerPlugin::populateOpenWithMenu()
} // for editor factories
// Add all suitable external editors
foreach (Core::IExternalEditor *externalEditor, externalEditors) {
QAction * const action = m_openWithMenu->addAction(externalEditor->kind());
QAction * const action = m_openWithMenu->addAction(qApp->translate("OpenWith::Editors", externalEditor->kind().toAscii()));
} // matches
......@@ -39,7 +39,7 @@ const char * const C_PROFILEEDITOR_PANEL = ".pro File Editor (embedded)";
// kinds
const char * const PROJECT_KIND = "Qt4";
const char * const PROFILE_EDITOR = ".pro File Editor";
const char * const PROFILE_EDITOR = QT_TRANSLATE_NOOP("OpenWith::Editors", ".pro File Editor");
const char * const PROFILE_MIMETYPE = "application/";
const char * const PROINCLUDEFILE_MIMETYPE = "application/";
const char * const CPP_SOURCE_MIMETYPE = "text/x-c++src";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment