GH-2724 update group view geometries in more cases

Fixes crashes when adding instances to groups that didn't exist before.
This commit is contained in:
Petr Mrázek 2019-07-02 02:09:41 +02:00
parent 8ee11b1a8e
commit ee83d432f6

View File

@ -220,6 +220,8 @@ VisualGroup *GroupView::categoryAt(const QPoint &pos, VisualGroup::HitResults &
QString GroupView::groupNameAt(const QPoint &point) QString GroupView::groupNameAt(const QPoint &point)
{ {
executeDelayedItemsLayout();
VisualGroup::HitResults hitresult; VisualGroup::HitResults hitresult;
auto group = categoryAt(point + offset(), hitresult); auto group = categoryAt(point + offset(), hitresult);
if(group && (hitresult & (VisualGroup::HeaderHit | VisualGroup::BodyHit))) if(group && (hitresult & (VisualGroup::HeaderHit | VisualGroup::BodyHit)))
@ -246,7 +248,7 @@ int GroupView::itemWidth() const
void GroupView::mousePressEvent(QMouseEvent *event) void GroupView::mousePressEvent(QMouseEvent *event)
{ {
// endCategoryEditor(); executeDelayedItemsLayout();
QPoint visualPos = event->pos(); QPoint visualPos = event->pos();
QPoint geometryPos = event->pos() + offset(); QPoint geometryPos = event->pos() + offset();
@ -295,6 +297,8 @@ void GroupView::mousePressEvent(QMouseEvent *event)
void GroupView::mouseMoveEvent(QMouseEvent *event) void GroupView::mouseMoveEvent(QMouseEvent *event)
{ {
executeDelayedItemsLayout();
QPoint topLeft; QPoint topLeft;
QPoint visualPos = event->pos(); QPoint visualPos = event->pos();
QPoint geometryPos = event->pos() + offset(); QPoint geometryPos = event->pos() + offset();
@ -351,6 +355,8 @@ void GroupView::mouseMoveEvent(QMouseEvent *event)
void GroupView::mouseReleaseEvent(QMouseEvent *event) void GroupView::mouseReleaseEvent(QMouseEvent *event)
{ {
executeDelayedItemsLayout();
QPoint visualPos = event->pos(); QPoint visualPos = event->pos();
QPoint geometryPos = event->pos() + offset(); QPoint geometryPos = event->pos() + offset();
QPersistentModelIndex index = indexAt(visualPos); QPersistentModelIndex index = indexAt(visualPos);
@ -405,6 +411,8 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event)
void GroupView::mouseDoubleClickEvent(QMouseEvent *event) void GroupView::mouseDoubleClickEvent(QMouseEvent *event)
{ {
executeDelayedItemsLayout();
QModelIndex index = indexAt(event->pos()); QModelIndex index = indexAt(event->pos());
if (!index.isValid() || !(index.flags() & Qt::ItemIsEnabled) || (m_pressedIndex != index)) if (!index.isValid() || !(index.flags() & Qt::ItemIsEnabled) || (m_pressedIndex != index))
{ {
@ -528,6 +536,8 @@ void GroupView::resizeEvent(QResizeEvent *event)
void GroupView::dragEnterEvent(QDragEnterEvent *event) void GroupView::dragEnterEvent(QDragEnterEvent *event)
{ {
executeDelayedItemsLayout();
if (!isDragEventAccepted(event)) if (!isDragEventAccepted(event))
{ {
return; return;
@ -539,6 +549,8 @@ void GroupView::dragEnterEvent(QDragEnterEvent *event)
void GroupView::dragMoveEvent(QDragMoveEvent *event) void GroupView::dragMoveEvent(QDragMoveEvent *event)
{ {
executeDelayedItemsLayout();
if (!isDragEventAccepted(event)) if (!isDragEventAccepted(event))
{ {
return; return;
@ -550,12 +562,16 @@ void GroupView::dragMoveEvent(QDragMoveEvent *event)
void GroupView::dragLeaveEvent(QDragLeaveEvent *event) void GroupView::dragLeaveEvent(QDragLeaveEvent *event)
{ {
executeDelayedItemsLayout();
m_lastDragPosition = QPoint(); m_lastDragPosition = QPoint();
viewport()->update(); viewport()->update();
} }
void GroupView::dropEvent(QDropEvent *event) void GroupView::dropEvent(QDropEvent *event)
{ {
executeDelayedItemsLayout();
m_lastDragPosition = QPoint(); m_lastDragPosition = QPoint();
stopAutoScroll(); stopAutoScroll();
@ -606,6 +622,8 @@ void GroupView::dropEvent(QDropEvent *event)
void GroupView::startDrag(Qt::DropActions supportedActions) void GroupView::startDrag(Qt::DropActions supportedActions)
{ {
executeDelayedItemsLayout();
QModelIndexList indexes = selectionModel()->selectedIndexes(); QModelIndexList indexes = selectionModel()->selectedIndexes();
if(indexes.count() == 0) if(indexes.count() == 0)
return; return;
@ -651,11 +669,15 @@ void GroupView::startDrag(Qt::DropActions supportedActions)
QRect GroupView::visualRect(const QModelIndex &index) const QRect GroupView::visualRect(const QModelIndex &index) const
{ {
const_cast<GroupView*>(this)->executeDelayedItemsLayout();
return geometryRect(index).translated(-offset()); return geometryRect(index).translated(-offset());
} }
QRect GroupView::geometryRect(const QModelIndex &index) const QRect GroupView::geometryRect(const QModelIndex &index) const
{ {
const_cast<GroupView*>(this)->executeDelayedItemsLayout();
if (!index.isValid() || isIndexHidden(index) || index.column() > 0) if (!index.isValid() || isIndexHidden(index) || index.column() > 0)
{ {
return QRect(); return QRect();
@ -695,9 +717,10 @@ QModelIndex GroupView::indexAt(const QPoint &point) const
return QModelIndex(); return QModelIndex();
} }
void GroupView::setSelection(const QRect &rect, void GroupView::setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands)
const QItemSelectionModel::SelectionFlags commands)
{ {
executeDelayedItemsLayout();
for (int i = 0; i < model()->rowCount(); ++i) for (int i = 0; i < model()->rowCount(); ++i)
{ {
QModelIndex index = model()->index(i, 0); QModelIndex index = model()->index(i, 0);
@ -732,8 +755,7 @@ QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) cons
return pixmap; return pixmap;
} }
QList<QPair<QRect, QModelIndex>> GroupView::draggablePaintPairs(const QModelIndexList &indices, QList<QPair<QRect, QModelIndex>> GroupView::draggablePaintPairs(const QModelIndexList &indices, QRect *r) const
QRect *r) const
{ {
Q_ASSERT(r); Q_ASSERT(r);
QRect &rect = *r; QRect &rect = *r;