File indexing completed on 2024-04-28 05:50:45
0001 /* 0002 This source file is part of Konsole, a terminal emulator. 0003 0004 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef PROFILEGROUP_H 0010 #define PROFILEGROUP_H 0011 0012 // Konsole 0013 #include "Profile.h" 0014 0015 // Qt 0016 #include <QVariant> 0017 0018 namespace Konsole 0019 { 0020 /** 0021 * A composite profile which allows a group of profiles to be treated as one. 0022 * When setting a property, the new value is applied to all profiles in the 0023 * group. When reading a property, if all profiles in the group have the same 0024 * value then that value is returned, otherwise the result is null. 0025 * 0026 * Profiles can be added to the group using addProfile(). When all profiles 0027 * have been added updateValues() must be called 0028 * to sync the group's property values with those of the group's profiles. 0029 * 0030 * The Profile::Name and Profile::Path properties are unique to individual 0031 * profiles, setting these properties on a ProfileGroup has no effect. 0032 */ 0033 class KONSOLEPRIVATE_EXPORT ProfileGroup : public Profile 0034 { 0035 public: 0036 using Ptr = QExplicitlySharedDataPointer<ProfileGroup>; 0037 0038 /** Construct a new profile group, which is hidden by default. */ 0039 explicit ProfileGroup(const Profile::Ptr &profileParent = Profile::Ptr()); 0040 0041 /** Add a profile to the group. Calling setProperty() will update this 0042 * profile. When creating a group, add the profiles to the group then 0043 * call updateValues() to make the group's property values reflect the 0044 * profiles currently in the group. 0045 */ 0046 void addProfile(const Profile::Ptr &profile); 0047 0048 /** Remove a profile from the group. Calling setProperty() will no longer 0049 * affect this profile. */ 0050 void removeProfile(const Profile::Ptr &profile); 0051 0052 /** Returns the profiles in this group .*/ 0053 QList<Profile::Ptr> profiles() const; 0054 0055 /** 0056 * Updates the property values in this ProfileGroup to match those from 0057 * the group's profiles() 0058 * 0059 * For each available property, if each profile in the group has the same 0060 * value then the ProfileGroup will use that value for the property. 0061 * Otherwise the value for the property will be set to a null QVariant 0062 * 0063 * Some properties such as the name and the path of the profile 0064 * will always be set to null if the group has more than one profile. 0065 */ 0066 void updateValues(); 0067 0068 /** Sets the value of @p property in each of the group's profiles to 0069 * @p value. 0070 */ 0071 void setProperty(Property p, const QVariant &value) override; 0072 0073 private: 0074 Q_DISABLE_COPY(ProfileGroup) 0075 0076 QList<Profile::Ptr> _profiles; 0077 }; 0078 0079 inline ProfileGroup::ProfileGroup(const Profile::Ptr &profileParent) 0080 : Profile(profileParent) 0081 , _profiles(QList<Profile::Ptr>()) 0082 { 0083 setHidden(true); 0084 } 0085 } 0086 0087 #endif