| 155 | |
| 156 | template<class T> |
| 157 | T get(const QString &key, bool* exists = nullptr, bool useDefaultIfMissing = true) |
| 158 | { |
| 159 | auto variant = _conf->getVariant(key, true, exists); |
| 160 | |
| 161 | if(useDefaultIfMissing) { |
| 162 | if(exists != nullptr && !*exists) { |
| 163 | Log::debug(QString("Key '%1' unset, loading default value").arg(key)); |
| 164 | variant = _defaultConf->getVariant(key, true, exists); |
| 165 | } |
| 166 | if(exists != nullptr && !*exists) |
| 167 | Log::error(QString("Key '%1' unset and no default value found").arg(key)); |
| 168 | } |
| 169 | |
| 170 | if constexpr (std::is_same_v<T, QVariant>) { |
| 171 | return (T)(variant); |
| 172 | } |
| 173 | if constexpr (std::is_same_v<T, std::string>) { |
| 174 | return (T)(variant.toString().toStdString()); |
| 175 | } |
| 176 | if constexpr (std::is_same_v<T, QString>) { |
| 177 | return (T)(variant.toString()); |
| 178 | } |
| 179 | if constexpr (std::is_same_v<T, int>) { |
| 180 | return (T)(variant.toInt()); |
| 181 | } |
| 182 | if constexpr (std::is_same_v<T, float>) { |
| 183 | return (T)(variant.toFloat()); |
| 184 | } |
| 185 | if constexpr (std::is_same_v<T, bool>) { |
| 186 | return (T)(variant.toBool()); |
| 187 | } |
| 188 | |
| 189 | Log::error("Unknown type T"); |
| 190 | throw new std::exception; |
| 191 | } |
| 192 | |
| 193 | template<class T> |
| 194 | T get(const Key &key, bool* exists = nullptr, bool useDefaultIfMissing = true) |
nothing calls this directly
no test coverage detected