fix crashes after ListView navigation
This commit is contained in:
parent
db5d289edc
commit
dac45a9f7f
2 changed files with 16 additions and 4 deletions
|
|
@ -88,6 +88,8 @@ FocusController::FocusController(QQmlApplicationEngine* engine, QObject *parent)
|
|||
|
||||
void FocusController::nextItem(Direction direction)
|
||||
{
|
||||
reload(direction);
|
||||
|
||||
if (m_lvfc) {
|
||||
direction == Direction::Forward ? focusNextListViewItem() : focusPreviousListViewItem();
|
||||
qDebug() << "===>> [handling the ListView]";
|
||||
|
|
@ -95,15 +97,13 @@ void FocusController::nextItem(Direction direction)
|
|||
return;
|
||||
}
|
||||
|
||||
reload(direction);
|
||||
|
||||
if(m_focusChain.empty()) {
|
||||
qWarning() << "There are no items to navigate";
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_focusedItemIndex == (m_focusChain.size() - 1)) {
|
||||
qDebug() << "Last focus index. Making it zero";
|
||||
qDebug() << "Last focus index. Making it zero...";
|
||||
m_focusedItemIndex = 0;
|
||||
} else {
|
||||
qDebug() << "Incrementing focus index";
|
||||
|
|
@ -232,6 +232,7 @@ void FocusController::reload(Direction direction)
|
|||
qCritical() << "No ROOT OBJECT found!";
|
||||
m_focusedItemIndex = -1;
|
||||
resetRootObject();
|
||||
resetListView();
|
||||
setFocusOnDefaultItem();
|
||||
return;
|
||||
}
|
||||
|
|
@ -246,6 +247,7 @@ void FocusController::reload(Direction direction)
|
|||
qWarning() << "Focus chain is empty!";
|
||||
m_focusedItemIndex = -1;
|
||||
resetRootObject();
|
||||
resetListView();
|
||||
setFocusOnDefaultItem();
|
||||
return;
|
||||
}
|
||||
|
|
@ -254,11 +256,20 @@ void FocusController::reload(Direction direction)
|
|||
|
||||
if(m_focusedItemIndex == -1) {
|
||||
qInfo() << "No focus item in chain.";
|
||||
resetListView();
|
||||
setFocusOnDefaultItem();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void FocusController::resetListView()
|
||||
{
|
||||
if(m_lvfc) {
|
||||
delete m_lvfc;
|
||||
m_lvfc = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void FocusController::pushRootObject(QObject* object)
|
||||
{
|
||||
m_rootObjects.push(object);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ private:
|
|||
void focusNextListViewItem();
|
||||
void focusPreviousListViewItem();
|
||||
void reload(Direction direction);
|
||||
void resetListView();
|
||||
|
||||
QSharedPointer<QQmlApplicationEngine> m_engine; // Pointer to engine to get root object
|
||||
QList<QObject*> m_focusChain; // List of current objects to be focused
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue