37 #include <QJsonParseError> 39 #include <QJsonDocument> 49 QObject(parent), m_ready(false)
55 connect(m_reader, SIGNAL(openComplete(
bool,QString,QVariantMap)),
56 SLOT(onBackgroundOpenComplete(
bool,QString,QVariantMap)));
58 connect(m_reader, SIGNAL(notifyFileSize(qint64)),
59 this, SIGNAL(notifyFileSize(qint64)));
67 m_model->setColumnCount(1);
69 m_model->addRole(0,
"searchObject");
82 qmlRegisterType<ZLogReader>(
"org.zuble.qml", 1, 0,
"ZLogReader");
84 qmlRegisterUncreatableType<ZLogBookmark>(
"org.zuble.qml", 1, 0,
85 "ZLogBookmark",
"ZLogBookmark objects are created using ZLogReader.");
87 qmlRegisterUncreatableType<ZblLogSearch>(
"org.zuble.qml", 1, 0,
88 "ZblLogSearch",
"ZblLogSearch objects are created automatically.");
90 qmlRegisterUncreatableType<ZLogSearch>(
"org.zuble.qml", 1, 0,
91 "ZLogSearch",
"ZLogSearch objects are created using ZLogReader.");
93 qmlRegisterUncreatableType<ZLogReclinkModel>(
"org.zuble.qml", 1, 0,
94 "ZLogReclinkModel",
"ZLogReclinkModel objects are created using ZLogSearch.");
96 qRegisterMetaType<Zbl::ZblLogSearchList>(
"ZblLogSearchList");
98 qRegisterMetaType<Zbl::ZblLogSearchParams>(
"ZblLogSearchParams");
106 void ZLogReader::openLogFile(
const QString&
filePath)
111 context.insert(
"loadOnOpen", QVariant(
true));
112 context.insert(
"recordCount", QVariant(-1));
113 context.insert(
"recordIndex", QVariant(0));
115 QMetaObject::invokeMethod(
m_reader,
"openFile",
116 Qt::QueuedConnection,
117 Q_ARG(
const QString&, filePath),
118 Q_ARG(QVariantMap, context));
124 zDebug() <<
"Background log file opened!!";
130 bool loadFile = contextMap.value(
"loadOnOpen",
false).toBool();
137 qint64 recordCount = contextMap.value(
"recordCount", QVariant(1000)).toInt();
139 qint64 recordIndex = contextMap.value(
"recordIndex", QVariant(0)).toInt();
146 QMetaObject::invokeMethod(
m_reader,
"loadViewport",
147 Qt::QueuedConnection,
148 Q_ARG(QObject*, viewport),
149 Q_ARG(qint64, recordIndex),
150 Q_ARG(qint64, recordCount),
151 Q_ARG(QVariantMap, contextMap));
168 void ZLogReader::onBackgroundLoadIndexComplete(QObject *viewport,
170 QVariantMap contextMap)
172 emit loadComplete(viewport, errorMsg);
185 QMetaObject::invokeMethod(
m_reader,
"openFile",
186 Qt::QueuedConnection,
187 Q_ARG(
const QString&, filePath),
188 Q_ARG(QVariantMap, context));
204 QMetaObject::invokeMethod(
m_reader,
"close", Qt::QueuedConnection);
242 QString msg(
"Error: Bookmark name: %1 already exists.");
261 QMetaObject::invokeMethod(
this,
"newBookmark",
262 Qt::BlockingQueuedConnection,
264 Q_ARG(
const QString&, name)
284 for(
int i=0; i<count; i++)
297 QMetaObject::invokeMethod(
this,
"getBookmark",
298 Qt::BlockingQueuedConnection,
300 Q_ARG(
const QString&, name)
311 QObject* ZLogReader::newSearchmark(
const QString& searchPhrase,
int searchType)
319 if(hasSearchmark(searchPhrase, searchType))
321 QString msg(
"Error: Searchmark phrase: %1 already exists.");
322 msg.arg(searchPhrase);
326 QString markName = QString(
"Search: %1:%2").arg(searchType).arg(searchPhrase);
330 searchmark->setMarkName(markName);
332 searchmark->setPhrase(searchPhrase);
334 searchmark->setSearchType(searchType);
345 QMetaObject::invokeMethod(
this,
"newSearchmark",
346 Qt::BlockingQueuedConnection,
348 Q_ARG(
const QString&, searchPhrase),
349 Q_ARG(
int, searchType)
354 Z_FAC_JS, ZLogReader::newSearchmark, newSearchmark failed)
365 if(!searchPhrase.isEmpty())
371 zDebug() <<
"ZLogReader returning search: " << searchPhrase <<
";;;;; type=" << sType <<
"; roles=" << roles;
375 zDebug() <<
"Search name = " << searchName;
377 QWeakPointer<ZblLogSearch> wkSearch =
m_searchmarks.value(searchName);
379 if(!wkSearch.isNull())
383 if(!searchPtr.isNull())
385 zDebug() <<
"Returning existing search object.";
411 zDebug() <<
"Creating new search object.";
424 QQmlEngine::setObjectOwnership(newSearch.data(), QQmlEngine::CppOwnership);
428 newSearch->setMarkName(searchName);
441 zDebug() <<
"Adding search object to model: " << search->getMarkName();
445 searchWrapper->setParent(
this);
447 QVariant vSearch = QVariant::fromValue(searchWrapper);
462 for(
int i=0; i<rowCount; i++)
468 QSharedPointer<ZblLogSearch> pSearch(wSearch->
getZSearch());
470 if(pSearch.data() == search)
472 if(pSearch->getMarkName() != search->
getMarkName())
477 wSearch->deleteLater();
490 for(
int i=0; i<rowCount; i++)
496 wSearch->deleteLater();
520 return searchWrapper;
524 void ZLogReader::purgeSearch()
531 zWarning() <<
"Programming error: ZLogReader::purgeSearch() - Invalid connection or call!";
540 zWarning() <<
"Programming error: Search object not found in search object map.";
549 for(
int i=0; i<count; i++)
558 QMap<QString, QWeakPointer<ZblLogSearch> >::iterator i =
m_searchmarks.find(searchName);
565 return !searchObject.isNull();
571 bool ZLogReader::updateLogmark(
const QObject* logMark,
const QString& name)
587 zDebug() <<
"ZLogReader::deleteBookmark function unimplelemted!";
601 zWarning() <<
"Programming error: search parameter must be a ZLogSearch object.";
610 if(pSearch->isNull())
612 zWarning() <<
"Programming error: dangling ZLogSearch object.";
618 QString searchName = pSearch->getMarkName();
625 pSearch->invalidate();
631 QMap<qint64, QStringList> markset;
638 throw ZblException(
"Error: lastID must be greater than or equal to firstID");
640 for(qint64 i=firstID; i<=lastID; i++)
645 QMetaObject::invokeMethod(
this,
"getBookmarkSet",
646 Qt::BlockingQueuedConnection,
648 Q_ARG(qint64, firstID),
649 Q_ARG(qint64, lastID)
667 for(
int i=0; i<count; i++)
671 if(bookmark->
hasMark(recordID))
678 QMetaObject::invokeMethod(
this,
"getBookmarkNames",
679 Qt::BlockingQueuedConnection,
680 Q_RETURN_ARG(QStringList, names),
681 Q_ARG(qint64, recordID)
691 return QMap<qint64, QStringList>();
698 int ZLogReader::getMarkTypes(qint64 recordID)
703 const int count = m_logMaps.count();
705 for(
int i=0; i<count; i++)
707 ZLogMap* nextMap = m_logMaps.at(i);
711 if(nextType && markTypes)
715 markTypes |= nextType;
725 QList<QObject*> ZLogReader::getMarks(qint64 recordID,
int markTypes)
727 QList<QObject*> marks;
729 const int count = m_logMaps.count();
731 for(
int i=0; i<count; i++)
733 ZLogMap* nextMap = m_logMaps.at(i);
735 if((nextMap->getMarkType() | markTypes) && nextMap->
hasMark(recordID))
736 marks.append(nextMap);
Encapsulates information necessary to locate a collection of log records in a log file...
Q_INVOKABLE QObject * getSearchModel()
Obtain a pointer to the data model containing search objects for this log file.
QMap< qint64, QStringList > zMarkSet
virtual ~ZLogReader()
Virtual object destructor.
QObject * getBookmark(const QString &name)
Obtains the bookmark or searchmark with the given name.
static void registerType()
Registers ZLogReader as a QML type.
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...
bool deleteBookmark(const QString &name)
Remove the specified bookmark or searchmark by name.
void openFile(const QString &filePath)
Opens the log file in a background thread concurrently but does not load it. Sends the openComplete s...
This class performs log file I/O operations and JSON parsing in a background thread on behalf of a ZL...
Q_INVOKABLE void clearData()
Removes all data from the model. Roles and role names remain intact.
ZLogBookmark::zLogBookmarkList m_bookmarks
A central repository for log file marks. This is the definitive mark list for the log file...
bool setLogmapParameters(const QObject *parameters, const QString &name)
Updates the specified logmark parameters (note, search type) for the bookmark with the specified name...
A QML type that manages reading JSON formatted Zuble log files. QML programs create using Zbl...
ZblLogReader * getBackgroundReader()
Obtains a pointer to the background reader object that services this log file.
QMap< qint64, QStringList > getBookmarkSet(qint64 firstID, qint64 lastID)
Returns a map containing log mark information for the specified set of log records.
QString getMarkName() const
Maintains a list of log record links pertaining to a specific log file.
ZBL_DECLARE_LOGGED_OBJECT ZblLogReader * m_reader
A log reader worker object to perform log file input and parsing operations in a background thread...
void invalidate()
Sent when a request to delete this object requires all references to be released. ...
#define ZBL_REGISTER_LOGGED_OBJECT
A wrapper for the explicitly shared ZblLogSearch object.
void onBackgroundOpenComplete(bool success, QString errorMsg, QVariantMap contextMap)
Called by the background thread when file has been opened.
void closeAlert()
Sent when the close() function has been called.
void bookmarksUpdated()
Sent when the master log mark database has been updated.
static QString getSearchmarkName(QString searchPhrase, int searchType, QList< int > searchRoles)
Creates a unique name string for a given set of search parameters.
bool hasMark(qint64 recordID)
Determine if the log map contains a mark for the specified log record.
Q_INVOKABLE QVariant getValue(int role, int row)
Obtains the value of the specified data cell.
bool m_ready
true when when log file is opened and ready to be used, false otherwise.
Q_INVOKABLE zblLogSearchPtr getZSearch(const QString &searchPhrase, int searchType, QList< int > searchRoles)
Obtains or creates a search mark with the given search parameters.
bool getReady()
Obtains the state of the ready flag..
A log viewport encapsulates a ZTableModel containing a contiguous subset of log records from a Zuble ...
QObject * newBookmark(const QString &name)
Creates a new ZLogBookmark object and returns it.
static void zInit()
Initializes search engine. Must be called only once before calling newLogSearcher() the first time...
QObject * newViewport()
Obtains a new empty foreground ZLogViewport object on the log file.
static void zInit(int logRecordRoleCount)
Must be called only once before calling newLogReader();.
void appendSearchModel(zblLogSearchPtr search)
#define ZBL_SLOT_BEGIN_TRY
void setMarkName(const QString &name)
bool hasSearchMap(const QString &searchName)
QStringList getBookmarkNames(qint64 recordID)
Obtains a list of bookmark names for the specified log record.
static ZblLogReader * newLogReader()
creates a new ZblLogReader object and moves it to the shared background log reader thread...
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
void releaseSearchReferences(QString searchObjectName)
Sent when a request to delete a ZLogSearch object has been received.
This two dimensional table model is used to store and manipulate data.
QSharedPointer< ZblLogSearch > zblLogSearchPtr
MarkType
Types of log maps: Invalid, Selection, Search, Bookmark.
Q_INVOKABLE QObject * getSearch(const QString &searchPhrase, int searchType, QList< int > searchRoles)
Obtains or creates the searchmark with the given search parameters.
void selectionUpdated()
Sent whenever the ZLogMap state has been changed.
static void dismiss(QObject *search)
QSharedPointer deleter method called when last strong reference has gone out of scope; sends detach()...
bool inObjectThread(const QObject &object)
Q_INVOKABLE int modelRowCount() const
Returns the number of rows in the data set. This method may block the current thread.
void removeSearchModel(ZblLogSearch *search)
void close()
Close the log file input object and release resources.
Q_INVOKABLE bool hasSearch(const QString &searchPhrase, int searchType, QList< int > searchRoles)
Determine if a specific search object exists.
QString filePath
Path to the log file being read by this object.
Zuble's Qt Exception Object.
bool hasBookmark(const QString &name)
static void zInit()
Initializes search engine. Must be called only once before constructing the first ZblLogSearch object...
QSharedPointer< ZblLogSearch > getZSearch()
void onInvalidate()
Handler for the ZblLogSearch::invalidate signal.
QString m_filePath
Path to log file being read.
Q_INVOKABLE bool isValid() const
Determine if this wrapper object points to a valid search object.
Q_INVOKABLE void removeRow(int row)
QString getFilePath()
Obtains the path to the log file.
ZTableModel * m_model
A data model used to display search objects.
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
QMap< QString, QWeakPointer< ZblLogSearch > > m_searchmarks
A central repository for log file marks. This is the definitive mark list for the log file...
This object encapsulates search operation parameters, results, and steady state.
QMap< qint64, QStringList > getSearchmarkSet(qint64 firstID, qint64 lastID)
Returns a map containing log mark information for the specified set of log records.
bool deleteSearch(QObject *search)
Remove the specified search object from the search map and model.
QList< QVariant > ZDataRow
Represents a single row (or column for column headers) of data cell values for a single role...
void openComplete(QString filePath, bool success, QString errorMsg)
Sent when an openFile() operation has completed;.