1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-16 03:40:16 +00:00

Scroll the selected row to the middle of the viewport.

This commit is contained in:
cc9cii 2015-05-30 18:25:43 +10:00
parent 4152086890
commit 16bf9716a3
2 changed files with 19 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include <QMenu>
#include <QContextMenuEvent>
#include <QString>
#include <QMetaObject>
#include <QtCore/qnamespace.h>
#include "../../model/doc/document.hpp"
@ -744,6 +745,10 @@ std::vector< CSMWorld::UniversalId > CSVWorld::Table::getDraggedRecords() const
return idToDrag;
}
// parent, start and end depend on the model sending the signal, in this case mProxyModel
//
// If, for example, mModel was used instead, then scrolTo() should use the index
// mProxyModel->mapFromSource(mModel->index(end, 0))
void CSVWorld::Table::rowsInsertedEvent(const QModelIndex& parent, int start, int end)
{
tableSizeUpdate();
@ -752,17 +757,29 @@ void CSVWorld::Table::rowsInsertedEvent(const QModelIndex& parent, int start, in
{
selectRow(end);
// without this delay the scroll works but goes to top for add/clone
QMetaObject::invokeMethod(this, "queuedScrollTo", Qt::QueuedConnection, Q_ARG(int, end));
if(mUnselectAfterJump)
clearSelection();
}
}
void CSVWorld::Table::queuedScrollTo(int row)
{
scrollTo(mProxyModel->index(row, 0), QAbstractItemView::PositionAtCenter);
}
void CSVWorld::Table::dataChangedEvent(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
tableSizeUpdate();
if (mAutoJump)
{
selectRow(bottomRight.row());
scrollTo(mProxyModel->index(bottomRight.row(), 0), QAbstractItemView::PositionAtCenter);
//scrollTo(bottomRight, QAbstractItemView::PositionAtCenter); // alternative
}
}
void CSVWorld::Table::jumpAfterModChanged(int state)

View File

@ -148,6 +148,8 @@ namespace CSVWorld
void dataChangedEvent(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void jumpAfterModChanged(int state);
void queuedScrollTo(int state);
};
}