X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fuisupport%2Fbufferview.cpp;h=22d55c21be4d72c80e22c98e798ddda29c99d620;hb=c8ddabf364eff2400c61cea395aefe69eb8ba1b3;hp=9711755807bdd09e31ca10e9ce565513fdaabe52;hpb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;p=quassel.git diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 97117558..22d55c21 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 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 * @@ -44,8 +44,8 @@ /***************************************** * 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) { @@ -493,14 +493,18 @@ void BufferView::changeBuffer(Direction direction) QModelIndex newParent = currentIndex.sibling(currentIndex.row() - 1, 0); if (currentIndex.row() == 0) newParent = lastNetIndex; - if (model()->hasChildren(newParent)) - resultingIndex = newParent.child(model()->rowCount(newParent) - 1, 0); + 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.child(0, 0); + 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); } @@ -509,8 +513,10 @@ void BufferView::changeBuffer(Direction direction) if (!resultingIndex.isValid()) { if (direction == Forward) resultingIndex = model()->index(0, 0, QModelIndex()); - else - resultingIndex = lastNetIndex.child(model()->rowCount(lastNetIndex) - 1, 0); + else { + // Assume model is valid + resultingIndex = lastNetIndex.model()->index(model()->rowCount(lastNetIndex) - 1, 0, lastNetIndex); + } } selectionModel()->setCurrentIndex(resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); @@ -575,24 +581,6 @@ void BufferView::filterTextChanged(const QString& filterString) on_configChanged(); // make sure collapsation is correct } -QSize BufferView::sizeHint() const -{ - return TreeViewTouch::sizeHint(); - - if (!model()) - return TreeViewTouch::sizeHint(); - - if (model()->rowCount() == 0) - return {120, 50}; - - int columnSize = 0; - for (int i = 0; i < model()->columnCount(); i++) { - if (!isColumnHidden(i)) - columnSize += sizeHintForColumn(i); - } - return {columnSize, 50}; -} - void BufferView::changeHighlight(BufferView::Direction direction) { // If for some weird reason we get a new delegate @@ -740,7 +728,7 @@ BufferViewDock::BufferViewDock(BufferViewConfig* config, QWidget* parent) void BufferViewDock::setLocked(bool locked) { if (locked) { - setFeatures(nullptr); + setFeatures({}); } else { setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);