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
ZLogMap.cpp
Go to the documentation of this file.
1 #include "ZLogMap.h"
2 #include <QtQml>
3 #include "ZLogReader.h"
4 
5 namespace Zbl
6 {
7 
9 
10 //qint64 ZLogMap::m_nextMarkID = 0;
11 
12 //ZLogMap::ZLogMap(QObject* reader) : m_reader(NULL)
13 
14 ZLogMap::ZLogMap(ZLogReader* reader) : QObject(NULL), m_reader(NULL)
15 {
16  if(!reader)
17  {
18  zCritical() << "Programming error: reader parameter must be non-null!";
19 
20  return;
21  }
22 
23  ZLogReader* rdr = qobject_cast<ZLogReader*>(reader);
24 
25  if(!rdr)
26  zCritical() << "Programming error: reader parameter must be a pointer to a ZLogReader object!";
27  else
28  m_reader = rdr;
29 
30 }
31 
33 {
35 
36  qmlRegisterUncreatableType<ZLogMap>
37  ("org.zuble.qml", 1, 0, "ZLogMap",
38  "Use ZLogViewport or ZLogReader to create ZLogMap objects.");
39 }
40 
42 {
43  return Selection;
44 }
45 
46 
47 
49 {
50  return m_reader;
51 }
52 
53 QObject* ZLogMap::getReader() const
54 {
55  return m_reader;
56 }
57 
58 
59 #if 0
60 bool ZLogMap::createMapModel(ZTableModel* model)
61 {
62  if(!model)
63  return false;
64 
65  model->clearRoles();
66 
67  model->setColumnCount(1);
68 
69  model->addRole(FirstID, "rec_id");
70  //model->addRole(LastID, "last_id");
71  model->addRole(SeekPosition, "pos");
72  //model->addRole(roleName, "name");
73  //model->addRole(roleNote, "note");
74 
75  //appendModelRoles(model, roleFIRST_USER);
76 
77  return true;
78 }
79 #endif
80 
81 #if 0
82 QObject* ZLogMap::getMarkModel()
83 {
84  ZTableModel* model = new ZTableModel();
85 
86  createMapModel(model);
87 
88  QMap<qint64, MarkNode>::const_iterator it = m_map.begin();
89 
90  ZDataRow data;
91 
92  while(it != m_map.end())
93  {
94  // WARNING: the following data.append() calls are order dependent!
95 
96  data.append(it->m_recordID);
97  //data.append(it->m_lastID);
98  data.append(it->m_seekPos);
99 
100  // TBD: APPEND ROLES FOUND HERE?
101 
102  model->appendCells(data);
103  it++;
104  }
105 
106  return model;
107  return NULL;
108 
109 }
110 #endif
111 
112 #if 0
113 bool ZLogMap::initializeFromModel(QObject* mapModel)
114 {
115 
116  ZTableModel* zModel = qobject_cast<ZTableModel*>(mapModel);
117 
118  if(!zModel)
119  {
120  zWarning() << "Programming error: You must pass a ZTableModel "
121  "object to this method.";
122  return false;
123  }
124 
125  // TBD: validate that model contains necessary roles!!!!
126 
127  // delete map and copy model data to map
128 
129  m_map.clear();
130 
131  const int rowCount = zModel->modelRowCount();
132 
133  for(int row=0; row < rowCount; row++)
134  {
135  const qint64 firstID = zModel->getValue(FirstID, row).toInt();
136  //const qint64 lastID = zModel->getValue(LastID, row).toInt();
137  const qint64 seekPos = zModel->getValue(SeekPosition, row).toInt();
138 
139  m_map.insert(firstID, MarkNode(firstID, lastID, seekPos));
140  }
141 
142  return false;
143 }
144 #endif
145 
146 
147 void ZLogMap::insertMark(qint64 recordID,
148  qint64 lastRecordID,
149  qint64 seekPosition)
150 {
151  zDebug() << "Insert mark, recordID: " << recordID
152  << ", lastRecordID: " << lastRecordID
153  << ", seekPosition: " << seekPosition;
154 
155  if(m_map.insertMark(recordID, lastRecordID, seekPosition))
156  emit selectionUpdated();
157 
158 }
159 
161 {
162  if(m_map.clear())
163  emit selectionUpdated();
164 }
165 
166 bool ZLogMap::hasMark(qint64 recordID)
167 {
168  return m_map.hasMark(recordID);
169 }
170 
171 bool ZLogMap::removeMark(qint64 recordID, qint64 lastRecordID)
172 {
173  zDebug() << "Remove mark, recordID: " << recordID
174  << ", lastRecordID: " << lastRecordID;
175 
176  bool retval = m_map.removeMark(recordID, lastRecordID);
177 
178  if(retval)
179  emit selectionUpdated();
180 
181  return retval;
182 }
183 
185 {
186  return MarkType(logMapType());
187 }
188 
189 qint64 ZLogMap::findNextMark(qint64 startID, bool forward) const
190 {
191  return m_map.findNextMark(startID, forward);
192 }
193 
194 
195 } // Zbl
bool hasMark(qint64 recordID)
Determine if the log map contains a mark for the specified log record.
Definition: ZblLogMap.h:75
Q_INVOKABLE void appendCells(QVariant data, bool truncateModel=false)
Asynchronously converts an array of cell data into one or more rows of model data and appends it to t...
MarkType getMapType()
returns this log map&#39;s mark type
Definition: ZLogMap.cpp:184
bool clear()
Removes all marks from the log map.
Definition: ZblLogMap.h:119
A QML type that manages reading JSON formatted Zuble log files. QML programs create using Zbl...
Definition: ZLogReader.h:62
ZLogReader * getZReader() const
Returns the foreground log file reader object for this search.
Definition: ZLogMap.cpp:48
void insertMark(qint64 recordID, qint64 lastRecordID, qint64 seekPosition)
Creates a new log mark in the database.
Definition: ZLogMap.cpp:147
Maintains a list of log record links pertaining to a specific log file.
Definition: ZLogMap.h:28
bool removeMark(qint64 recordID, qint64 lastRecordID)
Removes the specified mark from the log map.
Definition: ZblLogMap.h:107
#define ZBL_REGISTER_LOGGED_OBJECT
Definition: zglobal.h:104
bool hasMark(qint64 recordID)
Determine if the log map contains a mark for the specified log record.
Definition: ZLogMap.cpp:166
Q_INVOKABLE QVariant getValue(int role, int row)
Obtains the value of the specified data cell.
ZLogReader * m_reader
The log file reader that created this search object.
Definition: ZLogMap.h:281
Definition: ZAndGate.cpp:6
static void registerType()
Registers ZLogMap as a QML type.
Definition: ZLogMap.cpp:32
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
Definition: zglobal.h:99
#define zWarning()
Definition: zglobal.h:111
void clear()
Removes all marks from the log map.
Definition: ZLogMap.cpp:160
This two dimensional table model is used to store and manipulate data.
Definition: ZTableModel.h:96
MarkType
Types of log maps: Invalid, Selection, Search, Bookmark.
Definition: ZLogMap.h:42
bool removeMark(qint64 recordID, qint64 lastRecordID)
Removes the specified mark from the log map.
Definition: ZLogMap.cpp:171
Q_INVOKABLE void clearRoles()
Removes all roles, role names and data from the model.
ZBL_DECLARE_LOGGED_OBJECT ZblLogMap m_map
Create the m_tag object that presents a Javascript interface to constant integer values.
Definition: ZLogMap.h:275
#define zDebug()
Definition: zglobal.h:113
virtual int logMapType()
Returns log map type. Subclasses override this to return their map type.
Definition: ZLogMap.cpp:41
void selectionUpdated()
Sent whenever the ZLogMap state has been changed.
bool insertMark(qint64 recordID, qint64 lastRecordID, qint64 seekPosition)
Creates a new log mark in the database.
Definition: ZblLogMap.h:59
Q_INVOKABLE void setColumnCount(int count)
Sets the number of columns the table will contain. This method may block the current thread...
Q_INVOKABLE int modelRowCount() const
Returns the number of rows in the data set. This method may block the current thread.
Q_INVOKABLE QObject * getReader() const
Returns the foreground log file reader object for this log map.
Definition: ZLogMap.cpp:53
qint64 findNextMark(qint64 startID, bool forward=true) const
Search forward or backward for the next mark from a specified starting position.
Definition: ZblLogMap.h:95
Q_INVOKABLE bool addRole(int roleNumber)
Adds the specified role to the data model. This method may block the current thread.
qint64 findNextMark(qint64 startID, bool forward=true) const
Search forward or backward for the next mark from a specified starting position.
Definition: ZLogMap.cpp:189
#define zCritical()
Definition: zglobal.h:112
QList< QVariant > ZDataRow
Represents a single row (or column for column headers) of data cell values for a single role...
Definition: ZTableModel.h:57