File indexing completed on 2024-05-12 05:52:35
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include "categorytypecombobox.h" 0009 #include "loggingmanager.h" 0010 #include "model/categorytypemodel.h" 0011 #include "model/categorytypeproxymodel.h" 0012 #include <KLocalizedString> 0013 0014 CategoryTypeComboBox::CategoryTypeComboBox(bool customType, QWidget *parent) 0015 : QComboBox(parent) 0016 { 0017 auto proxy = new CategoryTypeProxyModel(this); 0018 proxy->setObjectName(QLatin1StringView("proxy")); 0019 proxy->setSourceModel(LoggingManager::self().categoryTypeModel()); 0020 proxy->setShowOffType(!customType); 0021 setModel(proxy); 0022 } 0023 0024 CategoryTypeComboBox::~CategoryTypeComboBox() = default; 0025 0026 void CategoryTypeComboBox::restoreToDefault() 0027 { 0028 setType(mDefaultCategories); 0029 } 0030 0031 void CategoryTypeComboBox::setType(LoggingCategory::LoggingType type) 0032 { 0033 const int pos = findData(QVariant::fromValue(type), CategoryTypeModel::LoggingCategoryTypeRole); 0034 if (pos != -1) { 0035 setCurrentIndex(pos); 0036 } else { 0037 // Default; 0038 setCurrentIndex(0); 0039 } 0040 } 0041 0042 LoggingCategory::LoggingType CategoryTypeComboBox::type() const 0043 { 0044 return currentData(CategoryTypeModel::LoggingCategoryTypeRole).value<LoggingCategory::LoggingType>(); 0045 } 0046 0047 bool CategoryTypeComboBox::loggingCategoryIsNotDefault() const 0048 { 0049 return type() != mDefaultCategories; 0050 } 0051 0052 void CategoryTypeComboBox::setDefaultCategories(LoggingCategory::LoggingType defaultCategories) 0053 { 0054 mDefaultCategories = defaultCategories; 0055 } 0056 0057 LoggingCategory::LoggingType CategoryTypeComboBox::defaultCategories() const 0058 { 0059 return mDefaultCategories; 0060 } 0061 0062 #include "moc_categorytypecombobox.cpp"