disconnect(_bufferModel, 0, this, 0);
}
_bufferModel = bufferModel;
- connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
- this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+
+ if(bufferModel) {
+ connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+ this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+ }
}
void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
disconnect(_selectionModel, 0, this, 0);
}
_selectionModel = selectionModel;
- connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+
+ if(selectionModel) {
+ connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+ }
}
void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
}
void BufferWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
- Q_UNUSED(previous);
- QVariant variant;
-
- variant = current.data(NetworkModel::BufferIdRole);
- if(!variant.isValid())
- return;
- setCurrentBuffer(variant.value<BufferId>());
+ BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
+ BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
+ if(newBufferId != oldBufferId)
+ setCurrentBuffer(newBufferId);
}
void BufferWidget::setCurrentBuffer(BufferId bufferId) {
+ if(!bufferId.isValid()) {
+ ui.stackedWidget->setCurrentWidget(ui.page);
+ return;
+ }
+
ChatWidget *chatWidget = 0;
Buffer *buf = Client::buffer(bufferId);
if(!buf) {