2021-03-12 13:16:36 +01:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CALAMARES_MODULESYSTEM_PRESET_H
|
|
|
|
#define CALAMARES_MODULESYSTEM_PRESET_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariantMap>
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
namespace Calamares
|
|
|
|
{
|
|
|
|
namespace ModuleSystem
|
|
|
|
{
|
|
|
|
/** @brief The settings for a single field
|
|
|
|
*
|
|
|
|
* The settings apply to a single field; **often** this will
|
|
|
|
* correspond to a single value or property of a Config
|
|
|
|
* object, but there is no guarantee of a correspondence
|
|
|
|
* between names here and names in the code.
|
|
|
|
*
|
|
|
|
* The value is stored as a string; consumers (e.g. the UI)
|
|
|
|
* will need to translate the value to whatever is actually
|
|
|
|
* used (e.g. in the case of an integer field).
|
|
|
|
*
|
|
|
|
* By default, presets are still editable. Set that to @c false
|
|
|
|
* to make the field unchangeable (again, the UI is responsible
|
|
|
|
* for setting that up).
|
|
|
|
*/
|
|
|
|
struct PresetField
|
|
|
|
{
|
|
|
|
QString fieldName;
|
2021-03-12 17:20:36 +01:00
|
|
|
QVariant value;
|
2021-03-12 13:16:36 +01:00
|
|
|
bool editable = true;
|
2021-03-12 17:20:36 +01:00
|
|
|
|
|
|
|
bool isValid() const { return !fieldName.isEmpty(); }
|
2021-03-12 13:16:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief All the presets for one UI entity
|
|
|
|
*
|
|
|
|
* This is a collection of presets read from a module
|
|
|
|
* configuration file, one setting per field.
|
|
|
|
*/
|
|
|
|
class Presets : public QVector< PresetField >
|
|
|
|
{
|
|
|
|
public:
|
2021-03-12 14:49:46 +01:00
|
|
|
/** @brief Reads preset entries from the map
|
|
|
|
*
|
|
|
|
* The map's keys are used as field name, and each value entry
|
|
|
|
* should specify an initial value and whether the entry is editable.
|
|
|
|
* Fields are editable by default.
|
|
|
|
*/
|
2021-03-12 13:16:36 +01:00
|
|
|
explicit Presets( const QVariantMap& configurationMap );
|
2021-03-12 14:49:46 +01:00
|
|
|
/** @brief Reads preset entries from the @p configurationMap
|
|
|
|
*
|
|
|
|
* As above, but only field names that occur in @p recognizedKeys
|
|
|
|
* are kept; others are discarded.
|
|
|
|
*/
|
2021-03-12 13:16:36 +01:00
|
|
|
Presets( const QVariantMap& configurationMap, const QStringList& recognizedKeys );
|
2021-03-12 14:49:46 +01:00
|
|
|
|
2021-03-12 17:20:36 +01:00
|
|
|
/** @brief Creates an empty presets map
|
|
|
|
*
|
|
|
|
* This constructor is primarily intended for use by the ApplyPresets
|
|
|
|
* helper class, which will reserve suitable space and load
|
|
|
|
* presets on-demand.
|
|
|
|
*/
|
|
|
|
Presets() = default;
|
|
|
|
|
2021-03-12 14:49:46 +01:00
|
|
|
/** @brief Is the given @p fieldName editable?
|
|
|
|
*
|
|
|
|
* Fields are editable by default, so if there is no explicit setting,
|
|
|
|
* returns @c true.
|
|
|
|
*/
|
|
|
|
bool isEditable( const QString& fieldName ) const;
|
2021-03-12 18:42:37 +01:00
|
|
|
|
|
|
|
/** @brief Finds the settings for a field @p fieldName
|
|
|
|
*
|
|
|
|
* If there is no such field, returns an invalid PresetField.
|
|
|
|
*/
|
|
|
|
PresetField find( const QString& fieldName ) const;
|
2021-03-12 13:16:36 +01:00
|
|
|
};
|
|
|
|
} // namespace ModuleSystem
|
|
|
|
} // namespace Calamares
|
|
|
|
|
|
|
|
#endif
|