forked from facontidavide/PlotJuggler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suggest_dialog.cpp
73 lines (60 loc) · 1.91 KB
/
suggest_dialog.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
/*
* 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 <QSettings>
#include "suggest_dialog.h"
#include "ui_suggest_dialog.h"
SuggestDialog::SuggestDialog(const std::string& name_x, const std::string& name_y,
QWidget* parent)
: QDialog(parent), ui(new Ui::SuggestDialog)
{
ui->setupUi(this);
QSettings settings;
restoreGeometry(settings.value("SuggestDialog.geometry").toByteArray());
ui->lineEditX->setText(QString::fromStdString(name_x));
ui->lineEditY->setText(QString::fromStdString(name_y));
updateSuggestion();
}
SuggestDialog::~SuggestDialog()
{
QSettings settings;
settings.setValue("SuggestDialog.geometry", saveGeometry());
delete ui;
}
QString SuggestDialog::nameX() const
{
return ui->lineEditX->text();
}
QString SuggestDialog::nameY() const
{
return ui->lineEditY->text();
}
QString SuggestDialog::suggestedName() const
{
return ui->lineEditName->text();
}
void SuggestDialog::updateSuggestion()
{
std::string common_prefix;
std::string name_x = ui->lineEditX->text().toStdString();
std::string name_y = ui->lineEditY->text().toStdString();
if (name_x.size() > name_y.size())
{
std::swap(name_x, name_y);
}
common_prefix = std::string(
name_x.begin(), std::mismatch(name_x.begin(), name_x.end(), name_y.begin()).first);
std::string suffix_x = name_x.substr(common_prefix.size());
std::string suffix_y = name_y.substr(common_prefix.size());
std::string suggestion = common_prefix + "[" + suffix_x + ";" + suffix_y + "]";
ui->lineEditName->setText(QString::fromStdString(suggestion));
}
void SuggestDialog::on_pushButtonSwap_pressed()
{
auto temp = ui->lineEditX->text();
ui->lineEditX->setText(ui->lineEditY->text());
ui->lineEditY->setText(temp);
updateSuggestion();
}