forked from qt-creator/qt-creator
Axivion: Fix sort toggling glitches
The resize handle of a header has some margin to decide whether to start a resize attempt. This margin interfered with our randomly chosen one. Take the needed margin into account and beside this store an additional information about the column that triggered our sort toggling attempt. This avoids starting to toggle some column and moving slightly to the next one and ending up in sorting the final column of the move. Change-Id: I8199f90fd06145c61d2c5e7574b6f040c72022b6 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -61,8 +61,10 @@ void IssueHeaderView::mousePressEvent(QMouseEvent *event)
|
|||||||
if (y > 1 && y < height() - 2) { // TODO improve
|
if (y > 1 && y < height() - 2) { // TODO improve
|
||||||
const int pos = position.x();
|
const int pos = position.x();
|
||||||
const int logical = logicalIndexAt(pos);
|
const int logical = logicalIndexAt(pos);
|
||||||
const int end = sectionViewportPosition(logical) + sectionSize(logical);
|
m_lastToggleLogicalPos = logical;
|
||||||
const int start = end - ICON_SIZE - 2;
|
const int margin = style()->pixelMetric(QStyle::PM_HeaderGripMargin, nullptr, this);
|
||||||
|
const int end = sectionViewportPosition(logical) + sectionSize(logical) - margin;
|
||||||
|
const int start = end - ICON_SIZE;
|
||||||
m_maybeToggleSort = start < pos && end > pos;
|
m_maybeToggleSort = start < pos && end > pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +81,8 @@ void IssueHeaderView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
const QPoint position = event->position().toPoint();
|
const QPoint position = event->position().toPoint();
|
||||||
const int y = position.y();
|
const int y = position.y();
|
||||||
const int logical = logicalIndexAt(position.x());
|
const int logical = logicalIndexAt(position.x());
|
||||||
if (logical > -1 && logical < m_sortableColumns.size()) {
|
if (logical == m_lastToggleLogicalPos
|
||||||
|
&& logical > -1 && logical < m_sortableColumns.size()) {
|
||||||
if (m_sortableColumns.at(logical)) { // ignore non-sortable
|
if (m_sortableColumns.at(logical)) { // ignore non-sortable
|
||||||
if (y < height() / 2) // TODO improve
|
if (y < height() / 2) // TODO improve
|
||||||
onToggleSort(logical, SortOrder::Ascending);
|
onToggleSort(logical, SortOrder::Ascending);
|
||||||
@@ -88,6 +91,7 @@ void IssueHeaderView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_lastToggleLogicalPos = -1;
|
||||||
QHeaderView::mouseReleaseEvent(event);
|
QHeaderView::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +122,10 @@ QSize IssueHeaderView::sectionSizeFromContents(int logicalIndex) const
|
|||||||
const QSize oldSize = QHeaderView::sectionSizeFromContents(logicalIndex);
|
const QSize oldSize = QHeaderView::sectionSizeFromContents(logicalIndex);
|
||||||
const QSize newSize = logicalIndex < m_columnWidths.size()
|
const QSize newSize = logicalIndex < m_columnWidths.size()
|
||||||
? QSize(qMax(m_columnWidths.at(logicalIndex), oldSize.width()), oldSize.height()) : oldSize;
|
? QSize(qMax(m_columnWidths.at(logicalIndex), oldSize.width()), oldSize.height()) : oldSize;
|
||||||
// add icon size and margin (2)
|
|
||||||
return QSize{newSize.width() + ICON_SIZE + 2, qMax(newSize.height(), ICON_SIZE)};
|
const int margin = style()->pixelMetric(QStyle::PM_HeaderGripMargin, nullptr, this);
|
||||||
|
// add icon size and margin (default resize handle margin + 1)
|
||||||
|
return QSize{newSize.width() + ICON_SIZE + margin, qMax(newSize.height(), ICON_SIZE)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void IssueHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
|
void IssueHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
|
||||||
@@ -132,9 +138,10 @@ void IssueHeaderView::paintSection(QPainter *painter, const QRect &rect, int log
|
|||||||
if (!m_sortableColumns.at(logicalIndex))
|
if (!m_sortableColumns.at(logicalIndex))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const int margin = style()->pixelMetric(QStyle::PM_HeaderGripMargin, nullptr, this);
|
||||||
const QIcon icon = iconForSorted(logicalIndex == m_currentSortIndex ? m_currentSortOrder : SortOrder::None);
|
const QIcon icon = iconForSorted(logicalIndex == m_currentSortIndex ? m_currentSortOrder : SortOrder::None);
|
||||||
const int offset = qMax((rect.height() - ICON_SIZE), 0) / 2;
|
const int offset = qMax((rect.height() - ICON_SIZE), 0) / 2;
|
||||||
const QRect iconRect(rect.left() + rect.width() - ICON_SIZE - 2, offset, ICON_SIZE, ICON_SIZE);
|
const QRect iconRect(rect.left() + rect.width() - ICON_SIZE - margin, offset, ICON_SIZE, ICON_SIZE);
|
||||||
icon.paint(painter, iconRect);
|
icon.paint(painter, iconRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ private:
|
|||||||
void onToggleSort(int index, SortOrder order);
|
void onToggleSort(int index, SortOrder order);
|
||||||
bool m_dragging = false;
|
bool m_dragging = false;
|
||||||
bool m_maybeToggleSort = false;
|
bool m_maybeToggleSort = false;
|
||||||
|
int m_lastToggleLogicalPos = -1;
|
||||||
int m_currentSortIndex = -1;
|
int m_currentSortIndex = -1;
|
||||||
SortOrder m_currentSortOrder = SortOrder::None;
|
SortOrder m_currentSortOrder = SortOrder::None;
|
||||||
QList<bool> m_sortableColumns;
|
QList<bool> m_sortableColumns;
|
||||||
|
Reference in New Issue
Block a user