CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
FxUIAbstractItemModel.h
Go to the documentation of this file.
1//
2// (C) Copyright 2005-2025 by Graebert GmbH.
3//
4// Permission to use, copy, modify, and distribute this software in
5// object code form for any purpose and without fee is hereby granted,
6// provided that the above copyright notice appears in all copies and
7// that both that copyright notice and the limited warranty and
8// restricted rights notice below appear in all supporting
9// documentation.
10//
11// GRAEBERT PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
12// GRAEBERT SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
13// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. GRAEBERT GMBH
14// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
15// UNINTERRUPTED OR ERROR FREE.
16
17#pragma once
18
19#include "../UI/FxUIObject.h"
20#include "FxUIModelIndex.h"
21#include "../UI/FxUISignal.h"
22#include "../Core/FxUIVariant.h"
23
24
26{
27public:
28
29 explicit CFxUIAbstractItemModel( CFxUIObject *parent = nullptr ) :
30 m_beginInsertRows( this ),
31 m_beginRemoveRows( this ),
32 m_endInsertRows( this ),
33 m_endRemoveRows( this ),
34 m_dataChanged( this ),
35 m_layoutChanged( this ),
36 m_beginResetModel( this ),
37 m_endResetModel( this )
38 {
40 };
41
43
44 virtual CFxUIModelIndex index( int row, int column, const CFxUIModelIndex &parent = CFxUIModelIndex() ) const = 0;
45 virtual CFxUIModelIndex parent( const CFxUIModelIndex &child ) const = 0;
46
47 virtual int rowCount( const CFxUIModelIndex &parent = CFxUIModelIndex() ) const = 0;
48 virtual int columnCount( const CFxUIModelIndex &parent = CFxUIModelIndex() ) const = 0;
49
51 virtual bool setData( const CFxUIModelIndex &index, const CFxUIVariant &value, int role = CFxUIModelIndex::UIDataRole::EditRole ) { return false; };
52 bool hasIndex( int row, int column, const CFxUIModelIndex &parent = CFxUIModelIndex() ) const
53 {
54 if( row < 0 || column < 0 )
55 return false;
56 return row < rowCount( parent ) && column < columnCount( parent );
57 };
58
59 virtual CFxUIVariant headerData( int section,
62
71
72 virtual void sort( int column, int order ) {};
73
74 inline CFxUIModelIndex createIndex( int row, int column, void *data = nullptr ) const;
75 inline CFxUIModelIndex createIndex( int row, int column, quintptr id ) const;
76
77 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )>& beginInsertRows()
78 {
79 return m_beginInsertRows;
80 };
81
82 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )>& beginRemoveRows()
83 {
84 return m_beginRemoveRows;
85 };
86
88 {
89 return m_endInsertRows;
90 };
91
93 {
94 return m_endRemoveRows;
95 };
96
97 CFxUISignal<void( const CFxUIModelIndex& topLeft, const CFxUIModelIndex& bottomRight )>& dataChanged()
98 {
99 return m_dataChanged;
100 }
101
103 {
104 return m_layoutChanged;
105 }
106
108 {
109 return m_beginResetModel;
110 }
111
113 {
114 return m_endResetModel;
115 }
116
117 virtual void onBeginInsertRows( const CFxUIModelIndex &parent, int first, int last )
118 {
119 m_beginInsertRows.Emit( parent, first, last );
120 };
121
122 virtual void onBeginRemoveRows( const CFxUIModelIndex &parent, int first, int last )
123 {
124 m_beginRemoveRows.Emit( parent, first, last );
125 };
126
127 virtual void onEndInsertRows()
128 {
129 m_endInsertRows.Emit();
130 };
131
132 virtual void onEndRemoveRows()
133 {
134 m_endRemoveRows.Emit();
135 };
136
137 virtual void onDataChanged( const CFxUIModelIndex& topLeft, const CFxUIModelIndex& bottomRight )
138 {
139 m_dataChanged.Emit( topLeft, bottomRight );
140 }
141
142 virtual void onLayoutChanged()
143 {
144 m_layoutChanged.Emit();
145 }
146
147 virtual void onBeginResetModel()
148 {
149 m_beginResetModel.Emit();
150 }
151
152 virtual void onEndResetModel()
153 {
154 m_endResetModel.Emit();
155 }
156
157protected:
158 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )> m_beginInsertRows;
160 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )> m_beginRemoveRows;
162 CFxUISignal<void( const CFxUIModelIndex& topLeft, const CFxUIModelIndex& bottomRight )> m_dataChanged;
166};
167
168inline CFxUIModelIndex CFxUIAbstractItemModel::createIndex( int arow, int acolumn, void *adata ) const
169{
170 return CFxUIModelIndex( arow, acolumn, adata, this );
171}
172inline CFxUIModelIndex CFxUIAbstractItemModel::createIndex( int arow, int acolumn, quintptr aid ) const
173{
174 return CFxUIModelIndex( arow, acolumn, aid, this );
175}
176
178{
179 return m ? m->parent( *this ) : CFxUIModelIndex();
180}
181
182inline CFxUIVariant CFxUIModelIndex::data( int arole ) const
183{
184 return m ? m->data( *this, arole ) : CFxUIVariant();
185}
186
188{
189 return m ? m->flags( *this ) : CFxUIModelIndex::UIItemFlags();
190}
#define COMMONUI_API
IntegerForSizeof< void * >::Unsigned quintptr
virtual bool setData(const CFxUIModelIndex &index, const CFxUIVariant &value, int role=CFxUIModelIndex::UIDataRole::EditRole)
CFxUISignal< void(const CFxUIModelIndex &parent, int first, int last)> & beginInsertRows()
CFxUISignal< void(const CFxUIModelIndex &topLeft, const CFxUIModelIndex &bottomRight)> & dataChanged()
CFxUISignal< void()> & endRemoveRows()
virtual CFxUIVariant data(const CFxUIModelIndex &index, int role=CFxUIModelIndex::UIDataRole::DisplayRole) const =0
bool hasIndex(int row, int column, const CFxUIModelIndex &parent=CFxUIModelIndex()) const
virtual void onBeginRemoveRows(const CFxUIModelIndex &parent, int first, int last)
CFxUISignal< void(void)> & beginResetModel()
CFxUIModelIndex createIndex(int row, int column, void *data=nullptr) const
CFxUISignal< void()> m_endRemoveRows
CFxUISignal< void()> m_endInsertRows
CFxUISignal< void(void)> m_beginResetModel
CFxUISignal< void(const CFxUIModelIndex &parent, int first, int last)> & beginRemoveRows()
virtual CFxUIVariant headerData(int section, CFxUIModelIndex::UIOrientation orientation, int role=CFxUIModelIndex::UIDataRole::DisplayRole) const
virtual CFxUIModelIndex index(int row, int column, const CFxUIModelIndex &parent=CFxUIModelIndex()) const =0
virtual void sort(int column, int order)
virtual void onBeginInsertRows(const CFxUIModelIndex &parent, int first, int last)
CFxUIAbstractItemModel(CFxUIObject *parent=nullptr)
CFxUISignal< void(const CFxUIModelIndex &parent, int first, int last)> m_beginInsertRows
CFxUISignal< void(const CFxUIModelIndex &parent, int first, int last)> m_beginRemoveRows
virtual void onDataChanged(const CFxUIModelIndex &topLeft, const CFxUIModelIndex &bottomRight)
CFxUISignal< void(void)> m_endResetModel
virtual CFxUIModelIndex parent(const CFxUIModelIndex &child) const =0
CFxUISignal< void()> & endInsertRows()
virtual int columnCount(const CFxUIModelIndex &parent=CFxUIModelIndex()) const =0
virtual CFxUIModelIndex::UIItemFlags flags(const CFxUIModelIndex &index) const
CFxUISignal< void(void)> & layoutChanged()
CFxUISignal< void(const CFxUIModelIndex &topLeft, const CFxUIModelIndex &bottomRight)> m_dataChanged
virtual int rowCount(const CFxUIModelIndex &parent=CFxUIModelIndex()) const =0
CFxUISignal< void(void)> m_layoutChanged
CFxUISignal< void(void)> & endResetModel()
UIItemFlags flags() const
CFxUIModelIndex parent() const
CFxUIVariant data(int role=UIDataRole::DisplayRole) const
void setParent(CFxUIObject *parent)
typedef void(APIENTRYP PFNGLACTIVETEXTUREPROC)(GLenum texture)
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition gles2_ext.h:110
GLsizei const GLfloat * value
Definition gles2_ext.h:302