--- 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')