WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZLogReclinkModel.cpp
Go to the documentation of this file.
1 #include "ZLogReclinkModel.h"
2 #include "ZLogMap.h"
3 #include "ZTableModel.h"
4 #include <QSortFilterProxyModel>
5 #include <QAbstractItemModel>
6 
7 namespace Zbl {
8 
10 
12 
13 
14 ZLogReclinkModel::ZLogReclinkModel(QSharedPointer<ZblLogReclinkData> data, QObject *parent) :
15  QAbstractListModel(parent)
16 {
17  zDebug() << "Constructing ZLogReclinkModel object";
18 
20 
21  m_d = data;
22 }
23 
25 {
26  zDebug() << "Destroying ZLogReclinkModel object";
27 
28 }
29 
30 
32 {
33  if(!m_initialized)
34  {
36  ZBL_REGISTER_LOGGED_CATEGORY(ZblLogReclinkData::m_log)
37  m_initialized = true;
38  }
39 }
40 
41 
42 #if 0
43 ZTableModel* ZLogReclinkModel::zModel()
44 {
45  return m_model;
46 }
47 
48 
49 void ZLogReclinkModel::insertLink(
50  quint64 recordID,
51  quint64 seekPosition,
52  const QString& messageText)
53 {
54  ZDataRow cellBuf;
55 
56  cellBuf.append(recordID);
57  cellBuf.append(seekPosition);
58  cellBuf.append(messageText);
59 
60  zDebug() << "inserting log record link: " << cellBuf;
61 
62  m_model->appendCells(cellBuf);
63 }
64 
65 
66 QObject* ZLogReclinkModel::model()
67 {
68  return m_proxy;
69 }
70 #endif
71 
72 
73 
75  const QModelIndex & parent) const
76 {
77  if(parent.isValid())
78  return 0;
79 
80  int count = -1;
81 
83 
84  count = m_d->zModel()->rowCount(QModelIndex());
85 
86  ZBL_SLOT_END_RETURN(count, -1,
88 
89  return 0;
90 
91 }
92 
94  const QModelIndex & index,
95  int role) const
96 {
97 
98  //qDebug() << "ZTableModel::data role/row/col" << role << index.row() << index.column();
99 
100 #if 1
101 
102  // Check boudaries
103  if(index.column() < 0 ||
104  index.row() < 0 ||
105  index.row() > rowCount() )
106  {
107  qDebug() << "ZLogReclinkModel::data - Warning out of bounds: " << index.row() << ", " << index.column();
108  return QVariant();
109  }
110 
112  //ZBL_SLOT_END_RETURN(m_d->model()->data(index, role), QVariant(),
113  ZBL_SLOT_END_RETURN(m_d->zModel()->data(index, role), QVariant(),
115 
116 #endif
117 
118 
119  return QVariant();
120 
121 }
122 
123 
124 QHash<int, QByteArray> ZLogReclinkModel::roleNames() const
125 {
126  QHash<int, QByteArray> retval;
127 
129  ZBL_SLOT_END_RETURN(m_d->zModel()->roleNames(), retval,
131 
132  return retval;
133 }
134 
135 QVariant ZLogReclinkModel::getData(int index, int role)
136 {
137  return m_d->getData(index, role);
138 }
139 
140 #if 0
141 QVariant ZLogReclinkModel::getData(int index, const QString& roleName)
142 {
143  return QVariant("no");
144 
145 }
146 #endif
147 
148 QVariantMap ZLogReclinkModel::roleMap() const
149 {
150  QVariantMap map;
151 
153 
154  if(inObjectThread(this))
155  {
156  QHash<int, QByteArray> hash = roleNames();
157 
158  QList<int> keys = hash.keys();
159 
160  const int keyCount = keys.size();
161 
162  for(int i=0; i<keyCount; i++)
163  {
164  const int nextRole = keys.at(i);
165 
166  map.insert(QString::fromUtf8(hash.value(nextRole)), QVariant(nextRole));
167  }
168 
169  }
170  else
171  {
172  QMetaObject::invokeMethod(const_cast<ZLogReclinkModel*>(this),"roleMap",
173  Qt::BlockingQueuedConnection,
174  Q_RETURN_ARG(QVariantMap, map));
175  }
176 
177  ZBL_SLOT_END_RETURN(map, QVariantMap(),
179 
180 }
181 
182 QVariant ZLogReclinkModel::getValue(int role, int row)
183 {
184  // TBD: index should be translated into proxy model index!!!!! or asynchronous random updates
185  // will not be sorted
186  QVariant value;
187 
188  //if(role < 0 || row < 0)
189  // return value;
190 
192 
193  if(inObjectThread(this))
194  {
195  value = m_d->getData(row, role);
196  }
197  else
198  {
199  QMetaObject::invokeMethod(const_cast<ZLogReclinkModel*>(this),"getValue",
200  Qt::BlockingQueuedConnection,
201  Q_RETURN_ARG(QVariant, value),
202  Q_ARG(int,role),
203  Q_ARG(int,row));
204  }
205 
206  ZBL_SLOT_END_RETURN(value, false,
208 }
209 
210 QVariant ZLogReclinkModel::getValue(int role, int row, int column)
211 {
212  // TBD: index should be translated into proxy model index!!!!! or asynchronous random updates
213  // will not be sorted
214 
215  QVariant value;
216 
217  //if(role < 0 || row < 0)
218  // return value;
219 
221 
222  if(inObjectThread(this))
223  {
224  value = m_d->getData(row, role);
225  }
226  else
227  {
228  QMetaObject::invokeMethod(const_cast<ZLogReclinkModel*>(this),"getValue",
229  Qt::BlockingQueuedConnection,
230  Q_RETURN_ARG(QVariant, value),
231  Q_ARG(int,role),
232  Q_ARG(int,row),
233  Q_ARG(int,column));
234  }
235 
236  ZBL_SLOT_END_RETURN(value, false,
238 }
239 
241 {
243 
244 
245 
246  if(inObjectThread(this))
247  {
248  beginResetModel();
249  endResetModel();
250  }
251  else
252  {
253  QMetaObject::invokeMethod(this,"invalidateModel",
254  Qt::BlockingQueuedConnection
255  );
256  }
257 
258 
261 }
262 
263 
264 
265 } // Zbl
A data model containing a list of log record links. This is used for displaying a ZLogMap object...
ZLogReclinkModel(QSharedPointer< ZblLogReclinkData > data, QObject *parent=0)
#define Z_FAC_JS
Definition: zglobal.h:123
QVariant getData(int index, int role)
#define ZBL_REGISTER_LOGGED_OBJECT
Definition: zglobal.h:104
Definition: ZAndGate.cpp:6
static void registerLoggedObject()
QVariantMap roleMap() const
#define ZBL_SLOT_BEGIN_TRY
Definition: zglobal.h:128
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
Definition: zglobal.h:99
This two dimensional table model is used to store and manipulate data.
Definition: ZTableModel.h:96
static bool m_initialized
Used to optimize logging initializer.
#define ZBL_SLOT_END_VOID(facility, code, error_message)
Definition: zglobal.h:134
virtual QHash< int, QByteArray > roleNames() const
QAbstractTableModel override.
#define zDebug()
Definition: zglobal.h:113
bool inObjectThread(const QObject &object)
Definition: zglobal.h:173
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Obtains the embedded data model.
void invalidateModel()
Sends begin and end reset signals to the model forcing views to refetch data from the entire model...
QVariant getValue(int role, int row)
Obtains the value of the specified data cell.
QSharedPointer< ZblLogReclinkData > m_d
#define ZBL_REGISTER_LOGGED_CATEGORY(variable_name)
Definition: zglobal.h:102
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
QAbstractTableModel override.
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
Definition: zglobal.h:141
QList< QVariant > ZDataRow
Represents a single row (or column for column headers) of data cell values for a single role...
Definition: ZTableModel.h:57