forked from facontidavide/PlotJuggler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multifile_prefix.cpp
92 lines (72 loc) · 2.2 KB
/
multifile_prefix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "multifile_prefix.h"
#include "ui_multifile_prefix.h"
#include <QLabel>
#include <QFormLayout>
#include <QFileInfo>
#include <QSettings>
DialogMultifilePrefix::DialogMultifilePrefix(QStringList filenames, QWidget* parent)
: QDialog(parent), ui(new Ui::DialogMultifilePrefix)
{
ui->setupUi(this);
QVBoxLayout* vlayout = ui->verticalLayoutFrame;
QSettings settings;
QStringList prev_prefixes =
settings.value("DialogMultifilePrefix::previous").toStringList();
for (int i = 0; i < prev_prefixes.size(); i += 2)
{
_previous_prefixes.insert({ prev_prefixes[i], prev_prefixes[i + 1] });
}
int index = 0;
for (QString filename : filenames)
{
auto label_file = new QLabel(filename, this);
label_file->setTextInteractionFlags(Qt::TextSelectableByMouse);
auto form_layout = new QFormLayout();
auto label = new QLabel("Prefix: ");
auto line_edit = new QLineEdit();
form_layout->addRow(label, line_edit);
vlayout->insertWidget(index++, label_file);
vlayout->insertLayout(index++, form_layout);
if (_previous_prefixes.count(filename))
{
line_edit->setText(_previous_prefixes[filename]);
}
else
{
line_edit->setText(QFileInfo(filename).baseName());
}
_prefixes[filename] = line_edit->text();
_line_edits.insert({ filename, line_edit });
}
}
std::map<QString, QString> DialogMultifilePrefix::getPrefixes() const
{
return _prefixes;
}
DialogMultifilePrefix::~DialogMultifilePrefix()
{
delete ui;
}
void DialogMultifilePrefix::accept()
{
QSettings settings;
QStringList prev_prefixes;
// merge new with old
for (const auto& [filename, line_edit] : _line_edits)
{
_prefixes[filename] = line_edit->text();
_previous_prefixes[filename] = line_edit->text();
}
for (const auto& [filename, prefix] : _previous_prefixes)
{
prev_prefixes.push_back(filename);
prev_prefixes.push_back(prefix);
}
settings.setValue("DialogMultifilePrefix::previous", prev_prefixes);
QDialog::accept();
}