Repository navigation
Expand file tree
/
Copy pathdialogpreferences.cpp
More file actions
123 lines (109 loc) · 3.73 KB
/
Copy pathdialogpreferences.cpp
File metadata and controls
123 lines (109 loc) · 3.73 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "dialogpreferences.h"
#include "qpushbutton.h"
#include "ui_dialogpreferences.h"
#include "mainwindow.h"
#include "filedownloader.h"
DialogPreferences::DialogPreferences(QWidget *parent)
: QDialog(parent)
, ui(new Ui::DialogPreferences)
{
ui->setupUi(this);
config = Configuration::instance();
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
ui->edTileServer->setText(config->tileServerUrl);
tileServerUrl = new QUrl(config->tileServerUrl);
MainWindow::instance()->initRouteSortCb(ui->cbRouteSort);
ui->chkDisplayInBrowser->setChecked(config->bRunInBrowser);
connect(ui->chkDisplayInBrowser, &QCheckBox::stateChanged,this,[=](int state){
sDisplayInBrowser = (Qt::CheckState)state;
bDirty = true;
switch(sDisplayInBrowser)
{
case Qt::CheckState::Checked:
ui->lblError->setText(tr("will run in browser after restart"));
break;
case Qt::CheckState::Unchecked:
ui->lblError->setText(tr("will run in app after restart"));
break;
case Qt::CheckState::PartiallyChecked:
break;
}
ui->lblError->setStyleSheet("color: green");
});
connect(ui->edTileServer, &QLineEdit::editingFinished, this,[=]{
QString txt = ui->edTileServer->text().trimmed();
QUrl* url = new QUrl(txt);
check_all();
bDirty = true;
m_dataCtrl = new FileDownloader(url->toString(), this);
connect (m_dataCtrl, &FileDownloader::downloaded,this,[=](QString err){
ui->lblError->setText(err);
if(!err.isEmpty())
ui->lblError->setStyleSheet("color: red");
});
});
connect(ui->buttonBox, &QDialogButtonBox::clicked, this,[=](QAbstractButton* button){
if(!check_all())
return;
QString txt = button->text();
if(ui->buttonBox->standardButton(button) == QDialogButtonBox::Ok)
{
if(tileServerUrl->isValid())
{
config->tileServerUrl = tileServerUrl->toString();
}
switch(sDisplayInBrowser)
{
case Qt::CheckState::Checked:
config->bRunInBrowser = true;
break;
case Qt::CheckState::Unchecked:
config->bRunInBrowser = false;
break;
case Qt::CheckState::PartiallyChecked:
break;
}
//connect(cbSort, SIGNAL(currentIndexChanged(int)), this, SLOT(cbSortSelectionChanged(int)));
config->currCity->routeSortType = ui->cbRouteSort->currentIndex();
accept();
return;
}
else if(ui->buttonBox->standardButton(button) == QDialogButtonBox::Cancel)
{
reject(); // cancel
}
else if(ui->buttonBox->standardButton(button) == QDialogButtonBox::Save)
{
if(bDirty)
config->saveSettings();
bDirty = false;
}
else
return;
});
}
DialogPreferences::~DialogPreferences()
{
delete ui;
}
bool DialogPreferences::checkUrl()
{
tileServerUrl = new QUrl(ui->edTileServer->text().trimmed());
if(tileServerUrl->isValid())
{
return true;
}
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
return false;
}
bool DialogPreferences::check_all()
{
if(!checkUrl())
return false;
// enable Save and Ok buttons
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
return true;
}