File indexing completed on 2024-05-05 04:38:44
0001 /* 0002 SPDX-FileCopyrightText: 2013 Ivan Shapovalov <intelfx100@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef ENVIRONMENTSELECTIONMODEL_H 0008 #define ENVIRONMENTSELECTIONMODEL_H 0009 0010 #include "environmentprofilelist.h" 0011 0012 #include <QStringListModel> 0013 #include <QSet> 0014 0015 namespace KDevelop { 0016 0017 class EnvironmentSelectionModel : public QStringListModel 0018 { 0019 Q_OBJECT 0020 0021 public: 0022 enum SpecialRoles 0023 { 0024 EffectiveNameRole = Qt::UserRole + 1 0025 }; 0026 0027 explicit EnvironmentSelectionModel(QObject* parent = nullptr); 0028 0029 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0030 0031 QVariant data(const QModelIndex& index, int role) const override; 0032 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; 0033 0034 /** 0035 * @returns The @ref EnvironmentProfileList which has been used to populate this 0036 * model. 0037 */ 0038 EnvironmentProfileList environmentProfiles() const; 0039 0040 /** 0041 * Reloads the model from the global config. 0042 */ 0043 void reload(); 0044 0045 /** 0046 * Shall be used by views to update selection (current item) after the model has been reloaded. 0047 * 0048 * @param currentProfile Previous selected item. 0049 * @returns The item which shall become selected. 0050 */ 0051 QString reloadSelectedItem(const QString& currentProfile); 0052 0053 private: 0054 EnvironmentProfileList m_env; 0055 QSet<QString> m_profilesLookupTable; 0056 }; 0057 0058 } // namespace KDevelop 0059 0060 #endif // ENVIRONMENTSELECTIONMODEL_H