removed loadCovers and reloadCovers methods

This commit is contained in:
Luis Ángel San Martín 2014-11-20 21:39:10 +01:00
parent bb852f6451
commit 58765649c2
8 changed files with 66 additions and 132 deletions

View File

@ -107,6 +107,8 @@ void ClassicComicsView::setModel(ComicModel *model)
connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(removeItemsFromFlow(QModelIndex,int,int)),Qt::UniqueConnection); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(removeItemsFromFlow(QModelIndex,int,int)),Qt::UniqueConnection);
tableView->setModel(model); tableView->setModel(model);
if(model->rowCount()>0)
tableView->setCurrentIndex(model->index(0,0));
tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000

View File

@ -598,7 +598,7 @@ qint64 ComicModel::asignNumbers(QList<QModelIndex> list,int startingNumber)
db.close(); db.close();
QSqlDatabase::removeDatabase(_databasePath); QSqlDatabase::removeDatabase(_databasePath);
//emit dataChanged(index(list.first().row(),READ),index(list.last().row(),READ)); //emit dataChanged(index(0,ComicModel::Number),index(_data.count()-1,ComicModel::HasBeenOpened));
return idFirst; return idFirst;
} }

View File

@ -542,14 +542,14 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod
FolderItem * item = new FolderItem(data); FolderItem * item = new FolderItem(data);
item->id = newFolder.id; item->id = newFolder.id;
beginInsertRows(parent,0,0); //TODO calculate the destRow before inserting the new child
parentItem->appendChild(item); parentItem->appendChild(item);
destRow = parentItem->children().indexOf(item); //TODO optimize this, appendChild should return the index of the new item destRow = parentItem->children().indexOf(item); //TODO optimize this, appendChild should return the index of the new item
beginInsertRows(parent,destRow,destRow);
endInsertRows();
items.insert(item->id,item); items.insert(item->id,item);
endInsertRows();
return index(destRow,0,parent); return index(destRow,0,parent);
} }

View File

@ -62,6 +62,9 @@ void GridComicsView::setModel(ComicModel *model)
ctxt->setContextProperty("comicsSelectionHelper", this); ctxt->setContextProperty("comicsSelectionHelper", this);
ctxt->setContextProperty("comicRatingHelper", this); ctxt->setContextProperty("comicRatingHelper", this);
ctxt->setContextProperty("dummyValue", true); ctxt->setContextProperty("dummyValue", true);
if(model->rowCount()>0)
setCurrentIndex(model->index(0,0));
} }
#ifdef Q_OS_MAC #ifdef Q_OS_MAC

View File

