Skip to content

Commit

Permalink
Prepared ToolsBundleField.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Oct 21, 2024
1 parent 455e6f9 commit 4a8adbb
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 149 deletions.
10 changes: 5 additions & 5 deletions app/cc_view/src/DefaultMessageDisplayHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ class WidgetCreator : public field_wrapper::FieldWrapperHandler
m_widget = std::move(widget);
}

virtual void handle(field_wrapper::BundleWrapper& wrapper) override
virtual void handle(field::ToolsBundleField& field) override
{
auto& membersWrappers = wrapper.getMembers();
auto& memberFields = field.getMembers();
std::vector<FieldWidgetPtr> membersWidgets;
membersWidgets.reserve(membersWrappers.size());
for (auto& mem : membersWrappers) {
membersWidgets.reserve(memberFields.size());
for (auto& mem : memberFields) {
mem->dispatch(*this);
membersWidgets.push_back(getWidget());
}

std::unique_ptr<BundleFieldWidget> widget(new BundleFieldWidget(wrapper.clone(), m_parent));
std::unique_ptr<BundleFieldWidget> widget(new BundleFieldWidget(field.clone(), m_parent));
for (auto& memWidget : membersWidgets) {
widget->addMemberField(memWidget.release());
}
Expand Down
14 changes: 7 additions & 7 deletions app/cc_view/src/widget/field/BundleFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace cc_tools_qt
{

BundleFieldWidget::BundleFieldWidget(
WrapperPtr wrapper,
FieldPtr fieldPtr,
QWidget* parentObj)
: Base(parentObj),
m_wrapper(std::move(wrapper)),
m_fieldPtr(std::move(fieldPtr)),
m_membersLayout(new QVBoxLayout),
m_label(new QLabel)
{
Expand Down Expand Up @@ -67,8 +67,8 @@ void BundleFieldWidget::addMemberField(FieldWidget* memberFieldWidget)

ToolsField& BundleFieldWidget::fieldImpl()
{
assert(m_wrapper);
return *m_wrapper;
assert(m_fieldPtr);
return *m_fieldPtr;
}

void BundleFieldWidget::refreshImpl()
Expand Down Expand Up @@ -103,9 +103,9 @@ void BundleFieldWidget::memberFieldUpdated()
auto senderIter = std::find(m_members.begin(), m_members.end(), qobject_cast<FieldWidget*>(sender()));
assert(senderIter != m_members.end());
auto idx = static_cast<unsigned>(std::distance(m_members.begin(), senderIter));
auto& memWrappers = m_wrapper->getMembers();
assert(idx < memWrappers.size());
auto& memWrapPtr = memWrappers[idx];
auto& memFields = m_fieldPtr->getMembers();
assert(idx < memFields.size());
auto& memWrapPtr = memFields[idx];
if (!memWrapPtr->canWrite()) {
memWrapPtr->reset();
assert(memWrapPtr->canWrite());
Expand Down
10 changes: 5 additions & 5 deletions app/cc_view/src/widget/field/BundleFieldWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLabel>

#include "cc_tools_qt/field_wrapper/BundleWrapper.h"
#include "cc_tools_qt/field/ToolsBundleField.h"
#include "FieldWidget.h"

namespace cc_tools_qt
Expand All @@ -35,11 +35,11 @@ class BundleFieldWidget : public FieldWidget
typedef FieldWidget Base;
public:

using Wrapper = field_wrapper::BundleWrapper;
using WrapperPtr = field_wrapper::BundleWrapperPtr;
using Field = field::ToolsBundleField;
using FieldPtr = field::ToolsBundleFieldPtr;

explicit BundleFieldWidget(
WrapperPtr wrapper,
FieldPtr fieldPtr,
QWidget* parentObj = nullptr);

~BundleFieldWidget() noexcept;
Expand All @@ -57,7 +57,7 @@ private slots:

private:

WrapperPtr m_wrapper;
FieldPtr m_fieldPtr;
QVBoxLayout* m_membersLayout = nullptr;
QLabel* m_label = nullptr;
std::vector<FieldWidget*> m_members;
Expand Down
74 changes: 74 additions & 0 deletions lib/include/cc_tools_qt/details/ToolsBundleFieldImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Copyright 2014 - 2024 (C). Alex Robenko. All rights reserved.
//

// This file 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 "cc_tools_qt/details/ToolsFieldBase.h"
#include "cc_tools_qt/field/ToolsBundleField.h"

#include "comms/field/Bundle.h"

#include <cstdint>
#include <cassert>
#include <memory>
#include <vector>

namespace cc_tools_qt
{

namespace details
{

template <typename TField>
class ToolsBundleFieldImpl : public ToolsFieldBase<cc_tools_qt::field::ToolsBundleField, TField>
{
using Base = ToolsFieldBase<cc_tools_qt::field::ToolsBundleField, TField>;
using Field = TField;

static_assert(comms::field::isBundle<Field>(), "Must be of Bundle field type");

public:
using ActPtr = typename Base::ActPtr;

explicit ToolsBundleFieldImpl(Field& fieldRef)
: Base(fieldRef)
{
}

ToolsBundleFieldImpl(const ToolsBundleFieldImpl&) = default;
ToolsBundleFieldImpl(ToolsBundleFieldImpl&&) = default;
virtual ~ToolsBundleFieldImpl() noexcept = default;

ToolsBundleFieldImpl& operator=(const ToolsBundleFieldImpl&) = delete;

protected:
virtual ActPtr cloneImpl() override
{
return ActPtr(new ToolsBundleFieldImpl(Base::field()));
}
};

template <typename TField>
auto makeBundleField(TField& field)
{
return std::make_unique<ToolsBundleFieldImpl<TField>>(field);
}

} // namespace details

} // namespace cc_tools_qt
20 changes: 10 additions & 10 deletions lib/include/cc_tools_qt/details/ToolsFieldCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "cc_tools_qt/details/ToolsArrayListFieldImpl.h"
#include "cc_tools_qt/details/ToolsBitfieldFieldImpl.h"
#include "cc_tools_qt/details/ToolsBitmaskFieldImpl.h"
#include "cc_tools_qt/details/ToolsBundleFieldImpl.h"
#include "cc_tools_qt/details/ToolsEnumFieldImpl.h"
#include "cc_tools_qt/details/ToolsFloatFieldImpl.h"
#include "cc_tools_qt/details/ToolsIntFieldImpl.h"
Expand All @@ -33,7 +34,6 @@
#include "cc_tools_qt/details/ToolsStringFieldImpl.h"
#include "cc_tools_qt/details/ToolsUnsignedLongFieldImpl.h"

#include "cc_tools_qt/field_wrapper/BundleWrapper.h"
#include "cc_tools_qt/field_wrapper/VariantWrapper.h"
#include "cc_tools_qt/field_wrapper/UnknownValueWrapper.h"

Expand Down Expand Up @@ -195,24 +195,24 @@ class ToolsFieldCreator
template <typename TField>
static ToolsFieldPtr createFieldInternal(TField& field, BundleTag)
{
auto wrapper = field_wrapper::makeBundleWrapper(field);
auto fieldPtr = makeBundleField(field);

typedef typename std::decay<decltype(wrapper)>::type WrapperPtrType;
typedef typename WrapperPtrType::element_type WrapperType;
typedef typename WrapperType::Members MembersWrappersList;
using FieldPtrType = std::decay_t<decltype(fieldPtr)>;
using FieldType = typename FieldPtrType::element_type;
using MemberFieldsList = typename FieldType::Members;

MembersWrappersList subWrappers;
MemberFieldsList subFields;
auto& memberFields = field.value();
comms::util::tupleForEach(
memberFields,
SubfieldsCreateHelper(
[&subWrappers](ToolsFieldPtr fieldWrapper)
[&subFields](ToolsFieldPtr fieldParam)
{
subWrappers.push_back(std::move(fieldWrapper));
subFields.push_back(std::move(fieldParam));
}));

wrapper->setMembers(std::move(subWrappers));
return wrapper;
fieldPtr->setMembers(std::move(subFields));
return fieldPtr;
}

template <typename TField>
Expand Down
2 changes: 0 additions & 2 deletions lib/include/cc_tools_qt/details/ToolsStringFieldImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include <memory>
#include <limits>

#include "cc_tools_qt/ToolsField.h"

namespace cc_tools_qt
{

Expand Down
66 changes: 66 additions & 0 deletions lib/include/cc_tools_qt/field/ToolsBundleField.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// Copyright 2014 - 2024 (C). Alex Robenko. All rights reserved.
//

// This file 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 "cc_tools_qt/ToolsField.h"

#include <memory>
#include <vector>

namespace cc_tools_qt
{

namespace field
{

class CC_API ToolsBundleField : public ToolsField
{
using Base = ToolsField;
public:
using Members = std::vector<ToolsFieldPtr>;
using ActPtr = std::unique_ptr<ToolsBundleField>;

ToolsBundleField();
ToolsBundleField(const ToolsBundleField&) =delete;
ToolsBundleField& operator=(const ToolsBundleField&) =delete;

virtual ~ToolsBundleField() noexcept;

Members& getMembers();

const Members& getMembers() const;

void setMembers(Members&& members);

ActPtr clone();

protected:
virtual ActPtr cloneImpl() = 0;

void dispatchImpl(field_wrapper::FieldWrapperHandler& handler);

private:
Members m_members;
};

using ToolsBundleFieldPtr = ToolsBundleField::ActPtr;

} // namespace field

} // namespace cc_tools_qt
4 changes: 2 additions & 2 deletions lib/include/cc_tools_qt/field_wrapper/AllWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "cc_tools_qt/field/ToolsArrayListField.h"
#include "cc_tools_qt/field/ToolsBitfieldField.h"
#include "cc_tools_qt/field/ToolsBitmaskField.h"
#include "cc_tools_qt/field/ToolsBundleField.h"
#include "cc_tools_qt/field/ToolsEnumField.h"
#include "cc_tools_qt/field/ToolsFloatField.h"
#include "cc_tools_qt/field/ToolsIntField.h"
Expand All @@ -29,7 +30,6 @@
#include "cc_tools_qt/field/ToolsStringField.h"
#include "cc_tools_qt/field/ToolsUnsignedLongField.h"

#include "BundleWrapper.h"
#include "VariantWrapper.h"
#include "UnknownValueWrapper.h"

Expand All @@ -49,7 +49,7 @@ typedef std::tuple<
cc_tools_qt::field::ToolsStringField,
cc_tools_qt::field::ToolsBitfieldField,
cc_tools_qt::field::ToolsOptionalField,
BundleWrapper,
cc_tools_qt::field::ToolsBundleField,
cc_tools_qt::field::ToolsRawDataField,
cc_tools_qt::field::ToolsArrayListField,
cc_tools_qt::field::ToolsFloatField,
Expand Down
Loading

0 comments on commit 4a8adbb

Please sign in to comment.