File indexing completed on 2024-06-23 05:36:16

0001 #include "AbstractWriter.hpp"
0002 #include "AbstractWriterAttachedType.hpp"
0003 
0004 #include <cutehmi/shareddatabase/Database.hpp>
0005 
0006 #include <QTimer>
0007 
0008 namespace cutehmi {
0009 namespace dataacquisition {
0010 
0011 AbstractWriter::AbstractWriter(QObject * parent):
0012     QObject(parent),
0013     m(new Members(this))
0014 {
0015 }
0016 
0017 cutehmi::dataacquisition::AbstractWriterAttachedType * AbstractWriter::qmlAttachedProperties(QObject * object)
0018 {
0019     return new AbstractWriterAttachedType(object);
0020 }
0021 
0022 QQmlListProperty<TagValue> AbstractWriter::valueList()
0023 {
0024     return m->valueList;
0025 }
0026 
0027 Schema * AbstractWriter::schema() const
0028 {
0029     return m->schema;
0030 }
0031 
0032 void AbstractWriter::setSchema(Schema * schema)
0033 {
0034     if (m->schema != schema) {
0035         if (m->schema)
0036             m->schema->disconnect(this);
0037 
0038         m->schema = schema;
0039         emit schemaChanged();
0040 
0041         if (m->schema) {
0042             connect(m->schema, & Schema::validated, this, & AbstractWriter::onSchemaValidated);
0043             connect(m->schema, & Schema::errored, this, & AbstractWriter::broke);
0044         }
0045     }
0046 }
0047 
0048 TagValue * AbstractWriter::getValue(int index)
0049 {
0050     return ValueListAt(& m->valueList, index);
0051 }
0052 
0053 void AbstractWriter::appendValue(TagValue * value)
0054 {
0055     ValueListAppend(& m->valueList, value);
0056 }
0057 
0058 void AbstractWriter::clearValues()
0059 {
0060     ValueListClear(& m->valueList);
0061 }
0062 
0063 const AbstractWriter::TagValueContainer & AbstractWriter::values() const
0064 {
0065     return m->values;
0066 }
0067 
0068 void AbstractWriter::onSchemaValidated(bool result)
0069 {
0070     if (result)
0071         emit schemaValidated();
0072     else
0073         emit broke();
0074 }
0075 
0076 workarounds::qt5compatibility::sizeType AbstractWriter::ValueListCount(QQmlListProperty<TagValue> * property)
0077 {
0078     return static_cast<TagValueContainer *>(property->data)->count();
0079 }
0080 
0081 TagValue * AbstractWriter::ValueListAt(QQmlListProperty<TagValue> * property, workarounds::qt5compatibility::sizeType index)
0082 {
0083     return static_cast<TagValueContainer *>(property->data)->value(index);
0084 }
0085 
0086 void AbstractWriter::ValueListClear(QQmlListProperty<TagValue> * property)
0087 {
0088     AbstractWriter * writer = static_cast<AbstractWriter *>(property->object);
0089 
0090     for (TagValueContainer::const_iterator it = writer->values().begin(); it != writer->values().end(); ++it)
0091         writer->onValueRemove(*it);
0092 
0093     static_cast<TagValueContainer *>(property->data)->clear();
0094 }
0095 
0096 void AbstractWriter::ValueListAppend(QQmlListProperty<TagValue> * property, TagValue * value)
0097 {
0098     static_cast<AbstractWriter *>(property->object)->onValueAppend(value);
0099     static_cast<TagValueContainer *>(property->data)->append(value);
0100 }
0101 
0102 }
0103 }
0104 
0105 //(c)C: Copyright © 2022-2023, Michał Policht <michal@policht.pl>. All rights reserved.
0106 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
0107 //(c)C: This file is a part of CuteHMI.
0108 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
0109 //(c)C: CuteHMI 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 Lesser General Public License for more details.
0110 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI.  If not, see <https://www.gnu.org/licenses/>.
0111 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
0112 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
0113 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
0114 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.