Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.3KB

  1. /*
  2. * Carla plugin host
  3. * Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "qsafesettings.hpp"
  18. //---------------------------------------------------------------------------------------------------------------------
  19. bool QSafeSettings::valueBool(const QString& key, const bool defaultValue) const
  20. {
  21. QVariant var(value(key, defaultValue));
  22. if (!var.isNull() && var.convert(QVariant::Bool) && var.isValid())
  23. return var.toBool();
  24. return defaultValue;
  25. }
  26. Qt::CheckState QSafeSettings::valueCheckState(const QString& key, const Qt::CheckState defaultValue) const
  27. {
  28. QVariant var(value(key, defaultValue));
  29. if (!var.isNull() && var.convert(QVariant::UInt) && var.isValid())
  30. {
  31. const uint value = var.toUInt();
  32. switch (value)
  33. {
  34. case Qt::Unchecked:
  35. case Qt::PartiallyChecked:
  36. case Qt::Checked:
  37. return static_cast<Qt::CheckState>(value);
  38. }
  39. }
  40. return defaultValue;
  41. }
  42. int QSafeSettings::valueIntPositive(const QString& key, const int defaultValue) const
  43. {
  44. QVariant var(value(key, defaultValue));
  45. if (!var.isNull() && var.convert(QVariant::Int) && var.isValid())
  46. {
  47. const int value = var.toInt();
  48. return value >= 0 ? value : defaultValue;
  49. }
  50. return defaultValue;
  51. }
  52. uint QSafeSettings::valueUInt(const QString& key, const uint defaultValue) const
  53. {
  54. QVariant var(value(key, defaultValue));
  55. if (!var.isNull() && var.convert(QVariant::UInt) && var.isValid())
  56. return var.toUInt();
  57. return defaultValue;
  58. }
  59. double QSafeSettings::valueDouble(const QString& key, const double defaultValue) const
  60. {
  61. QVariant var(value(key, defaultValue));
  62. if (!var.isNull() && var.convert(QVariant::Double) && var.isValid())
  63. return var.toDouble();
  64. return defaultValue;
  65. }
  66. QString QSafeSettings::valueString(const QString& key, const QString& defaultValue) const
  67. {
  68. QVariant var(value(key, defaultValue));
  69. if (!var.isNull() && var.convert(QVariant::String) && var.isValid())
  70. return var.toString();
  71. return defaultValue;
  72. }
  73. QByteArray QSafeSettings::valueByteArray(const QString& key, const QByteArray defaultValue) const
  74. {
  75. QVariant var(value(key, defaultValue));
  76. if (!var.isNull() && var.convert(QVariant::ByteArray) && var.isValid())
  77. return var.toByteArray();
  78. return defaultValue;
  79. }
  80. QStringList QSafeSettings::valueStringList(const QString& key, const QStringList defaultValue) const
  81. {
  82. QVariant var(value(key, defaultValue));
  83. if (!var.isNull() && var.convert(QVariant::StringList) && var.isValid())
  84. return var.toStringList();
  85. return defaultValue;
  86. }
  87. //---------------------------------------------------------------------------------------------------------------------