Commit 7c63889a authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

manage an initialIndex in ViewManager and set it to "All Albums" index

parent 36fcaa2b
......@@ -55,6 +55,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openChildView({{DataTypes::TitleRole, QStringLiteral("album1")},
{DataTypes::ArtistRole, QStringLiteral("artist1")},
{DataTypes::DatabaseIdRole, 12},
......@@ -100,6 +107,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openView(3);
QCOMPARE(openGridViewSpy.count(), 1);
......@@ -191,6 +205,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openView(3);
QCOMPARE(openGridViewSpy.count(), 1);
......@@ -278,6 +299,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openChildView({{DataTypes::TitleRole, QStringLiteral("artist1")},
{DataTypes::DatabaseIdRole, 12},
{DataTypes::ElementTypeRole, ElisaUtils::Artist}});
......@@ -323,6 +351,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openView(4);
QCOMPARE(openGridViewSpy.count(), 1);
......@@ -414,6 +449,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openView(4);
QCOMPARE(openGridViewSpy.count(), 1);
......@@ -501,6 +543,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openChildView({{DataTypes::TitleRole, QStringLiteral("genre1")},
{DataTypes::DatabaseIdRole, 12},
{DataTypes::ElementTypeRole, ElisaUtils::Genre}});
......@@ -546,6 +595,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openView(6);
QCOMPARE(openGridViewSpy.count(), 1);
......@@ -637,6 +693,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openView(6);
QCOMPARE(openGridViewSpy.count(), 1);
......@@ -724,6 +787,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openView(6);
QCOMPARE(openGridViewSpy.count(), 1);
......@@ -793,6 +863,13 @@ private Q_SLOTS:
QSignalSpy switchFilesBrowserViewSpy(&viewManager, &ViewManager::switchFilesBrowserView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openChildView({{DataTypes::TitleRole, QStringLiteral("artist1")},
{DataTypes::DatabaseIdRole, 12},
{DataTypes::ElementTypeRole, ElisaUtils::Artist}});
......@@ -874,13 +951,21 @@ private Q_SLOTS:
QSignalSpy switchContextViewSpy(&viewManager, &ViewManager::switchContextView);
QSignalSpy popOneViewSpy(&viewManager, &ViewManager::popOneView);
viewManager.setInitialIndex(0);
QCOMPARE(openGridViewSpy.count(), 0);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(switchContextViewSpy.count(), 1);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openChildView({{DataTypes::TitleRole, QStringLiteral("album1")},
{DataTypes::ArtistRole, QStringLiteral("artist1")},
{DataTypes::DatabaseIdRole, 12},
{DataTypes::ElementTypeRole, ElisaUtils::Album}});
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(switchContextViewSpy.count(), 0);
QCOMPARE(switchContextViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 0);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
......@@ -893,7 +978,7 @@ private Q_SLOTS:
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 1);
QCOMPARE(switchContextViewSpy.count(), 0);
QCOMPARE(switchContextViewSpy.count(), 1);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
......@@ -905,14 +990,14 @@ private Q_SLOTS:
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 1);
QCOMPARE(switchContextViewSpy.count(), 0);
QCOMPARE(switchContextViewSpy.count(), 1);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
viewManager.openNowPlaying();
QCOMPARE(openGridViewSpy.count(), 1);
QCOMPARE(openListViewSpy.count(), 1);
QCOMPARE(switchContextViewSpy.count(), 1);
QCOMPARE(switchContextViewSpy.count(), 2);
QCOMPARE(switchFilesBrowserViewSpy.count(), 0);
QCOMPARE(popOneViewSpy.count(), 0);
}
......
......@@ -41,6 +41,7 @@ RowLayout {
id: viewManager
viewsData: viewsData
initialIndex: 3
onOpenGridView: {
if (configurationData.expectedDepth === 1) {
......
......@@ -101,14 +101,6 @@ FocusScope {
onCurrentItemChanged: if (!ignoreCurrentItemChanges) switchView(currentIndex)
}
Connections {
target: ElisaApplication
function onInitializationDone() {
viewModeView.currentIndex = 3
}
}
Behavior on implicitWidth {
NumberAnimation {
easing.type: Easing.InOutQuad
......
......@@ -89,7 +89,9 @@ public:
ViewManager::IsFlatModel}},
};
int mViewIndex = 0;
int mViewIndex = -1;
int mInitialIndex = -1;
QList<ViewParameters> mViewParametersStack = (mViewsListData ? QList<ViewParameters>{mViewsListData->viewParameters(0)} : QList<ViewParameters>{});
......@@ -107,6 +109,11 @@ int ViewManager::viewIndex() const
return d->mViewIndex;
}
int ViewManager::initialIndex() const
{
return d->mInitialIndex;
}
ViewsListData *ViewManager::viewsData() const
{
return d->mViewsListData;
......@@ -118,11 +125,7 @@ void ViewManager::openView(int viewIndex)
{
qCDebug(orgKdeElisaViews()) << "ViewManager::openView" << viewIndex << d->mViewParametersStack.size() << d->mViewsListData;
if (!d->mViewsListData) {
return;
}
if (!d->mViewParametersStack.size()) {
if (!d->mViewsListData || d->mViewsListData->isEmpty()) {
return;
}
......@@ -132,9 +135,9 @@ void ViewManager::openView(int viewIndex)
const auto &viewParameters = d->mViewsListData->viewParameters(viewIndex);
qCDebug(orgKdeElisaViews()) << "ViewManager::openView" << "selected view";
qCDebug(orgKdeElisaViews()) << "ViewManager::openView" << "selected view" << viewIndex;
if (viewParameters != d->mViewParametersStack.back()) {
if (d->mViewParametersStack.isEmpty() || viewParameters != d->mViewParametersStack.back()) {
qCDebug(orgKdeElisaViews()) << "ViewManager::openView" << "changing view";
d->mViewIndex = viewIndex;
Q_EMIT viewIndexChanged();
......@@ -493,9 +496,29 @@ void ViewManager::setViewsData(ViewsListData *viewsData)
d->mViewsListData = viewsData;
Q_EMIT viewsDataChanged();
if (d->mViewsListData) {
d->mViewParametersStack = {d->mViewsListData->viewParameters(d->mViewIndex)};
if (d->mViewsListData && (d->mViewIndex < 0 || d->mViewIndex >= d->mViewsListData->count())) {
d->mViewIndex = d->mInitialIndex;
}
if (d->mViewsListData && d->mViewIndex >= 0 && d->mViewIndex < d->mViewsListData->count()) {
openView(d->mViewIndex);
}
}
void ViewManager::setInitialIndex(int newIndex)
{
if (d->mInitialIndex == newIndex) {
return;
}
d->mInitialIndex = newIndex;
Q_EMIT initialIndexChanged();
if (d->mViewsListData && (d->mViewIndex < 0 || d->mViewIndex >= d->mViewsListData->count())) {
d->mViewIndex = d->mInitialIndex;
}
if (d->mViewsListData && d->mViewIndex >= 0 && d->mViewIndex < d->mViewsListData->count()) {
openView(d->mViewIndex);
}
}
......
......@@ -31,6 +31,11 @@ class ELISALIB_EXPORT ViewManager : public QObject
READ viewIndex
NOTIFY viewIndexChanged)
Q_PROPERTY(int initialIndex
READ initialIndex
WRITE setInitialIndex
NOTIFY initialIndexChanged)
Q_PROPERTY(ViewsListData* viewsData READ viewsData WRITE setViewsData NOTIFY viewsDataChanged)
public:
......@@ -100,6 +105,8 @@ public:
int viewIndex() const;
int initialIndex() const;
ViewsListData* viewsData() const;
Q_SIGNALS:
......@@ -116,6 +123,8 @@ Q_SIGNALS:
void viewIndexChanged();
void initialIndexChanged();
void viewsDataChanged();
public Q_SLOTS:
......@@ -140,6 +149,8 @@ public Q_SLOTS:
void sortRoleChanged(int sortRole);
void setInitialIndex(int newIndex);
private:
void openViewFromData(const ViewParameters &viewParamaters);
......
......@@ -173,6 +173,11 @@ int ViewsListData::count() const
return d->mViewsParameters.count();
}
bool ViewsListData::isEmpty() const
{
return d->mViewsParameters.isEmpty();
}
const ViewParameters &ViewsListData::viewParameters(int index) const
{
return d->mViewsParameters[index];
......
......@@ -302,6 +302,8 @@ public:
int count() const;
bool isEmpty() const;
const ViewParameters& viewParameters(int index) const;
const QString& title(int index) const;
......
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