Use QSharedPointer to manage TimelineViews and RoomInfoListItems

This commit is contained in:
Konstantinos Sideris 2017-05-14 16:31:59 +03:00
parent ccad3f6bd6
commit 7502f167ae
6 changed files with 7 additions and 20 deletions

View file

@ -60,7 +60,7 @@ private:
Ui::RoomList *ui; Ui::RoomList *ui;
QMap<QString, RoomInfoListItem *> rooms_; QMap<QString, QSharedPointer<RoomInfoListItem>> rooms_;
QSharedPointer<MatrixClient> client_; QSharedPointer<MatrixClient> client_;
}; };

View file

@ -73,7 +73,6 @@ public:
void addUserTextMessage(const QString &msg, int txn_id); void addUserTextMessage(const QString &msg, int txn_id);
void updatePendingMessage(int txn_id, QString event_id); void updatePendingMessage(int txn_id, QString event_id);
void scrollDown(); void scrollDown();
void clear();
public slots: public slots:
void sliderRangeChanged(int min, int max); void sliderRangeChanged(int min, int max);

View file

@ -58,7 +58,7 @@ private slots:
private: private:
QString active_room_; QString active_room_;
QMap<QString, TimelineView *> views_; QMap<QString, QSharedPointer<TimelineView>> views_;
QSharedPointer<MatrixClient> client_; QSharedPointer<MatrixClient> client_;
}; };

View file

@ -51,9 +51,6 @@ RoomList::~RoomList()
void RoomList::clear() void RoomList::clear()
{ {
for (const auto &room : rooms_)
room->deleteLater();
rooms_.clear(); rooms_.clear();
} }
@ -93,7 +90,7 @@ void RoomList::setInitialRooms(const QMap<QString, RoomState> &states)
RoomInfoListItem *room_item = new RoomInfoListItem(state, room_id, ui->scrollArea); RoomInfoListItem *room_item = new RoomInfoListItem(state, room_id, ui->scrollArea);
connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom); 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; int pos = ui->scrollVerticalLayout->count() - 1;
ui->scrollVerticalLayout->insertWidget(pos, room_item); ui->scrollVerticalLayout->insertWidget(pos, room_item);

View file

@ -49,12 +49,6 @@ TimelineView::TimelineView(const Timeline &timeline,
addEvents(timeline); addEvents(timeline);
} }
void TimelineView::clear()
{
for (const auto msg : scroll_layout_->children())
msg->deleteLater();
}
void TimelineView::sliderRangeChanged(int min, int max) void TimelineView::sliderRangeChanged(int min, int max)
{ {
Q_UNUSED(min); Q_UNUSED(min);

View file

@ -65,11 +65,8 @@ void TimelineViewManager::clearAll()
{ {
NICK_COLORS.clear(); NICK_COLORS.clear();
for (const auto &view : views_) { for (auto view : views_)
view->clear(); removeWidget(view.data());
removeWidget(view);
view->deleteLater();
}
views_.clear(); views_.clear();
} }
@ -81,7 +78,7 @@ void TimelineViewManager::initialize(const Rooms &rooms)
// Create a history view with the room events. // Create a history view with the room events.
TimelineView *view = new TimelineView(it.value().timeline(), client_, it.key()); 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. // Add the view in the widget stack.
addWidget(view); addWidget(view);
@ -124,7 +121,7 @@ void TimelineViewManager::setHistoryView(const QString &room_id)
auto widget = views_.value(room_id); auto widget = views_.value(room_id);
widget->scrollDown(); widget->scrollDown();
setCurrentWidget(widget); setCurrentWidget(widget.data());
} }
QMap<QString, QString> TimelineViewManager::NICK_COLORS; QMap<QString, QString> TimelineViewManager::NICK_COLORS;