31 QAbstractTableModel(parent)
34 maxNewLogLevelType = eUNDEFINED;
39 return logEntries.size();
50 const int& row =
index.row();
51 const int& column =
index.column();
57 std::unique_lock lock(logEntriesMutex);
58 if (row >= (
signed int)logEntries.size() || row < 0)
60 return QString(
"n/A");
63 const LogMessage& entry = logEntries[row];
69 if (role == Qt::ToolTipRole)
76 if (!entry.backtrace.empty())
78 whatStr = QString::fromStdString(entry.what +
"\nBacktrace:\n" + entry.backtrace);
82 whatStr = QString::fromStdString(entry.what);
94 std::unique_lock lock(logEntriesMutex);
97 if (row >= (
signed int)logEntries.size() || row < 0)
99 return QString(
"n/A");
102 const LogMessage& entry = logEntries[row];
108 IceUtil::Time time = IceUtil::Time::microSeconds(entry.time);
109 std::string timeStr = time.toDateTime();
110 timeStr = timeStr.substr(timeStr.find(
' '));
111 return QString::fromStdString(timeStr);
116 return QString::fromStdString(entry.who);
121 return QString::fromStdString(entry.tag);
126 if (entry.type != eUNDEFINED)
138 if (role == Qt::ToolTipRole)
145 if (!entry.backtrace.empty())
147 whatStr = QString::fromStdString(entry.what +
"\nBacktrace:\n...");
151 whatStr = QString::fromStdString(entry.what);
154 int maxLinesToShow = 50;
156 for (
int i = 0; i < whatStr.length(); i++)
158 auto c = whatStr.at(i);
163 if (lines == maxLinesToShow)
169 if (lines >= maxLinesToShow)
171 whatStr.truncate(pos);
172 return whatStr +
"\n...";
179 if (role == Qt::ToolTipRole)
181 return QString::fromStdString(
"Double click to open file in editor: " + entry.file +
":" + QString::number(entry.line).toStdString());
183 else if (!entry.file.empty())
185 return QString::fromStdString(entry.file +
":" + QString::number(entry.line).toStdString());
195 return QString::fromStdString(entry.function);
200 return QString::fromStdString(entry.group);
208 case Qt::DecorationRole:
212 return QIcon(
":icons/document-open-4.ico");
218 case Qt::BackgroundColorRole:
222 if (row >= (
signed int)logEntries.size() || row < 0)
227 const LogMessage& entry = logEntries[row];
232 return QColor(200, 200, 250);
235 return QColor(50, 255, 50);
238 return QColor(216, 88, 0);
241 return QColor(255, 64, 64);
244 return QColor(176, 0, 0);
252 if (activeSearchStr.length() == 0)
258 std::unique_lock lock(logEntriesMutex);
261 if (row >= (
signed int)logEntries.size() || row < 0)
266 const LogMessage& entry = logEntries[row];
270 return QColor(255, 244, 127);
300 if (searchStr.length() == 0)
307 if (
data(createIndex(row, i), Qt::DisplayRole).toString().contains(searchStr, Qt::CaseInsensitive))
318 if (QString(logMsg.who.c_str()).contains(searchStr, Qt::CaseInsensitive))
323 if (QString(logMsg.tag.c_str()).contains(searchStr, Qt::CaseInsensitive))
328 if (QString(logMsg.what.c_str()).contains(searchStr, Qt::CaseInsensitive))
333 if (QString(logMsg.backtrace.c_str()).contains(searchStr, Qt::CaseInsensitive))
338 if (QString(logMsg.file.c_str()).contains(searchStr, Qt::CaseInsensitive))
343 if (QString(logMsg.function.c_str()).contains(searchStr, Qt::CaseInsensitive))
348 if (QString::number(logMsg.line).contains(searchStr, Qt::CaseInsensitive))
358 if (row < 0 || row >= (
signed int)logEntries.size())
363 const LogMessage& entry = logEntries[row];
365 if (logMsg.line != entry.line)
370 if (logMsg.who != entry.who)
375 if (logMsg.tag != entry.tag)
380 if (logMsg.what != entry.what)
385 if (logMsg.file != entry.file)
390 if (logMsg.function != entry.function)
400 activeSearchStr = searchStr;
401 QModelIndex leftTop =
index(0, 0);
402 QModelIndex rightBottom =
index(logEntries.size() - 1, 6);
404 emit dataChanged(leftTop, rightBottom);
414 if (role == Qt::DisplayRole)
416 if (orientation == Qt::Horizontal)
449 else if (role == Qt::ToolTipRole)
451 if (orientation == Qt::Horizontal)
471 return QString::fromStdString(std::string(
ARMARX_LOG_FILESTR) + std::string(
": Double click cell to open Qtcreator at that location"));
525 return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ;
529 return Qt::ItemIsSelectable | Qt::ItemIsEnabled ;
537 QModelIndex leftTop =
index(logEntries.size() - newEntryCount, 0);
538 QModelIndex rightBottom =
index(logEntries.size() - 1, 6);
540 emit dataChanged(leftTop, rightBottom);
542 maxNewLogLevelType = eUNDEFINED;
547 beginInsertRows(QModelIndex(), row, row + count - 1);
548 int newEntries = row + count - logEntries.size();
550 for (
int i = 0; i < newEntries; i++)
552 logEntries.push_back(LogMessage());
561 activeFilters.push_back(std::make_pair(columnName, filter));
568 std::unique_lock lock(logEntriesMutex);
569 std::vector < LogMessage>::iterator it = logEntries.begin();
572 for (; it != logEntries.end(); ++it)
574 const LogMessage& entry = *it;
578 beginRemoveRows(QModelIndex(), row, row);
579 it = logEntries.erase(it);
594 activeFilters.clear();
600 std::unique_lock lock(logEntriesMutex);
614 *logEntries.rbegin() = entry;
621 if (entry.type > maxNewLogLevelType)
623 maxNewLogLevelType = entry.type;
626 logEntries.push_back(entry);
639 if (entryList.size() == 0)
645 unsigned int size = entryList.size();
646 int entriesAdded = 0;
648 for (
unsigned int i = 0; i < size; i++)
655 if (entriesAdded > 0)
657 beginInsertRows(QModelIndex(), logEntries.size() - entriesAdded, logEntries.size() - 1);
668 if (columnName.empty())
673 QString qcolumnName = QString::fromStdString(columnName);
675 for (
int i = 0; i <
columnCount(QModelIndex()); i++)
677 if (
headerData(i, Qt::Horizontal, Qt::DisplayRole).toString().compare(qcolumnName) == 0)
690 beginRemoveRows(QModelIndex(), 0, logEntries.size() - 1);
691 std::unique_lock lock(logEntriesMutex);
692 size = (int)logEntries.size();
693 removeRows(0, logEntries.size() - 1);
703 return logEntries.at(row);
710 std::string columnName = filter.first;
711 QString filterStr = QString::fromStdString(filter.second);
726 if (QString(logMsg.group.c_str()).contains(filterStr, Qt::CaseSensitive))
737 if (QString(logMsg.who.c_str()).contains(filterStr, Qt::CaseInsensitive))
748 if (QString(logMsg.tag.c_str()).contains(filterStr, Qt::CaseInsensitive))
759 if (logMsg.type < QString(filterStr).
toInt())
770 if (QString(logMsg.what.c_str()).contains(filterStr, Qt::CaseInsensitive))
781 if (!QString(logMsg.file.c_str()).contains(filterStr, Qt::CaseInsensitive) && filterStr.toInt() != logMsg.line)
792 if (QString(logMsg.function.c_str()).contains(filterStr, Qt::CaseInsensitive))
812 return data(createIndex(row, column), Qt::DisplayRole).toString()
813 .contains(QString(filter.c_str()), Qt::CaseInsensitive);
819 for (
unsigned int i = 0; i < activeFilters.size(); i++)
832 for (
unsigned int i = 0; i < activeFilters.size(); i++)