added new history navigation for supporting different source containers

This commit is contained in:
Luis Ángel San Martín
2014-11-26 21:33:41 +01:00
parent 6f648f6d4d
commit c2f4ab403c
4 changed files with 108 additions and 28 deletions

View File

@ -9,7 +9,7 @@ void YACReaderHistoryController::clear()
{
currentFolderNavigation = 0;
history.clear();
history.append(QModelIndex()); //root folder is always the first item
history.append(YACReaderLibrarySourceContainer(QModelIndex(),YACReaderLibrarySourceContainer::Folder)); //root folder is always the first item
emit(enabledBackward(false));
emit(enabledForward(false));
@ -41,10 +41,10 @@ void YACReaderHistoryController::forward()
emit(enabledForward(false));
}
void YACReaderHistoryController::updateHistory(const QModelIndex &mi)
void YACReaderHistoryController::updateHistory(const YACReaderLibrarySourceContainer &source)
{
//remove history from current index
if(!mi.isValid() && history.count() == 1)
if(!source.sourceModelIndex.isValid() && history.count() == 1)
return;
int numElementsToRemove = history.count() - (currentFolderNavigation+1);
@ -54,9 +54,9 @@ void YACReaderHistoryController::updateHistory(const QModelIndex &mi)
history.removeLast();
}
if(mi!=history.at(currentFolderNavigation))
if(source!=history.at(currentFolderNavigation))
{
history.append(mi);
history.append(source);
emit(enabledBackward(true));
currentFolderNavigation++;
@ -65,12 +65,44 @@ void YACReaderHistoryController::updateHistory(const QModelIndex &mi)
emit(enabledForward(false));
}
QModelIndex YACReaderHistoryController::lastIndex()
YACReaderLibrarySourceContainer YACReaderHistoryController::lastSourceContainer()
{
return history.last();
}
QModelIndex YACReaderHistoryController::currentIndex()
YACReaderLibrarySourceContainer YACReaderHistoryController::currentSourceContainer()
{
return history.at(currentFolderNavigation);
}
//------------------------------------------------------------------------------
YACReaderLibrarySourceContainer::YACReaderLibrarySourceContainer()
:sourceModelIndex(QModelIndex()),type(None)
{
}
YACReaderLibrarySourceContainer::YACReaderLibrarySourceContainer(const QModelIndex &sourceModelIndex, YACReaderLibrarySourceContainer::SourceType type)
:sourceModelIndex(sourceModelIndex),type(type)
{}
QModelIndex YACReaderLibrarySourceContainer::getSourceModelIndex() const
{
return sourceModelIndex;
}
YACReaderLibrarySourceContainer::SourceType YACReaderLibrarySourceContainer::getType() const
{
return type;
}
bool YACReaderLibrarySourceContainer::operator==(const YACReaderLibrarySourceContainer &other) const
{
return sourceModelIndex == other.sourceModelIndex && type == other.type;
}
bool YACReaderLibrarySourceContainer::operator!=(const YACReaderLibrarySourceContainer &other) const
{
return !(*this == other);
}

View File

@ -5,6 +5,35 @@
#include <QModelIndex>
class YACReaderHistoryController;
class YACReaderLibrarySourceContainer
{
public:
enum SourceType {
None,
Folder,
List
};
explicit YACReaderLibrarySourceContainer();
explicit YACReaderLibrarySourceContainer(const QModelIndex & sourceModelIndex, YACReaderLibrarySourceContainer::SourceType type);
QModelIndex getSourceModelIndex() const;
YACReaderLibrarySourceContainer::SourceType getType() const;
bool operator==(const YACReaderLibrarySourceContainer& other) const;
bool operator!=(const YACReaderLibrarySourceContainer& other) const;
protected:
QModelIndex sourceModelIndex;
YACReaderLibrarySourceContainer::SourceType type;
friend class YACReaderHistoryController;
};
Q_DECLARE_METATYPE(YACReaderLibrarySourceContainer)
class YACReaderHistoryController : public QObject
{
Q_OBJECT
@ -14,19 +43,19 @@ public:
signals:
void enabledForward(bool enabled);
void enabledBackward(bool enabled);
void modelIndexSelected(QModelIndex mi);
void modelIndexSelected(YACReaderLibrarySourceContainer);
public slots:
void clear();
void backward();
void forward();
void updateHistory(const QModelIndex & mi);
QModelIndex lastIndex();
QModelIndex currentIndex();
void updateHistory(const YACReaderLibrarySourceContainer & source);
YACReaderLibrarySourceContainer lastSourceContainer();
YACReaderLibrarySourceContainer currentSourceContainer();
protected:
int currentFolderNavigation;
QList<QModelIndex> history;
QList<YACReaderLibrarySourceContainer> history;
};

