diff options
author | Antti Hölttä <AHoelttae@luxoft.com> | 2018-05-04 14:27:28 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2018-05-15 13:48:23 +0000 |
commit | 96d543c1d28fe84d19c75e812cf4cf34df7c3ad9 (patch) | |
tree | 94b17fab0ff6c43a496c3ad4341b28d17aaf5bb8 /src/tools | |
parent | 8c264c39f7acd510636b85a36cc29a6a1e05af38 (diff) |
Update the ivigenerator templates to use macros
Replace repetitive or complex parts of ivigenerator's templates with
macros. Add a directory for common code. Also some cleanup.
Task-number: QTAUTO-847
Change-Id: I12d7d6c25db14d4ab05583274742aec9e35d2bbf
Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
Diffstat (limited to 'src/tools')
34 files changed, 319 insertions, 514 deletions
diff --git a/src/tools/ivigenerator/templates_frontend/generated_comment.cpp.tpl b/src/tools/ivigenerator/common/generated_comment.cpp.tpl index 95878f2..95878f2 100644 --- a/src/tools/ivigenerator/templates_frontend/generated_comment.cpp.tpl +++ b/src/tools/ivigenerator/common/generated_comment.cpp.tpl diff --git a/src/tools/ivigenerator/common/qtivi_macros.j2 b/src/tools/ivigenerator/common/qtivi_macros.j2 new file mode 100644 index 0000000..1fb754f --- /dev/null +++ b/src/tools/ivigenerator/common/qtivi_macros.j2 @@ -0,0 +1,204 @@ +{# +# Copyright (C) 2018 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite licenses may use +# this file in accordance with the commercial license agreement provided +# with the Software or, alternatively, in accordance with the terms +# contained in a written agreement between you and The Qt Company. For +# licensing terms and conditions see https://www.qt.io/terms-conditions. +# For further information use the contact form at https://www.qt.io/contact-us. +# +# GNU Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# included in the packaging of this file. Please review the following +# information to ensure the GNU General Public License requirements will +# be met: https://www.gnu.org/licenses/gpl-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} + +{# these macros can be used to generate content for QtIvi code. The macros +# provide snippets that are commonly found in multiple templates and are not +# too template specific. +# Function macros do not generate the whole body of the function, but just +# the header line, so remember to add potential virtuals, overrides, +# semicolons etc. yourself! +#} + +{# join operation parameters, with type and name, into a comma separated list, +# optionally including the zone. +#} +{% macro join_params(operation, zoned = false) %} +{% set params = operation.parameters|map('parameter_type')|join(', ') %} +{% if zoned %} +{% if params|length %} +{% set params = params + ', const QString &zone' %} +{% else %} +{% set params = 'const QString &zone' %} +{% endif %} +{% endif %} +{{params}} +{%- endmacro %} + +{# function header for a custom slot. pass the class parameter in order to add +# the scope:: -specifier. use zoned to add the zone-specifier +#} +{% macro operation(operation, class = '', zoned = false) %} +{% if class|count %} +{% set scope = class+'::' %} +{% else %} +{% set scope = '' %} +{% endif %} +{% if operation.const %} +{% set const = ' const' %} +{% else%} +{% set const = '' %} +{% endif %} +QIviPendingReply<{{operation|return_type}}> {{scope}}{{operation}}({{join_params(operation, zoned)}}){{const}} +{%- endmacro %} + + +{# property declaration, Q_PROPERTY(...) #} +{% macro property(property) %} +{% if property.readonly or property.const %} +{% set write = '' %} +{% else %} +{% set write = ' WRITE ' + property|setter_name %} +{% endif %} +Q_PROPERTY({{property|return_type}} {{property}} READ {{property|getter_name}}{{write}} NOTIFY {{property}}Changed) +{% endmacro %} + + +{# function header for a property setter: setProperty(...) +# pass the class parameter in order to add the scope:: -specifier. +# use zoned to add the zone-specifier +#} +{% macro prop_setter(property, class = '', zoned = false) %} +{% if class|count %} +{% set scope = class+'::' %} +{% else %} +{% set scope = '' %} +{% endif %} +{% if zoned %} +{% set zone = ', const QString &zone' %} +{% else %} +{% set zone = '' %} +{% endif %} +void {{scope}}{{property|setter_name}}({{property|parameter_type}}{{zone}}) +{%- endmacro %} + + +{# function header for a property getter. +# pass the class parameter in order to add the scope:: -specifier. +#} +{% macro prop_getter(property, class = '') %} +{% if class|count %} +{% set scope = class+'::' %} +{% else %} +{% set scope = '' %} +{% endif %} +{{property|return_type}} {{scope}}{{property|getter_name}}() const +{%- endmacro %} + + +{# helper macro for defining a property notifier and a corresponding callback. +# This is an internal function and not intended to be used inside a template. +#} +{% macro _prop_notify(property, class, zoned, prefix) %} +{% if prefix|count %} +{% set prop = prefix + property|upperfirst %} +{% else %} +{% set prop = property %} +{% endif %} +{% if class|count %} +{% set scope = class+'::' %} +{% else %} +{% set scope = '' %} +{% endif %} +{% if zoned %} +{% set zone = ', const QString &zone' %} +{% else %} +{% set zone = '' %} +{% endif %} +void {{scope}}{{prop}}Changed({{property|parameter_type}}{{zone}}) +{%- endmacro %} + +{# signal declaration for property notifier. +# pass the class parameter in order to add the scope:: -specifier. +# use zoned to add the zone-specifier +#} +{% macro prop_notify(property, class = '', zoned = false) %} +{{_prop_notify(property, class, zoned, '')}} +{%- endmacro %} + +{# callback slot declaration for property notifier. +# pass the class parameter in order to add the scope:: -specifier. +# use zoned to add the zone-specifier +#} +{% macro on_prop_changed(property, class = '', zoned = false) %} +{{_prop_notify(property, class, zoned, 'on')}} +{%- endmacro %} + + +{# helper macro for defining a signal and a corresponding callback. +# This is an internal function and not intended to be used inside a template. +#} +{% macro _signal(signal, class, zoned, prefix) %} +{% if prefix|count %} +{% set sig = prefix + signal|upperfirst %} +{% else %} +{% set sig = signal %} +{% endif %} +{% if class|count %} +{% set scope = class+'::' %} +{% else %} +{% set scope = '' %} +{% endif %} +void {{scope}}{{sig}}({{join_params(signal, zoned)}}) +{%- endmacro %} + +{# custom signal declaration +# pass the class parameter in order to add the scope:: -specifier. +# use zoned to add the zone-specifier +#} +{% macro signal(signal, class = '', zoned = false) %} +{{_signal(signal, class, zoned, '')}} +{%- endmacro %} + +{# custom signal callback declaration +# pass the class parameter in order to add the scope:: -specifier. +# use zoned to add the zone-specifier +#} +{% macro on_signal(signal, class = '', zoned = false) %} +{{_signal(signal, class, zoned, 'on')}} +{%- endmacro %} + + +{% macro format_comments(comments) -%} +{% with doc = comments|parse_doc -%} +{% if doc.brief %} \brief {{doc.brief|join(' ')| wordwrap(width=100, wrapstring='\n ')}} +{% endif %} +{% if doc.description %} + {{doc.description|join(' ')| wordwrap(width=100, wrapstring='\n ')}}{% endif %} +{% endwith -%} +{% endmacro -%} diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py index 7ef5f80..3b55f04 100755 --- a/src/tools/ivigenerator/generate.py +++ b/src/tools/ivigenerator/generate.py @@ -564,7 +564,7 @@ def generate(tplconfig, moduleConfig, src, dst): FileSystem.strict = True Generator.strict = True system = FileSystem.parse(src) - generator = Generator(search_path=tplconfig) + generator = Generator(search_path=[tplconfig, here / "common"]) generator.register_filter('return_type', return_type) generator.register_filter('parameter_type', parameter_type) generator.register_filter('getter_name', getter_name) diff --git a/src/tools/ivigenerator/ivigenerator.pro b/src/tools/ivigenerator/ivigenerator.pro index d81914d..47f3bf4 100644 --- a/src/tools/ivigenerator/ivigenerator.pro +++ b/src/tools/ivigenerator/ivigenerator.pro @@ -8,10 +8,14 @@ QT_FOR_CONFIG += ivicore # This needs to be the last step as it unsets other configs and may have side effects CONFIG -= debug_and_release +common.files += \ + common/generated_comment.cpp.tpl \ + common/qtivi_macros.j2 +common.path = $$[QT_HOST_BINS]/ivigenerator/common + templates_frontend.files += \ templates_frontend/backendinterface.cpp.tpl \ templates_frontend/backendinterface.h.tpl \ - templates_frontend/generated_comment.cpp.tpl \ templates_frontend/global.h.tpl \ templates_frontend/interface.cpp.tpl \ templates_frontend/interface.h.tpl \ @@ -25,25 +29,21 @@ templates_frontend.files += \ templates_frontend/struct.h.tpl \ templates_frontend/structmodel.cpp.tpl \ templates_frontend/structmodel.h.tpl \ - templates_frontend/structmodel_p.h.tpl \ - templates_frontend/utils.tpl + templates_frontend/structmodel_p.h.tpl templates_frontend.path = $$[QT_HOST_BINS]/ivigenerator/templates_frontend templates_backend_simulator.files += \ templates_backend_simulator/backend.cpp.tpl \ templates_backend_simulator/backend.h.tpl \ templates_backend_simulator/backend_range.cpp.tpl \ - templates_backend_simulator/generated_comment.cpp.tpl \ templates_backend_simulator/plugin.cpp.tpl \ templates_backend_simulator/plugin.h.tpl \ templates_backend_simulator/plugin.json \ templates_backend_simulator/plugin.pri.tpl \ - templates_backend_simulator/plugin.pro \ - templates_backend_simulator/utils.tpl + templates_backend_simulator/plugin.pro templates_backend_simulator.path = $$[QT_HOST_BINS]/ivigenerator/templates_backend_simulator templates_generation_validator.files += \ - templates_generation_validator/generated_comment.cpp.tpl \ templates_generation_validator/generationstatusitem.cpp.tpl \ templates_generation_validator/generationstatusitem.h.tpl \ templates_generation_validator/main.cpp.tpl \ @@ -57,7 +57,6 @@ templates_generation_validator.path = $$[QT_HOST_BINS]/ivigenerator/templates_ge templates_control_panel.files += \ templates_control_panel/EnumControl.qml.tpl \ templates_control_panel/FlagControl.qml.tpl \ - templates_control_panel/generated_comment.cpp.tpl \ templates_control_panel/global.h.tpl \ templates_control_panel/interface.cpp.tpl \ templates_control_panel/interface.h.tpl \ @@ -67,12 +66,10 @@ templates_control_panel.files += \ templates_control_panel/module.cpp.tpl \ templates_control_panel/module.h.tpl \ templates_control_panel/qml.qrc.tpl \ - templates_control_panel/ui.pri.tpl \ - templates_control_panel/utils.tpl + templates_control_panel/ui.pri.tpl templates_control_panel.path = $$[QT_HOST_BINS]/ivigenerator/templates_control_panel templates_backend_qtro.files += \ - templates_backend_qtro/generated_comment.cpp.tpl \ templates_backend_qtro/backend.cpp.tpl \ templates_backend_qtro/backend.h.tpl \ templates_backend_qtro/plugin.cpp.tpl \ @@ -83,7 +80,6 @@ templates_backend_qtro.files += \ templates_backend_qtro.path = $$[QT_HOST_BINS]/ivigenerator/templates_backend_qtro templates_server_qtro.files += \ - templates_server_qtro/generated_comment.cpp.tpl \ templates_server_qtro/core.cpp.tpl \ templates_server_qtro/core.h.tpl \ templates_server_qtro/server.pri.tpl \ @@ -91,7 +87,6 @@ templates_server_qtro.files += \ templates_server_qtro.path = $$[QT_HOST_BINS]/ivigenerator/templates_server_qtro templates_test.files += \ - templates_test/generated_comment.cpp.tpl \ templates_test/tst_test.h.tpl \ templates_test/tst_test.cpp.tpl \ templates_test/module.pri.tpl \ @@ -123,6 +118,7 @@ qtConfig(remoteobjects) { } INSTALLS += generator \ + common \ templates_frontend \ templates_backend_simulator \ templates_generation_validator \ diff --git a/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl b/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl index 0d0f146..fe3695c 100644 --- a/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl +++ b/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl @@ -36,6 +36,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% include "generated_comment.cpp.tpl" %} {% set class = '{0}Backend'.format(interface) %} {% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} @@ -90,7 +91,7 @@ void {{class}}::initialize() {% for property in interface.properties %} {% if not property.readonly and not property.const %} -void {{class}}::set{{property|upperfirst}}({{ property|parameter_type }}) +{{ivi.prop_setter(property, class)}} { {% if not property.type.is_model %} m_replica->push{{property|upperfirst}}({{property}}); @@ -103,8 +104,7 @@ void {{class}}::set{{property|upperfirst}}({{ property|parameter_type }}) {% endfor %} {% for operation in interface.operations %} -{% set operation_parameters = operation.parameters|map('parameter_type')|join(', ') %} -QIviPendingReply<{{operation|return_type}}> {{class}}::{{operation}}({{operation_parameters}}){%if operation.const %} const{% endif %} +{{ ivi.operation(operation, class) }} { if (m_replica->state() != QRemoteObjectReplica::Valid) return QIviPendingReply<{{operation|return_type}}>::createFailedReply(); diff --git a/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl b/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl index eb50a38..2367913 100644 --- a/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl +++ b/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl @@ -36,6 +36,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% include "generated_comment.cpp.tpl" %} {% set class = '{0}Backend'.format(interface) %} {% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} @@ -66,12 +67,12 @@ public: public Q_SLOTS: {% for property in interface.properties %} {% if not property.readonly and not property.const %} - virtual void set{{property|upperfirst}}({{ property|parameter_type }}) override; + virtual {{ivi.prop_setter(property)}} override; {% endif %} {% endfor %} {% for operation in interface.operations %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}){%if operation.const %} const{% endif %} override; + virtual {{ivi.operation(operation)}} override; {% endfor %} protected Q_SLOTS: diff --git a/src/tools/ivigenerator/templates_backend_qtro/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_backend_qtro/generated_comment.cpp.tpl deleted file mode 100644 index 1ec9404..0000000 --- a/src/tools/ivigenerator/templates_backend_qtro/generated_comment.cpp.tpl +++ /dev/null @@ -1,46 +0,0 @@ -{# -# Copyright (C) 2017 Pelagicore AG -# Contact: https://www.qt.io/licensing/ -# -# This file is part of the QtIvi module of the Qt Toolkit. -# -# $QT_BEGIN_LICENSE:LGPL-QTAS$ -# Commercial License Usage -# Licensees holding valid commercial Qt Automotive Suite licenses may use -# this file in accordance with the commercial license agreement provided -# with the Software or, alternatively, in accordance with the terms -# contained in a written agreement between you and The Qt Company. For -# licensing terms and conditions see https://www.qt.io/terms-conditions. -# For further information use the contact form at https://www.qt.io/contact-us. -# -# GNU Lesser General Public License Usage -# Alternatively, this file may be used under the terms of the GNU Lesser -# General Public License version 3 as published by the Free Software -# Foundation and appearing in the file LICENSE.LGPL3 included in the -# packaging of this file. Please review the following information to -# ensure the GNU Lesser General Public License version 3 requirements -# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -# -# GNU General Public License Usage -# Alternatively, this file may be used under the terms of the GNU -# General Public License version 2.0 or (at your option) the GNU General -# Public license version 3 or any later version approved by the KDE Free -# Qt Foundation. The licenses are as published by the Free Software -# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -# included in the packaging of this file. Please review the following -# information to ensure the GNU General Public License requirements will -# be met: https://www.gnu.org/licenses/gpl-2.0.html and -# https://www.gnu.org/licenses/gpl-3.0.html. -# -# $QT_END_LICENSE$ -# -# SPDX-License-Identifier: LGPL-3.0 -#} -/**************************************************************************** -** Generated from '{{module}}.qface' -** -** Created by: The QFace generator (QtAS {{qtASVersion}}) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - diff --git a/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl b/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl index 3ba180b..9867d9a 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl @@ -37,8 +37,8 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% include "generated_comment.cpp.tpl" %} -{% import 'utils.tpl' as utils %} {% set class = '{0}Backend'.format(interface) %} {% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} #include "{{class|lower}}.h" @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE /*! \class {{class}} \inmodule {{module}} -{{ utils.format_comments(interface.comment) }} +{{ ivi.format_comments(interface.comment) }} */ {{class}}::{{class}}(QObject *parent) : {{class}}Interface(parent) @@ -164,15 +164,11 @@ void {{class}}::initialize() {% for property in interface.properties %} {% if not property.readonly and not property.const %} /*! - \fn virtual void {{class}}::set{{property|upperfirst}}({{ property|parameter_type }}{% if interface_zoned %}, const QString &zone){%endif%}) + \fn virtual {{ivi.prop_setter(property, class, interface_zoned)}} -{{ utils.format_comments(property.comment) }} +{{ ivi.format_comments(property.comment) }} */ -{% if interface_zoned %} -void {{class}}::set{{property|upperfirst}}({{ property|parameter_type }}, const QString &zone) -{% else %} -void {{class}}::set{{property|upperfirst}}({{ property|parameter_type }}) -{% endif %} +{{ivi.prop_setter(property, class, interface_zoned)}} { {% if property.tags.config_simulator and property.tags.config_simulator.unsupported %} Q_UNUSED({{ property }}); @@ -219,20 +215,12 @@ void {{class}}::set{{property|upperfirst}}({{ property|parameter_type }}) {% endfor %} {% for operation in interface.operations %} -{% set operation_parameters = operation.parameters|map('parameter_type')|join(', ') %} -{% if interface_zoned %} -{% if operation.parameters|length %} -{% set operation_parameters = operation_parameters + ', ' %} -{% endif %} -{% set operation_parameters = operation_parameters + 'const QString &zone' %} -{% endif%} /*! - \fn virtual void {{class}}::{{operation}}({{operation_parameters}}) + \fn virtual {{ivi.operation(operation, class, interface_zoned)}} -{{ utils.format_comments(operation.comment) }} +{{ ivi.format_comments(operation.comment) }} */ -QIviPendingReply<{{operation|return_type}}> {{class}}::{{operation}}({{operation_parameters}}){%if operation.const %} const{% endif %} - +{{ivi.operation(operation, class, interface_zoned)}} { {% for operation_parameter in operation.parameters %} Q_UNUSED({{operation_parameter.name}}); diff --git a/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl b/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl index 4503e6a..3ca00cd 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl @@ -37,6 +37,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% include "generated_comment.cpp.tpl" %} {% set class = '{0}Backend'.format(interface) %} {% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} @@ -74,24 +75,12 @@ public: public Q_SLOTS: {% for property in interface.properties %} {% if not property.readonly and not property.const %} -{% if interface_zoned %} - virtual void set{{property|upperfirst}}({{ property|parameter_type }}, const QString &zone) override; -{% else %} - virtual void set{{property|upperfirst}}({{ property|parameter_type }}) override; -{% endif %} + virtual {{ivi.prop_setter(property, zoned = interface_zoned)}} override; {% endif %} {% endfor %} {% for operation in interface.operations %} -{% if interface_zoned %} -{% if operation.parameters|length %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}, const QString &zone){%if operation.const %} const{% endif %} override; -{% else %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}(const QString &zone){%if operation.const %} const{% endif %} override; -{% endif %} -{% else %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}){%if operation.const %} const{% endif %} override; -{% endif %} + virtual {{ivi.operation(operation, zoned = interface_zoned)}} override; {% endfor %} protected: diff --git a/src/tools/ivigenerator/templates_backend_simulator/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_backend_simulator/generated_comment.cpp.tpl deleted file mode 100644 index 5056230..0000000 --- a/src/tools/ivigenerator/templates_backend_simulator/generated_comment.cpp.tpl +++ /dev/null @@ -1,47 +0,0 @@ -{# -# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -# Copyright (C) 2018 Pelagicore AG -# Contact: https://www.qt.io/licensing/ -# -# This file is part of the QtIvi module of the Qt Toolkit. -# -# $QT_BEGIN_LICENSE:LGPL-QTAS$ -# Commercial License Usage -# Licensees holding valid commercial Qt Automotive Suite licenses may use -# this file in accordance with the commercial license agreement provided -# with the Software or, alternatively, in accordance with the terms -# contained in a written agreement between you and The Qt Company. For -# licensing terms and conditions see https://www.qt.io/terms-conditions. -# For further information use the contact form at https://www.qt.io/contact-us. -# -# GNU Lesser General Public License Usage -# Alternatively, this file may be used under the terms of the GNU Lesser -# General Public License version 3 as published by the Free Software -# Foundation and appearing in the file LICENSE.LGPL3 included in the -# packaging of this file. Please review the following information to -# ensure the GNU Lesser General Public License version 3 requirements -# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -# -# GNU General Public License Usage -# Alternatively, this file may be used under the terms of the GNU -# General Public License version 2.0 or (at your option) the GNU General -# Public license version 3 or any later version approved by the KDE Free -# Qt Foundation. The licenses are as published by the Free Software -# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -# included in the packaging of this file. Please review the following -# information to ensure the GNU General Public License requirements will -# be met: https://www.gnu.org/licenses/gpl-2.0.html and -# https://www.gnu.org/licenses/gpl-3.0.html. -# -# $QT_END_LICENSE$ -# -# SPDX-License-Identifier: LGPL-3.0 -#} -/**************************************************************************** -** Generated from '{{module}}.qface' -** -** Created by: The QFace generator (QtAS {{qtASVersion}}) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - diff --git a/src/tools/ivigenerator/templates_backend_simulator/utils.tpl b/src/tools/ivigenerator/templates_backend_simulator/utils.tpl deleted file mode 100644 index e5cd338..0000000 --- a/src/tools/ivigenerator/templates_backend_simulator/utils.tpl +++ /dev/null @@ -1,9 +0,0 @@ -{% macro format_comments(comments) -%} -{% with doc = comments|parse_doc -%} -{% if doc.brief %} \brief {{doc.brief|join(' ')| wordwrap(width=100, wrapstring='\n ')}} -{% endif %} - -{% if doc.description %} - {{doc.description|join(' ')| wordwrap(width=100, wrapstring='\n ')}}{% endif %} -{% endwith -%} -{% endmacro -%} diff --git a/src/tools/ivigenerator/templates_control_panel/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_control_panel/generated_comment.cpp.tpl deleted file mode 100644 index 5056230..0000000 --- a/src/tools/ivigenerator/templates_control_panel/generated_comment.cpp.tpl +++ /dev/null @@ -1,47 +0,0 @@ -{# -# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -# Copyright (C) 2018 Pelagicore AG -# Contact: https://www.qt.io/licensing/ -# -# This file is part of the QtIvi module of the Qt Toolkit. -# -# $QT_BEGIN_LICENSE:LGPL-QTAS$ -# Commercial License Usage -# Licensees holding valid commercial Qt Automotive Suite licenses may use -# this file in accordance with the commercial license agreement provided -# with the Software or, alternatively, in accordance with the terms -# contained in a written agreement between you and The Qt Company. For -# licensing terms and conditions see https://www.qt.io/terms-conditions. -# For further information use the contact form at https://www.qt.io/contact-us. -# -# GNU Lesser General Public License Usage -# Alternatively, this file may be used under the terms of the GNU Lesser -# General Public License version 3 as published by the Free Software -# Foundation and appearing in the file LICENSE.LGPL3 included in the -# packaging of this file. Please review the following information to -# ensure the GNU Lesser General Public License version 3 requirements -# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -# -# GNU General Public License Usage -# Alternatively, this file may be used under the terms of the GNU -# General Public License version 2.0 or (at your option) the GNU General -# Public license version 3 or any later version approved by the KDE Free -# Qt Foundation. The licenses are as published by the Free Software -# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -# included in the packaging of this file. Please review the following -# information to ensure the GNU General Public License requirements will -# be met: https://www.gnu.org/licenses/gpl-2.0.html and -# https://www.gnu.org/licenses/gpl-3.0.html. -# -# $QT_END_LICENSE$ -# -# SPDX-License-Identifier: LGPL-3.0 -#} -/**************************************************************************** -** Generated from '{{module}}.qface' -** -** Created by: The QFace generator (QtAS {{qtASVersion}}) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - diff --git a/src/tools/ivigenerator/templates_control_panel/interface.cpp.tpl b/src/tools/ivigenerator/templates_control_panel/interface.cpp.tpl index 762264e..af5b6a0 100644 --- a/src/tools/ivigenerator/templates_control_panel/interface.cpp.tpl +++ b/src/tools/ivigenerator/templates_control_panel/interface.cpp.tpl @@ -36,10 +36,10 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}'.format(interface) %} {% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #include "{{class|lower}}.h" @@ -166,13 +166,12 @@ QVariantMap {{class}}::zoneAt() const {% endif %} {% for property in interface.properties %} - -{{property|return_type}} {{class}}::{{property|getter_name}}() const +{{ivi.prop_getter(property, class)}} { return m_{{property}}; } -void {{class}}::{{property|setter_name}}({{ property|parameter_type }}) +{{ivi.prop_setter(property, class)}} { if (m_{{property}} == {{property}}) return; @@ -192,7 +191,7 @@ void {{class}}::{{property|setter_name}}({{ property|parameter_type }}) } {% if interface.tags.config.zoned %} -void {{class}}::{{property|setter_name}}({{property|parameter_type}}, const QString &zone) +{{ivi.prop_setter(property, class, true)}} { QString z = zone; if (z.isEmpty()) @@ -214,7 +213,7 @@ void {{class}}::{{property|setter_name}}({{property|parameter_type}}, const QStr {% endfor %} {% for signal in interface.signals %} -void {{class}}::{{signal}}({{signal.parameters|map('parameter_type')|join(', ')}}) +{{ivi.signal(signal, class)}} { auto w = worker(); if (w) @@ -225,7 +224,7 @@ void {{class}}::{{signal}}({{signal.parameters|map('parameter_type')|join(', ')} {% if interface_zoned %} {% for operation in interface.operations %} -void {{class}}::{{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}{%if operation.parameters|count %}, {% endif %}const QString &zone) +{{ivi.operation(operation, class, true)}} { QString z = zone; if (z.isEmpty()) diff --git a/src/tools/ivigenerator/templates_control_panel/interface.h.tpl b/src/tools/ivigenerator/templates_control_panel/interface.h.tpl index 703020b..2e39194 100644 --- a/src/tools/ivigenerator/templates_control_panel/interface.h.tpl +++ b/src/tools/ivigenerator/templates_control_panel/interface.h.tpl @@ -36,6 +36,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}'.format(interface) %} {% set oncedefine = '{0}_{1}_H_'.format(module.module_name|upper, class|upper) %} {% set exportsymbol = 'Q_QT{0}_EXPORT'.format(module.module_name|upper) %} @@ -85,36 +86,36 @@ public: QVariantMap zoneAt() const; {% endif %} {% for property in interface.properties %} - {{property|return_type}} {{property|getter_name}}() const; + {{ivi.prop_getter(property)}}; {% endfor %} public Q_SLOTS: {% for property in interface.properties %} - void {{property|setter_name}}({{property|parameter_type}}); + {{ivi.prop_setter(property)}}; {% if interface_zoned %} - void {{property|setter_name}}({{property|parameter_type}}, const QString &zone); + {{ivi.prop_setter(property, zoned = true)}}; {% endif %} {% endfor %} {% for signal in interface.signals %} - void {{signal}}({{signal.parameters|map('parameter_type')|join(', ')}}); + {{ivi.signal(signal)}}; {% endfor %} Q_SIGNALS: {% for operation in interface.operations %} - void {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}); + {{ivi.operation(operation)}}; {% endfor %} {% if interface_zoned %} void currentZoneChanged(); void zonesChanged(); {% endif %} {% for property in interface.properties %} - void {{property}}Changed({{property|parameter_type}}); + {{ivi.prop_notify(property)}}; {% endfor %} private Q_SLOTS: {% if interface_zoned %} {% for operation in interface.operations %} - void {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}{%if operation.parameters|count %}, {% endif %}const QString &zone); + {{ivi.operation(operation, zoned = true)}}; {% endfor %} {% endif %} private: diff --git a/src/tools/ivigenerator/templates_control_panel/module.cpp.tpl b/src/tools/ivigenerator/templates_control_panel/module.cpp.tpl index 51e0408..3e5e229 100644 --- a/src/tools/ivigenerator/templates_control_panel/module.cpp.tpl +++ b/src/tools/ivigenerator/templates_control_panel/module.cpp.tpl @@ -38,7 +38,6 @@ #} {% set class = '{0}Module'.format(module.module_name) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #include "{{class|lower}}.h" {% for interface in module.interfaces %} @@ -61,7 +60,7 @@ QObject* {{class|lower}}_singletontype_provider(QQmlEngine*, QJSEngine*) \class {{class}} \inmodule {{module}} -{{ utils.format_comments(module.comment) }} +{{ ivi.format_comments(module.comment) }} */ {{class}}::{{class}}(QObject *parent) : QObject(parent) diff --git a/src/tools/ivigenerator/templates_control_panel/module.h.tpl b/src/tools/ivigenerator/templates_control_panel/module.h.tpl index 3a78efd..503ef47 100644 --- a/src/tools/ivigenerator/templates_control_panel/module.h.tpl +++ b/src/tools/ivigenerator/templates_control_panel/module.h.tpl @@ -40,7 +40,6 @@ {% set class = '{0}Module'.format(module.module_name) %} {% set oncedefine = '{0}_H_'.format(class|upper) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #ifndef {{oncedefine}} #define {{oncedefine}} diff --git a/src/tools/ivigenerator/templates_control_panel/utils.tpl b/src/tools/ivigenerator/templates_control_panel/utils.tpl deleted file mode 100644 index 42ffa5e..0000000 --- a/src/tools/ivigenerator/templates_control_panel/utils.tpl +++ /dev/null @@ -1,7 +0,0 @@ -{% macro format_comments(comments) -%} -{% with doc = comments|parse_doc -%} -{% if doc.brief %} \brief {{doc.brief}} {% endif %} -{% if doc.descriptiont -%} - {{doc.description|join(' ')}}{% endif -%} -{%- endwith %} -{%- endmacro %} diff --git a/src/tools/ivigenerator/templates_frontend/backendinterface.cpp.tpl b/src/tools/ivigenerator/templates_frontend/backendinterface.cpp.tpl index c4e453e..9bbb482 100644 --- a/src/tools/ivigenerator/templates_frontend/backendinterface.cpp.tpl +++ b/src/tools/ivigenerator/templates_frontend/backendinterface.cpp.tpl @@ -36,9 +36,9 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}BackendInterface'.format(interface) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #include "{{class|lower}}.h" @@ -79,11 +79,7 @@ QT_BEGIN_NAMESPACE {% for property in interface.properties %} {% if not property.readonly and not property.const %} /*! -{% if interface.tags.config.zoned %} - \fn void {{class}}::{{property|setter_name}}({{ property|parameter_type }}, const QString &zone); -{% else %} - \fn void {{class}}::{{property|setter_name}}({{ property|parameter_type }}); -{% endif %} + \fn {{ivi.prop_setter(property, class, interface.tags.config.zoned)}}; Setter for {{interface}}::{{property}}. Sets the property \e {{property}} to the new value passed by \a {{property}}. @@ -102,17 +98,9 @@ QT_BEGIN_NAMESPACE {% endfor %} {% for operation in interface.operations %} /*! -{% if interface.tags.config.zoned %} -{% if operation.parameters|length %} - \fn {{operation|return_type}} {{class}}::{{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}, const QString &zone){%if operation.const %} const{% endif %}; -{% else %} - \fn {{operation|return_type}} {{class}}::{{operation}}(const QString &zone){%if operation.const %} const{% endif %}; -{% endif %} -{% else %} - \fn {{operation|return_type}} {{class}}::{{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}){%if operation.const %} const{% endif %}; -{% endif %} + \fn {{ivi.operation(operation, class, interface.tags.config.zoned)}}; -{{ utils.format_comments(operation.comment) }} +{{ ivi.format_comments(operation.comment) }} {% if interface.tags.config.zoned %} The value of \a zone indicates the zone this operation should be done in. @@ -122,16 +110,9 @@ QT_BEGIN_NAMESPACE {% for signal in interface.signals %} /*! -{% if interface.tags.config.zoned %} -{% if signal.parameters|length %} - \fn void {{class}}::{{signal}}({{signal.parameters|map('parameter_type')|join(', ')}}, const QString &zone = QString()); -{% else %} - \fn void {{class}}::{{signal}}(const QString &zone = QString()); -{% endif %} -{% else %} - \fn void {{class}}::{{signal}}({{signal.parameters|map('parameter_type')|join(', ')}}); -{% endif %} -{{ utils.format_comments(signal.comment) }} + \fn {{ivi.signal(signal, class, interface.tags.config.zoned)}}; + +{{ ivi.format_comments(signal.comment) }} {% if interface.tags.config.zoned %} The value of \a zone indicates the zone this operation should be done in. @@ -140,11 +121,7 @@ QT_BEGIN_NAMESPACE {% endfor %} {% for property in interface.properties %} /*! -{% if interface.tags.config.zoned %} - \fn void {{class}}::{{property}}Changed({{ property|parameter_type }}, const QString &zone); -{% else %} - \fn void {{class}}::{{property}}Changed({{ property|parameter_type }}); -{% endif %} + \fn {{ivi.prop_notify(property, class, interface.tags.config.zoned)}}; The signal is emitted when the \e {{property}} property changed to \a {{property}}. diff --git a/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl b/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl index d06162f..83aeb58 100644 --- a/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl @@ -36,7 +36,13 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}BackendInterface'.format(interface) %} +{% if interface.tags.config.zoned %} +{% set base_class = 'QIviZonedFeatureInterface' %} +{% else %} +{% set base_class = 'QIviFeatureInterface' %} +{% endif %} {% set oncedefine = '{0}_{1}_H_'.format(module.module_name|upper, class|upper) %} {% set exportsymbol = 'Q_{0}_EXPORT'.format(module.module_name|upper) %} {% include 'generated_comment.cpp.tpl' %} @@ -54,20 +60,12 @@ {{inc}} {% endfor %} -{% if interface.tags.config.zoned %} -#include <QtIviCore/QIviZonedFeatureInterface> -{% else %} -#include <QtIviCore/QIviFeatureInterface> -{% endif %} +#include <QtIviCore/{{base_class}}> #include <QtIviCore/QIviPendingReply> QT_BEGIN_NAMESPACE -{% if interface.tags.config.zoned %} -class {{exportsymbol}} {{class}} : public QIviZonedFeatureInterface -{% else %} -class {{exportsymbol}} {{class}} : public QIviFeatureInterface -{% endif %} +class {{exportsymbol}} {{class}} : public {{base_class}} { Q_OBJECT public: @@ -76,43 +74,19 @@ public: {% for property in interface.properties %} {% if not property.readonly and not property.const %} -{% if interface.tags.config.zoned %} - virtual void {{property|setter_name}}({{ property|parameter_type }}, const QString &zone) = 0; -{% else %} - virtual void {{property|setter_name}}({{ property|parameter_type }}) = 0; -{% endif %} + virtual {{ivi.prop_setter(property, zoned = interface.tags.config.zoned)}} = 0; {% endif %} {% endfor %} {% for operation in interface.operations %} -{% if interface.tags.config.zoned %} -{% if operation.parameters|length %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}, const QString &zone){%if operation.const %} const{% endif %} = 0; -{% else %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}(const QString &zone){%if operation.const %} const{% endif %} = 0; -{% endif %} -{% else %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}){%if operation.const %} const{% endif %} = 0; -{% endif %} + virtual {{ivi.operation(operation, zoned = interface.tags.config.zoned)}} = 0; {% endfor %} Q_SIGNALS: {% for signal in interface.signals %} -{% if interface.tags.config.zoned %} -{% if signal.parameters|length %} - void {{signal}}({{signal.parameters|map('parameter_type')|join(', ')}}, const QString &zone = QString()); -{% else %} - void {{signal}}(const QString &zone = QString()); -{% endif %} -{% else %} - void {{signal}}({{signal.parameters|map('parameter_type')|join(', ')}}); -{% endif %} + {{ivi.signal(signal, zoned = interface.tags.config.zoned)}}; {% endfor %} {% for property in interface.properties %} -{% if interface.tags.config.zoned %} - void {{property}}Changed({{ property|parameter_type }}, const QString &zone); -{% else %} - void {{property}}Changed({{ property|parameter_type }}); -{% endif %} + {{ivi.prop_notify(property, zoned = interface.tags.config.zoned)}}; {% endfor %} }; diff --git a/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl b/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl index 8dc6002..1344082 100644 --- a/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl +++ b/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl @@ -36,9 +36,9 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}'.format(interface) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #include "{{class|lower}}.h" #include "{{class|lower}}_p.h" @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE /*! \class {{interface}} \inmodule {{module}} -{{ utils.format_comments(interface.comment) }} +{{ ivi.format_comments(interface.comment) }} */ /*! @@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE \inherits AbstractFeature {% endif %} -{{ utils.format_comments(interface.comment) }} +{{ ivi.format_comments(interface.comment) }} */ /*! \internal */ @@ -178,7 +178,7 @@ void {{class}}Private::on{{property|upperfirst}}Changed({{property|parameter_typ {% for signal in interface.signals %} /*! \internal */ {% if interface.tags.config.zoned %} -void {{class}}Private::on{{signal|upperfirst}}({{signal.parameters|map('parameter_type')|join(', ')}}{%if signal.parameters|length %}, {%endif%}const QString &zone) +void {{class}}Private::on{{signal|upperfirst}}({{ivi.join_params(signal, true)}}) { auto q = getParent(); auto f = qobject_cast<{{class}}*>(q->zoneAt(zone)); @@ -189,7 +189,7 @@ void {{class}}Private::on{{signal|upperfirst}}({{signal.parameters|map('paramete emit f->{{signal}}({{signal.parameters|join(', ')}}); } {% else %} -void {{class}}Private::on{{signal|upperfirst}}({{signal.parameters|map('parameter_type')|join(', ')}}) +void {{class}}Private::on{{signal|upperfirst}}({{ivi.join_params(signal)}}) { auto q = getParent(); emit q->{{signal}}({{signal.parameters|join(', ')}}); @@ -279,7 +279,7 @@ void {{class}}::registerQmlTypes(const QString& uri, int majorVersion, int minor /*! \property {{class}}::{{property}} -{{ utils.format_comments(property.comment) }} +{{ ivi.format_comments(property.comment) }} {% if property.const %} \note This property is constant and the value will not change once the plugin is initialized. {% endif %} @@ -287,12 +287,12 @@ void {{class}}::registerQmlTypes(const QString& uri, int majorVersion, int minor /*! \qmlproperty {{property|return_type}} {{interface|qml_type}}::{{property}} -{{ utils.format_comments(property.comment) }} +{{ ivi.format_comments(property.comment) }} {% if property.const %} \note This property is constant and the value will not change once the plugin is initialized. {% endif %} */ -{{property|return_type}} {{class}}::{{property|getter_name}}() const +{{ivi.prop_getter(property, class)}} { const auto d = {{class}}Private::get(this); {% if not module.tags.config.disablePrivateIVI %} @@ -303,7 +303,7 @@ void {{class}}::registerQmlTypes(const QString& uri, int majorVersion, int minor } {% if not property.readonly and not property.const %} -void {{class}}::{{property|setter_name}}({{ property|parameter_type }}) +{{ivi.prop_setter(property, class)}} { auto d = {{class}}Private::get(this); bool forceUpdate = false; @@ -334,14 +334,13 @@ void {{class}}::{{property|setter_name}}({{ property|parameter_type }}) {%- for operation in interface.operations %} /*! - \qmlmethod {{interface|qml_type}}::{{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}) -{{ utils.format_comments(operation.comment) }} + \qmlmethod {{interface|qml_type}}::{{operation}}({{ivi.join_params(operation)}}) +{{ ivi.format_comments(operation.comment) }} */ /*! -{{ utils.format_comments(operation.comment) }} +{{ ivi.format_comments(operation.comment) }} */ -QIviPendingReply<{{operation|return_type}}> {{class}}::{{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}){% if operation.const %} const{% endif %} - +{{ivi.operation(operation, class)}} { if ({{class}}BackendInterface *backend = ({{class}}BackendInterface *) this->backend()) {% if interface.tags.config.zoned %} diff --git a/src/tools/ivigenerator/templates_frontend/interface.h.tpl b/src/tools/ivigenerator/templates_frontend/interface.h.tpl index 0c33c65..6db880a 100644 --- a/src/tools/ivigenerator/templates_frontend/interface.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/interface.h.tpl @@ -36,7 +36,13 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}'.format(interface) %} +{% if interface.tags.config.zoned %} +{% set base_class = 'QIviAbstractZonedFeature' %} +{% else %} +{% set base_class = 'QIviAbstractFeature' %} +{% endif %} {% set oncedefine = '{0}_{1}_H_'.format(module.module_name|upper, class|upper) %} {% set exportsymbol = 'Q_{0}_EXPORT'.format(module.module_name|upper) %} {% include 'generated_comment.cpp.tpl' %} @@ -54,11 +60,7 @@ {{inc}} {% endfor %} -{% if interface.tags.config.zoned %} -#include <QtIviCore/QIviAbstractZonedFeature> -{% else %} -#include <QtIviCore/QIviAbstractFeature> -{% endif %} +#include <QtIviCore/{{base_class}}> #include <QtIviCore/QIviPendingReply> QT_BEGIN_NAMESPACE @@ -66,14 +68,10 @@ QT_BEGIN_NAMESPACE class {{class}}Private; class {{class}}BackendInterface; -{% if interface.tags.config.zoned %} -class {{exportsymbol}} {{class}} : public QIviAbstractZonedFeature { -{% else %} -class {{exportsymbol}} {{class}} : public QIviAbstractFeature { -{% endif %} +class {{exportsymbol}} {{class}} : public {{base_class}} { Q_OBJECT {% for property in interface.properties %} - Q_PROPERTY({{property|return_type}} {{property}} READ {{property|getter_name}}{% if not property.readonly and not property.const %} WRITE {{property|setter_name}}{% endif %} NOTIFY {{property}}Changed) + {{ivi.property(property)}} {% endfor %} Q_CLASSINFO("IviPropertyDomains", "{{ interface.properties|json_domain|replace("\"", "\\\"") }}") {% if interface.module.tags.config.validation_info %} @@ -90,25 +88,25 @@ public: static void registerQmlTypes(const QString& uri, int majorVersion=1, int minorVersion=0); {% for property in interface.properties %} - {{property|return_type}} {{property|getter_name}}() const; + {{ivi.prop_getter(property)}}; {% endfor %} public Q_SLOTS: {% for operation in interface.operations %} - QIviPendingReply<{{operation|return_type}}> {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}){% if operation.const %} const{% endif %}; + {{ ivi.operation(operation) }}; {% endfor %} {% for property in interface.properties %} {% if not property.readonly and not property.const %} - void {{property|setter_name}}({{property|parameter_type}}); + {{ivi.prop_setter(property)}}; {% endif %} {% endfor %} Q_SIGNALS: {% for signal in interface.signals %} - void {{signal}}({{signal.parameters|map('parameter_type')|join(', ')}}); + {{ivi.signal(signal)}}; {% endfor %} {% for property in interface.properties %} - void {{property}}Changed({{property|parameter_type}}); + {{ivi.prop_notify(property)}}; {% endfor %} protected: diff --git a/src/tools/ivigenerator/templates_frontend/interface_p.h.tpl b/src/tools/ivigenerator/templates_frontend/interface_p.h.tpl index cd7e65c..b51c749 100644 --- a/src/tools/ivigenerator/templates_frontend/interface_p.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/interface_p.h.tpl @@ -36,7 +36,13 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}'.format(interface) %} +{% if interface.tags.config.zoned %} +{% set base_class = 'QIviAbstractZonedFeature' %} +{% else %} +{% set base_class = 'QIviAbstractFeature' %} +{% endif %} {% set oncedefine = '{0}_{1}PRIVATE_H_'.format(module.module_name|upper, class|upper) %} {% include 'generated_comment.cpp.tpl' %} @@ -59,11 +65,7 @@ {% if module.tags.config.disablePrivateIVI %} #include <QObject> {% else %} -{% if interface.tags.config.zoned %} -#include <QtIviCore/private/qiviabstractzonedfeature_p.h> -{% else %} -#include <QtIviCore/private/qiviabstractfeature_p.h> -{% endif %} +#include <QtIviCore/private/{{base_class|lower}}_p.h> {% endif %} QT_BEGIN_NAMESPACE @@ -73,11 +75,7 @@ class {{class}}; {% if module.tags.config.disablePrivateIVI %} class {{class}}Private : public QObject {% else %} -{% if interface.tags.config.zoned %} -class {{class}}Private : public QIviAbstractZonedFeaturePrivate -{% else %} -class {{class}}Private : public QIviAbstractFeaturePrivate -{% endif %} +class {{class}}Private : public {{base_class}}Private {% endif %} { public: @@ -98,18 +96,10 @@ public: void clearToDefaults(); {% for property in interface.properties %} -{% if interface.tags.config.zoned %} - void on{{property|upperfirst}}Changed({{property|parameter_type}}, const QString &zone); -{% else %} - void on{{property|upperfirst}}Changed({{property|parameter_type}}); -{% endif %} + {{ivi.on_prop_changed(property, zoned = interface.tags.config.zoned)}}; {% endfor %} {% for signal in interface.signals %} -{% if interface.tags.config.zoned %} - void on{{signal|upperfirst}}({{signal.parameters|map('parameter_type')|join(', ')}}{%if signal.parameters|length %}, {%endif%}const QString &zone); -{% else %} - void on{{signal|upperfirst}}({{signal.parameters|map('parameter_type')|join(', ')}}); -{% endif %} + void on{{signal|upperfirst}}({{ivi.join_params(signal, zoned = interface.tags.config.zoned)}}); {% endfor %} {% if not module.tags.config.disablePrivateIVI %} diff --git a/src/tools/ivigenerator/templates_frontend/module.cpp.tpl b/src/tools/ivigenerator/templates_frontend/module.cpp.tpl index ef6e112..96c9e4e 100644 --- a/src/tools/ivigenerator/templates_frontend/module.cpp.tpl +++ b/src/tools/ivigenerator/templates_frontend/module.cpp.tpl @@ -38,7 +38,7 @@ #} {% set class = '{0}Module'.format(module.module_name|upperfirst) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} +{% import 'qtivi_macros.j2' as ivi %} #include "{{class|lower}}.h" #include "{{class|lower}}factory.h" @@ -71,11 +71,11 @@ QObject* {{class|lower}}_singletontype_provider(QQmlEngine*, QJSEngine*) {% for enum in module.enums %} /*! \enum {{class}}::{{enum}} - {{ utils.format_comments(enum.comment) }} + {{ ivi.format_comments(enum.comment) }} {% for member in enum.members %} \value {{member}} - {{ utils.format_comments(member.comment) }} + {{ ivi.format_comments(member.comment) }} {% endfor %} */ {% endfor %} diff --git a/src/tools/ivigenerator/templates_frontend/module.h.tpl b/src/tools/ivigenerator/templates_frontend/module.h.tpl index aa10866..12c1dcb 100644 --- a/src/tools/ivigenerator/templates_frontend/module.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/module.h.tpl @@ -40,7 +40,6 @@ {% set class = '{0}Module'.format(module.module_name|upperfirst) %} {% set oncedefine = '{0}_H_'.format(class|upper) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #ifndef {{oncedefine}} #define {{oncedefine}} diff --git a/src/tools/ivigenerator/templates_frontend/modulefactory.cpp.tpl b/src/tools/ivigenerator/templates_frontend/modulefactory.cpp.tpl index d343f00..ede6670 100644 --- a/src/tools/ivigenerator/templates_frontend/modulefactory.cpp.tpl +++ b/src/tools/ivigenerator/templates_frontend/modulefactory.cpp.tpl @@ -38,7 +38,6 @@ #} {% set class = '{0}ModuleFactory'.format(module.module_name|upperfirst) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #include "{{class|lower}}.h" diff --git a/src/tools/ivigenerator/templates_frontend/modulefactory.h.tpl b/src/tools/ivigenerator/templates_frontend/modulefactory.h.tpl index c805956..a4c3274 100644 --- a/src/tools/ivigenerator/templates_frontend/modulefactory.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/modulefactory.h.tpl @@ -40,7 +40,6 @@ {% set class = '{0}ModuleFactory'.format(module.module_name|upperfirst) %} {% set oncedefine = '{0}_H_'.format(class|upper) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #ifndef {{oncedefine}} #define {{oncedefine}} diff --git a/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl b/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl index 1447dfe..d0309c6 100644 --- a/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl +++ b/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl @@ -37,9 +37,9 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}'.format(struct) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #include "{{class|lower}}.h" @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE /*! \class {{struct}} \inmodule {{module}} -{{ utils.format_comments(struct.comment) }} +{{ ivi.format_comments(struct.comment) }} */ {{class}}::{{class}}() @@ -74,18 +74,18 @@ QT_BEGIN_NAMESPACE /*! \property {{class}}::{{field}} -{{ utils.format_comments(field.comment) }} +{{ ivi.format_comments(field.comment) }} {% if field.const %} \note This property is constant and the value will not change once an instance has been created. {% endif %} */ -{{field|return_type}} {{class}}::{{field}}() const +{{ivi.prop_getter(field, class)}} { return m_{{field}}; } {% if not field.readonly and not field.const %} -void {{class}}::set{{field|upperfirst}}({{ field|parameter_type }}) +{{ivi.prop_setter(field, class)}} { m_{{field}} = {{field}}; } diff --git a/src/tools/ivigenerator/templates_frontend/struct.h.tpl b/src/tools/ivigenerator/templates_frontend/struct.h.tpl index ed97d4f..0f4a26f 100644 --- a/src/tools/ivigenerator/templates_frontend/struct.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/struct.h.tpl @@ -37,6 +37,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% set class = '{0}'.format(struct) %} {% set oncedefine = '{0}_{1}_H_'.format(module.module_name|upper, class|upper) %} {% set exportsymbol = 'Q_{0}_EXPORT'.format(module.module_name|upper) %} @@ -63,7 +64,7 @@ class {{exportsymbol}} {{class}} { Q_GADGET {% for field in struct.fields %} - Q_PROPERTY({{field|return_type}} {{field}} READ {{field}}{% if not field.readonly and not field.const %} WRITE set{{field|upperfirst}}{% endif %}) + {{ivi.property(field)}} {% endfor %} Q_CLASSINFO("IviPropertyDomains", "{{ struct.fields|json_domain|replace("\"", "\\\"") }}") public: @@ -72,9 +73,9 @@ public: ~{{class}}(); {% for field in struct.fields %} - {{field|return_type}} {{field}}() const; + {{ivi.prop_getter(field)}}; {% if not field.readonly and not field.const %} - void set{{field|upperfirst}}({{field|parameter_type}}); + {{ivi.prop_setter(field)}}; {% endif %} {% endfor %} diff --git a/src/tools/ivigenerator/templates_frontend/structmodel.cpp.tpl b/src/tools/ivigenerator/templates_frontend/structmodel.cpp.tpl index 64a6772..a372e78 100644 --- a/src/tools/ivigenerator/templates_frontend/structmodel.cpp.tpl +++ b/src/tools/ivigenerator/templates_frontend/structmodel.cpp.tpl @@ -39,7 +39,6 @@ #} {% set class = '{0}Model'.format(struct) %} {% include 'generated_comment.cpp.tpl' %} -{% import 'utils.tpl' as utils %} #include "{{class|lower}}.h" #include "{{class|lower}}_p.h" diff --git a/src/tools/ivigenerator/templates_frontend/utils.tpl b/src/tools/ivigenerator/templates_frontend/utils.tpl deleted file mode 100644 index e5cd338..0000000 --- a/src/tools/ivigenerator/templates_frontend/utils.tpl +++ /dev/null @@ -1,9 +0,0 @@ -{% macro format_comments(comments) -%} -{% with doc = comments|parse_doc -%} -{% if doc.brief %} \brief {{doc.brief|join(' ')| wordwrap(width=100, wrapstring='\n ')}} -{% endif %} - -{% if doc.description %} - {{doc.description|join(' ')| wordwrap(width=100, wrapstring='\n ')}}{% endif %} -{% endwith -%} -{% endmacro -%} diff --git a/src/tools/ivigenerator/templates_generation_validator/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_generation_validator/generated_comment.cpp.tpl deleted file mode 100644 index 5056230..0000000 --- a/src/tools/ivigenerator/templates_generation_validator/generated_comment.cpp.tpl +++ /dev/null @@ -1,47 +0,0 @@ -{# -# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -# Copyright (C) 2018 Pelagicore AG -# Contact: https://www.qt.io/licensing/ -# -# This file is part of the QtIvi module of the Qt Toolkit. -# -# $QT_BEGIN_LICENSE:LGPL-QTAS$ -# Commercial License Usage -# Licensees holding valid commercial Qt Automotive Suite licenses may use -# this file in accordance with the commercial license agreement provided -# with the Software or, alternatively, in accordance with the terms -# contained in a written agreement between you and The Qt Company. For -# licensing terms and conditions see https://www.qt.io/terms-conditions. -# For further information use the contact form at https://www.qt.io/contact-us. -# -# GNU Lesser General Public License Usage -# Alternatively, this file may be used under the terms of the GNU Lesser -# General Public License version 3 as published by the Free Software -# Foundation and appearing in the file LICENSE.LGPL3 included in the -# packaging of this file. Please review the following information to -# ensure the GNU Lesser General Public License version 3 requirements -# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -# -# GNU General Public License Usage -# Alternatively, this file may be used under the terms of the GNU -# General Public License version 2.0 or (at your option) the GNU General -# Public license version 3 or any later version approved by the KDE Free -# Qt Foundation. The licenses are as published by the Free Software -# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -# included in the packaging of this file. Please review the following -# information to ensure the GNU General Public License requirements will -# be met: https://www.gnu.org/licenses/gpl-2.0.html and -# https://www.gnu.org/licenses/gpl-3.0.html. -# -# $QT_END_LICENSE$ -# -# SPDX-License-Identifier: LGPL-3.0 -#} -/**************************************************************************** -** Generated from '{{module}}.qface' -** -** Created by: The QFace generator (QtAS {{qtASVersion}}) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - diff --git a/src/tools/ivigenerator/templates_server_qtro/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_server_qtro/generated_comment.cpp.tpl deleted file mode 100644 index 1ec9404..0000000 --- a/src/tools/ivigenerator/templates_server_qtro/generated_comment.cpp.tpl +++ /dev/null @@ -1,46 +0,0 @@ -{# -# Copyright (C) 2017 Pelagicore AG -# Contact: https://www.qt.io/licensing/ -# -# This file is part of the QtIvi module of the Qt Toolkit. -# -# $QT_BEGIN_LICENSE:LGPL-QTAS$ -# Commercial License Usage -# Licensees holding valid commercial Qt Automotive Suite licenses may use -# this file in accordance with the commercial license agreement provided -# with the Software or, alternatively, in accordance with the terms -# contained in a written agreement between you and The Qt Company. For -# licensing terms and conditions see https://www.qt.io/terms-conditions. -# For further information use the contact form at https://www.qt.io/contact-us. -# -# GNU Lesser General Public License Usage -# Alternatively, this file may be used under the terms of the GNU Lesser -# General Public License version 3 as published by the Free Software -# Foundation and appearing in the file LICENSE.LGPL3 included in the -# packaging of this file. Please review the following information to -# ensure the GNU Lesser General Public License version 3 requirements -# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -# -# GNU General Public License Usage -# Alternatively, this file may be used under the terms of the GNU -# General Public License version 2.0 or (at your option) the GNU General -# Public license version 3 or any later version approved by the KDE Free -# Qt Foundation. The licenses are as published by the Free Software -# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -# included in the packaging of this file. Please review the following -# information to ensure the GNU General Public License requirements will -# be met: https://www.gnu.org/licenses/gpl-2.0.html and -# https://www.gnu.org/licenses/gpl-3.0.html. -# -# $QT_END_LICENSE$ -# -# SPDX-License-Identifier: LGPL-3.0 -#} -/**************************************************************************** -** Generated from '{{module}}.qface' -** -** Created by: The QFace generator (QtAS {{qtASVersion}}) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - diff --git a/src/tools/ivigenerator/templates_test/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_test/generated_comment.cpp.tpl deleted file mode 100644 index 1ec9404..0000000 --- a/src/tools/ivigenerator/templates_test/generated_comment.cpp.tpl +++ /dev/null @@ -1,46 +0,0 @@ -{# -# Copyright (C) 2017 Pelagicore AG -# Contact: https://www.qt.io/licensing/ -# -# This file is part of the QtIvi module of the Qt Toolkit. -# -# $QT_BEGIN_LICENSE:LGPL-QTAS$ -# Commercial License Usage -# Licensees holding valid commercial Qt Automotive Suite licenses may use -# this file in accordance with the commercial license agreement provided -# with the Software or, alternatively, in accordance with the terms -# contained in a written agreement between you and The Qt Company. For -# licensing terms and conditions see https://www.qt.io/terms-conditions. -# For further information use the contact form at https://www.qt.io/contact-us. -# -# GNU Lesser General Public License Usage -# Alternatively, this file may be used under the terms of the GNU Lesser -# General Public License version 3 as published by the Free Software -# Foundation and appearing in the file LICENSE.LGPL3 included in the -# packaging of this file. Please review the following information to -# ensure the GNU Lesser General Public License version 3 requirements -# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -# -# GNU General Public License Usage -# Alternatively, this file may be used under the terms of the GNU -# General Public License version 2.0 or (at your option) the GNU General -# Public license version 3 or any later version approved by the KDE Free -# Qt Foundation. The licenses are as published by the Free Software -# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -# included in the packaging of this file. Please review the following -# information to ensure the GNU General Public License requirements will -# be met: https://www.gnu.org/licenses/gpl-2.0.html and -# https://www.gnu.org/licenses/gpl-3.0.html. -# -# $QT_END_LICENSE$ -# -# SPDX-License-Identifier: LGPL-3.0 -#} -/**************************************************************************** -** Generated from '{{module}}.qface' -** -** Created by: The QFace generator (QtAS {{qtASVersion}}) -** -** WARNING! All changes made in this file will be lost! -*****************************************************************************/ - diff --git a/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl b/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl index 94778a4..35ab010 100644 --- a/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl +++ b/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl @@ -36,6 +36,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} +{% import 'qtivi_macros.j2' as ivi %} {% include "generated_comment.cpp.tpl" %} {% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} #include "tst_{{interface|lower}}.h" @@ -130,8 +131,7 @@ public: {% endif %} {% for signal in interface.signals %} - virtual void trigger{{signal|upperfirst}}({{signal.parameters|map('parameter_type')|join(', ')}}{% if interface_zoned %}{% - if signal.parameters|length %}, {%endif%}const QString &zone{% endif %}) + virtual void trigger{{signal|upperfirst}}({{ivi.join_params(signal, interface_zoned)}}) { emit {{signal}}({% if signal.parameters|length %}{{signal.parameters|join(', ')}}{% endif %}{% if interface_zoned %}{%if signal.parameters|length %}, {%endif%} zone{% endif %}); @@ -139,8 +139,7 @@ public: {% endfor %} {% for operation in interface.operations %} - virtual QIviPendingReply<{{operation|return_type}}> {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}{% if interface_zoned %}{% - if operation.parameters|length %}, {%endif%}const QString &zone{% endif %}) override + virtual {{ivi.operation(operation, zoned = interface_zoned)}} override { emit {{operation}}Called({% if operation.parameters|length %}{{operation.parameters|join(', ')}}{% endif %}{% if interface_zoned %}{%if operation.parameters|length %}, {%endif%} zone{% endif %}); @@ -148,8 +147,7 @@ public: return QIviPendingReply<{{operation|return_type}}>::createFailedReply(); } - Q_SIGNAL void {{operation}}Called({{operation.parameters|map('parameter_type')|join(', ')}}{% if interface_zoned %}{% - if operation.parameters|length %}, {%endif%}const QString &zone{% endif %}); + Q_SIGNAL void {{operation}}Called({{ivi.join_params(operation, interface_zoned)}}); {% endfor %} |