File indexing completed on 2024-05-05 04:39:18

0001 /*
0002     SPDX-FileCopyrightText: 2020 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "checksetselectioncombobox.h"
0008 
0009 // KF
0010 #include <KLocalizedString>
0011 
0012 namespace Clazy {
0013 
0014 CheckSetSelectionComboBox::CheckSetSelectionComboBox(QWidget* parent)
0015     : KComboBox(parent)
0016 {
0017     connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged),
0018             this, &CheckSetSelectionComboBox::onCurrentIndexChanged);
0019 }
0020 
0021 void CheckSetSelectionComboBox::setCheckSetSelections(const QVector<CheckSetSelection>& checkSetSelections,
0022                                                       const QString& defaultCheckSetSelectionId)
0023 {
0024     clear();
0025 
0026     addItem(i18nc("@item:inlistbox", "Custom"), QVariant());
0027 
0028     for (const auto& checkSetSelection : checkSetSelections) {
0029         if (checkSetSelection.id() == defaultCheckSetSelectionId) {
0030             addItem(i18nc("@item:inlistbox", "Use default (currently: %1)", checkSetSelection.name()),
0031                     QStringLiteral("Default"));
0032             break;
0033         }
0034     }
0035 
0036     for (const auto& checkSetSelection : checkSetSelections) {
0037         addItem(checkSetSelection.name(), checkSetSelection.id());
0038     }
0039 }
0040 
0041 QString CheckSetSelectionComboBox::selection() const
0042 {
0043     return currentData().toString();
0044 }
0045 
0046 void CheckSetSelectionComboBox::setSelection(const QString& selection)
0047 {
0048     const int index = findData(selection);
0049     setCurrentIndex(index);
0050 }
0051 
0052 void CheckSetSelectionComboBox::onCurrentIndexChanged()
0053 {
0054     emit selectionChanged(currentData().toString());
0055 }
0056 
0057 }
0058 
0059 #include "moc_checksetselectioncombobox.cpp"