OGS
FileListDialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "FileListDialog.h"
5
6#include <QFileInfo>
7#include <QFont>
8#include <QLineEdit>
9#include <QSettings>
10
12#include "BaseLib/StringTools.h"
13
14FileListDialog::FileListDialog(FileType input, FileType output, QWidget* parent)
15 : QDialog(parent),
16 _output_dir(""),
17 _input_file_type(input),
18 _output_file_type(output)
19{
20 setupUi(this);
21
23 {
25 }
26
27 this->listView->setModel(&_allFiles);
28}
29
31
33{
34 QSettings settings("UFZ", "OpenGeoSys-5");
35 QFileDialog dlg(this);
36 dlg.setDirectory(settings.value("lastOpenedOgsFileDirectory").toString());
37 dlg.setFileMode(QFileDialog::ExistingFiles);
38 dlg.setNameFilter(this->getFileTypeString(_input_file_type));
39
40 if (dlg.exec())
41 {
42 QStringList const file_names = dlg.selectedFiles();
43
44 if (file_names.empty())
45 {
46 return;
47 }
48
49 QStringList list = _allFiles.stringList();
50 list.append(file_names);
51 _allFiles.setStringList(list);
52 QDir const dir = QDir(file_names[0]);
53 settings.setValue("lastOpenedOgsFileDirectory", dir.absolutePath());
54 }
55}
56
58{
59 QModelIndexList selected =
60 this->listView->selectionModel()->selectedIndexes();
61 for (auto& item : selected)
62 {
63 this->_allFiles.removeRow(item.row());
64 }
65}
66
68{
69 QSettings const settings("UFZ", "OpenGeoSys-5");
70 QFileInfo const fi(settings.value("lastOpenedOgsFileDirectory").toString());
71 QString const dirName = QFileDialog::getExistingDirectory(
72 this, "Save to", fi.absolutePath().append("/"));
73 this->outputDirEdit->setText(dirName);
74}
75
77{
78 if (_allFiles.stringList().empty())
79 {
80 OGSError::box("No files selected.");
81 return;
82 }
83
84 _output_dir = this->outputDirEdit->text();
85 if (!this->outputDirEdit->text().isEmpty() && QDir(_output_dir).exists())
86 {
87 this->done(QDialog::Accepted);
88 }
89 else
90 {
91 OGSError::box("Output directory not found.");
92 }
93}
94
96{
97 this->done(QDialog::Rejected);
98}
99
101{
102 if (file_type == FileType::GML)
103 {
104 return "OpenGeoSys geometry files (*.gml)";
105 }
106 if (file_type == FileType::VTU)
107 {
108 return "OpenGeoSys mesh files (*.vtu)";
109 }
110 if (file_type == FileType::GLI)
111 {
112 return "GeoSys geometry files (*.gli)";
113 }
114 if (file_type == FileType::MSH)
115 {
116 return "GeoSys mesh files (*.msh)";
117 }
118 return "All files (*.*)";
119}
120
122{
123 this->warningLabel->setFixedWidth(300);
124 this->warningLabel->setFixedHeight(40);
125 QFont font = this->warningLabel->font();
126 font.setPointSize(9);
127 font.setBold(true);
128 warningLabel->setFont(font);
129 this->warningLabel->setStyleSheet("QLabel { color : red; }");
130 this->warningLabel->setText(
131 "Warning: all scalar information except<br />MaterialIDs will be "
132 "lost!");
133}
FileType
void on_addButton_pressed()
~FileListDialog() override
Destructor.
void on_browseButton_pressed()
QStringListModel _allFiles
void accept() override
Instructions if the OK-Button has been pressed.
QString getFileTypeString(FileType file_type) const
Returns a string for the given file type enum.
const FileType _input_file_type
void displayWarningLabel() const
Display a warning for vtu- to msh-conversion.
FileListDialog(FileType input, FileType output, QWidget *parent=nullptr)
Constructor.
void reject() override
Instructions if the Cancel-Button has been pressed.
const FileType _output_file_type
void on_removeButton_pressed()
static void box(const QString &e)
Definition OGSError.cpp:13