Marble

RoutingProfileSettingsDialog.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Niko Sams <niko.sams@gmail.com>
4//
5
6
7#include "RoutingProfileSettingsDialog.h"
8
9#include <QStandardItemModel>
10
11#include "MarbleGlobal.h"
12#include "MarbleDebug.h"
13#include "RoutingProfilesModel.h"
14#include "PluginManager.h"
15
16#include "ui_RoutingProfileSettingsDialog.h"
17
18namespace Marble {
19
20
21RoutingProfileSettingsDialog::RoutingProfileSettingsDialog( const PluginManager *pluginManager, RoutingProfilesModel *profilesModel, QWidget* parent )
22 : QDialog( parent ),
23 m_profilesModel ( profilesModel ), m_dialog( nullptr ), m_dialogLayout( nullptr )
24{
25 m_ui = new Ui_RoutingProfileSettingsDialog();
26 m_ui->setupUi( this );
27 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
28 if ( smallScreen ) {
29 setMinimumHeight( 480 );
30 m_ui->services->setMinimumWidth( 280 );
31 m_ui->buttonBox->hide();
32 }
33
34 QList<RoutingRunnerPlugin*> allPlugins = pluginManager->routingRunnerPlugins();
35 for( RoutingRunnerPlugin* plugin: allPlugins ) {
36 m_plugins << plugin;
37 RoutingRunnerPlugin::ConfigWidget* configWidget = plugin->configWidget();
38 if ( configWidget ) {
39 m_configWidgets.insert( plugin, configWidget );
40 m_ui->settingsStack->addWidget( configWidget );
41 }
42 }
43
44 m_servicesModel = new QStandardItemModel;
45 m_ui->services->setModel( m_servicesModel );
46 connect ( m_ui->services->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(updateConfigWidget()), Qt::QueuedConnection );
47 connect ( m_servicesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(updateConfigWidget()) );
48
49 connect ( m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()) );
50 connect ( m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()) );
51
52 connect( m_ui->configureButton, SIGNAL(clicked()), this, SLOT(openConfigDialog()) );
53}
54
55RoutingProfileSettingsDialog::~RoutingProfileSettingsDialog()
56{
57 qDeleteAll( m_configWidgets );
58 delete m_ui;
59}
60
61void RoutingProfileSettingsDialog::updateConfigWidget( )
62{
63 QModelIndex current = m_ui->services->selectionModel()->currentIndex();
64
65 if ( !current.isValid() ) {
66 m_ui->settingsStack->setEnabled( false );
67 return;
68 }
69
70 RoutingRunnerPlugin *plugin = m_plugins.at( current.row() );
71 QWidget* configWidget = m_configWidgets[plugin];
72 if ( configWidget ) {
73 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
74 m_ui->settingsStack->setCurrentWidget( smallScreen ? m_ui->configurePage : configWidget );
75 m_ui->descriptionLabel->setText( plugin->description() );
76 m_ui->statusLabel->setText( plugin->statusMessage() );
77 QStandardItem *item = m_servicesModel->invisibleRootItem()->child( current.row() );
78 m_ui->settingsStack->setEnabled( item->checkState() == Qt::Checked );
79 } else {
80 m_ui->settingsStack->setEnabled( false );
81 m_ui->noConfigDescriptionLabel->setText( plugin->description() );
82 m_ui->noConfigStatusLabel->setText( plugin->statusMessage() );
83 m_ui->settingsStack->setCurrentWidget( m_ui->noConfigAvailablePage );
84 }
85}
86
87void RoutingProfileSettingsDialog::editProfile( int profileIndex )
88{
89 QList<RoutingProfile> profiles = m_profilesModel->profiles();
90 m_ui->name->setText( profiles.at( profileIndex ).name() );
91
92 m_servicesModel->clear();
93 for( RoutingRunnerPlugin *plugin: m_plugins ) {
94 QStandardItem *item = new QStandardItem( plugin->guiString() );
95 item->setCheckable( true );
96 if ( profiles[ profileIndex ].pluginSettings().contains( plugin->nameId() ) ) {
98 QHash<QString, QVariant> settings = profiles[ profileIndex ].pluginSettings()[ plugin->nameId() ];
99 mDebug() << settings;
100 if ( m_configWidgets[plugin] ) {
101 m_configWidgets[plugin]->loadSettings( settings );
102 }
103 }
104 m_servicesModel->invisibleRootItem()->appendRow( item );
105 }
106 m_ui->settingsStack->setCurrentWidget( m_ui->selectServicePage );
107 m_ui->settingsStack->setEnabled( false );
108
109 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
110 // Small screen profile (like maemo 5) does not have the "buttonBox"
111 if ( exec() != QDialog::Accepted && !smallScreen ) {
112 return;
113 }
114
115 m_profilesModel->setProfileName( profileIndex, m_ui->name->text() );
116
118 for ( int i=0; i < m_servicesModel->invisibleRootItem()->rowCount(); ++i) {
119 QStandardItem *item = m_servicesModel->invisibleRootItem()->child( i );
120 if ( item->checkState() == Qt::Checked ) {
122 if ( m_configWidgets[m_plugins[ i ]] ) {
123 settings = m_configWidgets[m_plugins[ i ]]->settings();
124 }
125 mDebug() << i << m_plugins[ i ]->nameId() << settings;
126 pluginSettings.insert( m_plugins[ i ]->nameId(), settings );
127 } else {
128 pluginSettings.remove( m_plugins[ i ]->nameId() );
129 }
130 }
131 m_profilesModel->setProfilePluginSettings( profileIndex, pluginSettings );
132}
133
134void RoutingProfileSettingsDialog::openConfigDialog()
135{
136 QModelIndex current = m_ui->services->selectionModel()->currentIndex();
137 if ( current.isValid() ) {
138 RoutingRunnerPlugin *plugin = m_plugins.at( current.row() );
139
140 if ( !m_dialog ) {
141 m_dialog = new QDialog( this );
142
143 m_dialogLayout = new QHBoxLayout();
144 m_dialogLayout->addWidget( m_configWidgets[plugin] );
145
146 m_dialog->setLayout( m_dialogLayout );
147 m_dialog->setMinimumHeight( 480 );
148 } else {
149 m_dialogLayout->insertWidget( 0, m_configWidgets[plugin] );
150 }
151
152 m_configWidgets[plugin]->show();
153 m_dialog->setWindowTitle( plugin->guiString() );
154 m_dialog->exec();
155 m_configWidgets[plugin]->hide();
156 m_dialogLayout->removeWidget( m_configWidgets[plugin] );
157 }
158}
159
160}
161
162#include "moc_RoutingProfileSettingsDialog.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
iterator insert(const Key &key, const T &value)
bool remove(const Key &key)
const_reference at(qsizetype i) const const
void clear()
iterator insert(const_iterator before, parameter_type value)
bool isValid() const const
int row() const const
Qt::CheckState checkState() const const
QStandardItem * child(int row, int column) const const
void setCheckState(Qt::CheckState state)
void setCheckable(bool checkable)
void setEnabled(bool enabled)
QueuedConnection
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:54:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.