XPlor/xtreewidgetitem.cpp

43 lines
1.3 KiB
C++
Raw Normal View History

2025-02-14 16:06:27 -05:00
#include "xtreewidgetitem.h"
XTreeWidgetItem::XTreeWidgetItem(QTreeWidget *parent, bool group)
: QTreeWidgetItem(parent), isGroup(group) {
}
XTreeWidgetItem::XTreeWidgetItem(QTreeWidgetItem *parent, bool group)
: QTreeWidgetItem(parent), isGroup(group) {
}
bool XTreeWidgetItem::operator<(const QTreeWidgetItem &other) const {
// Attempt to cast the other item to our custom type.
const XTreeWidgetItem* otherItem = dynamic_cast<const XTreeWidgetItem*>(&other);
if (otherItem) {
2025-02-19 19:17:31 -05:00
bool thisIsGroup = this->childCount() > 0;
bool otherIsGroup = otherItem->childCount() > 0;
if (thisIsGroup != otherIsGroup) {
return otherIsGroup; // Groups should come before non-groups
}
2025-02-14 16:06:27 -05:00
}
// Fallback to the default string comparison on the current sort column.
2025-02-19 19:17:31 -05:00
return QTreeWidgetItem::operator<(other);
2025-02-14 16:06:27 -05:00
}
2025-02-19 19:17:31 -05:00
2025-02-14 16:06:27 -05:00
XTreeWidgetItem& XTreeWidgetItem::operator=(const XTreeWidgetItem &other)
{
if (this != &other) {
// Copy text and icon for each column.
const int colCount = other.columnCount();
for (int i = 0; i < colCount; ++i) {
setText(i, other.text(i));
setIcon(i, other.icon(i));
}
// Copy custom members.
this->isGroup = other.isGroup;
}
return *this;
}