2020-01-13 01:44:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NESTED_SETTINGS_H_
|
|
|
|
#define NESTED_SETTINGS_H_
|
|
|
|
|
|
|
|
#include <settings/json_settings.h>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
|
|
|
|
* Instead of being backed by a JSON file on disk, it loads and stores to its parent.
|
|
|
|
*/
|
2024-03-14 02:49:01 +00:00
|
|
|
class KICOMMON_API NESTED_SETTINGS : public JSON_SETTINGS
|
2020-01-13 01:44:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NESTED_SETTINGS( const std::string& aName, int aSchemaVersion, JSON_SETTINGS* aParent,
|
2024-05-05 18:08:55 +00:00
|
|
|
const std::string& aPath, bool aLoadFromFile = true );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-02-28 03:53:00 +00:00
|
|
|
virtual ~NESTED_SETTINGS();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the JSON document from the parent and then calls Load()
|
|
|
|
* @param aDirectory
|
|
|
|
*/
|
2020-08-02 09:23:21 +00:00
|
|
|
bool LoadFromFile( const wxString& aDirectory = "" ) override;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS
|
|
|
|
* @param aDirectory is ignored
|
2020-05-30 16:56:16 +00:00
|
|
|
* @return true if the document contents were updated
|
2020-01-13 01:44:19 +00:00
|
|
|
*/
|
2020-08-02 09:23:21 +00:00
|
|
|
bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-01-27 02:51:36 +00:00
|
|
|
void SetParent( JSON_SETTINGS* aParent, bool aLoadFromFile = true );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
|
|
|
JSON_SETTINGS* GetParent()
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
/// A pointer to the parent object to load and store from
|
|
|
|
JSON_SETTINGS* m_parent;
|
|
|
|
|
|
|
|
/// The path (in pointer format) of where to store this document in the parent
|
|
|
|
std::string m_path;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|