suggest_dialog.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 <QSettings>
8 #include "suggest_dialog.h"
9 #include "ui_suggest_dialog.h"
10 
11 SuggestDialog::SuggestDialog(const std::string& name_x, const std::string& name_y,
12  QWidget* parent)
13  : QDialog(parent), ui(new Ui::SuggestDialog)
14 {
15  ui->setupUi(this);
16 
17  QSettings settings;
18  restoreGeometry(settings.value("SuggestDialog.geometry").toByteArray());
19 
20  ui->lineEditX->setText(QString::fromStdString(name_x));
21  ui->lineEditY->setText(QString::fromStdString(name_y));
23 }
24 
26 {
27  QSettings settings;
28  settings.setValue("SuggestDialog.geometry", saveGeometry());
29  delete ui;
30 }
31 
32 QString SuggestDialog::nameX() const
33 {
34  return ui->lineEditX->text();
35 }
36 
37 QString SuggestDialog::nameY() const
38 {
39  return ui->lineEditY->text();
40 }
41 
43 {
44  return ui->lineEditName->text();
45 }
46 
48 {
49  std::string common_prefix;
50  std::string name_x = ui->lineEditX->text().toStdString();
51  std::string name_y = ui->lineEditY->text().toStdString();
52 
53  if (name_x.size() > name_y.size())
54  {
55  std::swap(name_x, name_y);
56  }
57  common_prefix = std::string(
58  name_x.begin(), std::mismatch(name_x.begin(), name_x.end(), name_y.begin()).first);
59 
60  std::string suffix_x = name_x.substr(common_prefix.size());
61  std::string suffix_y = name_y.substr(common_prefix.size());
62 
63  std::string suggestion = common_prefix + "[" + suffix_x + ";" + suffix_y + "]";
64  ui->lineEditName->setText(QString::fromStdString(suggestion));
65 }
66 
68 {
69  auto temp = ui->lineEditX->text();
70  ui->lineEditX->setText(ui->lineEditY->text());
71  ui->lineEditY->setText(temp);
73 }
SuggestDialog::updateSuggestion
void updateSuggestion()
Definition: suggest_dialog.cpp:47
suggest_dialog.h
SuggestDialog::nameX
QString nameX() const
Definition: suggest_dialog.cpp:32
SuggestDialog::SuggestDialog
SuggestDialog(const std::string &name_x, const std::string &name_y, QWidget *parent=nullptr)
Definition: suggest_dialog.cpp:11
SuggestDialog::~SuggestDialog
~SuggestDialog()
Definition: suggest_dialog.cpp:25
Ui
Definition: cheatsheet_dialog.h:6
SuggestDialog
Definition: suggest_dialog.h:17
std::swap
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:21884
SuggestDialog::suggestedName
QString suggestedName() const
Definition: suggest_dialog.cpp:42
SuggestDialog::ui
Ui::SuggestDialog * ui
Definition: suggest_dialog.h:36
SuggestDialog::nameY
QString nameY() const
Definition: suggest_dialog.cpp:37
SuggestDialog::on_pushButtonSwap_pressed
void on_pushButtonSwap_pressed()
Definition: suggest_dialog.cpp:67


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