Marble

RoutingProfilesWidget.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Niko Sams <niko.sams@gmail.com>
4// SPDX-FileCopyrightText: 2011-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
5//
6
7#include "RoutingProfilesWidget.h"
8#include "MarbleWidget.h"
9#include "ui_RoutingSettingsWidget.h"
10
11#include "MarbleDebug.h"
12#include "MarbleModel.h"
13#include "PluginManager.h"
14#include "RoutingManager.h"
15#include "RoutingProfileSettingsDialog.h"
16#include "RoutingProfilesModel.h"
17#include "RoutingRunnerPlugin.h"
18#include <QStandardItemModel>
19
20namespace Marble
21{
22
23class Q_DECL_HIDDEN RoutingProfilesWidget::Private
24{
25public:
26 Private(MarbleModel *marbleModel, RoutingProfilesWidget *parent);
27
28 void add();
29 void configure();
30 void remove();
31 void moveUp();
32 void moveDown();
33 void updateButtons();
34
35 RoutingProfilesWidget *const q;
36 const PluginManager *const m_pluginManager;
37 RoutingProfilesModel *const m_profilesModel;
38 Ui_RoutingSettingsWidget m_ui;
39};
40
41RoutingProfilesWidget::Private::Private(MarbleModel *marbleModel, RoutingProfilesWidget *parent)
42 : q(parent)
43 , m_pluginManager(marbleModel->pluginManager())
44 , m_profilesModel(marbleModel->routingManager()->profilesModel())
45{
46}
47
48RoutingProfilesWidget::RoutingProfilesWidget(MarbleModel *marbleModel)
49 : QWidget(nullptr)
50 , d(new Private(marbleModel, this))
51{
52 d->m_ui.setupUi(this);
53 d->m_ui.profilesList->setModel(d->m_profilesModel);
54
55 connect(d->m_ui.addButton, SIGNAL(clicked(bool)), SLOT(add()));
56 connect(d->m_ui.removeButton, SIGNAL(clicked(bool)), SLOT(remove()));
57 connect(d->m_ui.configureButton, SIGNAL(clicked(bool)), SLOT(configure()));
58 connect(d->m_ui.moveUpButton, SIGNAL(clicked(bool)), SLOT(moveUp()));
59 connect(d->m_ui.moveDownButton, SIGNAL(clicked(bool)), SLOT(moveDown()));
60 connect(d->m_ui.profilesList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), SLOT(updateButtons()), Qt::QueuedConnection);
61 connect(d->m_ui.profilesList, SIGNAL(doubleClicked(QModelIndex)), SLOT(configure()));
62
63 connect(d->m_profilesModel, SIGNAL(layoutChanged()), SLOT(updateButtons()));
64}
65
66RoutingProfilesWidget::~RoutingProfilesWidget()
67{
68 delete d;
69}
70
71void RoutingProfilesWidget::Private::add()
72{
73 m_profilesModel->addProfile(tr("New Profile"));
74
75 int profileIndex = m_profilesModel->rowCount() - 1;
76 m_ui.profilesList->selectionModel()->select(m_profilesModel->index(profileIndex, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
77
78 RoutingProfileSettingsDialog dialog(m_pluginManager, m_profilesModel, q);
79 dialog.editProfile(profileIndex);
80}
81
82void RoutingProfilesWidget::Private::remove()
83{
84 if (m_ui.profilesList->selectionModel()->selectedRows().isEmpty()) {
85 return;
86 }
87 m_profilesModel->removeRows(m_ui.profilesList->selectionModel()->selectedRows().first().row(), 1);
88}
89
90void RoutingProfilesWidget::Private::configure()
91{
92 if (m_ui.profilesList->selectionModel()->selectedRows().isEmpty()) {
93 return;
94 }
95
96 int profileIndex = m_ui.profilesList->selectionModel()->selectedRows().first().row();
97
98 RoutingProfileSettingsDialog dialog(m_pluginManager, m_profilesModel, q);
99 dialog.editProfile(profileIndex);
100}
101
102void RoutingProfilesWidget::Private::moveUp()
103{
104 if (m_ui.profilesList->selectionModel()->selectedRows().isEmpty()) {
105 return;
106 }
107 m_profilesModel->moveUp(m_ui.profilesList->selectionModel()->selectedRows().first().row());
108}
109
110void RoutingProfilesWidget::Private::moveDown()
111{
112 if (m_ui.profilesList->selectionModel()->selectedRows().isEmpty()) {
113 return;
114 }
115 m_profilesModel->moveDown(m_ui.profilesList->selectionModel()->selectedRows().first().row());
116}
117
118void RoutingProfilesWidget::Private::updateButtons()
119{
120 QModelIndex current;
121 if (!m_ui.profilesList->selectionModel()->selectedRows().isEmpty()) {
122 current = m_ui.profilesList->selectionModel()->selectedRows().first();
123 }
124 m_ui.configureButton->setEnabled(current.isValid());
125 m_ui.removeButton->setEnabled(current.isValid());
126 m_ui.moveUpButton->setEnabled(current.isValid() && current.row() > 0);
127 m_ui.moveDownButton->setEnabled(current.isValid() && current.row() + 1 < m_profilesModel->rowCount());
128}
129
130}
131
132#include "moc_RoutingProfilesWidget.cpp"
This file contains the headers for MarbleModel.
This file contains the headers for MarbleWidget.
KGuiItem add()
KGuiItem remove()
KGuiItem configure()
Binds a QML item to a specific geodetic location in screen coordinates.
bool isValid() const const
int row() const const
QueuedConnection
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.