@@ -175,10 +175,10 @@ QVariant Settings::value(QString path, const QVariant &defaultValue) const
175175}
176176
177177/* !
178- * \qmlmethod variant Settings::setValue(string path, variant value)
178+ * \qmlmethod variant Settings::setValue(string path, var value)
179179 * Adds a new value `value` to the project settings at the given `path`. Returns `true` if the operation succeeded.
180180 */
181- bool Settings::setValue (QString path, const QVariant &value)
181+ bool Settings::setValue (QString path, const QJSValue &value)
182182{
183183 LOG (" Settings::setValue" , path, value);
184184
@@ -190,34 +190,47 @@ bool Settings::setValue(QString path, const QVariant &value)
190190 if (!path.startsWith (' /' ))
191191 path.prepend (' /' );
192192
193- auto jsonPath = nlohmann::json::json_pointer (path.toStdString ());
194- switch (static_cast <QMetaType::Type>(value.typeId ())) {
193+ const auto jsonPath = nlohmann::json::json_pointer (path.toStdString ());
194+
195+ const auto var = value.toVariant ();
196+
197+ switch (static_cast <QMetaType::Type>(var.typeId ())) {
195198 case QMetaType::Bool:
196- m_settings[jsonPath] = value .toBool ();
197- m_projectSettings[jsonPath] = value .toBool ();
199+ m_settings[jsonPath] = var .toBool ();
200+ m_projectSettings[jsonPath] = var .toBool ();
198201 break ;
199202 case QMetaType::Int:
200203 case QMetaType::LongLong:
201- m_settings[jsonPath] = value .toInt ();
202- m_projectSettings[jsonPath] = value .toInt ();
204+ m_settings[jsonPath] = var .toInt ();
205+ m_projectSettings[jsonPath] = var .toInt ();
203206 break ;
204207 case QMetaType::UInt:
205208 case QMetaType::ULongLong:
206- m_settings[jsonPath] = value .toUInt ();
207- m_projectSettings[jsonPath] = value .toUInt ();
209+ m_settings[jsonPath] = var .toUInt ();
210+ m_projectSettings[jsonPath] = var .toUInt ();
208211 break ;
209212 case QMetaType::Double:
210- m_settings[jsonPath] = value .toDouble ();
211- m_projectSettings[jsonPath] = value .toDouble ();
213+ m_settings[jsonPath] = var .toDouble ();
214+ m_projectSettings[jsonPath] = var .toDouble ();
212215 break ;
213216 case QMetaType::QString:
214- m_settings[jsonPath] = value .toString ();
217+ m_settings[jsonPath] = var .toString ();
215218 m_projectSettings[jsonPath] = value.toString ();
216219 break ;
217220 case QMetaType::QStringList:
218- m_settings[jsonPath] = value .toStringList ();
219- m_projectSettings[jsonPath] = value .toStringList ();
221+ m_settings[jsonPath] = var .toStringList ();
222+ m_projectSettings[jsonPath] = var .toStringList ();
220223 break ;
224+ case QMetaType::QVariantList: {
225+ // A stringlist from QML will have a QVariantList meta type
226+ const QStringList list = var.toStringList ();
227+ if (list.size () == var.toList ().size ()) {
228+ m_settings[jsonPath] = list;
229+ m_projectSettings[jsonPath] = list;
230+ } else {
231+ spdlog::error (" Settings::setValue {} in {} - only string lists are supported" , value.toString (), path);
232+ }
233+ } break ;
221234 default :
222235 spdlog::error (" Settings::setValue {} in {} - value type not handled" , value.toString (), path);
223236 return false ;
0 commit comments