1 /**********************************************************************************************
2     Copyright (C) 2014-2015 Oliver Eichler <oliver.eichler@gmx.de>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #include "CMainWindow.h"
20 #include "gis/rte/router/routino/CRouterRoutinoPathSetup.h"
21 
22 #include <QtWidgets>
23 
CRouterRoutinoPathSetup(QStringList & paths)24 CRouterRoutinoPathSetup::CRouterRoutinoPathSetup(QStringList& paths)
25     : QDialog(CMainWindow::getBestWidgetForParent())
26     , paths(paths)
27 {
28     setupUi(this);
29 
30     connect(toolAdd, &QToolButton::clicked, this, &CRouterRoutinoPathSetup::slotAddPath);
31     connect(toolDelete, &QToolButton::clicked, this, &CRouterRoutinoPathSetup::slotDelPath);
32     connect(listWidget, &QListWidget::itemSelectionChanged, this, &CRouterRoutinoPathSetup::slotItemSelectionChanged);
33 
34     for(const QString& path : paths)
35     {
36         QListWidgetItem* item = new QListWidgetItem(listWidget);
37         item->setText(path);
38     }
39 
40     labelHelp->setText(tr("Add or remove paths containing Routino data. There can be multiple databases in a path but no sub-path is parsed."));
41 }
42 
~CRouterRoutinoPathSetup()43 CRouterRoutinoPathSetup::~CRouterRoutinoPathSetup()
44 {
45 }
46 
slotItemSelectionChanged()47 void CRouterRoutinoPathSetup::slotItemSelectionChanged()
48 {
49     QList<QListWidgetItem*> items = listWidget->selectedItems();
50     toolDelete->setEnabled(!items.isEmpty());
51 }
52 
slotAddPath()53 void CRouterRoutinoPathSetup::slotAddPath()
54 {
55     QString path = QFileDialog::getExistingDirectory(this, tr("Select routing data file path..."), QDir::homePath());
56     if(!path.isEmpty())
57     {
58         QListWidgetItem* item = new QListWidgetItem(listWidget);
59         item->setText(path);
60     }
61 }
62 
slotDelPath()63 void CRouterRoutinoPathSetup::slotDelPath()
64 {
65     QList<QListWidgetItem*> items = listWidget->selectedItems();
66     qDeleteAll(items);
67 }
68 
accept()69 void CRouterRoutinoPathSetup::accept()
70 {
71     paths.clear();
72     for(int i = 0; i < listWidget->count(); i++)
73     {
74         QListWidgetItem* item = listWidget->item(i);
75         paths << item->text();
76     }
77 
78     QDialog::accept();
79 }
80