//----------------------------------------------------------------------------- // $Id: Q3GUI/DiagMsgDataModel.cpp 2014/05/25 15:59:20 philw $ // Diagnostic Message List QAbstractTableModel //----------------------------------------------------------------------------- // returns 'shown' (vis-a-vis message filtering) bool DiagMsgDataModel::appendItem (cwDiagData* diagData, const QWidget* refWid) { //------------------------------------------------------- // NOTE: The diagData instance is DELETED by this method. //------------------------------------------------------- static const char* mname ("DiagMsgDataModel::appendItem"); static int callCnt (0); ++callCnt; // *********************************** // *** Assess Diagnostic Message *** // *********************************** // remove leading and trailing spaces, and condense multiple contiguous // spaces to a single space. const QString ctx = diagData->getContext().simplified(); const QString msg = diagData->getMessage().simplified(); const cwDiagLevel level = diagData->getLevel(); bool shown (true); // tentative if (!_filterStr.isEmpty()) { const bool highPriorityMessage = (level == cwDiagError) || (level == cwDiagInternError); if (!highPriorityMessage) { if (_filter_plainText) { shown = ctx.contains (_filterStr, _filter_caseSense) || msg.contains (_filterStr, _filter_caseSense); } else { shown = (ctx + msg).contains (_filterRegExp); } } } const int initBlockCnt = _messageBlockList.count(); const int initItemCnt = (initBlockCnt == 0) ? 0 : ( ((initBlockCnt-1) * Block::CAPACITY) + _messageBlockList [initBlockCnt-1].recCount() ); //-------------------------------------------------------- beginInsertRows (QModelIndex(), initItemCnt, initItemCnt); //-------------------------------------------------------- // ********************* // *** Append Item *** // ********************* const bool addBlock = (initBlockCnt == 0) || _messageBlockList [initBlockCnt-1] .isFull(); if (addBlock) { _messageBlockList.append (Block()); } const int targetBlockIndex = _messageBlockList.count() - 1; _messageBlockList [targetBlockIndex] .appendItem (level, ctx, msg, shown); const int ctxLen = ctx.length(); const int msgLen = msg.length(); // ****************************************** // *** Measure Text Width: All Messages *** // ****************************************** // Perform actual pixel measurements only if the character counts // are above prior encountered character counts. const bool longerCtx = (ctxLen > _ctxMaxCharCnt); const bool longerMsg = (msgLen > _msgMaxCharCnt); if ((longerCtx || longerMsg) && rwAssert (refWid != NULL)) { const QFontMetrics fm = refWid->fontMetrics(); if (longerCtx) { const int ctxWidth = fm.width (ctx); _ctxColDataWidth = std::max (_ctxColDataWidth, ctxWidth); _ctxMaxCharCnt = ctxLen; _ctxMaxCharStr = ctx; } if (longerMsg) { const int msgWidth = fm.width (msg); _msgColDataWidth = std::max (_msgColDataWidth, msgWidth); _msgMaxCharCnt = msgLen; _msgMaxCharStr = msg; } // std::cout << mname << " [#" << callCnt << "]" // << " ctx reg " << _ctxMaxCharCnt // << " " << _ctxColDataWidth // << " \"" << qPrintable (ctx) << "\"" // << std::endl; if (_ctxColDataWidth > 10000) { static int hugeCnt (0); ++hugeCnt; } } // ******************************************************* // *** Measure Text Width: Shown (Filtered) Messages *** // ******************************************************* // Note: When filtering is re-applied (and thus, turned on), the // longest shown context and message strings are provided to this // class, computed in the course of setting the "shown" state of // all existing messages. The code below updates the local // "longest string" values as messages are ADDED to the list. // It needs to be run only when filtering is on. const bool filtOn = !_filterStr.isEmpty(); if (shown && filtOn) { _lastVisFilterItemInx = initItemCnt; const bool longerFiltCtx = (ctxLen > _ctxMaxCharCnt_filt); const bool longerFiltMsg = (msgLen > _msgMaxCharCnt_filt); if ((longerFiltCtx || longerFiltMsg) && rwAssert (refWid != NULL)) { const QFontMetrics fm = refWid->fontMetrics(); if (longerFiltCtx) { const int ctxWidth = fm.width (ctx); _ctxColDataWidth_filt = std::max (_ctxColDataWidth_filt, ctxWidth); _ctxMaxCharCnt_filt = ctxLen; _ctxMaxCharStr_filt = ctx; } if (longerFiltMsg) { const int msgWidth = fm.width (msg); _msgColDataWidth_filt = std::max (_msgColDataWidth_filt, msgWidth); _msgMaxCharCnt_filt = msgLen; _msgMaxCharStr_filt = msg; } // std::cout << mname << " [#" << callCnt << "]" // << " ctx flt " << _ctxMaxCharCnt_filt // << " " << _ctxColDataWidth_filt // << " \"" << qPrintable (ctx) << "\"" // << std::endl; } } //-------------------------------------------------------- endInsertRows(); //-------------------------------------------------------- // ************************************** // *** Delete the cwDiagData Instance *** // ************************************** delete diagData; diagData = NULL; return (shown); }