Skip to content
Permalink
Browse files

GH-2724 update group view geometries in more cases

Fixes crashes when adding instances to groups that didn't exist before.
  • Loading branch information...
peterix committed Jul 2, 2019
1 parent 8ee11b1 commit ee83d432f673d5263f208206e0a414f7b33bec70
Showing with 27 additions and 5 deletions.
  1. +27 −5 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;

0 comments on commit ee83d43

Please sign in to comment.
You can’t perform that action at this time.