File indexing completed on 2024-05-05 04:38:44
0001 /* 0002 SPDX-FileCopyrightText: 2007 Dukju Ahn <dukjuahn@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "environmentselectionwidget.h" 0008 #include "environmentprofilelist.h" 0009 #include "environmentselectionmodel.h" 0010 0011 #include <QHBoxLayout> 0012 0013 #include <KConfigDialogManager> 0014 #include <KComboBox> 0015 0016 #include <interfaces/icore.h> 0017 0018 namespace KDevelop { 0019 0020 class EnvironmentSelectionWidgetPrivate 0021 { 0022 public: 0023 KComboBox* comboBox; 0024 EnvironmentSelectionModel* model; 0025 EnvironmentSelectionWidget* owner; 0026 0027 explicit EnvironmentSelectionWidgetPrivate(EnvironmentSelectionWidget* _owner) 0028 : comboBox(new KComboBox(_owner)) 0029 , model(new EnvironmentSelectionModel(_owner)) 0030 , owner(_owner) 0031 { 0032 comboBox->setModel(model); 0033 comboBox->setEditable(false); 0034 } 0035 }; 0036 0037 EnvironmentSelectionWidget::EnvironmentSelectionWidget(QWidget* parent) 0038 : QWidget(parent) 0039 , d_ptr(new EnvironmentSelectionWidgetPrivate(this)) 0040 { 0041 Q_D(EnvironmentSelectionWidget); 0042 0043 setLayout(new QHBoxLayout(this)); 0044 layout()->addWidget(d->comboBox); 0045 layout()->setContentsMargins(0, 0, 0, 0); 0046 0047 setCurrentProfile(QString()); // select the default profile 0048 0049 connect(d->comboBox, &QComboBox::currentTextChanged, 0050 this, &EnvironmentSelectionWidget::currentProfileChanged); 0051 } 0052 0053 EnvironmentSelectionWidget::~EnvironmentSelectionWidget() = default; 0054 0055 QString EnvironmentSelectionWidget::currentProfile() const 0056 { 0057 Q_D(const EnvironmentSelectionWidget); 0058 0059 return d->model->index(d->comboBox->currentIndex(), 0).data(Qt::EditRole).toString(); 0060 } 0061 0062 void EnvironmentSelectionWidget::setCurrentProfile(const QString& profile) 0063 { 0064 Q_D(EnvironmentSelectionWidget); 0065 0066 d->comboBox->setCurrentIndex(d->comboBox->findData(profile, Qt::EditRole)); 0067 emit currentProfileChanged(profile); 0068 } 0069 0070 void EnvironmentSelectionWidget::reconfigure() 0071 { 0072 Q_D(EnvironmentSelectionWidget); 0073 0074 QString selectedProfile = currentProfile(); 0075 d->model->reload(); 0076 setCurrentProfile(d->model->reloadSelectedItem(selectedProfile)); 0077 } 0078 0079 QString EnvironmentSelectionWidget::effectiveProfileName() const 0080 { 0081 Q_D(const EnvironmentSelectionWidget); 0082 0083 return d->model->index(d->comboBox->currentIndex(), 0084 0).data(EnvironmentSelectionModel::EffectiveNameRole).toString(); 0085 } 0086 0087 EnvironmentProfileList EnvironmentSelectionWidget::environmentProfiles() const 0088 { 0089 Q_D(const EnvironmentSelectionWidget); 0090 0091 return d->model->environmentProfiles(); 0092 } 0093 0094 } 0095 0096 #include "moc_environmentselectionwidget.cpp"