Commit a7b318dd authored by Matthieu Gallien's avatar Matthieu Gallien 🎵 Committed by Nate Graham
Browse files

prefer viewIndex from ViewManager to ViewModel::indexFromViewType

clean really ugly code from ViewModel
parent a1921b02
......@@ -150,40 +150,5 @@ QModelIndex ViewsModel::parent(const QModelIndex &child) const
return result;
}
int ViewsModel::indexFromViewType(ViewManager::ViewsType type)
{
switch(type)
{
case ViewManager::Context:
return 0;
case ViewManager::RecentlyPlayedTracks:
return 1;
case ViewManager::FrequentlyPlayedTracks:
return 2;
case ViewManager::AllAlbums:
return 3;
case ViewManager::AllArtists:
return 4;
case ViewManager::AllTracks:
return 5;
case ViewManager::AllGenres:
return 6;
case ViewManager::FilesBrowser:
return 7;
case ViewManager::RadiosBrowser:
return 8;
case ViewManager::OneAlbum:
case ViewManager::OneArtist:
case ViewManager::OneAlbumFromArtist:
case ViewManager::OneArtistFromGenre:
case ViewManager::OneAlbumFromArtistAndGenre:
case ViewManager::AllArtistsFromGenre:
case ViewManager::UnknownView:
break;
}
return -1;
}
#include "moc_viewsmodel.cpp"
......@@ -55,8 +55,6 @@ public:
QModelIndex parent(const QModelIndex &child) const override;
Q_INVOKABLE int indexFromViewType(ViewManager::ViewsType type);
private:
std::unique_ptr<ViewsModelPrivate> d;
......
......@@ -52,7 +52,7 @@ RowLayout {
onOpenGridView: {
if (expectedDepth === 1) {
listViews.setCurrentIndex(pageModel.indexFromViewType(viewType))
listViews.setCurrentIndex(viewManager.viewIndex)
}
while(browseStackView.depth > expectedDepth) {
......@@ -79,7 +79,7 @@ RowLayout {
onOpenListView: {
if (expectedDepth === 1) {
listViews.setCurrentIndex(pageModel.indexFromViewType(viewType))
listViews.setCurrentIndex(viewManager.viewIndex)
}
while(browseStackView.depth > expectedDepth) {
......@@ -106,7 +106,7 @@ RowLayout {
}
onSwitchFilesBrowserView: {
listViews.setCurrentIndex(pageModel.indexFromViewType(viewType))
listViews.setCurrentIndex(viewManager.viewIndex)
while(browseStackView.depth > expectedDepth) {
browseStackView.pop()
......@@ -121,7 +121,7 @@ RowLayout {
}
onSwitchContextView: {
listViews.setCurrentIndex(pageModel.indexFromViewType(viewType))
listViews.setCurrentIndex(viewManager.viewIndex)
while(browseStackView.depth > expectedDepth) {
browseStackView.pop()
......
......@@ -270,7 +270,10 @@ public:
ViewManager::ViewShowRating}},
};
QList<ViewParameters> mViewParametersStack = {mViewsParameters[0]};
int mViewIndex = 0;
QList<ViewParameters> mViewParametersStack = {mViewsParameters[mViewIndex]};
ViewParameters mNextViewParameters;
};
......@@ -280,6 +283,11 @@ ViewManager::ViewManager(QObject *parent)
{
}
int ViewManager::viewIndex() const
{
return d->mViewIndex;
}
ViewManager::~ViewManager() = default;
void ViewManager::openView(int viewIndex)
......@@ -289,7 +297,9 @@ void ViewManager::openView(int viewIndex)
const auto &viewParameters = d->mViewsParameters[viewIndex];
if (viewParameters != d->mViewParametersStack.back()) {
d->mViewParametersStack.clear();
d->mViewIndex = viewIndex;
Q_EMIT viewIndexChanged();
d->mNextViewParameters = viewParameters;
openViewFromData(viewParameters);
}
......@@ -347,6 +357,9 @@ void ViewManager::openChildView(const QString &innerMainTitle, const QString & i
if (lastView.mDataType != dataType) {
for(int i = 0; i < d->mViewsParameters.size(); ++i) {
if (d->mViewsParameters.at(i).mDataType == dataType) {
d->mViewIndex = i;
Q_EMIT viewIndexChanged();
nextViewParameters = d->mViewsParameters.at(i);
break;
}
......
......@@ -33,6 +33,11 @@ class ViewParameters;
class ELISALIB_EXPORT ViewManager : public QObject
{
Q_OBJECT
Q_PROPERTY(int viewIndex
READ viewIndex
NOTIFY viewIndexChanged)
public:
enum ViewsType {
......@@ -113,6 +118,8 @@ public:
~ViewManager() override;
int viewIndex() const;
Q_SIGNALS:
void openGridView(ViewManager::ViewsType viewType, ElisaUtils::FilterType filterType, int expectedDepth,
......@@ -136,6 +143,8 @@ Q_SIGNALS:
void popOneView();
void viewIndexChanged();
public Q_SLOTS:
void openView(int viewIndex);
......
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