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
ZblLogSearch.cpp
Go to the documentation of this file.
1 #include "ZblLogSearch.h"
2 #include "ZLogReclinkModel.h"
3 #include "ZLogReader.h"
4 #include "ZblLogReader.h"
5 #include "ZblLogLinkList.h"
6 #include "ZblLogBkSearch.h"
7 #include "ZblLogSearchParams.h"
8 
9 
10 namespace Zbl
11 {
12 
14 
15 
17  const QString& searchPhrase,
18  int searchType,
19  QList<int> searchRoles,
20  ZblLogSearch::TextSearchDirections directions,
21  qint64 startPosition,
22  ZLogReader* reader
23  ) : ZLogBookmark(reader), m_searchArea(reader),
24  m_searchPhrase(searchPhrase),
25  m_startPosition(startPosition),
26  m_endSize(-1)
27 {
28 #if 1
29 
30  m_active = true;
31 
32  m_saved = false;
33 
34  m_searchType = zValidateSearchType(searchType);
35 
36  m_rolesSearched = QSet<int>::fromList(searchRoles);
37 
38  m_searchDirection = directions;
39 
41 
42  QString markName = getSearchmarkName(searchPhrase, searchType, searchRoles);
43 
44  setMarkName(markName);
45 
46  m_searcher = new ZblLogBkSearch(startPosition, getSearchParameters(), reader->getBackgroundReader());
47 
48  m_searcher->moveToThread(m_searcherThread);
49 
51 
52  //connect(reader, &ZblLogReader::linkMessageText, this, &ZblLogSearch::onLinkMessageText);
53 #endif
54 }
55 
56 
58 {
59  m_searcherThread = new QThread();
60  m_searcherThread->start();
61 }
62 
64 {
65  return reader == m_reader;
66 }
67 
68 
70 {
71  ZblLogSearch* zSearch = qobject_cast<ZblLogSearch*>(search);
72 
73  if(!zSearch)
74  {
75  qWarning("Programming error: ZblLogSearch::dismiss called for invalid object type.");
76  return;
77  }
78 
79  //emit zSearch->detach();
80 
81  zSearch->deleteLater();
82 }
83 
85 {
86  return m_searcher;
87 }
88 
89 
90 
92 {
93 
94 }
95 
97 {
98 
99 }
100 
102 {
103 
104 }
105 
106 
107 QString ZblLogSearch::getSearchmarkName(QString searchPhrase, int searchType, QList<int> searchRoles)
108 {
109  QString markName("%1:%2:%3");
110  markName = markName.arg(searchPhrase).arg(searchType).arg(getSearchRolesName(searchRoles));
111  return markName;
112 }
113 
114 QString ZblLogSearch::getSearchRolesName(QList<int> searchRoles)
115 {
116  QString name;
117 
118  // eliminate duplicates
119 
120  QSet<int> roles = QSet<int>::fromList(searchRoles);
121 
122  searchRoles = roles.toList();
123 
124  // sort and concatenate
125 
126  std::sort(searchRoles.begin(), searchRoles.end());
127 
128  for(int i=0; i<searchRoles.count(); i++)
129  name += QString("%1:").arg(searchRoles.at(i));
130 
131  return name;
132 }
133 
134 
135 #if 0
136 
137 int ZLogSearch::appendModelRoles(ZTableModel* model, int nextRole)
138 {
139  nextRole = ZLogBookmark::appendModelRoles(model, nextRole);
140  model->addRole(nextRole++, "search_phrase");
141  return nextRole;
142 }
143 
144 void ZLogSearch::appendModelData(
145  const MarkNode& logMark,
146  ZDataRow data)
147 {
148  ZLogBookmark::appendModelData(logMark, data);
149 
150  data.append(m_searchPhrase);
151 }
152 
153 #endif
154 
155 QString ZblLogSearch::getPhrase() const
156 {
157  return m_searchPhrase;
158 }
159 
161 {
162  return m_searchType;
163 }
164 
166 {
167  return m_searchState;
168 }
169 
170 
172 {
174 }
175 
177 {
178  // TBD: changing direction bits has state implications!
179 
180  if(forward)
182  else
184 }
185 
187 {
189 }
190 
192 {
193  // TBD: changing direction bits has state implications!
194 
195  if(backward)
197  else
199 
200 }
201 
202 ZblLogSearch::TextSearchDirections ZblLogSearch::getSearchDirections() const
203 {
204  return m_searchDirection;
205 }
206 
207 void ZblLogSearch::setSearchDirections(ZblLogSearch::TextSearchDirections directions)
208 {
209  // TBD: changing direction bits has state implications!
210 
211  m_searchDirection = directions;
212 
213 }
214 
216 {
217  return m_active;
218 }
219 
221 {
222  return m_saved;
223 }
224 
226 {
227  return m_endSize;
228 }
229 
231 {
232  return Searchmap;
233 }
234 
235 void ZblLogSearch::addRoleFound(int roleNumber)
236 {
237  m_rolesFound.insert(roleNumber);
238 }
239 
240 void ZblLogSearch::addRolesFound(QList<int> rolesFound)
241 {
242  QSet<int>addSet = QSet<int>::fromList(rolesFound);
243 
244  m_rolesFound.unite(addSet);
245 }
246 
248 {
249  m_rolesFound.clear();
250 }
251 
252 QList<int> ZblLogSearch::getRolesFound() const
253 {
254  return m_rolesFound.toList();
255 }
256 
257 void ZblLogSearch::addSearchRole(int roleNumber)
258 {
259  if(!m_rolesSearched.contains(roleNumber))
260  {
261  m_rolesSearched.insert(roleNumber);
262 
263  clear();
264  }
265 }
266 
267 void ZblLogSearch::addSearchRoles(QList<int> rolesToSearch)
268 {
269  QSet<int>addSet = QSet<int>::fromList(rolesToSearch);
270 
271  if(!m_rolesSearched.contains(addSet))
272  {
273  m_rolesSearched.unite(addSet);
274 
275  clear();
276  }
277 }
278 
280 {
281  m_rolesSearched.clear();
282 
283  clear();
284 }
285 
287 {
288  return m_rolesSearched.toList();
289 }
290 
291 bool ZblLogSearch::containsSearchRoles(QList<int> searchRoles) const
292 {
293  QSet<int> roleSet = QSet<int>::fromList(searchRoles);
294 
295  return m_rolesSearched.contains(roleSet);
296 }
297 
298 
299 bool ZblLogSearch::equalsSearchRoles(QList<int> searchRoles) const
300 {
301  QSet<int> roleSet = QSet<int>::fromList(searchRoles);
302 
303  return m_rolesSearched == roleSet;
304 }
305 
306 bool ZblLogSearch::isSearch(const QString& searchPhrase, int searchType, QList<int> searchRoles) const
307 {
308  QSet<int> testRoles = QSet<int>::fromList(searchRoles);
309 
310  return (searchPhrase == m_searchPhrase) && (searchType == m_searchType) && (testRoles == m_rolesSearched);
311 }
312 
314 {
315  if(m_searchPhrase.isEmpty() || m_rolesSearched.isEmpty())
316  return true;
317  else
318  return false;
319 }
320 
321 
323  qint64 recordID,
324  qint64 seekPosition,
325  QList<int> modelRoles)
326 {
327  // TDB: this will be deprecated in favor of onSearchRowsMatched, below
328 
329  zDebug() << "Search row matched - id =" << recordID
330  << "seekPosition =" << seekPosition << ", modelRoles ="
331  << modelRoles;
332 
333  // TBD: send signal to add row to attached link data models
334 
335  insertMark(recordID, recordID, seekPosition);
336 
337  addRolesFound(modelRoles);
338 
339 }
340 
342 {
343  zDebug() << "Search rows matched, count = " << rowsFound.m_links.count();
344 
345  // TBD: should get message text here?
346 
347  const int rowCount = rowsFound.m_links.count();
348 
349  for(int i=0; i < rowCount; i++)
350  {
351  const ZblLogSearchList::LinkNode& nextNode = rowsFound.m_links.at(i);
352 
353  // TBD: should have insertMark convenience method for a single-record mark?
354 
355  insertMark(nextNode.m_recordID, nextNode.m_recordID, nextNode.m_seekPos);
356  }
357 }
358 
359 
361 {
362  // TBD: make threadsafe? Should only be used in foreground thread
363 
364  QSharedPointer<ZblLogReclinkData> strongRef = m_linkModel.toStrongRef();
365 
366  if(!strongRef.isNull())
367  {
368  return new ZLogReclinkModel(strongRef);
369  }
370  else
371  {
372  QSharedPointer<ZblLogReclinkData>
373  newRef(new ZblLogReclinkData(), deleteReclinkData);
374 
375  populateLinkModel(*newRef.data());
376 
377 #if 0
378 
379  // TBD: should connect to onSearchRowsMatched instead?
380 
381  connect(this, &ZblLogSearch::searchRowMatched,
382  newRef.data(), &ZblLogReclinkData::onSearchRowMatched);
383 #endif
384  m_linkModel = newRef.toWeakRef();
385 
386  return new ZLogReclinkModel(newRef);
387  }
388 }
389 
390 
392 {
393  // TBD: check if m_linkModel has a reference here - it should not!
394 
395  data->deleteLater();
396 }
397 
399 {
400  ZDataRow data;
402 
403  for(int i=0; i < links.m_links.count(); i++)
404  {
405 
406  //qint64 id = it->getFirstID();
407 
408  const ZblLogLinkList::LinkNode& node = links.m_links.at(i);
409 
410 
411  // WARNING: the following data.append() calls are order dependent!
412 
413  data.append(node.m_index);
414  data.append(node.m_value);
415  data.append(QVariant("<data unavailable>")); // dummy message
416 
417  // TBD: APPEND ROLES FOUND HERE?
418 
419  linkModel.zModel()->appendCells(data);
420  data.clear();
421 
422  }
423 
424  //ZblLogReader* reader = getReader()->getBackgroundReader();
425 
426  QVariant vLinks(QVariant::fromValue<ZblLogLinkList>(links));
427 
428  QMetaObject::invokeMethod(m_reader, "loadRecordLinkMessageText",
429  Qt::QueuedConnection,
430  Q_ARG(QObject*, this),
431  Q_ARG(QVariant, vLinks));
432 
433 
434 }
435 
436 void ZblLogSearch::onLinkTextComplete(QVariant linkList)
437 {
438  zDebug() << "Processing onLinkTextComplete...";
439 
440  ZblLogLinkList links = linkList.value<Zbl::ZblLogLinkList>();
441 
442  QSharedPointer<ZblLogReclinkData> linkModel = m_linkModel.toStrongRef();
443 
444  if(linkModel.isNull())
445  return;
446 
447  ZTableModel* tableModel = linkModel->zModel();
448 
449  for(int i=0; i<links.m_links.count(); i++)
450  {
451  const ZblLogLinkList::LinkNode& nextNode = links.m_links.at(i);
452 
453  zDebug() << "index = " << nextNode.m_index << ", text = " << nextNode.m_value;
454 
455  // TBD: is row index correct? only on first invocation? need to send model row number in message text request?
456 
457  tableModel->putValue(ZLogMap::MessageText, i, nextNode.m_value);
458  }
459 
460  tableModel->invalidateModel();
461 
462 }
463 
465  int direction,
466  qint64 startPos
467  )
468 {
469  zDebug() << "search function entered...";
470 
471 #if 0
472 
473  if(m_motionLock)
474  {
475  zDebug() << "Programming error - Can't search while background "
476  "operation is in progress.";
477 
478  return false;
479  }
480 #endif
481 
482  //TBD: don't search if a search is already in progress
483  // validate columns exist in viewport model
484  // validate type
485  // validate phrase
486 
487  // TBD: check if search was already executed
488 
489  ZblLogSearchParams searchParams(getSearchParameters());
490 
491  //m_currentSearch->clear();
492 
493  // STATE_CHANGE: ENTER SCAN STATE
494 
495  QMetaObject::invokeMethod(m_searcher, "search",
496  Qt::QueuedConnection,
497  Q_ARG(QObject*, this),
498  Q_ARG(ZblLogSearchParams, searchParams));
499 
500  return true;
501 
502 }
503 
505 {
507  0,
508  m_rolesSearched.toList(),
510  m_searchType);
511 }
512 
513 
514 
515 
516 
517 } // Zbl
searchState getSearchState() const
QObject * linkModel()
Obtain a list model containing an item for each log record represented in the ZLogSearchMark&#39;s result...
Encapsulates information necessary to locate a collection of log records in a log file...
Definition: ZLogBookmark.h:46
TextSearchDirections getSearchDirections() const
void addSearchRole(int roleNumber)
Adds the specified role to the set of roles that will be scanned during a text search.
textSearchType m_searchType
The type of search: case sensitive/insensitive or regular expression.
Definition: ZblLogSearch.h:564
void resume()
Resume the background search operation.
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...
QList< int > getSearchRoles() const
Returns the set of roles in the log file data model that will be scanned by the text search engine wh...
bool search(int direction, qint64 startPos)
Scans the log file for text matching the current search criteria.
void onSearchRowsMatched(ZblLogSearchList rowsFound)
Called when the search engine has found target records in the log file.
ZblLogBkSearch * getSearcher()
Obtain the background searcher object associated with this search.
bool m_saved
True is search is saved, false if unsaved.
Definition: ZblLogSearch.h:631
A QML type that manages reading JSON formatted Zuble log files. QML programs create using Zbl...
Definition: ZLogReader.h:62
void clearRolesFound()
Removes all roles from the set of search result roles.
qint64 m_endSize
The file size at the successful conclusion of the search operation.
Definition: ZblLogSearch.h:652
ZblLogReader * getBackgroundReader()
Obtains a pointer to the background reader object that services this log file.
Definition: ZLogReader.cpp:226
void pause()
Pause the background search operation.
bool isSearch(const QString &searchPhrase, int searchType, QList< int > searchRoles) const
Determines if this object contains results from searching for the specified search phrase and type...
void clearSearchRoles()
Removes all roles from the set of search result roles.
bool getSearchBackward() const
int getSearchType() const
void onSearchRowMatched(qint64 recordID, qint64 seekPosition, QList< int > modelRoles)
Called when the search engine has found a target record in the log file.
void insertMark(qint64 recordID, qint64 lastRecordID, qint64 seekPosition)
Creates a new log mark in the database.
Definition: ZLogMap.cpp:147
void onSearchRowMatched(qint64 recordID, qint64 seekPosition, QList< int > modelRoles)
Called when the search engine has found a target record in the log file.
Q_INVOKABLE void putValue(int role, int row, const QVariant &value)
Sets the value of the specified cell in the data set.
This class allows Zuble log file viewer text search operations to pass parameters between threads...
void setSearchDirections(ZblLogSearch::TextSearchDirections directions)
void invalidateModel()
Resets the model.
bool getActive() const
bool m_active
True if search is active, false if inactive.
Definition: ZblLogSearch.h:622
void abort()
Resume the background search operation.
ZblLogSearchParams getSearchParameters()
Obtain parameters for this search.
static QThread * m_searcherThread
A single background thread services all ZblLogBkSearch objects.
Definition: ZblLogSearch.h:670
QWeakPointer< ZblLogReclinkData > m_linkModel
A log record link data model that is shared by all ZLogReclinkModel objects created by this ZlogSearc...
Definition: ZblLogSearch.h:605
static QString getSearchmarkName(QString searchPhrase, int searchType, QList< int > searchRoles)
Creates a unique name string for a given set of search parameters.
bool containsSearchRoles(QList< int > searchRoles) const
Determine if the set of roles to scan when processing this searchmark contains the specified roles...
virtual int logMapType()
Returns log map type. Override of ZLogBookmark::logMapType().
void populateLinkModel(ZblLogReclinkData &linkModel)
Creates an expanded data model of this ZLogSearch object&#39;s log record links in the specified object...
void onLinkTextComplete(QVariant linkList)
Called by ZblLogReader when loadRecordLinkMessageText has completed.
ZLogReader * m_reader
The log file reader that created this search object.
Definition: ZLogMap.h:281
bool equalsSearchRoles(QList< int > searchRoles) const
Determine if the set of roles to scan when processing this searchmark contains exactly the specified ...
Performs log file searches in a background thread.
Definition: ZAndGate.cpp:6
void setSearchForward(bool forward)
void setSearchBackward(bool backward)
void addRolesFound(QList< int > rolesFound)
Adds the specified roles to the set of roles where search results were found.
void searchRowsMatched(ZblLogSearchList rowsFound)
Sent when log records matching the search criteria have been located.
void setMarkName(const QString &name)
void addSearchRoles(QList< int > rolesToSearch)
Adds the specified roles to the set of roles that will be scanned during a text search.
ZblLogSearch(const QString &searchPhrase, int searchType, QList< int > searchRoles, ZblLogSearch::TextSearchDirections directions, qint64 startPosition, ZLogReader *reader)
ZTableModel * zModel()
Obtains the table model in which log record link data is stored.
QSet< int > m_rolesSearched
The log record rolls that are searched.
Definition: ZblLogSearch.h:573
QList< LinkNode > m_links
Explicitly shared data object encapsulates a list of log record links.
QString getPhrase() const
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
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
bool isNull()
Determine if this search is null.
bool validateReader(ZLogReader *reader)
Determine if the specified background file reader is connected to this search object.
bool getSearchForward() const
static void dismiss(QObject *search)
QSharedPointer deleter method called when last strong reference has gone out of scope; sends detach()...
friend class ZLogReclinkModel
Definition: ZLogMap.h:30
QSet< int > m_rolesFound
The roles in which a search result was found.
Definition: ZblLogSearch.h:584
searchState
States of a search.
Definition: ZblLogSearch.h:46
QList< int > getRolesFound() const
Returns the set of roles for which search results were found.
TextSearchDirections m_searchDirection
Specifies direction of search from active viewport location.
Definition: ZblLogSearch.h:637
searchState m_searchState
Tracks the state of a search operation.
Definition: ZblLogSearch.h:612
ZblLogLinkList getLogLinkList() const
Obtain a ZblLogLinkList object containing expanded log links.
Definition: ZblLogMap.h:127
qint64 getCompletionFileSize() const
This class allows Zuble log file viewer text search operations to pass search results between threads...
ZblLogBkSearch * m_searcher
A background searcher object to service foreground log file search requests.
Definition: ZblLogSearch.h:665
static void zInit()
Initializes search engine. Must be called only once before constructing the first ZblLogSearch object...
bool getSaved() const
void addRoleFound(int roleNumber)
Adds the specified role to the set of roles where search results were found.
Q_INVOKABLE bool addRole(int roleNumber)
Adds the specified role to the data model. This method may block the current thread.
textSearchType zValidateSearchType(int searchType)
Validates an integer value to be type textSearchType and returns it or a valid default value if out o...
Definition: zglobal.h:222
static QString getSearchRolesName(QList< int > searchRoles)
Returns a name concatenated from the specified search role list.
This object encapsulates search operation parameters, results, and steady state.
Definition: ZblLogSearch.h:35
QString m_searchPhrase
The search phrase used to generate these search results.
Definition: ZblLogSearch.h:558
QList< QVariant > ZDataRow
Represents a single row (or column for column headers) of data cell values for a single role...
Definition: ZTableModel.h:57
static void deleteReclinkData(ZblLogReclinkData *data)
calls deleteLater() method of the specified ZblLogReclinkData object.