1 /*
2     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "logViewWidgetItem.h"
8 
9 // Qt includes
10 
11 #include <QBrush>
12 
13 // KDE includes
14 #include "ksystemlog_debug.h"
15 
16 #include "logModeItemBuilder.h"
17 #include "logViewWidget.h"
18 
19 #include "logMode.h"
20 
LogViewWidgetItem(LogViewWidget * list,LogLine * l)21 LogViewWidgetItem::LogViewWidgetItem(LogViewWidget *list, LogLine *l)
22     : QTreeWidgetItem()
23     , mLine(l)
24 {
25     // Add this item to the LogLine, to let the LogLine initialize it
26     mLine->setItem(this);
27     list->addTopLevelItem(this);
28 }
29 
~LogViewWidgetItem()30 LogViewWidgetItem::~LogViewWidgetItem()
31 {
32     delete mLine;
33 }
34 
logLine() const35 LogLine *LogViewWidgetItem::logLine() const
36 {
37     return mLine;
38 }
39 
toggleToolTip(bool displayed)40 void LogViewWidgetItem::toggleToolTip(bool displayed)
41 {
42     if (displayed) {
43         setToolTip(columnCount() - 1, mLine->logMode()->itemBuilder()->createToolTipText(mLine));
44     } else {
45         setToolTip(columnCount() - 1, QString());
46     }
47 }
48 
operator <(const QTreeWidgetItem & other) const49 bool LogViewWidgetItem::operator<(const QTreeWidgetItem &other) const
50 {
51     const int sortedColumn = treeWidget()->sortColumn();
52 
53     // If we sort items by date (always the first column)
54     if (sortedColumn == 0) {
55         const auto &otherItem = static_cast<const LogViewWidgetItem &>(other);
56         return mLine->isOlderThan(*(otherItem.logLine()));
57     }
58     // Default sorting
59     else {
60         return text(sortedColumn) < other.text(sortedColumn);
61     }
62 }
63