Warning, file /utilities/okteta/kasten/controllers/libconfigentries/addresscomboboxcodingconfigentry.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2023 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "addresscomboboxcodingconfigentry.hpp"
0010 
0011 // Std
0012 #include <algorithm>
0013 #include <array>
0014 #include <iterator>
0015 
0016 // Matching Okteta::AddressComboBox::Coding
0017 static constexpr int AddressCcodingCount = 3;
0018 static const std::array<QString, AddressCcodingCount> addressCodingConfigValueList = {
0019     QStringLiteral("Hexadecimal"),
0020     QStringLiteral("Decimal"),
0021     QStringLiteral("Expression"),
0022 };
0023 
0024 template <>
0025 Okteta::AddressComboBox::Coding
0026 KConfigGroup::readEntry(const char *key,
0027                         const Okteta::AddressComboBox::Coding &defaultValue) const
0028 {
0029     const QString entry = readEntry(key, QString());
0030 
0031     auto it = std::find(addressCodingConfigValueList.cbegin(), addressCodingConfigValueList.cend(), entry);
0032     if (it == addressCodingConfigValueList.cend()) {
0033         return defaultValue;
0034     }
0035 
0036     const int listIndex = std::distance(addressCodingConfigValueList.cbegin(), it);
0037     return static_cast<Okteta::AddressComboBox::Coding>(listIndex);
0038 }
0039 
0040 template <>
0041 void KConfigGroup::writeEntry(const char *key,
0042                               const Okteta::AddressComboBox::Coding &value,
0043                               KConfigBase::WriteConfigFlags flags)
0044 {
0045     QString configValue;
0046     if (value == Okteta::AddressComboBox::InvalidCoding) {
0047         configValue = QStringLiteral("Invalid");
0048     } else {
0049         const int listIndex = static_cast<int>(value);
0050         configValue = addressCodingConfigValueList[listIndex];
0051     }
0052     writeEntry(key, configValue, flags);
0053 }