Mon, 06 Mar 2017 12:15:33 +0200
Configuration changes can now be detected with signals.
--- a/CMakeLists.txt Mon Mar 06 11:49:00 2017 +0200 +++ b/CMakeLists.txt Mon Mar 06 12:15:33 2017 +0200 @@ -85,6 +85,7 @@ src/toolsets/toolset.cpp src/toolsets/viewtoolset.cpp src/types/matrix.cpp + ${CMAKE_BINARY_DIR}/configuration.cpp ) set (LDFORGE_HEADERS @@ -152,6 +153,7 @@ src/toolsets/viewtoolset.h src/types/matrix.h src/types/resourcevector.h + ${CMAKE_BINARY_DIR}/configuration.h ) set (LDFORGE_FORMS @@ -219,8 +221,7 @@ qt5_add_resources (LDFORGE_QRC ${LDFORGE_RESOURCES}) qt5_wrap_ui (LDFORGE_FORMS_HEADERS ${LDFORGE_FORMS}) add_executable (ldforge WIN32 ${LDFORGE_SOURCES} ${LDFORGE_HEADERS} ${LDFORGE_OTHER_FILES} - ${LDFORGE_QRC} ${LDFORGE_FORMS_HEADERS} - ${CMAKE_BINARY_DIR}/configuration.cpp) + ${LDFORGE_QRC} ${LDFORGE_FORMS_HEADERS}) set_source_files_properties(${LDFORGE_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties(${LDFORGE_OTHER_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)
--- a/src/configurationoptions.txt Mon Mar 06 11:49:00 2017 +0200 +++ b/src/configurationoptions.txt Mon Mar 06 12:15:33 2017 +0200 @@ -2,11 +2,14 @@ # LDForge configuration option definitions # # Syntax: +# include file # option OptionName = value # option OptionName = type {value} # # comment # +include "basics.h" + # Editing options option Grid = 1 option GridCoarseCoordinateSnap = 5.0
--- a/tools/configcollector.py Mon Mar 06 11:49:00 2017 +0200 +++ b/tools/configcollector.py Mon Mar 06 12:15:33 2017 +0200 @@ -73,6 +73,7 @@ self.declarations = OrderedDict() self.qtTypes = set() self.args = args + self.includes = [] def collect(self, filename): with open(filename) as file: @@ -81,17 +82,27 @@ if line and not line.startswith('#'): from re import search match = search('^option (\w+) = (.+)$', line) - if not match: - raise ValueError('unable to parse: %r' % line) - name, value = match.groups() - match = search(r'^(\w+)\s*\{(.*)\}$', value) - try: - typename, value = match.groups() - if not value: - value = typename + ' {}' - except: - typename = deduce_type(value) - self.declare(name, typename, value) + if match: + name, value = match.groups() + match = search(r'^(\w+)\s*\{(.*)\}$', value) + try: + typename, value = match.groups() + if not value: + value = typename + ' {}' + except: + typename = deduce_type(value) + self.declare(name, typename, value) + else: + match = search('^include (.+)$', line) + if match: + filename = match.group(1) + if filename.startswith('"'): + from os.path import join + filename = '"' + join(self.args.sourcedir, filename[1:-1]) + '"' + self.includes.append(filename) + else: + raise ValueError('unable to parse: %r' % line) + # Sort the declarations in alphabetical order self.declarations = OrderedDict(sorted(self.declarations.items(), key = lambda t: t[1]['name'])) # Fill in additional information @@ -118,14 +129,19 @@ 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\n') + write('class Configuration : public QObject\n') write('{\n') + write('\tQ_OBJECT\n') + write('\n') write('public:\n') write('\tConfiguration();\n') write('\t~Configuration();\n') @@ -139,6 +155,9 @@ 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') @@ -188,10 +207,15 @@ for declaration in self.declarations.values(): device.write('void Configuration::{writegate}({typereference} value)\n'.format(**declaration)) device.write('{\n') - device.write('\tif(value != {default})\n'.format(**declaration)) - device.write('\t\tm_settings->setValue("{name}", QVariant::fromValue<{type}>(value));\n'.format(**declaration)) - device.write('\telse\n') - device.write('\t\tm_settings->remove("{name}");\n'.format(**declaration)) + device.write('\tif (value != {readgate}())\n'.format(**declaration)) + device.write('\t{\n') + device.write('\t\tQVariant oldValue = {readgate}();\n'.format(**declaration)) + device.write('\t\tif(value != {default})\n'.format(**declaration)) + device.write('\t\t\tm_settings->setValue("{name}", QVariant::fromValue<{type}>(value));\n'.format(**declaration)) + device.write('\t\telse\n') + device.write('\t\t\tm_settings->remove("{name}");\n'.format(**declaration)) + device.write('\t\temit configurationChanged("{name}", oldValue, value);\n'.format(**declaration)) + device.write('\t}\n') device.write('}\n') device.write('\n') for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()):