cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsVariantField.h
1//
2// Copyright 2017 - 2025 (C). Alex Robenko. All rights reserved.
3//
4
5// This file is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19#pragma once
20
21#include "cc_tools_qt/ToolsField.h"
22
23#include <QtCore/QString>
24#include <QtCore/QList>
25
26#include <functional>
27#include <memory>
28#include <vector>
29
30namespace cc_tools_qt
31{
32
33namespace field
34{
35
36class CC_TOOLS_API ToolsVariantField : public ToolsField
37{
38 using Base = ToolsField;
39public:
40 using ActPtr = std::unique_ptr<ToolsVariantField>;
41
42 using MemberCreateCallbackFunc = std::function<ToolsFieldPtr ()>;
43
44 ToolsVariantField();
45 ToolsVariantField(const ToolsVariantField&) =delete;
46 ToolsVariantField& operator=(const ToolsVariantField&) =delete;
47
48 virtual ~ToolsVariantField() noexcept;
49
50 ToolsField* getCurrent();
51
52 const ToolsField* getCurrent() const;
53
54 void setCurrent(ToolsFieldPtr current);
55
56 void updateCurrent();
57
58 QStringList membersNames() const;
59
60 int getCurrentIndex() const;
61
62 void setCurrentIndex(int index);
63
64 int getMembersCount() const;
65
66 template <typename TFunc>
67 void setMemberCreateCallback(TFunc&& func)
68 {
69 m_createMemberCb = std::forward<TFunc>(func);
70 }
71
72 ActPtr actClone();
73
74protected:
75 virtual QStringList membersNamesImpl() const = 0;
76 virtual void dispatchImpl(ToolsFieldHandler& handler);
77 virtual int getCurrentIndexImpl() const = 0;
78 virtual void setCurrentIndexImpl(int index) = 0;
79 virtual int getMembersCountImpl() const = 0;
80
81private:
82 MemberCreateCallbackFunc m_createMemberCb;
83};
84
85using ToolsVariantFieldPtr = ToolsVariantField::ActPtr;
86
87} // namespace field
88
89} // namespace cc_tools_qt
Main namespace for all classes / functions of the shared library.