Don't use file dialog in the address book example
On small screen devices such as iPhone targets, the save file dialog is using a non-native dialog, and it doesn't fit the screen real estate to the extent that the [Ok] button is clipped away. In addition, the open file dialog and the save file dialog doesn't cooperate very well on platforms such as iOS without more plumbing. Since using the file dialog is out of the scope for this example we remove all usages of it. Change-Id: Ie165355ed0b671d93e44d2d55791156367b0ea5c Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 4dbb07f614c914e78437aacf7a1716f632da5e8a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
61f7b89e6f
commit
be95bb0358
@ -381,17 +381,15 @@
|
||||
respective slots, we also connect \c AddressWidget's
|
||||
\c selectionChanged() signal to its \c updateActions() slot.
|
||||
|
||||
The \c openFile() function allows the user to choose a file with
|
||||
the \l{QFileDialog::getOpenFileName()}{open file dialog}. The chosen
|
||||
file has to be a custom \c{.dat} file that contains address book
|
||||
contacts. This function is a slot connected to \c openAct in the
|
||||
\uicontrol File menu.
|
||||
The \c openFile() function opens a custom \c{addressbook.dat} file that
|
||||
contains address book contacts. This function is a slot connected to
|
||||
\c openAct in the \uicontrol File menu.
|
||||
|
||||
\snippet itemviews/addressbook/mainwindow.cpp 2
|
||||
|
||||
The \c saveFile() function allows the user to save a file with
|
||||
the \l{QFileDialog::getSaveFileName()}{save file dialog}. This function
|
||||
is a slot connected to \c saveAct in the \uicontrol File menu.
|
||||
The \c saveFile() function saves a custom \c{addressbook.dat} file that
|
||||
will contain the address book contacts. This function is a slot connected
|
||||
to \c saveAct in the \uicontrol File menu.
|
||||
|
||||
\snippet itemviews/addressbook/mainwindow.cpp 3
|
||||
|
||||
|
@ -146,7 +146,7 @@ void AddressWidget::setupTabs()
|
||||
//! [1]
|
||||
|
||||
//! [7]
|
||||
void AddressWidget::readFromFile(const QString &fileName)
|
||||
void AddressWidget::readFromFile()
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
||||
@ -171,7 +171,7 @@ void AddressWidget::readFromFile(const QString &fileName)
|
||||
//! [7]
|
||||
|
||||
//! [6]
|
||||
void AddressWidget::writeToFile(const QString &fileName)
|
||||
void AddressWidget::writeToFile()
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <QItemSelection>
|
||||
#include <QTabWidget>
|
||||
#include <QStandardPaths>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSortFilterProxyModel;
|
||||
@ -22,8 +23,8 @@ class AddressWidget : public QTabWidget
|
||||
|
||||
public:
|
||||
AddressWidget(QWidget *parent = nullptr);
|
||||
void readFromFile(const QString &fileName);
|
||||
void writeToFile(const QString &fileName);
|
||||
void readFromFile();
|
||||
void writeToFile();
|
||||
|
||||
public slots:
|
||||
void showAddEntryDialog();
|
||||
@ -37,6 +38,9 @@ signals:
|
||||
private:
|
||||
void setupTabs();
|
||||
|
||||
inline static QString fileName =
|
||||
QStandardPaths::standardLocations(QStandardPaths::TempLocation).value(0)
|
||||
+ QStringLiteral("/addressbook.dat");
|
||||
TableModel *table;
|
||||
NewAddressTab *newAddressTab;
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ void MainWindow::createMenus()
|
||||
connect(openAct, &QAction::triggered, this, &MainWindow::openFile);
|
||||
//! [1a]
|
||||
|
||||
QAction *saveAct = new QAction(tr("&Save As..."), this);
|
||||
QAction *saveAct = new QAction(tr("&Save"), this);
|
||||
fileMenu->addAction(saveAct);
|
||||
connect(saveAct, &QAction::triggered, this, &MainWindow::saveFile);
|
||||
|
||||
@ -66,18 +66,14 @@ void MainWindow::createMenus()
|
||||
//! [2]
|
||||
void MainWindow::openFile()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this);
|
||||
if (!fileName.isEmpty())
|
||||
addressWidget->readFromFile(fileName);
|
||||
addressWidget->readFromFile();
|
||||
}
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
void MainWindow::saveFile()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this);
|
||||
if (!fileName.isEmpty())
|
||||
addressWidget->writeToFile(fileName);
|
||||
addressWidget->writeToFile();
|
||||
}
|
||||
//! [3]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user