/***************************************************************************
- * Copyright (C) 2005-2019 by the Quassel Project *
+ * Copyright (C) 2005-2022 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
/*****************************************
* The TreeView showing the Buffers
*****************************************/
-// Please be carefull when reimplementing methods which are used to inform the view about changes to the data
-// to be on the safe side: call QTreeView's method aswell (or TreeViewTouch's)
+// Please be careful when reimplementing methods which are used to inform the view about changes to the data
+// to be on the safe side: call QTreeView's method as well (or TreeViewTouch's)
BufferView::BufferView(QWidget* parent)
: TreeViewTouch(parent)
{
QModelIndex newParent = currentIndex.sibling(currentIndex.row() - 1, 0);
if (currentIndex.row() == 0)
newParent = lastNetIndex;
- if (model()->hasChildren(newParent))
- resultingIndex = newParent.model()->index(model()->rowCount(newParent) - 1, 0, newParent);
+ if (model()->hasChildren(newParent)) {
+ // Treat an invalid QAbstractItemModel as an invalid QModelIndex
+ resultingIndex = (newParent.model() ? newParent.model()->index(model()->rowCount(newParent) - 1, 0, newParent) : QModelIndex());
+ }
else
resultingIndex = newParent;
}
else {
- if (model()->hasChildren(currentIndex))
- resultingIndex = currentIndex.model()->index(0, 0, currentIndex);
+ if (model()->hasChildren(currentIndex)) {
+ // Treat an invalid QAbstractItemModel as an invalid QModelIndex
+ resultingIndex = (currentIndex.model() ? currentIndex.model()->index(0, 0, currentIndex) : QModelIndex());
+ }
else
resultingIndex = currentIndex.sibling(currentIndex.row() + 1, 0);
}
if (!resultingIndex.isValid()) {
if (direction == Forward)
resultingIndex = model()->index(0, 0, QModelIndex());
- else
+ else {
+ // Assume model is valid
resultingIndex = lastNetIndex.model()->index(model()->rowCount(lastNetIndex) - 1, 0, lastNetIndex);
+ }
}
selectionModel()->setCurrentIndex(resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
void BufferViewDock::setLocked(bool locked)
{
if (locked) {
- setFeatures(nullptr);
+ setFeatures({});
}
else {
setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);