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