File indexing completed on 2024-12-01 04:37:05
0001 /* 0002 SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "teamselectdeletedroomwidget.h" 0008 #include "model/teamroomsfilterproxymodel.h" 0009 #include "model/teamroomsmodel.h" 0010 #include <KLineEditEventHandler> 0011 #include <KLocalizedString> 0012 #include <QLineEdit> 0013 #include <QListView> 0014 #include <QVBoxLayout> 0015 0016 TeamSelectDeletedRoomWidget::TeamSelectDeletedRoomWidget(QWidget *parent) 0017 : QWidget(parent) 0018 , mListView(new QListView(this)) 0019 , mSearchLineEdit(new QLineEdit(this)) 0020 , mTeamRoomsModel(new TeamRoomsModel(this)) 0021 , mTeamSelectProxyModel(new TeamRoomsFilterProxyModel(mTeamRoomsModel, this)) 0022 { 0023 auto mainLayout = new QVBoxLayout(this); 0024 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0025 mainLayout->setContentsMargins({}); 0026 0027 mSearchLineEdit->setObjectName(QStringLiteral("mSearchLineEdit")); 0028 connect(mSearchLineEdit, &QLineEdit::textChanged, this, &TeamSelectDeletedRoomWidget::slotTextChanged); 0029 0030 mainLayout->addWidget(mSearchLineEdit); 0031 0032 mSearchLineEdit->setPlaceholderText(i18n("Search room...")); 0033 mSearchLineEdit->setClearButtonEnabled(true); 0034 KLineEditEventHandler::catchReturnKey(mSearchLineEdit); 0035 0036 mListView->setObjectName(QStringLiteral("mListView")); 0037 mainLayout->addWidget(mListView); 0038 0039 mTeamRoomsModel->setIsCheckable(true); 0040 mListView->setModel(mTeamSelectProxyModel); 0041 } 0042 0043 TeamSelectDeletedRoomWidget::~TeamSelectDeletedRoomWidget() = default; 0044 0045 void TeamSelectDeletedRoomWidget::slotTextChanged(const QString &str) 0046 { 0047 mTeamSelectProxyModel->setFilterString(str); 0048 } 0049 0050 void TeamSelectDeletedRoomWidget::setTeamRooms(const QVector<TeamRoom> &rooms) 0051 { 0052 mTeamRoomsModel->setTeamRooms(rooms); 0053 } 0054 0055 QStringList TeamSelectDeletedRoomWidget::roomsId() const 0056 { 0057 QStringList lst; 0058 for (int i = 0, cnt = mTeamRoomsModel->rowCount(); i < cnt; ++i) { 0059 const QModelIndex idx = mTeamRoomsModel->index(i, 0, QModelIndex()); 0060 if (mTeamRoomsModel->data(idx, Qt::CheckStateRole).toInt() == Qt::Checked) { 0061 lst.append(mTeamRoomsModel->data(idx, TeamRoomsModel::Identifier).toString()); 0062 } 0063 } 0064 return lst; 0065 } 0066 0067 #include "moc_teamselectdeletedroomwidget.cpp"