mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Use QSharedPointer to manage TimelineViews and RoomInfoListItems
This commit is contained in:
parent
ccad3f6bd6
commit
7502f167ae
6 changed files with 7 additions and 20 deletions
|
@ -60,7 +60,7 @@ private:
|
|||
|
||||
Ui::RoomList *ui;
|
||||
|
||||
QMap<QString, RoomInfoListItem *> rooms_;
|
||||
QMap<QString, QSharedPointer<RoomInfoListItem>> rooms_;
|
||||
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
|
|
@ -73,7 +73,6 @@ public:
|
|||
void addUserTextMessage(const QString &msg, int txn_id);
|
||||
void updatePendingMessage(int txn_id, QString event_id);
|
||||
void scrollDown();
|
||||
void clear();
|
||||
|
||||
public slots:
|
||||
void sliderRangeChanged(int min, int max);
|
||||
|
|
|
@ -58,7 +58,7 @@ private slots:
|
|||
|
||||
private:
|
||||
QString active_room_;
|
||||
QMap<QString, TimelineView *> views_;
|
||||
QMap<QString, QSharedPointer<TimelineView>> views_;
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
|
||||
|
|
|
@ -51,9 +51,6 @@ RoomList::~RoomList()
|
|||
|
||||
void RoomList::clear()
|
||||
{
|
||||
for (const auto &room : rooms_)
|
||||
room->deleteLater();
|
||||
|
||||
rooms_.clear();
|
||||
}
|
||||
|
||||
|
@ -93,7 +90,7 @@ void RoomList::setInitialRooms(const QMap<QString, RoomState> &states)
|
|||
RoomInfoListItem *room_item = new RoomInfoListItem(state, room_id, ui->scrollArea);
|
||||
connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom);
|
||||
|
||||
rooms_.insert(room_id, room_item);
|
||||
rooms_.insert(room_id, QSharedPointer<RoomInfoListItem>(room_item));
|
||||
|
||||
int pos = ui->scrollVerticalLayout->count() - 1;
|
||||
ui->scrollVerticalLayout->insertWidget(pos, room_item);
|
||||
|
|
|
@ -49,12 +49,6 @@ TimelineView::TimelineView(const Timeline &timeline,
|
|||
addEvents(timeline);
|
||||
}
|
||||
|
||||
void TimelineView::clear()
|
||||
{
|
||||
for (const auto msg : scroll_layout_->children())
|
||||
msg->deleteLater();
|
||||
}
|
||||
|
||||
void TimelineView::sliderRangeChanged(int min, int max)
|
||||
{
|
||||
Q_UNUSED(min);
|
||||
|
|
|
@ -65,11 +65,8 @@ void TimelineViewManager::clearAll()
|
|||
{
|
||||
NICK_COLORS.clear();
|
||||
|
||||
for (const auto &view : views_) {
|
||||
view->clear();
|
||||
removeWidget(view);
|
||||
view->deleteLater();
|
||||
}
|
||||
for (auto view : views_)
|
||||
removeWidget(view.data());
|
||||
|
||||
views_.clear();
|
||||
}
|
||||
|
@ -81,7 +78,7 @@ void TimelineViewManager::initialize(const Rooms &rooms)
|
|||
|
||||
// Create a history view with the room events.
|
||||
TimelineView *view = new TimelineView(it.value().timeline(), client_, it.key());
|
||||
views_.insert(it.key(), view);
|
||||
views_.insert(it.key(), QSharedPointer<TimelineView>(view));
|
||||
|
||||
// Add the view in the widget stack.
|
||||
addWidget(view);
|
||||
|
@ -124,7 +121,7 @@ void TimelineViewManager::setHistoryView(const QString &room_id)
|
|||
auto widget = views_.value(room_id);
|
||||
widget->scrollDown();
|
||||
|
||||
setCurrentWidget(widget);
|
||||
setCurrentWidget(widget.data());
|
||||
}
|
||||
|
||||
QMap<QString, QString> TimelineViewManager::NICK_COLORS;
|
||||
|
|
Loading…
Reference in a new issue