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 // Own
0010 #include "ProfileGroup.h"
0011 
0012 // Konsole
0013 
0014 using namespace Konsole;
0015 
0016 void ProfileGroup::addProfile(const Profile::Ptr &profile)
0017 {
0018     _profiles.append(profile);
0019 }
0020 
0021 void ProfileGroup::removeProfile(const Profile::Ptr &profile)
0022 {
0023     _profiles.removeAll(profile);
0024 }
0025 
0026 QList<Profile::Ptr> ProfileGroup::profiles() const
0027 {
0028     return _profiles;
0029 }
0030 
0031 void ProfileGroup::updateValues()
0032 {
0033     for (const PropertyInfo &info : Profile::DefaultProperties) {
0034         // the profile group does not store a value for some properties
0035         // (eg. name, path) if even they are equal between profiles -
0036         //
0037         // the exception is when the group has only one profile in which
0038         // case it behaves like a standard Profile
0039         if (_profiles.count() > 1 && !canInheritProperty(info.property)) {
0040             continue;
0041         }
0042 
0043         QVariant value;
0044         for (int i = 0; i < _profiles.count(); i++) {
0045             QVariant profileValue = _profiles[i]->property<QVariant>(info.property);
0046             if (value.isNull()) {
0047                 value = profileValue;
0048             } else if (value != profileValue) {
0049                 value = QVariant();
0050                 break;
0051             }
0052         }
0053         Profile::setProperty(info.property, value);
0054     }
0055 }
0056 
0057 void ProfileGroup::setProperty(Property p, const QVariant &value)
0058 {
0059     if (_profiles.count() > 1 && !canInheritProperty(p)) {
0060         return;
0061     }
0062 
0063     Profile::setProperty(p, value);
0064     for (const Profile::Ptr &profile : std::as_const(_profiles)) {
0065         profile->setProperty(p, value);
0066     }
0067 }