-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdialogeditstreets.cpp
More file actions
106 lines (100 loc) · 2.92 KB
/
Copy pathdialogeditstreets.cpp
File metadata and controls
106 lines (100 loc) · 2.92 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "dialogeditstreets.h"
#include "ui_dialogeditstreets.h"
#include <QMenu>
DialogEditStreets::DialogEditStreets(QWidget *parent)
: QDialog(parent)
, ui(new Ui::DialogEditStreets)
{
ui->setupUi(this);
Parameters parms = sql->getParameters();
abbreviations = parms.abbreviationsList;
ui->cbAbbreviations->clear();
for(const QPair<QString, QString> &pair : abbreviations)
{
ui->cbAbbreviations->addItem(pair.first+":"+pair.second);
}
ui->ssw->initialize();
ui->ssw->cbSegments()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->ssw->cbSegments(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_cbSegmentsCustomContextMenuRequested(QPoint)));
}
void DialogEditStreets::on_cbSegmentsCustomContextMenuRequested(const QPoint &pos)
{
QMenu* menu = new QMenu();
QAction* replaceAct = new QAction(tr("Replace abbreviations"),this);
connect(replaceAct, SIGNAL(triggered(bool)), this, SLOT(replaceAbbreviations()));
menu->addAction(replaceAct);
menu->exec(QCursor::pos());
};
DialogEditStreets::~DialogEditStreets()
{
delete ui;
}
#if 0
bool DialogEditStreets::isValidFormat(SegmentInfo si)
{
return !tokenize(si.description()).isEmpty();
}
QStringList DialogEditStreets::tokenize(QString descr)
{
QStringList rslt;
QString tgt = descr.remove('.');
QStringList sl1 = tgt.split(",");
if(sl1.isEmpty() || sl1.count() !=2)
return rslt;
QStringList sl2 = sl1.at(1).split(" - ");
if(sl2.count()==2)
{
rslt.append(sl1.at(0));
rslt.append(sl2);
return rslt;
}
sl2 = sl1.at(1).split(" to ");
if(sl2.count()==2)
{
rslt.append(sl1.at(0));
rslt.append(sl2);
return rslt;
}
sl2 = sl1.at(1).split(" zur ");
if(sl2.count()==2)
{
rslt.append(sl1.at(0));
rslt.append(sl2);
return rslt;
}
return rslt;
}
QString DialogEditStreets::buildDescription(QStringList tokens)
{
return QString("%1, %2 - %3").arg(tokens.at(0).trimmed(),tokens.at(1).trimmed(),tokens.at(2).trimmed());
}
#endif
void DialogEditStreets::replaceAbbreviations(bool refresh)
{
int segmentId = ui->ssw->cbSegments()->currentData().toInt();
SegmentInfo si = sql->getSegmentInfo(segmentId);
QString descr = si.description();
//descr = sd->replaceAbbreviations(descr);
si.setDescription(descr);
sql->updateSegment(&si);
if(refresh)
ui->ssw->refreshSegmentCB();
}
#if 0
QString DialogEditStreets::updateToken(QString str){
QString result = str;
for(const QPair<QString,QString> pair : abbreviations)
{
if(result.endsWith(pair.second))
break;
if(result.endsWith(pair.first))
{
int loc = result.lastIndexOf(pair.first);
QString remainder = str.mid(0,loc );
result = remainder.append(pair.second);
break;
}
}
return result;
}
#endif