Commit 99282e9d authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

should fix the init problem due to undefined views data

parent 208172ce
......@@ -16,7 +16,7 @@
*/
#include "viewmanager.h"
#include "viewslistdata.h"
#include <QtTest>
......@@ -47,6 +47,8 @@ private Q_SLOTS:
void openAlbumViewTest()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -86,6 +88,8 @@ private Q_SLOTS:
void openAlbumView2Test()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -168,6 +172,8 @@ private Q_SLOTS:
void openAlbumView3Test()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -246,6 +252,8 @@ private Q_SLOTS:
void openArtistViewTest()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -286,6 +294,8 @@ private Q_SLOTS:
void openArtistView2Test()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -370,6 +380,8 @@ private Q_SLOTS:
void openArtistView3Test()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -450,6 +462,8 @@ private Q_SLOTS:
void openGenreViewTest()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -490,6 +504,8 @@ private Q_SLOTS:
void openGenreView2Test()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -574,6 +590,8 @@ private Q_SLOTS:
void openGenreView3Test()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -654,6 +672,8 @@ private Q_SLOTS:
void openArtistFromGenreViewTest()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......@@ -716,6 +736,8 @@ private Q_SLOTS:
void openArtistViewAndAlbumFromAnotherArtistTest()
{
ViewManager viewManager;
ViewsListData viewsData;
viewManager.setViewsData(&viewsData);
QSignalSpy openGridViewSpy(&viewManager, &ViewManager::openGridView);
QSignalSpy openListViewSpy(&viewManager, &ViewManager::openListView);
......
......@@ -50,6 +50,8 @@ RowLayout {
ViewManager {
id: viewManager
viewsData: viewsData
onOpenGridView: {
if (expectedDepth === 1) {
listViews.setCurrentIndex(viewManager.viewIndex)
......@@ -140,7 +142,11 @@ RowLayout {
ViewsModel {
id: pageModel
viewsData: viewManager.viewsListData
viewsData: viewsData
}
ViewsListData {
id: viewsData
}
ViewSelector {
......
......@@ -26,7 +26,7 @@
class ViewManagerPrivate
{
public:
ViewsListData mViewsListData;
ViewsListData *mViewsListData = nullptr;
QMap<ElisaUtils::PlayListEntryType, ViewParameters> mChildViews = {
{ElisaUtils::Album, {{},
......@@ -59,7 +59,7 @@ public:
int mViewIndex = 0;
QList<ViewParameters> mViewParametersStack = {mViewsListData.viewParameters(0)};
QList<ViewParameters> mViewParametersStack = (mViewsListData ? QList<ViewParameters>{mViewsListData->viewParameters(0)} : QList<ViewParameters>{});
ViewParameters mNextViewParameters;
};
......@@ -77,16 +77,24 @@ int ViewManager::viewIndex() const
ViewsListData *ViewManager::viewsData() const
{
return &d->mViewsListData;
return d->mViewsListData;
}
ViewManager::~ViewManager() = default;
void ViewManager::openView(int viewIndex)
{
if (!d->mViewsListData) {
return;
}
if (!d->mViewParametersStack.size()) {
return;
}
qCDebug(orgKdeElisaViews()) << "ViewManager::openView" << viewIndex << d->mViewParametersStack.size();
const auto &viewParameters = d->mViewsListData.viewParameters(viewIndex);
const auto &viewParameters = d->mViewsListData->viewParameters(viewIndex);
if (viewParameters != d->mViewParametersStack.back()) {
d->mViewIndex = viewIndex;
......@@ -104,6 +112,10 @@ void ViewManager::openChildView(const QString &innerMainTitle, const QString & i
qCDebug(orgKdeElisaViews()) << "ViewManager::openChildView" << innerMainTitle << innerSecondaryTitle
<< innerImage << databaseId << dataType << d->mViewParametersStack.size();
if (!d->mViewParametersStack.size()) {
return;
}
const auto &lastView = d->mViewParametersStack.back();
auto nextViewParameters = d->mChildViews[dataType];
......@@ -142,12 +154,12 @@ void ViewManager::openChildView(const QString &innerMainTitle, const QString & i
d->mNextViewParameters = nextViewParameters;
if (lastView.mDataType != dataType) {
for(int i = 0; i < d->mViewsListData.count(); ++i) {
if (d->mViewsListData.viewParameters(i).mDataType == dataType) {
for(int i = 0; i < d->mViewsListData->count(); ++i) {
if (d->mViewsListData->viewParameters(i).mDataType == dataType) {
d->mViewIndex = i;
Q_EMIT viewIndexChanged();
nextViewParameters = d->mViewsListData.viewParameters(i);
nextViewParameters = d->mViewsListData->viewParameters(i);
break;
}
}
......@@ -165,6 +177,10 @@ void ViewManager::viewIsLoaded()
{
qCDebug(orgKdeElisaViews()) << "ViewManager::viewIsLoaded" << d->mViewParametersStack.size();
if (!d->mViewParametersStack.size()) {
return;
}
if (d->mNextViewParameters.mIsValid && d->mNextViewParameters != d->mViewParametersStack.back()) {
openViewFromData(d->mNextViewParameters);
}
......@@ -226,6 +242,9 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
void ViewManager::goBack()
{
qCDebug(orgKdeElisaViews()) << "ViewManager::goBack" << d->mViewParametersStack.size();
if (d->mViewParametersStack.size() <= 1) {
return;
}
Q_EMIT popOneView();
d->mViewParametersStack.pop_back();
......@@ -234,7 +253,16 @@ void ViewManager::goBack()
void ViewManager::setViewsData(ViewsListData *viewsData)
{
Q_UNUSED(viewsData)
if (d->mViewsListData == viewsData) {
return;
}
d->mViewsListData = viewsData;
Q_EMIT viewsDataChanged();
if (d->mViewsListData) {
d->mViewParametersStack = {d->mViewsListData->viewParameters(d->mViewIndex)};
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment