CFx SDK Documentation  2023 SP0
FxUIAbstractItemModel.h
Go to the documentation of this file.
1 //
2 // (C) Copyright 2005-2022 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 }
#define COMMONUI_API
QVariant CFxUIVariant
Definition: FxUIObject.h:52
CFxUISignal< void(void)> & layoutChanged()
virtual bool setData(const CFxUIModelIndex &index, const CFxUIVariant &value, int role=CFxUIModelIndex::UIDataRole::EditRole)
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)
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(void)> & beginResetModel()
virtual CFxUIVariant headerData(int section, CFxUIModelIndex::UIOrientation orientation, int role=CFxUIModelIndex::UIDataRole::DisplayRole) const
CFxUISignal< void()> & endInsertRows()
CFxUISignal< void()> & endRemoveRows()
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 &topLeft, const CFxUIModelIndex &bottomRight)> & dataChanged()
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(void)> & endResetModel()
CFxUISignal< void(const CFxUIModelIndex &parent, int first, int last)> & beginInsertRows()
virtual int columnCount(const CFxUIModelIndex &parent=CFxUIModelIndex()) const =0
virtual CFxUIModelIndex::UIItemFlags flags(const CFxUIModelIndex &index) const
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(const CFxUIModelIndex &parent, int first, int last)> & beginRemoveRows()
UIItemFlags flags() const
CFxUIModelIndex parent() const
CFxUIVariant data(int role=UIDataRole::DisplayRole) const
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
AECGEOMETRY_API FacetModeler::Body section(FacetModeler::Body &rBase, const OdGePlane &rCutter)