File indexing completed on 2024-05-12 04:38:19

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003     SPDX-FileCopyrightText: 2017 Friedrich W. H. Kossebau <kossebau@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDEVPLATFORM_ENVIRONMENTPROFILEMODEL_H
0009 #define KDEVPLATFORM_ENVIRONMENTPROFILEMODEL_H
0010 
0011 #include <QAbstractTableModel>
0012 #include <QStringList>
0013 
0014 namespace KDevelop
0015 {
0016 class EnvironmentProfileListModel;
0017 
0018 class EnvironmentProfileModel : public QAbstractTableModel
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     enum Role {
0024         VariableRole = Qt::UserRole + 1,
0025         ValueRole
0026     };
0027 
0028     enum Column {
0029         VariableColumn = 0,
0030         ValueColumn = 1
0031     };
0032 
0033     explicit EnvironmentProfileModel(EnvironmentProfileListModel* profileListModel, QObject* parent = nullptr);
0034 
0035     int rowCount(const QModelIndex& parent = {}) const override;
0036     int columnCount(const QModelIndex& parent = {}) const override;
0037     Qt::ItemFlags flags(const QModelIndex& index) const override;
0038     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0039     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0040     bool setData(const QModelIndex& index, const QVariant&, int role = Qt::EditRole) override;
0041 
0042     void setCurrentProfile(const QString& profileName);
0043 
0044     void addVariable(const QString& variableName, const QString& value);
0045     /**
0046      * Load a set of environment variables from a plaintext string.
0047      *
0048      * @p plainText In the form "FOO=1\nBAR=2"
0049      */
0050     void setVariablesFromString(const QString& plainText);
0051     void removeVariable(const QString& variableName);
0052     void removeVariables(const QStringList& variableNames);
0053 
0054 private:
0055     void onProfileAboutToBeRemoved(const QString& profileName);
0056 
0057 private:
0058     QStringList m_varsByIndex;
0059     QString m_currentProfileName;
0060     EnvironmentProfileListModel* m_profileListModel;
0061 };
0062 
0063 }
0064 
0065 #endif