View File

@ -31,7 +31,7 @@ void YACReaderNavigationController::selectedFolder(const QModelIndex &mi)
QModelIndex modelIndex = libraryWindow->foldersModelProxy->mapToSource(mi);
//update history
libraryWindow->historyController->updateHistory(modelIndex);
libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex, YACReaderLibrarySourceContainer::Folder));
if(libraryWindow->status == LibraryWindow::Searching)
{
@ -173,7 +173,7 @@ void YACReaderNavigationController::selectedList(const QModelIndex &mi)
QModelIndex modelIndex = libraryWindow->listsModelProxy->mapToSource(mi);
//update history
libraryWindow->historyController->updateHistory(modelIndex);
libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex,YACReaderLibrarySourceContainer::List));
if(libraryWindow->status == LibraryWindow::Searching)
{
@ -195,7 +195,7 @@ void YACReaderNavigationController::reselectCurrentList()
selectedList(libraryWindow->listsView->currentIndex());
}
void YACReaderNavigationController::selectedIndexFromHistory(const QModelIndex &sourceMI)
void YACReaderNavigationController::selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer)
{
//TODO NO searching allowed, just disable backward/forward actions in searching mode
if(libraryWindow->status == LibraryWindow::Searching)
@ -206,17 +206,38 @@ void YACReaderNavigationController::selectedIndexFromHistory(const QModelIndex &
}
//TODO more info about mi is needed (folder, lists...)
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
libraryWindow->foldersView->setCurrentIndex(mi);
loadFolderInfo(sourceMI);
loadIndexFromHistory(sourceContainer);
}
void YACReaderNavigationController::loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer)
{
QModelIndex sourceMI = sourceContainer.getSourceModelIndex();
switch(sourceContainer.getType())
{
case YACReaderLibrarySourceContainer::Folder:
{
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
libraryWindow->foldersView->setCurrentIndex(mi);
loadFolderInfo(sourceMI);
break;
}
case YACReaderLibrarySourceContainer::List:
{
QModelIndex mi = libraryWindow->listsModelProxy->mapFromSource(sourceMI);
libraryWindow->listsView->scrollTo(mi,QAbstractItemView::PositionAtTop);
libraryWindow->listsView->setCurrentIndex(mi);
loadListInfo(sourceMI);
break;
}
}
}
void YACReaderNavigationController::selectSubfolder(const QModelIndex &sourceMIParent, int child)
{
QModelIndex dest = libraryWindow->foldersModel->index(child,0,sourceMIParent);
libraryWindow->foldersView->setCurrentIndex(libraryWindow->foldersModelProxy->mapFromSource(dest));
libraryWindow->historyController->updateHistory(dest);
libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(dest,YACReaderLibrarySourceContainer::Folder));
loadFolderInfo(dest);
}
@ -229,18 +250,15 @@ void YACReaderNavigationController::loadEmptyFolderInfo(const QModelIndex &model
void YACReaderNavigationController::loadPreviousStatus()
{
QModelIndex sourceMI = libraryWindow->historyController->currentIndex();
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
libraryWindow->foldersView->setCurrentIndex(mi);
loadFolderInfo(sourceMI);
YACReaderLibrarySourceContainer sourceContainer = libraryWindow->historyController->currentSourceContainer();
loadIndexFromHistory(sourceContainer);
}
void YACReaderNavigationController::setupConnections()
{
connect(libraryWindow->foldersView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedFolder(QModelIndex)));
connect(libraryWindow->listsView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedList(QModelIndex)));
connect(libraryWindow->historyController,SIGNAL(modelIndexSelected(QModelIndex)),this,SLOT(selectedIndexFromHistory(QModelIndex)));
connect(libraryWindow->historyController,SIGNAL(modelIndexSelected(YACReaderLibrarySourceContainer)),this,SLOT(selectedIndexFromHistory(YACReaderLibrarySourceContainer)));
connect(libraryWindow->emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int)));
}

View File

@ -3,7 +3,7 @@
#include <QObject>
class LibraryWindow;
class YACReaderLibrarySourceContainer;
class YACReaderNavigationController : public QObject
{
@ -23,7 +23,8 @@ public slots:
void selectedList(const QModelIndex & mi);
void reselectCurrentList();
//history navigation
void selectedIndexFromHistory(const QModelIndex & mi);
void selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer);
void loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer);
//empty subfolder
void selectSubfolder(const QModelIndex &sourceMI, int child);