diff options
author | Petr Mrázek <peterix@gmail.com> | 2019-07-02 02:09:41 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2019-07-02 02:09:41 +0200 |
commit | ee83d432f673d5263f208206e0a414f7b33bec70 (patch) | |
tree | ee795b7064e51ff0b5e0b2a56b64119c520b2217 | |
parent | 8ee11b1a8e23d20accb3e34f8f36a2a5669f772f (diff) | |
download | MultiMC-ee83d432f673d5263f208206e0a414f7b33bec70.tar MultiMC-ee83d432f673d5263f208206e0a414f7b33bec70.tar.gz MultiMC-ee83d432f673d5263f208206e0a414f7b33bec70.tar.lz MultiMC-ee83d432f673d5263f208206e0a414f7b33bec70.tar.xz MultiMC-ee83d432f673d5263f208206e0a414f7b33bec70.zip |
GH-2724 update group view geometries in more cases
Fixes crashes when adding instances to groups that didn't exist before.
-rw-r--r-- | application/groupview/GroupView.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/application/groupview/GroupView.cpp b/application/groupview/GroupView.cpp index 0157d335..625e7e5f 100644 --- a/application/groupview/GroupView.cpp +++ b/application/groupview/GroupView.cpp @@ -220,6 +220,8 @@ VisualGroup *GroupView::categoryAt(const QPoint &pos, VisualGroup::HitResults & QString GroupView::groupNameAt(const QPoint &point) { + executeDelayedItemsLayout(); + VisualGroup::HitResults hitresult; auto group = categoryAt(point + offset(), hitresult); if(group && (hitresult & (VisualGroup::HeaderHit | VisualGroup::BodyHit))) @@ -246,7 +248,7 @@ int GroupView::itemWidth() const void GroupView::mousePressEvent(QMouseEvent *event) { - // endCategoryEditor(); + executeDelayedItemsLayout(); QPoint visualPos = event->pos(); QPoint geometryPos = event->pos() + offset(); @@ -295,6 +297,8 @@ void GroupView::mousePressEvent(QMouseEvent *event) void GroupView::mouseMoveEvent(QMouseEvent *event) { + executeDelayedItemsLayout(); + QPoint topLeft; QPoint visualPos = event->pos(); QPoint geometryPos = event->pos() + offset(); @@ -351,6 +355,8 @@ void GroupView::mouseMoveEvent(QMouseEvent *event) void GroupView::mouseReleaseEvent(QMouseEvent *event) { + executeDelayedItemsLayout(); + QPoint visualPos = event->pos(); QPoint geometryPos = event->pos() + offset(); QPersistentModelIndex index = indexAt(visualPos); @@ -405,6 +411,8 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event) void GroupView::mouseDoubleClickEvent(QMouseEvent *event) { + executeDelayedItemsLayout(); + QModelIndex index = indexAt(event->pos()); if (!index.isValid() || !(index.flags() & Qt::ItemIsEnabled) || (m_pressedIndex != index)) { @@ -528,6 +536,8 @@ void GroupView::resizeEvent(QResizeEvent *event) void GroupView::dragEnterEvent(QDragEnterEvent *event) { + executeDelayedItemsLayout(); + if (!isDragEventAccepted(event)) { return; @@ -539,6 +549,8 @@ void GroupView::dragEnterEvent(QDragEnterEvent *event) void GroupView::dragMoveEvent(QDragMoveEvent *event) { + executeDelayedItemsLayout(); + if (!isDragEventAccepted(event)) { return; @@ -550,12 +562,16 @@ void GroupView::dragMoveEvent(QDragMoveEvent *event) void GroupView::dragLeaveEvent(QDragLeaveEvent *event) { + executeDelayedItemsLayout(); + m_lastDragPosition = QPoint(); viewport()->update(); } void GroupView::dropEvent(QDropEvent *event) { + executeDelayedItemsLayout(); + m_lastDragPosition = QPoint(); stopAutoScroll(); @@ -606,6 +622,8 @@ void GroupView::dropEvent(QDropEvent *event) void GroupView::startDrag(Qt::DropActions supportedActions) { + executeDelayedItemsLayout(); + QModelIndexList indexes = selectionModel()->selectedIndexes(); if(indexes.count() == 0) return; @@ -651,11 +669,15 @@ void GroupView::startDrag(Qt::DropActions supportedActions) QRect GroupView::visualRect(const QModelIndex &index) const { + const_cast<GroupView*>(this)->executeDelayedItemsLayout(); + return geometryRect(index).translated(-offset()); } QRect GroupView::geometryRect(const QModelIndex &index) const { + const_cast<GroupView*>(this)->executeDelayedItemsLayout(); + if (!index.isValid() || isIndexHidden(index) || index.column() > 0) { return QRect(); @@ -695,9 +717,10 @@ QModelIndex GroupView::indexAt(const QPoint &point) const return QModelIndex(); } -void GroupView::setSelection(const QRect &rect, - const QItemSelectionModel::SelectionFlags commands) +void GroupView::setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands) { + executeDelayedItemsLayout(); + for (int i = 0; i < model()->rowCount(); ++i) { QModelIndex index = model()->index(i, 0); @@ -732,8 +755,7 @@ QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) cons return pixmap; } -QList<QPair<QRect, QModelIndex>> GroupView::draggablePaintPairs(const QModelIndexList &indices, - QRect *r) const +QList<QPair<QRect, QModelIndex>> GroupView::draggablePaintPairs(const QModelIndexList &indices, QRect *r) const { Q_ASSERT(r); QRect &rect = *r; |