src/baseconfiguration.h

Mon, 27 Mar 2017 14:56:05 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 27 Mar 2017 14:56:05 +0300
changeset 1211
83b8ed708909
parent 1206
743dc95e0be6
permissions
-rw-r--r--

LibraryCollection now derives from QObject and QVector<Library>

/*
 *  LDForge: LDraw parts authoring CAD
 *  Copyright (C) 2013 - 2017 Teemu Piippo
 *
 *  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/>.
 */

#pragma once
#include <QObject>
#include <QSettings>
#include "basics.h"

/*
 * This class encapsulates a simple interface around QSettings. It is derived by a subclass written by a code generator that implements
 * static, type-safe configuration entries.
 */
class BaseConfiguration : public QObject
{
	Q_OBJECT

public:
	BaseConfiguration();

	bool existsEntry(const QString& name);
	QVariant defaultValueByName(const QString& name);
	virtual void initDefaults();
	void setValue(const QString& name, const QVariant& value);
	void setValue(const QString& name, const QVariant& value, const QVariant& defaultValue);
	void sync();
	QVariant value(const QString& name);
	QVariant value(const QString& name, const QVariant& defaultValue);

signals:
	void configurationChanged(QString, QVariant, QVariant);

protected:
	void registerConfigurationEntry(const QString& name, const QVariant& value);

private:
	QMap<QString, QVariant> m_defaults;
	QSettings m_settings;
	bool m_isInitialized = false;
};

mercurial