• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • routing
RoutingProfilesWidget.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2010 Niko Sams <niko.sams@gmail.com>
9 // Copyright 2011-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
10 //
11 
12 #include "RoutingProfilesWidget.h"
13 #include "ui_RoutingSettingsWidget.h"
14 #include "MarbleWidget.h"
15 
16 #include <QStandardItemModel>
17 #include <QDialog>
18 #include "MarbleModel.h"
19 #include "PluginManager.h"
20 #include "RoutingRunnerPlugin.h"
21 #include "MarbleDebug.h"
22 #include "RoutingProfilesModel.h"
23 #include "RoutingManager.h"
24 #include "RoutingProfileSettingsDialog.h"
25 
26 namespace Marble
27 {
28 
29 class RoutingProfilesWidget::Private
30 {
31  public:
32  Private( MarbleModel *marbleModel, RoutingProfilesWidget *parent );
33 
34  void add();
35  void configure();
36  void remove();
37  void moveUp();
38  void moveDown();
39  void updateButtons();
40 
41  RoutingProfilesWidget *const q;
42  const PluginManager *const m_pluginManager;
43  RoutingProfilesModel *const m_profilesModel;
44  Ui_RoutingSettingsWidget m_ui;
45 };
46 
47 RoutingProfilesWidget::Private::Private( MarbleModel *marbleModel, RoutingProfilesWidget *parent ) :
48  q( parent ),
49  m_pluginManager( marbleModel->pluginManager() ),
50  m_profilesModel( marbleModel->routingManager()->profilesModel() )
51 {
52 }
53 
54 RoutingProfilesWidget::RoutingProfilesWidget( MarbleModel *marbleModel )
55  : QWidget( 0 ),
56  d( new Private( marbleModel, this ) )
57 {
58  d->m_ui.setupUi( this );
59  d->m_ui.profilesList->setModel( d->m_profilesModel );
60 
61  connect( d->m_ui.addButton, SIGNAL(clicked(bool)), SLOT(add()) );
62  connect( d->m_ui.removeButton, SIGNAL(clicked(bool)), SLOT(remove()) );
63  connect( d->m_ui.configureButton, SIGNAL(clicked(bool)), SLOT(configure()) );
64  connect( d->m_ui.moveUpButton, SIGNAL(clicked(bool)), SLOT(moveUp()) );
65  connect( d->m_ui.moveDownButton, SIGNAL(clicked(bool)), SLOT(moveDown()) );
66  connect( d->m_ui.profilesList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), SLOT(updateButtons()), Qt::QueuedConnection );
67  connect( d->m_ui.profilesList, SIGNAL(doubleClicked(QModelIndex)), SLOT(configure()) );
68 
69  connect( d->m_profilesModel, SIGNAL(layoutChanged()), SLOT(updateButtons()) );
70 }
71 
72 RoutingProfilesWidget::~RoutingProfilesWidget()
73 {
74  delete d;
75 }
76 
77 void RoutingProfilesWidget::Private::add()
78 {
79  m_profilesModel->addProfile( tr( "New Profile" ) );
80 
81  int profileIndex = m_profilesModel->rowCount() - 1;
82  m_ui.profilesList->selectionModel()->select( m_profilesModel->index( profileIndex, 0 ), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent );
83 
84  RoutingProfileSettingsDialog dialog( m_pluginManager, m_profilesModel, q );
85  dialog.editProfile( profileIndex );
86 }
87 
88 void RoutingProfilesWidget::Private::remove()
89 {
90  if ( m_ui.profilesList->selectionModel()->selectedRows().isEmpty() ) {
91  return;
92  }
93  m_profilesModel->removeRows( m_ui.profilesList->selectionModel()->selectedRows().first().row(), 1 );
94 }
95 
96 void RoutingProfilesWidget::Private::configure()
97 {
98  if ( m_ui.profilesList->selectionModel()->selectedRows().isEmpty() ) {
99  return;
100  }
101 
102  int profileIndex = m_ui.profilesList->selectionModel()->selectedRows().first().row();
103 
104  RoutingProfileSettingsDialog dialog( m_pluginManager, m_profilesModel, q );
105  dialog.editProfile( profileIndex );
106 }
107 
108 void RoutingProfilesWidget::Private::moveUp()
109 {
110  if ( m_ui.profilesList->selectionModel()->selectedRows().isEmpty() ) {
111  return;
112  }
113  m_profilesModel->moveUp( m_ui.profilesList->selectionModel()->selectedRows().first().row() );
114 }
115 
116 void RoutingProfilesWidget::Private::moveDown()
117 {
118  if ( m_ui.profilesList->selectionModel()->selectedRows().isEmpty() ) {
119  return;
120  }
121  m_profilesModel->moveDown( m_ui.profilesList->selectionModel()->selectedRows().first().row() );
122 }
123 
124 void RoutingProfilesWidget::Private::updateButtons()
125 {
126  QModelIndex current;
127  if ( !m_ui.profilesList->selectionModel()->selectedRows().isEmpty() ) {
128  current = m_ui.profilesList->selectionModel()->selectedRows().first();
129  }
130  m_ui.configureButton->setEnabled( current.isValid() );
131  m_ui.removeButton->setEnabled( current.isValid() );
132  m_ui.moveUpButton->setEnabled( current.isValid() && current.row() > 0 );
133  m_ui.moveDownButton->setEnabled( current.isValid() && current.row()+1 < m_profilesModel->rowCount() );
134 }
135 
136 }
137 
138 #include "RoutingProfilesWidget.moc"
Marble::RoutingProfilesWidget::RoutingProfilesWidget
RoutingProfilesWidget(MarbleModel *marbleModel)
Definition: RoutingProfilesWidget.cpp:54
MarbleModel.h
This file contains the headers for MarbleModel.
QWidget
Marble::RoutingProfilesWidget::~RoutingProfilesWidget
~RoutingProfilesWidget()
Definition: RoutingProfilesWidget.cpp:72
MarbleDebug.h
RoutingManager.h
RoutingRunnerPlugin.h
Marble::RoutingProfileSettingsDialog
Definition: RoutingProfileSettingsDialog.h:29
RoutingProfilesWidget.h
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
PluginManager.h
MarbleWidget.h
This file contains the headers for MarbleWidget.
RoutingProfileSettingsDialog.h
RoutingProfilesModel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal