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);
tableView->setModel(model);
if(model->rowCount()>0)
tableView->setCurrentIndex(model->index(0,0));
tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
#if QT_VERSION >= 0x050000

View File

@ -598,7 +598,7 @@ qint64 ComicModel::asignNumbers(QList<QModelIndex> list,int startingNumber)
db.close();
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;
}

View File

@ -542,14 +542,14 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod
FolderItem * item = new FolderItem(data);
item->id = newFolder.id;
beginInsertRows(parent,0,0); //TODO calculate the destRow before inserting the new child
parentItem->appendChild(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);
endInsertRows();
return index(destRow,0,parent);
}

View File

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

View File

@ -92,7 +92,8 @@
LibraryWindow::LibraryWindow()
:QMainWindow(),fullscreen(false),fetching(false),previousFilter(""),removeError(false),status(LibraryWindow::Normal)
{
setupUI();
setupUI();
loadLibraries();
if(libraries.isEmpty())
@ -105,7 +106,7 @@ LibraryWindow::LibraryWindow()
selectedLibrary->setCurrentIndex(0);
}
navigationController = new YACReaderNavigationController(this);
}
void LibraryWindow::setupUI()
@ -129,6 +130,9 @@ void LibraryWindow::setupUI()
createToolBars();
doDialogs();
createMenus();
navigationController = new YACReaderNavigationController(this);
createConnections();
setWindowTitle(tr("YACReader Library"));
@ -1100,10 +1104,10 @@ void LibraryWindow::createConnections()
connect(importComicsInfoAction,SIGNAL(triggered()),this,SLOT(showImportComicsInfo()));
//properties & config
connect(propertiesDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
connect(propertiesDialog,SIGNAL(accepted()),navigationController,SLOT(reselectCurrentFolder()));
//comic vine
connect(comicVineDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
connect(comicVineDialog,SIGNAL(accepted()),navigationController,SLOT(reselectCurrentFolder()));
connect(updateLibraryAction,SIGNAL(triggered()),this,SLOT(updateLibrary()));
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");
}
else
{
{
comicsView->setModel(NULL);
foldersView->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()
{
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)
@ -1523,7 +1470,9 @@ QProgressDialog *LibraryWindow::newProgressDialog(const QString &label, int maxV
void LibraryWindow::reloadAfterCopyMove(const QModelIndex & mi)
{
if(getCurrentFolderIndex() == mi)
reloadCovers();
{
navigationController->loadFolderInfo(mi);
}
foldersModel->fetchMoreFromDB(mi);
@ -1569,8 +1518,11 @@ void LibraryWindow::addFolderToCurrentIndex()
QDir newFolder(parentPath+"/"+newFolderName);
if(parentDir.mkdir(newFolderName) || newFolder.exists())
{
foldersView->setCurrentIndex(foldersModel->addFolderAtParent(newFolderName,currentIndex));
reloadCovers();
QModelIndex newIndex = foldersModel->addFolderAtParent(newFolderName,currentIndex);
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(remover, SIGNAL(remove(QModelIndex)), foldersModel, SLOT(deleteFolder(QModelIndex)));
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(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);
foldersView->setCurrentIndex(dest);
historyController->updateHistory(dest);
loadCovers(dest);
navigationController->selectedFolder(dest);
}
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()
{
if(!importedCovers)
@ -2002,8 +1929,7 @@ void LibraryWindow::setRootIndex()
QDir d; //TODO change this by static methods (utils class?? with delTree for example)
if(d.exists(path))
{
loadCovers(QModelIndex());
historyController->updateHistory(QModelIndex());
navigationController->selectedFolder(QModelIndex());
}
else
{
@ -2063,29 +1989,6 @@ void LibraryWindow::toNormal()
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())
{
status = LibraryWindow::Searching;
@ -2181,6 +2084,7 @@ void LibraryWindow::resetComicRating()
void LibraryWindow::switchToComicsView(ComicsView * from, ComicsView * to)
{
//setup views
disconnectComicsViewConnections(from);
from->close();
@ -2196,7 +2100,13 @@ void LibraryWindow::switchToComicsView(ComicsView * from, ComicsView * to)
delete from;
reloadCovers();
//load content into current view
loadCoversFromCurrentModel();
if(!searchEdit->text().isEmpty())
{
comicsView->enableFilterMode(true);
}
}
void LibraryWindow::showComicsViewTransition()
@ -2279,9 +2189,17 @@ void LibraryWindow::asignNumbers()
else
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()

View File

@ -293,10 +293,8 @@ public:
public slots:
void loadLibrary(const QString & path);
void loadCovers(const QModelIndex & mi);
void selectSubfolder(const QModelIndex & mi, int child);
void checkEmptyFolder(QStringList * paths = 0);
void reloadCovers();
void openComic();
void createLibrary();
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)
{
//Get FolderItem
@ -54,18 +59,16 @@ void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex
{
//updateView
libraryWindow->showComicsView();
libraryWindow->disableComicsActions(false);
}
else{
//showEmptyFolder
QStringList subfolders;
subfolders = libraryWindow->foldersModel->getSubfoldersNames(modelIndex);
libraryWindow->emptyFolderWidget->setSubfolders(modelIndex,subfolders);
loadEmptyFolderInfo(modelIndex);
libraryWindow->showEmptyFolderView();
libraryWindow->disableComicsActions(true);
}
}
void YACReaderNavigationController::selectedList(const QModelIndex &mi)
{
@ -96,6 +99,13 @@ void YACReaderNavigationController::selectSubfolder(const QModelIndex &sourceMIP
loadFolderInfo(dest);
}
void YACReaderNavigationController::loadEmptyFolderInfo(const QModelIndex &modelIndex)
{
QStringList subfolders;
subfolders = libraryWindow->foldersModel->getSubfoldersNames(modelIndex);
libraryWindow->emptyFolderWidget->setSubfolders(modelIndex,subfolders);
}
void YACReaderNavigationController::loadPreviousStatus()
{
QModelIndex sourceMI = libraryWindow->historyController->currentIndex();

View File

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