[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1425: Give message log items a sequence number so items with the s (trunk/src/gui/log)
Author: edmanm
Date: 2006-11-05 02:44:53 -0500 (Sun, 05 Nov 2006)
New Revision: 1425
Modified:
trunk/src/gui/log/logtreeitem.cpp
trunk/src/gui/log/logtreeitem.h
trunk/src/gui/log/logtreewidget.cpp
Log:
Give message log items a sequence number so items with the same timestamp
maintain the correct order relative to each other.
Modified: trunk/src/gui/log/logtreeitem.cpp
===================================================================
--- trunk/src/gui/log/logtreeitem.cpp 2006-11-05 05:21:20 UTC (rev 1424)
+++ trunk/src/gui/log/logtreeitem.cpp 2006-11-05 07:44:53 UTC (rev 1425)
@@ -26,6 +26,7 @@
*/
#include <util/string.h>
+
#include "logtreeitem.h"
#include "logtreewidget.h"
@@ -44,6 +45,10 @@
QDateTime timestamp)
: QTreeWidgetItem()
{
+ static quint32 seqnum = 0;
+
+ /* Set this message's sequence number */
+ _seqnum = seqnum++;
/* Set the item's log time */
setTimestamp(timestamp);
/* Set the item's severity and appropriate color. */
@@ -54,7 +59,7 @@
/** Returns a printable string representing the fields of this item. */
QString
-LogTreeItem::toString()
+LogTreeItem::toString() const
{
return QString("%1 [%2] %3\n").arg(text(COL_TIME))
.arg(text(COL_TYPE))
@@ -103,7 +108,7 @@
/** Returns the severity associated with this log item. */
LogEvent::Severity
-LogTreeItem::severity()
+LogTreeItem::severity() const
{
return (LogEvent::Severity)data(COL_TYPE, ROLE_TYPE).toUInt();
}
@@ -117,8 +122,41 @@
/** Returns the message for this log item. */
QString
-LogTreeItem::message()
+LogTreeItem::message() const
{
return text(COL_MESG);
}
+/** Compares <b>other</b> to this log message item based on the current sort
+ * column. */
+bool
+LogTreeItem::operator<(const QTreeWidgetItem &other) const
+{
+ LogTreeItem *that = (LogTreeItem *)&other;
+ int sortColumn = (treeWidget() ? treeWidget()->sortColumn() : COL_TIME);
+
+ switch (sortColumn) {
+ case COL_TIME:
+ /* Sort chronologically */
+ return (this->_seqnum < that->_seqnum);
+ case COL_TYPE:
+ /* Sort by severity, then chronologically */
+ if (this->severity() == that->severity()) {
+ return (this->_seqnum < that->_seqnum);
+ }
+ /* The comparison is flipped because higher severities have
+ * lower numeric values */
+ return (this->severity() > that->severity());
+ default:
+ /* Sort by message, then chronologically */
+ QString thisMessage = this->message().toLower();
+ QString thatMessage = that->message().toLower();
+
+ if (thisMessage == thatMessage) {
+ return (this->_seqnum < that->_seqnum);
+ }
+ return (thisMessage < thatMessage);
+ }
+ return QTreeWidgetItem::operator<(other);
+}
+
Modified: trunk/src/gui/log/logtreeitem.h
===================================================================
--- trunk/src/gui/log/logtreeitem.h 2006-11-05 05:21:20 UTC (rev 1424)
+++ trunk/src/gui/log/logtreeitem.h 2006-11-05 07:44:53 UTC (rev 1425)
@@ -48,15 +48,24 @@
/** Sets the item's message text. */
void setMessage(QString message);
+ /** Returns this message's sequence number. */
+ quint32 id() const { return _seqnum; }
/** Returns the timestamp for this log message. */
QDateTime timestamp() const;
/** Returns the severity associated with this log item. */
- LogEvent::Severity severity();
+ LogEvent::Severity severity() const;
/** Returns the message associated with this log item. */
- QString message();
+ QString message() const;
+
+ /** Returns a printable string representation of the item's contents.*/
+ QString toString() const;
+ /** Compares <b>other</b> to this log message item based on the current sort
+ * column and order. */
+ virtual bool operator<(const QTreeWidgetItem &other) const;
- /** Returns a printable string representation of the item's contents.*/
- QString toString();
+private:
+ quint32 _seqnum; /**< Sequence number used to disambiguate messages with
+ the same timestamp. */
};
#endif
Modified: trunk/src/gui/log/logtreewidget.cpp
===================================================================
--- trunk/src/gui/log/logtreewidget.cpp 2006-11-05 05:21:20 UTC (rev 1424)
+++ trunk/src/gui/log/logtreewidget.cpp 2006-11-05 07:44:53 UTC (rev 1425)
@@ -72,9 +72,9 @@
QList<LogTreeItem *>
LogTreeWidget::qlist_sort(QList<LogTreeItem *> inlist)
{
- QMultiMap<QDateTime, LogTreeItem *> outlist;
+ QMap<quint32, LogTreeItem *> outlist;
foreach (LogTreeItem *item, inlist) {
- outlist.insert(item->timestamp(), item);
+ outlist.insert(item->id(), item);
}
return outlist.values();
}