CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
FxUIAbstractItemModel.h
Go to the documentation of this file.
1//
2// (C) Copyright 2005-2023 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
24{
25public:
26
27 explicit CFxUIAbstractItemModel( CFxUIObject *parent = nullptr ) :
28 m_beginInsertRows( this ),
29 m_beginRemoveRows( this ),
30 m_endInsertRows( this ),
31 m_endRemoveRows( this ),
32 m_dataChanged( this ),
33 m_layoutChanged( this ),
34 m_beginResetModel( this ),
35 m_endResetModel( this )
36 {
37 setParent( parent );
38 };
39
41
42 virtual CFxUIModelIndex index( int row, int column, const CFxUIModelIndex &parent = CFxUIModelIndex() ) const = 0;
43 virtual CFxUIModelIndex parent( const CFxUIModelIndex &child ) const = 0;
44
45 virtual int rowCount( const CFxUIModelIndex &parent = CFxUIModelIndex() ) const = 0;
46 virtual int columnCount( const CFxUIModelIndex &parent = CFxUIModelIndex() ) const = 0;
47
49 virtual bool setData( const CFxUIModelIndex &index, const CFxUIVariant &value, int role = CFxUIModelIndex::UIDataRole::EditRole ) { return false; };
50 bool hasIndex( int row, int column, const CFxUIModelIndex &parent = CFxUIModelIndex() ) const
51 {
52 if( row < 0 || column < 0 )
53 return false;
54 return row < rowCount( parent ) && column < columnCount( parent );
55 };
56
58 {
60 return section + 1;
61 return CFxUIVariant();
62 };
63
65 {
66 if( !index.isValid() )
68
71 };
72
73 inline CFxUIModelIndex createIndex( int row, int column, void *data = nullptr ) const;
74 inline CFxUIModelIndex createIndex( int row, int column, quintptr id ) const;
75
76 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )>& beginInsertRows()
77 {
78 return m_beginInsertRows;
79 };
80
81 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )>& beginRemoveRows()
82 {
83 return m_beginRemoveRows;
84 };
85
87 {
88 return m_endInsertRows;
89 };
90
92 {
93 return m_endRemoveRows;
94 };
95
96 CFxUISignal<void( const CFxUIModelIndex& topLeft, const CFxUIModelIndex& bottomRight )>& dataChanged()
97 {
98 return m_dataChanged;
99 }
100
102 {
103 return m_layoutChanged;
104 }
105
107 {
108 return m_beginResetModel;
109 }
110
112 {
113 return m_endResetModel;
114 }
115
116 virtual void onBeginInsertRows( const CFxUIModelIndex &parent, int first, int last )
117 {
118 m_beginInsertRows.Emit( parent, first, last );
119 };
120
121 virtual void onBeginRemoveRows( const CFxUIModelIndex &parent, int first, int last )
122 {
123 m_beginRemoveRows.Emit( parent, first, last );
124 };
125
126 virtual void onEndInsertRows()
127 {
128 m_endInsertRows.Emit();
129 };
130
131 virtual void onEndRemoveRows()
132 {
133 m_endRemoveRows.Emit();
134 };
135
136 virtual void onDataChanged( const CFxUIModelIndex& topLeft, const CFxUIModelIndex& bottomRight )
137 {
138 m_dataChanged.Emit( topLeft, bottomRight );
139 }
140
141 virtual void onLayoutChanged()
142 {
143 m_layoutChanged.Emit();
144 }
145
146 virtual void onBeginResetModel()
147 {
148 m_beginResetModel.Emit();
149 }
150
151 virtual void onEndResetModel()
152 {
153 m_endResetModel.Emit();
154 }
155
156protected:
157 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )> m_beginInsertRows;
159 CFxUISignal<void( const CFxUIModelIndex &parent, int first, int last )> m_beginRemoveRows;
161 CFxUISignal<void( const CFxUIModelIndex& topLeft, const CFxUIModelIndex& bottomRight )> m_dataChanged;
165};
166
167inline CFxUIModelIndex CFxUIAbstractItemModel::createIndex( int arow, int acolumn, void *adata ) const
168{
169 return CFxUIModelIndex( arow, acolumn, adata, this );
170}
171inline CFxUIModelIndex CFxUIAbstractItemModel::createIndex( int arow, int acolumn, quintptr aid ) const
172{
173 return CFxUIModelIndex( arow, acolumn, aid, this );
174}
175
177{
178 return m ? m->parent( *this ) : CFxUIModelIndex();
179}
180
181inline CFxUIVariant CFxUIModelIndex::data( int arole ) const
182{
183 return m ? m->data( *this, arole ) : CFxUIVariant();
184}
185
187{
188 return m ? m->flags( *this ) : CFxUIModelIndex::UIItemFlags();
189}
#define COMMONUI_API
QVariant CFxUIVariant
Definition: FxUIObject.h:52
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 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
GLuint index
Definition: gles2_ext.h:265
GLsizei const GLfloat * value
Definition: gles2_ext.h:302