Wed, 08 Mar 2017 20:16:06 +0200
Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
--- a/CMakeLists.txt Mon Mar 06 12:15:33 2017 +0200 +++ b/CMakeLists.txt Wed Mar 08 20:16:06 2017 +0200 @@ -27,6 +27,7 @@ set_source_files_properties (${CMAKE_BINARY_DIR}/configuration.cpp PROPERTIES GENERATED TRUE) set (LDFORGE_SOURCES + src/baseconfiguration.cpp src/basics.cpp src/canvas.cpp src/colors.cpp @@ -89,6 +90,7 @@ ) set (LDFORGE_HEADERS + src/baseconfiguration.h src/basics.h src/canvas.h src/colors.h @@ -200,6 +202,11 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRANSPARENT_DIRECT_COLORS") endif() +set_source_files_properties( + ${CMAKE_BINARY_DIR}/configuration.h + ${CMAKE_BINARY_DIR}/configuration.cpp + PROPERTIES GENERATED TRUE) + # With clang, we need to set -Wno-deprecated since Qt headers seem to use the # register keyword which clang doesn't seem to like. It also appears that Qt # doesn't set Q_COMPILER_INITIALIZER_LISTS when compiling with clang? What's
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/baseconfiguration.cpp Wed Mar 08 20:16:06 2017 +0200 @@ -0,0 +1,49 @@ +/* + * 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/>. + */ + +#include <QSet> +#include <QSettings> +#include <QVariant> +#include "configuration.h" +#include "mainwindow.h" + +BaseConfiguration::BaseConfiguration() : + m_settings {MainWindow::makeSettings(this)} {} + +BaseConfiguration::~BaseConfiguration() +{ + delete m_settings; +} + +QVariant BaseConfiguration::defaultValueByName(const QString& name) +{ + if (m_isInitialized) + initDefaults(); + + return m_defaults.value(name); +} + +bool BaseConfiguration::existsEntry(const QString& name) +{ + return m_defaults.find(name) != m_defaults.end(); +} + +void BaseConfiguration::initDefaults() +{ + m_isInitialized = true; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/baseconfiguration.h Wed Mar 08 20:16:06 2017 +0200 @@ -0,0 +1,45 @@ +/* + * 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" + +class BaseConfiguration : public QObject +{ + Q_OBJECT + +public: + BaseConfiguration(); + ~BaseConfiguration(); + + bool existsEntry(const QString& name); + QVariant defaultValueByName(const QString& name); + virtual void initDefaults(); + +signals: + void configurationChanged(QString, QVariant, QVariant); + +protected: + QMap<QString, QVariant> m_defaults; + class QSettings* m_settings; + +private: + bool m_isInitialized = false; +};
--- a/tools/configcollector.py Mon Mar 06 12:15:33 2017 +0200 +++ b/tools/configcollector.py Wed Mar 08 20:16:06 2017 +0200 @@ -128,75 +128,32 @@ self.qtTypes.update(findall(r'Q\w+', typename)) def writeHeader(self, device): - device.write('#pragma once\n') - device.write('#include <QObject>\n') - device.write('#include <QMap>\n') - for include in sorted(self.includes): - device.write('#include %s\n' % include) - for qtType in sorted(self.qtTypes): - device.write('#include <%s>\n' % qtType) - device.write('\n') - formatargs = {} - write = lambda value: device.write(value) - write('class Configuration : public QObject\n') - write('{\n') - write('\tQ_OBJECT\n') - write('\n') - write('public:\n') - write('\tConfiguration();\n') - write('\t~Configuration();\n') - write('\tbool existsEntry(const QString& name);\n') - write('\tQVariant defaultValueByName(const QString& name);\n') + write = lambda value: device.write(value + '\n') + write('#pragma once') + write('#include "{sourcedir}/baseconfiguration.h"'.format(sourcedir = self.args.sourcedir)) + write('class Configuration : public BaseConfiguration') + write('{') + write('public:') + write('\tvoid initDefaults() override;') for declaration in self.declarations.values(): - write('\t{type} {readgate}() const;\n'.format(**declaration)) + write('\t{type} {readgate}() const;'.format(**declaration)) for declaration in self.declarations.values(): - write('\tvoid {writegate}({typereference} value);\n'.format(**declaration)) - + write('\tvoid {writegate}({typereference} value);'.format(**declaration)) for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()): - write('\tvoid {togglefunction}();\n'.format(**declaration)) - write('\n') - write('signals:\n') - write('\tvoid configurationChanged(QString, QVariant, QVariant);\n') - write('\n') - write('private:\n') - write('\tQMap<QString, QVariant> m_defaults;\n') - write('\tclass QSettings* m_settings;\n') - write('};\n') + write('\tvoid {togglefunction}();'.format(**declaration)) + write('};') + write('') def writeSource(self, device, headername): - device.write('#include <QSet>\n') - device.write('#include <QSettings>\n') - device.write('#include <QVariant>\n') - device.write('#include "%s/mainwindow.h"\n' % (self.args.sourcedir)) - device.write('#include "%s"\n' % headername) - device.write( - '\n' - 'Configuration::Configuration() :\n' - '\tm_settings(MainWindow::makeSettings(nullptr))\n' - '{\n') + for qttype in self.qtTypes: + device.write('#include <%s>\n' % qttype) + device.write('#include "configuration.h"\n') + device.write('void Configuration::initDefaults()\n') + device.write('{\n') + device.write('\tBaseConfiguration::initDefaults();\n') for declaration in self.declarations.values(): device.write('\tm_defaults["{name}"] = QVariant::fromValue<{type}>({default});\n'.format(**declaration)) - device.write('}\n' - '\n' - 'Configuration::~Configuration()\n' - '{\n' - '\tm_settings->deleteLater();\n' - '}\n' - '\n') - device.write('QVariant Configuration::defaultValueByName(const QString& name)\n') - device.write('{\n') - device.write('\tQMap<QString, QVariant>::iterator it = m_defaults.find(name);\n') - device.write('\tif(it != m_defaults.end())\n') - device.write('\t\treturn *it;\n') - device.write('\telse\n') - device.write('\t\treturn {};\n') device.write('}\n') - device.write('\n') - device.write('bool Configuration::existsEntry(const QString& name)\n') - device.write('{\n') - device.write('\treturn m_defaults.find(name) != m_defaults.end();\n') - device.write('}\n') - device.write('\n') for declaration in self.declarations.values(): device.write('{type} Configuration::{readgate}() const\n'.format(**declaration)) device.write('{\n')