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#pragma once
19
20#include "cc_tools_qt/ToolsField.h"
21
22#include <QtCore/QString>
23#include <QtCore/QList>
24
25#include <functional>
26#include <memory>
27#include <vector>
28
29namespace cc_tools_qt
30{
31
32namespace field
33{
34
35class CC_TOOLS_API ToolsVariantField : public ToolsField
36{
37 using Base = ToolsField;
38public:
39 using ActPtr = std::unique_ptr<ToolsVariantField>;
40
41 using MemberCreateCallbackFunc = std::function<ToolsFieldPtr ()>;
42
43 ToolsVariantField();
44 ToolsVariantField(const ToolsVariantField&) =delete;
45 ToolsVariantField& operator=(const ToolsVariantField&) =delete;
46
47 virtual ~ToolsVariantField() noexcept;
48
49 ToolsField* getCurrent();
50
51 const ToolsField* getCurrent() const;
52
53 void setCurrent(ToolsFieldPtr current);
54
55 void updateCurrent();
56
57 QStringList membersNames() const;
58
59 int getCurrentIndex() const;
60
61 void setCurrentIndex(int index);
62
63 int getMembersCount() const;
64
65 template <typename TFunc>
66 void setMemberCreateCallback(TFunc&& func)
67 {
68 m_createMemberCb = std::forward<TFunc>(func);
69 }
70
71 ActPtr actClone();
72
73protected:
74 virtual QStringList membersNamesImpl() const = 0;
75 virtual void dispatchImpl(ToolsFieldHandler& handler);
76 virtual int getCurrentIndexImpl() const = 0;
77 virtual void setCurrentIndexImpl(int index) = 0;
78 virtual int getMembersCountImpl() const = 0;
79
80private:
81 MemberCreateCallbackFunc m_createMemberCb;
82};
83
84using ToolsVariantFieldPtr = ToolsVariantField::ActPtr;
85
86} // namespace field
87
88} // namespace cc_tools_qt
Main namespace for all classes / functions of the shared library.