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