mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 12:46:35 +01:00
VerticalTabs: Reject drop on last row in pinned tabs model
It seems like a weird behavior in Qt because source model receives drop on last index (in filter model) as drop on last index in source model instead of filter model and it can't make a right decision. Source model: | 1 | 2 | 3 | 4 | 5 | 6 | Filter model: | 1 | 2 | 3 | 4 | ^ Dropping here propagates to source model as drop on index 7, not 5. Let's just ignore this case to workaround it.
This commit is contained in:
parent
9eccf4fae3
commit
aa332a4ed2
@ -37,6 +37,11 @@ void TabFilterModel::setFilterPinnedTabs(bool filter)
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void TabFilterModel::setRejectDropOnLastIndex(bool reject)
|
||||
{
|
||||
m_rejectDropOnLastIndex = reject;
|
||||
}
|
||||
|
||||
bool TabFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
if (m_mode == NoFilter) {
|
||||
@ -47,3 +52,10 @@ bool TabFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePa
|
||||
return index.data(TabModel::PinnedRole).toBool() != m_filterPinnedTabs;
|
||||
}
|
||||
|
||||
bool TabFilterModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
if (m_rejectDropOnLastIndex && row == rowCount()) {
|
||||
return false;
|
||||
}
|
||||
return QSortFilterProxyModel::canDropMimeData(data, action, row, column, parent);
|
||||
}
|
||||
|
@ -30,8 +30,11 @@ public:
|
||||
|
||||
void setFilterPinnedTabs(bool pinned);
|
||||
|
||||
void setRejectDropOnLastIndex(bool reject);
|
||||
|
||||
private:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
||||
|
||||
enum Mode {
|
||||
NoFilter,
|
||||
@ -40,4 +43,5 @@ private:
|
||||
|
||||
Mode m_mode = NoFilter;
|
||||
bool m_filterPinnedTabs = false;
|
||||
bool m_rejectDropOnLastIndex = false;
|
||||
};
|
||||
|
@ -43,6 +43,7 @@ VerticalTabsWidget::VerticalTabsWidget(BrowserWindow *window)
|
||||
m_pinnedView = new TabListView(this);
|
||||
TabFilterModel *model = new TabFilterModel(m_pinnedView);
|
||||
model->setFilterPinnedTabs(false);
|
||||
model->setRejectDropOnLastIndex(true);
|
||||
model->setSourceModel(m_window->tabModel());
|
||||
m_pinnedView->setModel(model);
|
||||
m_pinnedView->setHideWhenEmpty(true);
|
||||
|
Loading…
Reference in New Issue
Block a user