Marble

RoutingProfilesWidget.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2010 Niko Sams <[email protected]>
4 // SPDX-FileCopyrightText: 2011-2012 Bernhard Beschow <[email protected]>
5 //
6 
7 #include "RoutingProfilesWidget.h"
8 #include "ui_RoutingSettingsWidget.h"
9 #include "MarbleWidget.h"
10 
11 #include <QStandardItemModel>
12 #include "MarbleModel.h"
13 #include "PluginManager.h"
14 #include "RoutingRunnerPlugin.h"
15 #include "MarbleDebug.h"
16 #include "RoutingProfilesModel.h"
17 #include "RoutingManager.h"
18 #include "RoutingProfileSettingsDialog.h"
19 
20 namespace Marble
21 {
22 
23 class Q_DECL_HIDDEN RoutingProfilesWidget::Private
24 {
25  public:
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 
41 RoutingProfilesWidget::Private::Private( MarbleModel *marbleModel, RoutingProfilesWidget *parent ) :
42  q( parent ),
43  m_pluginManager( marbleModel->pluginManager() ),
44  m_profilesModel( marbleModel->routingManager()->profilesModel() )
45 {
46 }
47 
48 RoutingProfilesWidget::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 
66 RoutingProfilesWidget::~RoutingProfilesWidget()
67 {
68  delete d;
69 }
70 
71 void 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 
82 void 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 
90 void 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 
102 void 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 
110 void 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 
118 void 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"
KGuiItem configure()
bool remove(const QString &column, const QVariant &value)
KGuiItem add()
QueuedConnection
Binds a QML item to a specific geodetic location in screen coordinates.
void setupUi(QWidget *widget)
bool isValid() const const
int row() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 04:07:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.