@@ -83,6 +83,8 @@ QVariant TreeItem::data(int role) const
|
|||||||
if (std::holds_alternative<NeoChatRoomType::Types>(m_treeData)) {
|
if (std::holds_alternative<NeoChatRoomType::Types>(m_treeData)) {
|
||||||
const auto row = this->row();
|
const auto row = this->row();
|
||||||
switch (role) {
|
switch (role) {
|
||||||
|
case RoomTreeModel::IsCategoryRole:
|
||||||
|
return true;
|
||||||
case RoomTreeModel::DisplayNameRole:
|
case RoomTreeModel::DisplayNameRole:
|
||||||
return NeoChatRoomType::typeName(row);
|
return NeoChatRoomType::typeName(row);
|
||||||
case RoomTreeModel::DelegateTypeRole:
|
case RoomTreeModel::DelegateTypeRole:
|
||||||
@@ -105,6 +107,8 @@ QVariant TreeItem::data(int role) const
|
|||||||
const auto room = std::get<NeoChatRoom *>(m_treeData);
|
const auto room = std::get<NeoChatRoom *>(m_treeData);
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
|
case RoomTreeModel::IsCategoryRole:
|
||||||
|
return false;
|
||||||
case RoomTreeModel::DisplayNameRole:
|
case RoomTreeModel::DisplayNameRole:
|
||||||
return room->displayName();
|
return room->displayName();
|
||||||
case RoomTreeModel::AvatarRole:
|
case RoomTreeModel::AvatarRole:
|
||||||
@@ -187,7 +191,7 @@ RoomTreeModel::RoomTreeModel(QObject *parent)
|
|||||||
|
|
||||||
void RoomTreeModel::initializeCategories()
|
void RoomTreeModel::initializeCategories()
|
||||||
{
|
{
|
||||||
m_rootItem.reset(new TreeItem(nullptr));
|
m_rootItem.reset(new TreeItem(nullptr, nullptr));
|
||||||
for (int i = 0; i < NeoChatRoomType::TypesCount; i++) {
|
for (int i = 0; i < NeoChatRoomType::TypesCount; i++) {
|
||||||
m_rootItem->appendChild(std::make_unique<TreeItem>(NeoChatRoomType::Types(i), m_rootItem.get()));
|
m_rootItem->appendChild(std::make_unique<TreeItem>(NeoChatRoomType::Types(i), m_rootItem.get()));
|
||||||
}
|
}
|
||||||
@@ -239,8 +243,7 @@ void RoomTreeModel::newRoom(Room *r)
|
|||||||
|
|
||||||
auto categoryItem = m_rootItem->child(type);
|
auto categoryItem = m_rootItem->child(type);
|
||||||
beginInsertRows(index(type, 0), categoryItem->childCount(), categoryItem->childCount());
|
beginInsertRows(index(type, 0), categoryItem->childCount(), categoryItem->childCount());
|
||||||
categoryItem->appendChild(std::make_unique<TreeItem>(room));
|
categoryItem->appendChild(std::make_unique<TreeItem>(room, categoryItem));
|
||||||
qWarning() << "append" << index(type, 0) << categoryItem->childCount();
|
|
||||||
connectRoomSignals(room);
|
connectRoomSignals(room);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
@@ -299,17 +302,22 @@ void RoomTreeModel::moveRoom(Quotient::Room *room)
|
|||||||
auto newParentItem = getItem(newParent);
|
auto newParentItem = getItem(newParent);
|
||||||
Q_ASSERT(newParentItem);
|
Q_ASSERT(newParentItem);
|
||||||
|
|
||||||
|
qWarning() << "Moving" << room << "from" << oldType << "row" << oldRow << "to" << newType << "row" << newParentItem->childCount();
|
||||||
|
|
||||||
// HACK: We're doing this as a remove then insert because moving doesn't work
|
// HACK: We're doing this as a remove then insert because moving doesn't work
|
||||||
// properly with DelegateChooser for whatever reason.
|
// properly with DelegateChooser for whatever reason.
|
||||||
|
|
||||||
|
Q_ASSERT(checkIndex(index(oldRow, 0, oldParent), QAbstractItemModel::CheckIndexOption::IndexIsValid));
|
||||||
beginRemoveRows(oldParent, oldRow, oldRow);
|
beginRemoveRows(oldParent, oldRow, oldRow);
|
||||||
const bool success = oldParentItem->removeChildren(oldRow, 1);
|
const bool success = oldParentItem->removeChildren(oldRow, 1);
|
||||||
Q_ASSERT(success);
|
Q_ASSERT(success);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
beginInsertRows(newParent, newParentItem->childCount(), newParentItem->childCount());
|
beginInsertRows(newParent, newParentItem->childCount(), newParentItem->childCount());
|
||||||
newParentItem->appendChild(std::make_unique<TreeItem>(neochatRoom));
|
newParentItem->appendChild(std::make_unique<TreeItem>(neochatRoom, newParentItem));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
// Q_ASSERT(checkIndex(index(newParentItem->childCount() - 1, 0, newParent), QAbstractItemModel::CheckIndexOption::IndexIsValid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomTreeModel::connectRoomSignals(NeoChatRoom *room)
|
void RoomTreeModel::connectRoomSignals(NeoChatRoom *room)
|
||||||
@@ -358,8 +366,8 @@ NeoChatConnection *RoomTreeModel::connection() const
|
|||||||
|
|
||||||
int RoomTreeModel::columnCount(const QModelIndex &parent) const
|
int RoomTreeModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
const TreeItem *parentItem = getItem(parent);
|
||||||
return 1;
|
return parentItem ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RoomTreeModel::rowCount(const QModelIndex &parent) const
|
int RoomTreeModel::rowCount(const QModelIndex &parent) const
|
||||||
@@ -370,17 +378,15 @@ int RoomTreeModel::rowCount(const QModelIndex &parent) const
|
|||||||
|
|
||||||
QModelIndex RoomTreeModel::parent(const QModelIndex &index) const
|
QModelIndex RoomTreeModel::parent(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
qWarning() << "getting parent from" << index;
|
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem *childItem = getItem(index);
|
TreeItem *childItem = getItem(index);
|
||||||
TreeItem *parentItem = childItem ? childItem->parentItem() : nullptr;
|
Q_ASSERT(childItem);
|
||||||
|
TreeItem *parentItem = childItem->parentItem();
|
||||||
|
|
||||||
qWarning() << parentItem << m_rootItem.get();
|
return parentItem != m_rootItem.get() ? createIndex(parentItem->row(), 0, parentItem) : QModelIndex{};
|
||||||
|
|
||||||
return (parentItem != m_rootItem.get() && parentItem != nullptr) ? createIndex(parentItem->row(), 0, parentItem) : QModelIndex{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex RoomTreeModel::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex RoomTreeModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
@@ -426,7 +432,11 @@ QHash<int, QByteArray> RoomTreeModel::roleNames() const
|
|||||||
// TODO room type changes
|
// TODO room type changes
|
||||||
QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
|
QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid));
|
if (!checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid)) {
|
||||||
|
qWarning() << index.row() << rowCount(index.parent());
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
return getItem(index)->data(role);
|
return getItem(index)->data(role);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class TreeItem
|
|||||||
public:
|
public:
|
||||||
using TreeData = std::variant<NeoChatRoom *, NeoChatRoomType::Types>;
|
using TreeData = std::variant<NeoChatRoom *, NeoChatRoomType::Types>;
|
||||||
|
|
||||||
explicit TreeItem(TreeData data, TreeItem *parentItem = nullptr);
|
explicit TreeItem(TreeData data, TreeItem *parentItem);
|
||||||
|
|
||||||
TreeItem *child(int row);
|
TreeItem *child(int row);
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
@@ -74,6 +74,7 @@ public:
|
|||||||
IconRole,
|
IconRole,
|
||||||
AttentionRole, /**< Whether there are any notifications. */
|
AttentionRole, /**< Whether there are any notifications. */
|
||||||
FavouriteRole, /**< Whether the room is favourited. */
|
FavouriteRole, /**< Whether the room is favourited. */
|
||||||
|
IsCategoryRole, /**< Whether the item in the model is a category */
|
||||||
};
|
};
|
||||||
Q_ENUM(EventRoles)
|
Q_ENUM(EventRoles)
|
||||||
explicit RoomTreeModel(QObject *parent = nullptr);
|
explicit RoomTreeModel(QObject *parent = nullptr);
|
||||||
|
|||||||
@@ -119,20 +119,26 @@ QString SortFilterRoomTreeModel::filterText() const
|
|||||||
|
|
||||||
bool SortFilterRoomTreeModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
bool SortFilterRoomTreeModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||||
{
|
{
|
||||||
|
// root node
|
||||||
if (!source_parent.isValid()) {
|
if (!source_parent.isValid()) {
|
||||||
if (sourceModel()->data(sourceModel()->index(source_row, 0), RoomTreeModel::CategoryRole).toInt() == NeoChatRoomType::Search
|
return true;
|
||||||
&& NeoChatConfig::collapsed()) {
|
}
|
||||||
|
|
||||||
|
const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
||||||
|
if (!index.isValid()) {
|
||||||
|
qWarning() << source_row << source_parent << sourceModel()->rowCount(source_parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceModel()->data(index, RoomTreeModel::IsCategoryRole).toBool()) {
|
||||||
|
if (sourceModel()->data(index, RoomTreeModel::CategoryRole).toInt() == NeoChatRoomType::Search && NeoChatConfig::collapsed()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (sourceModel()->data(sourceModel()->index(source_row, 0), RoomTreeModel::CategoryRole).toInt() == NeoChatRoomType::AddDirect
|
if (sourceModel()->data(index, RoomTreeModel::CategoryRole).toInt() == NeoChatRoomType::AddDirect && m_mode == DirectChats) {
|
||||||
&& m_mode == DirectChats) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
|
||||||
|
|
||||||
bool acceptRoom = sourceModel()->data(index, RoomTreeModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive)
|
bool acceptRoom = sourceModel()->data(index, RoomTreeModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive)
|
||||||
&& sourceModel()->data(index, RoomTreeModel::IsSpaceRole).toBool() == false;
|
&& sourceModel()->data(index, RoomTreeModel::IsSpaceRole).toBool() == false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user