GUI: Use native file selection dialog when selecting report file.
This commit is contained in:
parent
5d0d21d668
commit
a19c9861da
|
@ -489,39 +489,32 @@ void MainWindow::ShowAuthors()
|
|||
|
||||
void MainWindow::Save()
|
||||
{
|
||||
QFileDialog dialog(this);
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
QString selectedFilter;
|
||||
QString filter(tr("XML files (*.xml);;Text files (*.txt)"));
|
||||
QString selectedFile = QFileDialog::getSaveFileName(this,
|
||||
tr("Save the report file"),
|
||||
QString(),
|
||||
filter,
|
||||
&selectedFilter);
|
||||
|
||||
QStringList filters;
|
||||
filters << tr("XML files (*.xml)") << tr("Text files (*.txt)");
|
||||
dialog.setNameFilters(filters);
|
||||
|
||||
if (dialog.exec())
|
||||
if (!selectedFile.isEmpty())
|
||||
{
|
||||
QStringList list = dialog.selectedFiles();
|
||||
|
||||
if (list.size() > 0)
|
||||
{
|
||||
QString filename = list[0];
|
||||
|
||||
//Check if xml file type was selected
|
||||
bool xml = (dialog.selectedNameFilter() == filters[0]);
|
||||
bool xml = selectedFilter == tr("XML files (*.xml)");
|
||||
|
||||
//Force xml extension to the file
|
||||
if (xml && !filename.endsWith(".xml", Qt::CaseInsensitive))
|
||||
if (xml && !selectedFile.endsWith(".xml", Qt::CaseInsensitive))
|
||||
{
|
||||
filename += ".xml";
|
||||
selectedFile += ".xml";
|
||||
}
|
||||
|
||||
//Force .txt extension
|
||||
if (!xml && !filename.endsWith(".txt", Qt::CaseInsensitive))
|
||||
if (!xml && !selectedFile.endsWith(".txt", Qt::CaseInsensitive))
|
||||
{
|
||||
filename += ".txt";
|
||||
selectedFile += ".txt";
|
||||
}
|
||||
|
||||
mResults.Save(filename, xml);
|
||||
}
|
||||
mResults.Save(selectedFile, xml);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue