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


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45