Brush up the imageviewer example
- Fix the save as file dialog being in "Open" mode by setting acceptMode - Fix clazy warnings about detaching QList by using constFirst() - Fix clazy warning about passing a context to slot connection Pick-to: 6.0 6.1 5.15 Change-Id: I0c800e9829e118fcec477322aa2a13660e3b51d2 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
parent
5dab1e931d
commit
fe1ef3ebcb
@ -176,6 +176,7 @@ static void initializeImageFileDialog(QFileDialog &dialog, QFileDialog::AcceptMo
|
||||
mimeTypeFilters.sort();
|
||||
dialog.setMimeTypeFilters(mimeTypeFilters);
|
||||
dialog.selectMimeTypeFilter("image/jpeg");
|
||||
dialog.setAcceptMode(acceptMode);
|
||||
if (acceptMode == QFileDialog::AcceptSave)
|
||||
dialog.setDefaultSuffix("jpg");
|
||||
}
|
||||
@ -185,7 +186,7 @@ void ImageViewer::open()
|
||||
QFileDialog dialog(this, tr("Open File"));
|
||||
initializeImageFileDialog(dialog, QFileDialog::AcceptOpen);
|
||||
|
||||
while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().first())) {}
|
||||
while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().constFirst())) {}
|
||||
}
|
||||
//! [1]
|
||||
|
||||
@ -194,7 +195,7 @@ void ImageViewer::saveAs()
|
||||
QFileDialog dialog(this, tr("Save File As"));
|
||||
initializeImageFileDialog(dialog, QFileDialog::AcceptSave);
|
||||
|
||||
while (dialog.exec() == QDialog::Accepted && !saveFile(dialog.selectedFiles().first())) {}
|
||||
while (dialog.exec() == QDialog::Accepted && !saveFile(dialog.selectedFiles().constFirst())) {}
|
||||
}
|
||||
|
||||
//! [5]
|
||||
@ -365,7 +366,7 @@ void ImageViewer::createActions()
|
||||
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
|
||||
helpMenu->addAction(tr("&About"), this, &ImageViewer::about);
|
||||
helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt);
|
||||
helpMenu->addAction(tr("About &Qt"), this, &QApplication::aboutQt);
|
||||
}
|
||||
//! [18]
|
||||
|
||||
|
@ -63,7 +63,7 @@ int main(int argc, char *argv[])
|
||||
commandLineParser.process(QCoreApplication::arguments());
|
||||
ImageViewer imageViewer;
|
||||
if (!commandLineParser.positionalArguments().isEmpty()
|
||||
&& !imageViewer.loadFile(commandLineParser.positionalArguments().front())) {
|
||||
&& !imageViewer.loadFile(commandLineParser.positionalArguments().constFirst())) {
|
||||
return -1;
|
||||
}
|
||||
imageViewer.show();
|
||||
|
Loading…
Reference in New Issue
Block a user