KanoopGuiQt
1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
headerstate.h
1
#ifndef HEADERSTATE_H
2
#define HEADERSTATE_H
3
#include <Kanoop/serialization/iserializabletojson.h>
4
#include <Kanoop/serialization/ideserializablefromjson.h>
5
#include <Kanoop/serialization/serializablejsonlist.h>
6
#include <Kanoop/gui/libkanoopgui.h>
7
8
/**
9
* @brief Serializable snapshot of a QHeaderView's section sizes and visibility.
10
*
11
* HeaderState captures per-section metadata (index, label, pixel width, and visibility)
12
* so that a header view layout can be saved to JSON and restored later.
13
*/
14
class
LIBKANOOPGUI_EXPORT
HeaderState
:
public
ISerializableToJson,
15
public
IDeserializableFromJson
16
{
17
public
:
18
/** @brief Virtual destructor. */
19
virtual
~HeaderState
() {}
20
21
/**
22
* @brief Serialize this header state to a JSON byte array.
23
* @return JSON-encoded representation
24
*/
25
virtual
QByteArray
serializeToJson
()
const override
;
26
27
/**
28
* @brief Deserialize a header state from a JSON byte array.
29
* @param json JSON-encoded representation
30
*/
31
virtual
void
deserializeFromJson
(
const
QByteArray &json)
override
;
32
33
/**
34
* @brief Describes the saved state of a single header section.
35
*/
36
class
LIBKANOOPGUI_EXPORT
SectionState
:
public
ISerializableToJsonObject,
37
public
IDeserializableFromJsonObject
38
{
39
public
:
40
/** @brief Default constructor — creates an invalid section state. */
41
SectionState
() :
42
_section(0), _size(100) {}
43
44
/**
45
* @brief Construct with explicit section attributes.
46
* @param section Logical section index
47
* @param text Header label text
48
* @param size Section pixel width
49
* @param visible Whether the section is visible
50
*/
51
SectionState
(
int
section,
const
QString& text,
int
size,
bool
visible) :
52
_section(section), _text(text), _size(size), _visible(visible) {}
53
54
/** @brief Virtual destructor. */
55
virtual
~SectionState
() {}
56
57
/** @brief Serialize this section state to a QJsonObject. */
58
virtual
QJsonObject
serializeToJsonObject
()
const override
;
59
/** @brief Deserialize this section state from a QJsonObject. */
60
virtual
void
deserializeFromJsonObject
(
const
QJsonObject &jsonObject)
override
;
61
62
/**
63
* @brief Return the logical section index.
64
* @return Section index
65
*/
66
int
section
()
const
{
return
_section; }
67
68
/**
69
* @brief Return the header label text.
70
* @return Header text string
71
*/
72
QString
text
()
const
{
return
_text; }
73
74
/**
75
* @brief Return the section pixel width.
76
* @return Width in pixels
77
*/
78
int
size
()
const
{
return
_size; }
79
80
/**
81
* @brief Return whether the section is visible.
82
* @return true if visible
83
*/
84
bool
isVisible
()
const
{
return
_visible; }
85
86
/**
87
* @brief Return whether this section state has a non-empty label.
88
* @return true if the text is non-empty
89
*/
90
bool
isValid
()
const
{
return
_text.isEmpty() ==
false
; }
91
92
/**
93
* @brief A serializable list of SectionState objects.
94
*/
95
class
List
:
public
SerializableJsonList<SectionState>
96
{
97
public
:
98
/**
99
* @brief Find the SectionState for a given section index.
100
* @param section Logical section index to find
101
* @return Matching SectionState, or an invalid one if not found
102
*/
103
SectionState
findForSection
(
int
section)
104
{
105
SectionState
result;
106
const_iterator it = std::find_if(constBegin(), constEnd(), [section](
const
SectionState
& s) {
return
s.
section
() == section; } );
107
if
(it != constEnd()) {
108
result = *it;
109
}
110
return
result;
111
}
112
};
113
114
private
:
115
int
_section = 0;
116
QString _text;
117
int
_size = 100;
118
bool
_visible =
true
;
119
};
120
121
/**
122
* @brief Record a section in this header state.
123
* @param section Logical section index
124
* @param text Header label text
125
* @param size Section pixel width
126
* @param visible Whether the section is visible
127
*/
128
void
addSection
(
int
section,
const
QString& text,
int
size,
bool
visible);
129
130
/**
131
* @brief Return the saved state for a given section index.
132
* @param section Logical section index
133
* @return Matching SectionState, or an invalid one if not found
134
*/
135
SectionState
getSection
(
int
section) {
return
_sections.findForSection(section); }
136
137
private
:
138
SectionState::List _sections;
139
};
140
141
#endif
// HEADERSTATE_H
HeaderState::SectionState::List
A serializable list of SectionState objects.
Definition
headerstate.h:96
HeaderState::SectionState::List::findForSection
SectionState findForSection(int section)
Find the SectionState for a given section index.
Definition
headerstate.h:103
HeaderState::SectionState
Describes the saved state of a single header section.
Definition
headerstate.h:38
HeaderState::SectionState::SectionState
SectionState(int section, const QString &text, int size, bool visible)
Construct with explicit section attributes.
Definition
headerstate.h:51
HeaderState::SectionState::~SectionState
virtual ~SectionState()
Virtual destructor.
Definition
headerstate.h:55
HeaderState::SectionState::section
int section() const
Return the logical section index.
Definition
headerstate.h:66
HeaderState::SectionState::serializeToJsonObject
virtual QJsonObject serializeToJsonObject() const override
Serialize this section state to a QJsonObject.
HeaderState::SectionState::text
QString text() const
Return the header label text.
Definition
headerstate.h:72
HeaderState::SectionState::isVisible
bool isVisible() const
Return whether the section is visible.
Definition
headerstate.h:84
HeaderState::SectionState::isValid
bool isValid() const
Return whether this section state has a non-empty label.
Definition
headerstate.h:90
HeaderState::SectionState::deserializeFromJsonObject
virtual void deserializeFromJsonObject(const QJsonObject &jsonObject) override
Deserialize this section state from a QJsonObject.
HeaderState::SectionState::size
int size() const
Return the section pixel width.
Definition
headerstate.h:78
HeaderState::SectionState::SectionState
SectionState()
Default constructor — creates an invalid section state.
Definition
headerstate.h:41
HeaderState
Serializable snapshot of a QHeaderView's section sizes and visibility.
Definition
headerstate.h:16
HeaderState::addSection
void addSection(int section, const QString &text, int size, bool visible)
Record a section in this header state.
HeaderState::deserializeFromJson
virtual void deserializeFromJson(const QByteArray &json) override
Deserialize a header state from a JSON byte array.
HeaderState::getSection
SectionState getSection(int section)
Return the saved state for a given section index.
Definition
headerstate.h:135
HeaderState::~HeaderState
virtual ~HeaderState()
Virtual destructor.
Definition
headerstate.h:19
HeaderState::serializeToJson
virtual QByteArray serializeToJson() const override
Serialize this header state to a JSON byte array.
include
Kanoop
gui
headerstate.h
Generated by
1.9.8