14 #include <QStandardItemModel>
22 #include "ui_RoutingProfileSettingsDialog.h"
29 m_profilesModel ( profilesModel ), m_dialog( 0 ), m_dialogLayout( 0 )
32 setAttribute( Qt::WA_Maemo5StackedWindow );
33 setWindowFlags( Qt::Window );
34 setWindowTitle( tr(
"Routing Profile - Marble" ) );
35 #endif // Q_WS_MAEMO_5
37 m_ui =
new Ui_RoutingProfileSettingsDialog();
38 m_ui->setupUi(
this );
41 setMinimumHeight( 480 );
42 m_ui->services->setMinimumWidth( 280 );
43 m_ui->buttonBox->hide();
51 m_configWidgets.insert( plugin, configWidget );
52 m_ui->settingsStack->addWidget( configWidget );
56 m_servicesModel =
new QStandardItemModel;
57 m_ui->services->setModel( m_servicesModel );
58 connect ( m_ui->services->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(updateConfigWidget()), Qt::QueuedConnection );
59 connect ( m_servicesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(updateConfigWidget()) );
61 connect ( m_ui->buttonBox, SIGNAL(accepted()),
this, SLOT(accept()) );
62 connect ( m_ui->buttonBox, SIGNAL(rejected()),
this, SLOT(reject()) );
64 connect( m_ui->configureButton, SIGNAL(clicked()),
this, SLOT(openConfigDialog()) );
69 qDeleteAll( m_configWidgets );
73 void RoutingProfileSettingsDialog::updateConfigWidget( )
75 QModelIndex current = m_ui->services->selectionModel()->currentIndex();
77 if ( !current.isValid() ) {
78 m_ui->settingsStack->setEnabled(
false );
82 RoutingRunnerPlugin *plugin = m_plugins.at( current.row() );
83 QWidget* configWidget = m_configWidgets[plugin];
86 m_ui->settingsStack->setCurrentWidget( smallScreen ? m_ui->configurePage : configWidget );
87 m_ui->descriptionLabel->setText( plugin->description() );
88 m_ui->statusLabel->setText( plugin->statusMessage() );
89 QStandardItem *item = m_servicesModel->invisibleRootItem()->child( current.row() );
90 m_ui->settingsStack->setEnabled( item->checkState() == Qt::Checked );
92 m_ui->settingsStack->setEnabled(
false );
93 m_ui->noConfigDescriptionLabel->setText( plugin->description() );
94 m_ui->noConfigStatusLabel->setText( plugin->statusMessage() );
95 m_ui->settingsStack->setCurrentWidget( m_ui->noConfigAvailablePage );
101 QList<RoutingProfile> profiles = m_profilesModel->
profiles();
102 m_ui->name->setText( profiles.at( profileIndex ).name() );
104 m_servicesModel->clear();
106 QStandardItem *item =
new QStandardItem( plugin->
guiString() );
107 item->setCheckable(
true );
108 if ( profiles[ profileIndex ].pluginSettings().contains( plugin->
nameId() ) ) {
109 item->setCheckState( Qt::Checked );
110 QHash<QString, QVariant> settings = profiles[ profileIndex ].pluginSettings()[ plugin->
nameId() ];
112 if ( m_configWidgets[plugin] ) {
113 m_configWidgets[plugin]->loadSettings( settings );
116 m_servicesModel->invisibleRootItem()->appendRow( item );
118 m_ui->settingsStack->setCurrentWidget( m_ui->selectServicePage );
119 m_ui->settingsStack->setEnabled(
false );
123 if ( exec() != QDialog::Accepted && !smallScreen ) {
127 m_profilesModel->
setProfileName( profileIndex, m_ui->name->text() );
129 QHash< QString, QHash< QString, QVariant > > pluginSettings;
130 for (
int i=0; i < m_servicesModel->invisibleRootItem()->rowCount(); ++i) {
131 QStandardItem *item = m_servicesModel->invisibleRootItem()->child( i );
132 if ( item->checkState() == Qt::Checked ) {
133 QHash<QString, QVariant> settings;
134 if ( m_configWidgets[m_plugins[ i ]] ) {
135 settings = m_configWidgets[m_plugins[ i ]]->settings();
137 mDebug() << i << m_plugins[ i ]->nameId() << settings;
138 pluginSettings.insert( m_plugins[ i ]->nameId(), settings );
140 pluginSettings.remove( m_plugins[ i ]->nameId() );
146 void RoutingProfileSettingsDialog::openConfigDialog()
148 QModelIndex current = m_ui->services->selectionModel()->currentIndex();
149 if ( current.isValid() ) {
153 m_dialog =
new QDialog(
this );
155 m_dialogLayout =
new QHBoxLayout();
156 m_dialogLayout->addWidget( m_configWidgets[plugin] );
158 m_dialog->setLayout( m_dialogLayout );
159 m_dialog->setMinimumHeight( 480 );
161 m_dialogLayout->insertWidget( 0, m_configWidgets[plugin] );
164 m_configWidgets[plugin]->show();
165 m_dialog->setWindowTitle( plugin->guiString() );
167 m_configWidgets[plugin]->hide();
168 m_dialogLayout->removeWidget( m_configWidgets[plugin] );
174 #include "RoutingProfileSettingsDialog.moc"
void editProfile(int profileIndex)
The class that handles Marble's plugins.
QList< RoutingProfile > profiles() const
~RoutingProfileSettingsDialog()
virtual QString guiString() const =0
Returns the string that should appear in the user interface.
QList< RoutingRunnerPlugin * > routingRunnerPlugins() const
Returns all routing runner plugins.
bool setProfilePluginSettings(int row, const QHash< QString, QHash< QString, QVariant > > &pluginSettings)
virtual QString nameId() const =0
Returns the unique name of the plugin.
bool setProfileName(int row, const QString &name)
static MarbleGlobal * getInstance()
A plugin for Marble to execute a routing task.
Profiles profiles() const
RoutingProfileSettingsDialog(const PluginManager *pluginManager, RoutingProfilesModel *profilesModel, QWidget *parent=0)
QDebug mDebug()
a function to replace qDebug() in Marble library code