OGS
FileListDialog.cpp
Go to the documentation of this file.
1
15#include "FileListDialog.h"
16
17#include <QFileInfo>
18#include <QFont>
19#include <QLineEdit>
20#include <QSettings>
21
23#include "BaseLib/StringTools.h"
24
25FileListDialog::FileListDialog(FileType input, FileType output, QWidget* parent)
26 : QDialog(parent),
27 _output_dir(""),
28 _input_file_type(input),
29 _output_file_type(output)
30{
31 setupUi(this);
32
34 {
36 }
37
38 this->listView->setModel(&_allFiles);
39}
40
42
44{
45 QSettings settings("UFZ", "OpenGeoSys-5");
46 QFileDialog dlg(this);
47 dlg.setDirectory(settings.value("lastOpenedOgsFileDirectory").toString());
48 dlg.setFileMode(QFileDialog::ExistingFiles);
49 dlg.setNameFilter(this->getFileTypeString(_input_file_type));
50
51 if (dlg.exec())
52 {
53 QStringList const file_names = dlg.selectedFiles();
54
55 if (file_names.empty())
56 {
57 return;
58 }
59
60 QStringList list = _allFiles.stringList();
61 list.append(file_names);
62 _allFiles.setStringList(list);
63 QDir const dir = QDir(file_names[0]);
64 settings.setValue("lastOpenedOgsFileDirectory", dir.absolutePath());
65 }
66}
67
69{
70 QModelIndexList selected =
71 this->listView->selectionModel()->selectedIndexes();
72 for (auto& item : selected)
73 {
74 this->_allFiles.removeRow(item.row());
75 }
76}
77
79{
80 QSettings const settings("UFZ", "OpenGeoSys-5");
81 QFileInfo const fi(settings.value("lastOpenedOgsFileDirectory").toString());
82 QString const dirName = QFileDialog::getExistingDirectory(
83 this, "Save to", fi.absolutePath().append("/"));
84 this->outputDirEdit->setText(dirName);
85}
86
88{
89 if (_allFiles.stringList().empty())
90 {
91 OGSError::box("No files selected.");
92 return;
93 }
94
95 _output_dir = this->outputDirEdit->text();
96 if (!this->outputDirEdit->text().isEmpty() && QDir(_output_dir).exists())
97 {
98 this->done(QDialog::Accepted);
99 }
100 else
101 {
102 OGSError::box("Output directory not found.");
103 }
104}
105
107{
108 this->done(QDialog::Rejected);
109}
110
112{
113 if (file_type == FileType::GML)
114 {
115 return "OpenGeoSys geometry files (*.gml)";
116 }
117 if (file_type == FileType::VTU)
118 {
119 return "OpenGeoSys mesh files (*.vtu)";
120 }
121 if (file_type == FileType::GLI)
122 {
123 return "GeoSys geometry files (*.gli)";
124 }
125 if (file_type == FileType::MSH)
126 {
127 return "GeoSys mesh files (*.msh)";
128 }
129 return "All files (*.*)";
130}
131
133{
134 this->warningLabel->setFixedWidth(300);
135 this->warningLabel->setFixedHeight(40);
136 QFont font = this->warningLabel->font();
137 font.setPointSize(9);
138 font.setBold(true);
139 warningLabel->setFont(font);
140 this->warningLabel->setStyleSheet("QLabel { color : red; }");
141 this->warningLabel->setText(
142 "Warning: all scalar information except<br />MaterialIDs will be "
143 "lost!");
144}
Definition of FileListDialog class.
FileType
Definition of the OGSError class.
Definition of string helper functions.
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:23