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