File indexing completed on 2024-05-12 05:55:42
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 = 4; 0018 static const std::array<QString, AddressCcodingCount> addressCodingConfigValueList = { 0019 QStringLiteral("Hexadecimal"), 0020 QStringLiteral("Decimal"), 0021 QStringLiteral("Octal"), 0022 QStringLiteral("Expression"), 0023 }; 0024 0025 template <> 0026 Okteta::AddressComboBox::Coding 0027 KConfigGroup::readEntry(const char *key, 0028 const Okteta::AddressComboBox::Coding &defaultValue) const 0029 { 0030 const QString entry = readEntry(key, QString()); 0031 0032 auto it = std::find(addressCodingConfigValueList.cbegin(), addressCodingConfigValueList.cend(), entry); 0033 if (it == addressCodingConfigValueList.cend()) { 0034 return defaultValue; 0035 } 0036 0037 const int listIndex = std::distance(addressCodingConfigValueList.cbegin(), it); 0038 return static_cast<Okteta::AddressComboBox::Coding>(listIndex); 0039 } 0040 0041 template <> 0042 void KConfigGroup::writeEntry(const char *key, 0043 const Okteta::AddressComboBox::Coding &value, 0044 KConfigBase::WriteConfigFlags flags) 0045 { 0046 QString configValue; 0047 if (value == Okteta::AddressComboBox::InvalidCoding) { 0048 configValue = QStringLiteral("Invalid"); 0049 } else { 0050 const int listIndex = static_cast<int>(value); 0051 configValue = addressCodingConfigValueList[listIndex]; 0052 } 0053 writeEntry(key, configValue, flags); 0054 }