QXRD  0.11.16
qcepdataobjectpropertiesmodel.cpp
Go to the documentation of this file.
2 #include "qcepdataobject.h"
3 #include <QObject>
4 #include <QMetaProperty>
5 
7  m_Object(obj)
8 {
9 
10 }
11 
12 int QcepDataObjectPropertiesModel::rowCount(const QModelIndex &parent) const
13 {
14  return 2 + propertyCount() + dynamicPropertyCount();
15 }
16 
17 int QcepDataObjectPropertiesModel::columnCount(const QModelIndex &parent) const
18 {
19  return 2;
20 }
21 
22 QVariant QcepDataObjectPropertiesModel::data(const QModelIndex &index, int role) const
23 {
24  QVariant res = QVariant();
25  int pc = propertyCount();
26  int dpc = dynamicPropertyCount();
28 
29  if (role == Qt::DisplayRole) {
30  if (index.isValid()) {
31  int r = index.row(), c = index.column();
32 
33  if (r == 0) {
34  if (c == 0) {
35  res = "Static";
36  } else if (c == 1) {
37  res = "Properties";
38  }
39  } else if (r < (pc+1)) {
40  if (obj) {
41  QMetaProperty mp = obj->metaObject()->property(r-1);
42  if (c == 0) {
43  res = mp.name();
44  } else if (c == 1) {
45  res = obj->property(mp.name());
46  }
47  }
48  } else if (r == (pc+1)) {
49  if (c == 0) {
50  res = "Dynamic";
51  } else if (c == 1) {
52  res = "Properties";
53  }
54  } else {
55  int idx = r - pc - 2;
56  if (obj) {
57  QString name = obj->dynamicPropertyNames().value(idx);
58 
59  if (c == 0) {
60  res = name;
61  } else if (c == 1) {
62  res = obj->property(qPrintable(name));
63  }
64  }
65  }
66  }
67  }
68 
69  return res;
70 }
71 
72 QVariant QcepDataObjectPropertiesModel::headerData(int section, Qt::Orientation orientation, int role) const
73 {
74  QVariant res = QVariant();
75 
76  if (role == Qt::DisplayRole) {
77  if (orientation == Qt::Horizontal) {
78  if (section == 0) {
79  res = "Name";
80  } else if (section == 1) {
81  res = "Value";
82  }
83  } else if (orientation == Qt::Vertical) {
84  int pc = propertyCount();
85  int dpc = dynamicPropertyCount();
86 
87  if (section == 0) {
88 
89  } else if (section < (pc+1)) {
90  return section - 1;
91  } else if (section == (pc+1)) {
92 
93  } else {
94  return section - pc - 2;
95  }
96  }
97  }
98 
99  return res;
100 }
101 
103 {
105 
106  if (obj) {
107  return obj->metaObject()->propertyCount();
108  } else {
109  return 0;
110  }
111 }
112 
114 {
116 
117  if (obj) {
118  return obj->dynamicPropertyNames().count();
119  } else {
120  return 0;
121  }
122 }
QcepDataObjectPropertiesModel(QcepDataObjectWPtr obj)
int rowCount(const QModelIndex &parent=QModelIndex()) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
QWeakPointer< QcepDataObject > QcepDataObjectWPtr
QSharedPointer< QcepDataObject > QcepDataObjectPtr
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const