@ -92,7 +92,8 @@
LibraryWindow::LibraryWindow() LibraryWindow::LibraryWindow()
:QMainWindow(),fullscreen(false),fetching(false),previousFilter(""),removeError(false),status(LibraryWindow::Normal) :QMainWindow(),fullscreen(false),fetching(false),previousFilter(""),removeError(false),status(LibraryWindow::Normal)
{ {
setupUI(); setupUI();
loadLibraries(); loadLibraries();
if(libraries.isEmpty()) if(libraries.isEmpty())
@ -105,7 +106,7 @@ LibraryWindow::LibraryWindow()
selectedLibrary->setCurrentIndex(0); selectedLibrary->setCurrentIndex(0);
} }
navigationController = new YACReaderNavigationController(this);
} }
void LibraryWindow::setupUI() void LibraryWindow::setupUI()
@ -129,6 +130,9 @@ void LibraryWindow::setupUI()
createToolBars(); createToolBars();
doDialogs(); doDialogs();
createMenus(); createMenus();
navigationController = new YACReaderNavigationController(this);
createConnections(); createConnections();
setWindowTitle(tr("YACReader Library")); setWindowTitle(tr("YACReader Library"));
@ -1100,10 +1104,10 @@ void LibraryWindow::createConnections()
connect(importComicsInfoAction,SIGNAL(triggered()),this,SLOT(showImportComicsInfo())); connect(importComicsInfoAction,SIGNAL(triggered()),this,SLOT(showImportComicsInfo()));
//properties & config //properties & config
connect(propertiesDialog,SIGNAL(accepted()),this,SLOT(reloadCovers())); connect(propertiesDialog,SIGNAL(accepted()),navigationController,SLOT(reselectCurrentFolder()));
//comic vine //comic vine
connect(comicVineDialog,SIGNAL(accepted()),this,SLOT(reloadCovers())); connect(comicVineDialog,SIGNAL(accepted()),navigationController,SLOT(reselectCurrentFolder()));
connect(updateLibraryAction,SIGNAL(triggered()),this,SLOT(updateLibrary())); connect(updateLibraryAction,SIGNAL(triggered()),this,SLOT(updateLibrary()));
connect(renameLibraryAction,SIGNAL(triggered()),this,SLOT(renameLibrary())); connect(renameLibraryAction,SIGNAL(triggered()),this,SLOT(renameLibrary()));
@ -1201,7 +1205,7 @@ void LibraryWindow::loadLibrary(const QString & name)
QMessageBox::critical(this,tr("Update failed"), tr("The current library can't be udpated. Check for write write permissions on: ") + path+"/library.ydb"); QMessageBox::critical(this,tr("Update failed"), tr("The current library can't be udpated. Check for write write permissions on: ") + path+"/library.ydb");
} }
else else
{ {
comicsView->setModel(NULL); comicsView->setModel(NULL);
foldersView->setModel(NULL); foldersView->setModel(NULL);
listsView->setModel(NULL); listsView->setModel(NULL);
@ -1325,66 +1329,9 @@ void LibraryWindow::loadLibrary(const QString & name)
} }
} }
void LibraryWindow::loadCovers(const QModelIndex & mi)
{
unsigned long long int folderId = 1;
if(mi.isValid())
{
FolderItem *item = static_cast<FolderItem*>(mi.internalPointer());
folderId = item->id;
#ifndef Q_OS_MAC
libraryToolBar->setCurrentFolderName(item->data(0).toString());
#endif
}
#ifndef Q_OS_MAC
else libraryToolBar->setCurrentFolderName(selectedLibrary->currentText());
#endif
//cambiado de orden, ya que al llamar a foldersFilter->clear() se invalidan los model index
/*
if(searchEdit->text()!="")
{
//setFoldersFilter("");
if(mi.isValid())
{
index = static_cast<FolderItem *>(mi.internalPointer())->originalItem;
column = mi.column();
searchEdit->clear();
}
}
else
{
index = static_cast<FolderItem *>(mi.internalPointer());
column = mi.column();
}
*/
//comicsView->setModel(NULL);
comicsModel->setupModelData(folderId,foldersModel->getDatabase());
comicsView->setModel(comicsModel);
QStringList paths = comicsModel->getPaths(currentPath());
checkEmptyFolder(&paths);
if(paths.size()>0) {
comicsView->setCurrentIndex(comicsModel->index(0,0));
if(comicsViewStack->currentWidget() != comicsView && comicsViewStack->currentWidget() != comicsViewTransition)
comicsViewStack->setCurrentWidget(comicsView);
}
else
emptyFolderWidget->setSubfolders(mi,foldersModel->getSubfoldersNames(mi));
}
void LibraryWindow::loadCoversFromCurrentModel() void LibraryWindow::loadCoversFromCurrentModel()
{ {
comicsView->setModel(comicsModel); comicsView->setModel(comicsModel);
QStringList paths = comicsModel->getPaths(currentPath());
if(paths.size()>0) {
comicsView->setCurrentIndex(comicsModel->index(0,0));
}
} }
void LibraryWindow::copyAndImportComicsToCurrentFolder(const QList<QPair<QString, QString> > &comics) void LibraryWindow::copyAndImportComicsToCurrentFolder(const QList<QPair<QString, QString> > &comics)
@ -1523,7 +1470,9 @@ QProgressDialog *LibraryWindow::newProgressDialog(const QString &label, int maxV
void LibraryWindow::reloadAfterCopyMove(const QModelIndex & mi) void LibraryWindow::reloadAfterCopyMove(const QModelIndex & mi)
{ {
if(getCurrentFolderIndex() == mi) if(getCurrentFolderIndex() == mi)
reloadCovers(); {
navigationController->loadFolderInfo(mi);
}
foldersModel->fetchMoreFromDB(mi); foldersModel->fetchMoreFromDB(mi);
@ -1569,8 +1518,11 @@ void LibraryWindow::addFolderToCurrentIndex()
QDir newFolder(parentPath+"/"+newFolderName); QDir newFolder(parentPath+"/"+newFolderName);
if(parentDir.mkdir(newFolderName) || newFolder.exists()) if(parentDir.mkdir(newFolderName) || newFolder.exists())
{ {
foldersView->setCurrentIndex(foldersModel->addFolderAtParent(newFolderName,currentIndex)); QModelIndex newIndex = foldersModel->addFolderAtParent(newFolderName,currentIndex);
reloadCovers(); foldersView->setCurrentIndex(foldersModelProxy->mapFromSource(newIndex));
navigationController->loadFolderInfo(newIndex);
//a new folder is always an empty folder
showEmptyFolderView();
} }
} }
} }
@ -1612,7 +1564,7 @@ void LibraryWindow::deleteSelectedFolder()
connect(thread, SIGNAL(started()), remover, SLOT(process())); connect(thread, SIGNAL(started()), remover, SLOT(process()));
connect(remover, SIGNAL(remove(QModelIndex)), foldersModel, SLOT(deleteFolder(QModelIndex))); connect(remover, SIGNAL(remove(QModelIndex)), foldersModel, SLOT(deleteFolder(QModelIndex)));
connect(remover, SIGNAL(removeError()),this,SLOT(errorDeletingFolder())); connect(remover, SIGNAL(removeError()),this,SLOT(errorDeletingFolder()));
connect(remover, SIGNAL(finished()),this,SLOT(reloadCovers())); connect(remover, SIGNAL(finished()),navigationController,SLOT(reselectCurrentFolder()));
connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater())); connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
@ -1702,8 +1654,7 @@ void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child)
{ {
QModelIndex dest = foldersModel->index(child,0,mi); QModelIndex dest = foldersModel->index(child,0,mi);
foldersView->setCurrentIndex(dest); foldersView->setCurrentIndex(dest);
historyController->updateHistory(dest); navigationController->selectedFolder(dest);
loadCovers(dest);
} }
void LibraryWindow::checkEmptyFolder(QStringList * paths) void LibraryWindow::checkEmptyFolder(QStringList * paths)
@ -1728,30 +1679,6 @@ void LibraryWindow::checkEmptyFolder(QStringList * paths)
} }
} }
void LibraryWindow::reloadCovers()
{
//comics view switch when filter/search is enabled
if(!searchEdit->text().isEmpty())
{
loadCoversFromCurrentModel();
comicsView->enableFilterMode(true);
return;
}
if(foldersView->selectionModel()->selectedRows().length()>0)
loadCovers(foldersModelProxy->mapToSource(foldersView->currentIndex()));
else
loadCovers(QModelIndex());
QLOG_INFO() << "reloaded covers at row : " << foldersModelProxy->mapToSource(foldersView->currentIndex()).row();
QModelIndex mi = comicsModel->getIndexFromId(_comicIdEdited);
if(mi.isValid())
{
comicsView->scrollTo(mi,QAbstractItemView::PositionAtCenter);
comicsView->setCurrentIndex(mi);
}
//centerComicFlow(mi);
}
void LibraryWindow::openComic() void LibraryWindow::openComic()
{ {
if(!importedCovers) if(!importedCovers)
@ -2002,8 +1929,7 @@ void LibraryWindow::setRootIndex()
QDir d; //TODO change this by static methods (utils class?? with delTree for example) QDir d; //TODO change this by static methods (utils class?? with delTree for example)
if(d.exists(path)) if(d.exists(path))
{ {
loadCovers(QModelIndex()); navigationController->selectedFolder(QModelIndex());
historyController->updateHistory(QModelIndex());
} }
else else
{ {
@ -2063,29 +1989,6 @@ void LibraryWindow::toNormal()
void LibraryWindow::setSearchFilter(const YACReader::SearchModifiers modifier, QString filter) void LibraryWindow::setSearchFilter(const YACReader::SearchModifiers modifier, QString filter)
{ {
/*
if(filter.isEmpty())
{
QLOG_DEBUG() << "clearing filter";
foldersModelProxy->clear();
comicsView->enableFilterMode(false);
foldersView->collapseAll();
//TODO scroll to folder after clearing the filter
//1. histoy last index
//2. scrollto
//3. setCurrentIndex
if(index != 0)
{
QModelIndex mi = foldersModel->indexFromItem(index,column);
foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
historyController->updateHistory(mi);
foldersView->setCurrentIndex(mi);
}
reloadCovers();
}*/
if(!filter.isEmpty()) if(!filter.isEmpty())
{ {
status = LibraryWindow::Searching; status = LibraryWindow::Searching;
@ -2181,6 +2084,7 @@ void LibraryWindow::resetComicRating()
void LibraryWindow::switchToComicsView(ComicsView * from, ComicsView * to) void LibraryWindow::switchToComicsView(ComicsView * from, ComicsView * to)
{ {
//setup views
disconnectComicsViewConnections(from); disconnectComicsViewConnections(from);
from->close(); from->close();
@ -2196,7 +2100,13 @@ void LibraryWindow::switchToComicsView(ComicsView * from, ComicsView * to)
delete from; delete from;
reloadCovers(); //load content into current view
loadCoversFromCurrentModel();
if(!searchEdit->text().isEmpty())
{
comicsView->enableFilterMode(true);
}
} }
void LibraryWindow::showComicsViewTransition() void LibraryWindow::showComicsViewTransition()
@ -2279,9 +2189,17 @@ void LibraryWindow::asignNumbers()
else else
return; return;
} }
_comicIdEdited = comicsModel->asignNumbers(indexList,startingNumber); qint64 edited = comicsModel->asignNumbers(indexList,startingNumber);
reloadCovers(); //TODO add resorting without reloading
navigationController->loadFolderInfo(foldersModelProxy->mapToSource(foldersView->currentIndex()));
const QModelIndex & mi = comicsModel->getIndexFromId(edited);
if(mi.isValid())
{
comicsView->scrollTo(mi,QAbstractItemView::PositionAtCenter);
comicsView->setCurrentIndex(mi);
}
} }
void LibraryWindow::openContainingFolderComic() void LibraryWindow::openContainingFolderComic()

View File

@ -293,10 +293,8 @@ public:
public slots: public slots:
void loadLibrary(const QString & path); void loadLibrary(const QString & path);
void loadCovers(const QModelIndex & mi);
void selectSubfolder(const QModelIndex & mi, int child); void selectSubfolder(const QModelIndex & mi, int child);
void checkEmptyFolder(QStringList * paths = 0); void checkEmptyFolder(QStringList * paths = 0);
void reloadCovers();
void openComic(); void openComic();
void createLibrary(); void createLibrary();
void create(QString source,QString dest, QString name); void create(QString source,QString dest, QString name);

View File

@ -40,6 +40,11 @@ void YACReaderNavigationController::selectedFolder(const QModelIndex &mi)
} }
void YACReaderNavigationController::reselectCurrentFolder()
{
selectedFolder(libraryWindow->foldersView->currentIndex());
}
void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex) void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex)
{ {
//Get FolderItem //Get FolderItem
@ -54,18 +59,16 @@ void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex
{ {
//updateView //updateView
libraryWindow->showComicsView(); libraryWindow->showComicsView();
libraryWindow->disableComicsActions(false);
} }
else{ else{
//showEmptyFolder //showEmptyFolder
QStringList subfolders; loadEmptyFolderInfo(modelIndex);
subfolders = libraryWindow->foldersModel->getSubfoldersNames(modelIndex);
libraryWindow->emptyFolderWidget->setSubfolders(modelIndex,subfolders);
libraryWindow->showEmptyFolderView(); libraryWindow->showEmptyFolderView();
libraryWindow->disableComicsActions(true);
} }
} }
void YACReaderNavigationController::selectedList(const QModelIndex &mi) void YACReaderNavigationController::selectedList(const QModelIndex &mi)
{ {
@ -96,6 +99,13 @@ void YACReaderNavigationController::selectSubfolder(const QModelIndex &sourceMIP
loadFolderInfo(dest); loadFolderInfo(dest);
} }
void YACReaderNavigationController::loadEmptyFolderInfo(const QModelIndex &modelIndex)
{
QStringList subfolders;
subfolders = libraryWindow->foldersModel->getSubfoldersNames(modelIndex);
libraryWindow->emptyFolderWidget->setSubfolders(modelIndex,subfolders);
}
void YACReaderNavigationController::loadPreviousStatus() void YACReaderNavigationController::loadPreviousStatus()
{ {
QModelIndex sourceMI = libraryWindow->historyController->currentIndex(); QModelIndex sourceMI = libraryWindow->historyController->currentIndex();

View File

@ -18,6 +18,7 @@ public slots:
//info origins //info origins
//folders view //folders view
void selectedFolder(const QModelIndex & mi); void selectedFolder(const QModelIndex & mi);
void reselectCurrentFolder();
//reading lists //reading lists
void selectedList(const QModelIndex & mi); void selectedList(const QModelIndex & mi);
//history navigation //history navigation
@ -25,6 +26,8 @@ public slots:
//empty subfolder //empty subfolder
void selectSubfolder(const QModelIndex &sourceMI, int child); void selectSubfolder(const QModelIndex &sourceMI, int child);
void loadEmptyFolderInfo(const QModelIndex & modelIndex);
void loadFolderInfo(const QModelIndex & modelIndex); void loadFolderInfo(const QModelIndex & modelIndex);
void loadPreviousStatus(); void loadPreviousStatus();