[TableWidget] fix: dragging didn't work correctly, it always used row 0 instead of the dragged row.
Dieser Commit ist enthalten in:
Ursprung
bfdb2a42b2
Commit
8750930cbb
@ -1,9 +1,8 @@
|
||||
/**
|
||||
* client/src/widget/tablewidget.cpp
|
||||
* This file is part of Traintastic,
|
||||
* see <https://github.com/traintastic/traintastic>.
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2021,2023-2024 Reinder Feenstra
|
||||
* Copyright (C) 2019-2026 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -170,9 +169,13 @@ void TableWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
QTableView::mouseMoveEvent(event);
|
||||
|
||||
if(event->button() == Qt::LeftButton)
|
||||
if(!m_dragStarted && (event->buttons() & Qt::LeftButton) && (event->pos() - m_dragStartPosition).manhattanLength() >= QApplication::startDragDistance())
|
||||
{
|
||||
m_dragStartPosition = event->pos();
|
||||
if(const int row = indexAt(m_dragStartPosition).row(); row >= 0)
|
||||
{
|
||||
m_dragStarted = true;
|
||||
emit rowDragged(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,8 +183,18 @@ void TableWidget::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QTableView::mousePressEvent(event);
|
||||
|
||||
if((event->buttons() & Qt::LeftButton) && (event->pos() - m_dragStartPosition).manhattanLength() >= QApplication::startDragDistance())
|
||||
if(event->button() == Qt::LeftButton)
|
||||
{
|
||||
emit rowDragged(indexAt(m_dragStartPosition).row());
|
||||
m_dragStartPosition = event->pos();
|
||||
}
|
||||
}
|
||||
|
||||
void TableWidget::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
QTableView::mouseReleaseEvent(event);
|
||||
|
||||
if(event->button() == Qt::LeftButton)
|
||||
{
|
||||
m_dragStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
/**
|
||||
* client/src/widget/tablewidget.hpp
|
||||
* This file is part of Traintastic,
|
||||
* see <https://github.com/traintastic/traintastic>.
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2020,2023-2024 Reinder Feenstra
|
||||
* Copyright (C) 2019-2026 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -34,10 +33,12 @@ class TableWidget : public QTableView
|
||||
TableModelPtr m_model;
|
||||
int m_selectedRow = -1;
|
||||
QPoint m_dragStartPosition;
|
||||
bool m_dragStarted = false;
|
||||
bool m_fetchAll = false;
|
||||
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
|
||||
protected slots:
|
||||
void updateRegion();
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren