YACReaderTableView, no se usar? de momento (custom_widgets.h)

toLongLong cambiado por toULongLong

antes de la edici?n se guarda el id del c?mic, o el id del primer c?mic, para
restaurar posteriormente la posici?n de comicsView y comicFlow

cambios en el orden en el que se a?aden las nueva bibliotecas a selectedLibrary
y se cargan
This commit is contained in:
Luis Ángel San Martín 2012-06-30 23:49:25 +02:00
parent aa1efea8ff
commit accf77d4b9
9 changed files with 102 additions and 38 deletions

View File

@ -45,8 +45,8 @@ QList<LibraryItem *> Comic::getComicsFromParent(qulonglong parentId, QSqlDatabas
data << record.value(i);
//TODO sort by sort indicator and name
currentItem = new Comic();
currentItem->id = record.value("id").toLongLong();
currentItem->parentId = record.value(1).toLongLong();
currentItem->id = record.value("id").toULongLong();
currentItem->parentId = record.value(1).toULongLong();
currentItem->name = record.value(2).toString();
currentItem->path = record.value(3).toString();
currentItem->info.load(record.value(4).toString(),db);
@ -77,19 +77,19 @@ QList<LibraryItem *> Comic::getComicsFromParent(qulonglong parentId, QSqlDatabas
return list;
}
bool Comic::load(qulonglong id, QSqlDatabase & db)
bool Comic::load(qulonglong idc, QSqlDatabase & db)
{
QSqlQuery selectQuery(db); //TODO check
selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.id = :id");
selectQuery.bindValue(":id", id);
selectQuery.bindValue(":id", idc);
selectQuery.exec();
this->id = idc;
if(selectQuery.next())
{
QSqlRecord record = selectQuery.record();
id = record.value("id").toLongLong();
parentId = record.value("parentId").toLongLong();
//id = record.value("id").toULongLong();
parentId = record.value("parentId").toULongLong();
name = record.value("name").toString();
info.load(record.value("hash").toString(),db);
return true;
@ -107,11 +107,12 @@ qulonglong Comic::insert(QSqlDatabase & db)
if(!info.existOnDb)
{
QSqlQuery comicInfoInsert(db);
comicInfoInsert.prepare("INSERT INTO comic_info (hash) "
"VALUES (:hash)");
comicInfoInsert.prepare("INSERT INTO comic_info (hash,numPages) "
"VALUES (:hash,:numPages)");
comicInfoInsert.bindValue(":hash", info.hash);
comicInfoInsert.bindValue(":numPages", *info.numPages);
comicInfoInsert.exec();
info.id =comicInfoInsert.lastInsertId().toLongLong();
info.id =comicInfoInsert.lastInsertId().toULongLong();
_hasCover = false;
}
else
@ -125,7 +126,7 @@ qulonglong Comic::insert(QSqlDatabase & db)
query.bindValue(":name", name);
query.bindValue(":path", path);
query.exec();
return query.lastInsertId().toLongLong();
return query.lastInsertId().toULongLong();
}
void Comic::update(QSqlDatabase & db)
@ -376,7 +377,7 @@ bool ComicInfo::load(QString hash, QSqlDatabase & db)
QSqlRecord record = findComicInfo.record();
hash = hash;
id = record.value("id").toLongLong();
id = record.value("id").toULongLong();
read = record.value("read").toBool();
edited = record.value("edited").toBool();

View File

@ -13,7 +13,7 @@ qulonglong Folder::insert(QSqlDatabase & db)
query.bindValue(":name", name);
query.bindValue(":path", path);
query.exec();
return query.lastInsertId().toLongLong();
return query.lastInsertId().toULongLong();
}
QList<LibraryItem *> Folder::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db)
@ -33,7 +33,7 @@ QList<LibraryItem *> Folder::getFoldersFromParent(qulonglong parentId, QSqlDatab
for(int i=0;i<record.count();i++)
data << record.value(i);
//TODO sort by sort indicator and name
currentItem = new Folder(record.value("id").toLongLong(),record.value("parentId").toLongLong(),record.value("name").toString(),record.value("path").toString());
currentItem = new Folder(record.value("id").toULongLong(),record.value("parentId").toULongLong(),record.value("name").toString(),record.value("path").toString());
int lessThan = 0;
if(list.isEmpty())
list.append(currentItem);

View File

@ -187,7 +187,7 @@ void TableModel::setupModelData(unsigned long long int folderId,const QString &
QString TableModel::getComicPath(QModelIndex mi)
{
if(mi.isValid())
return _data.at(mi.row())->data(6).toString();
return _data.at(mi.row())->data(PATH).toString();
return "";
}
void TableModel::setupModelData(QSqlQuery &sqlquery)
@ -231,7 +231,7 @@ Comic TableModel::getComic(const QModelIndex & mi)
Comic c;
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
c.load(_data.at(mi.row())->data(ID).toLongLong(),db);
c.load(_data.at(mi.row())->data(ID).toULongLong(),db);
db.close();
QSqlDatabase::removeDatabase(_databasePath);
@ -243,7 +243,7 @@ Comic TableModel::_getComic(const QModelIndex & mi)
Comic c;
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
c.load(_data.at(mi.row())->data(ID).toLongLong(),db);
c.load(_data.at(mi.row())->data(ID).toULongLong(),db);
db.close();
QSqlDatabase::removeDatabase(_databasePath);
@ -275,7 +275,7 @@ QVector<bool> TableModel::setAllComicsRead(bool read)
readList[i] = read;
_data.value(i)->data(READ) = QVariant(true);
Comic c;
c.load(_data.value(i)->data(ID).toLongLong(),db);
c.load(_data.value(i)->data(ID).toULongLong(),db);
c.info.read = read;
c.info.update(db);
}
@ -301,4 +301,18 @@ QList<Comic> TableModel::getComics(QList<QModelIndex> list)
db.close();
QSqlDatabase::removeDatabase(_databasePath);
return comics;
}
QModelIndex TableModel::getIndexFromId(quint64 id)
{
QList<TableItem *>::ConstIterator itr;
int i=0;
for(itr = _data.constBegin();itr != _data.constEnd();itr++)
{
if((*itr)->data(ID).toULongLong() == id)
break;
i++;
}
return index(i,0);
}

View File

@ -39,6 +39,7 @@ public:
QVector<bool> getReadList();
QVector<bool> setAllComicsRead(bool read);
QList<Comic> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
QModelIndex getIndexFromId(quint64 id);
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados

View File

@ -245,9 +245,9 @@ void TreeModel::setupModelData(QSqlQuery &sqlquery, TreeItem *parent)
data << record.value("path").toString();
TreeItem * item = new TreeItem(data);
item->id = record.value("id").toLongLong();
item->id = record.value("id").toULongLong();
//la inserción de hijos se hace de forma ordenada
items.value(record.value("parentId").toLongLong())->appendChild(item);
items.value(record.value("parentId").toULongLong())->appendChild(item);
//se añade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
items.insert(item->id,item);
}
@ -315,10 +315,10 @@ void TreeModel::setupFilteredModelData(QSqlQuery &sqlquery, TreeItem *parent)
data << record.value("name").toString();
data << record.value("path").toString();
TreeItem * item = new TreeItem(data);
item->id = sqlquery.value(0).toLongLong();
item->id = sqlquery.value(0).toULongLong();
//id del padre
quint64 parentId = record.value("parentId").toLongLong();
quint64 parentId = record.value("parentId").toULongLong();
//se añade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones
if(!filteredItems.contains(item->id))

View File

@ -123,7 +123,7 @@ qulonglong LibraryCreator::insertFolders()
query.bindValue(":name", folder.name);
query.bindValue(":path", folder.path);
query.exec();
return query.lastInsertId().toLongLong();
return query.lastInsertId().toULongLong();
}*/
/*qulonglong LibraryCreator::insertComic(const Comic & comic)
@ -134,7 +134,7 @@ qulonglong LibraryCreator::insertFolders()
"VALUES (:hash)");
comicInfoInsert.bindValue(":hash", comic.hash);
comicInfoInsert.exec();
qulonglong comicInfoId =comicInfoInsert.lastInsertId().toLongLong();
qulonglong comicInfoId =comicInfoInsert.lastInsertId().toULongLong();
QSqlQuery query(_database);
query.prepare("INSERT INTO comic (parentId, comicInfoId, fileName, path) "
@ -144,7 +144,7 @@ qulonglong LibraryCreator::insertFolders()
query.bindValue(":name", comic.name);
query.bindValue(":path", comic.path);
query.exec();
return query.lastInsertId().toLongLong();
return query.lastInsertId().toULongLong();
}*/
void LibraryCreator::create(QDir dir)
@ -190,13 +190,17 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo &
//hash Sha1 del primer 0.5MB + filesize
QString hash = QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
Comic comic(_currentPathFolders.last().id,fileInfo.fileName(),relativePath,hash,_database);
comic.insert(_database);
int numPages;
if(!comic.hasCover())
{
ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg");
//ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+fileInfo.fileName()+".jpg");
tc.create();
numPages = tc.getNumPages();
}
comic.info.setNumPages(numPages);
comic.insert(_database);
}
void LibraryCreator::update(QDir dirS)

View File

@ -91,14 +91,18 @@ void LibraryWindow::doLayout()
//comicView->setItemDelegate(new YACReaderComicViewDelegate());
comicView->setContextMenuPolicy(Qt::ActionsContextMenu);
comicView->setShowGrid(false);
comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
//comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
comicView->horizontalHeader()->setStretchLastSection(true);
comicView->horizontalHeader()->setClickable(false);
//comicView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
comicView->verticalHeader()->setDefaultSectionSize(24);
comicView->verticalHeader()->setClickable(false); //TODO comportamiento anómalo
comicView->setCornerButtonEnabled(false);
comicView->setStyleSheet("QTableView {selection-background-color: #d7d7c7; selection-color: #000000;}");
comicView->setStyleSheet("QTableView {selection-background-color: #d7d7c7; selection-color: #000000;}\n QTableView QTableView::item{"
"border-right-style:solid;"
"border-width:1;"
"border-color: #9B9B9B;"
"}");
// comicView->verticalHeader()->setStyleSheet("QHeaderView::section"
//"{"
// "background-color: white /* steelblue */"
@ -673,13 +677,18 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
//comicView->setModel(NULL);
dmCV->setupModelData(folderId,dm->getDatabase());
comicView->setModel(dmCV);
comicView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
comicView->horizontalHeader()->hideSection(4);
comicView->horizontalHeader()->hideSection(5);
comicView->horizontalHeader()->hideSection(6);
comicView->horizontalHeader()->hideSection(7);
comicView->horizontalHeader()->hideSection(8);
//debido a un bug, qt4 no es capaz de ajustar el ancho teniendo en cuenta todas la filas (no sólo las visibles)
//así que se ecala la primera vez y después se deja el control al usuario.
comicView->resizeColumnsToContents();
comicView->horizontalHeader()->setStretchLastSection(true);
QStringList paths = dmCV->getPaths(currentPath());
comicFlow->setImagePaths(paths);
comicFlow->setMarks(dmCV->getReadList());
@ -716,6 +725,11 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
void LibraryWindow::reloadCovers()
{
loadCovers(_rootIndexCV);
QModelIndex mi = dmCV->getIndexFromId(_comicIdEdited);
comicView->setCurrentIndex(mi);
//centerComicFlow(mi);
comicFlow->setCenterIndex(mi.row());
}
void LibraryWindow::centerComicFlow(const QModelIndex & mi)
@ -807,18 +821,27 @@ void LibraryWindow::createLibrary()
void LibraryWindow::create(QString source, QString dest, QString name)
{
_lastAdded = name;
libraries.insert(name,source);
selectedLibrary->addItem(name,source);
libraryCreator->createLibrary(source,dest);
libraryCreator->start();
saveLibraries();
_lastAdded = name;
_sourceLastAdded = source;
}
void LibraryWindow::openLastCreated()
{
loadLibrary(_lastAdded);
selectedLibrary->disconnect();
selectedLibrary->setCurrentIndex(selectedLibrary->findText(_lastAdded));
libraries.insert(_lastAdded,_sourceLastAdded);
selectedLibrary->addItem(_lastAdded,_sourceLastAdded);
selectedLibrary->setCurrentIndex(selectedLibrary->findText(_lastAdded));
saveLibraries();
connect(selectedLibrary,SIGNAL(currentIndexChanged(QString)),this,SLOT(loadLibrary(QString)));
loadLibrary(_lastAdded);
}
void LibraryWindow::showAddLibrary()
@ -829,10 +852,8 @@ void LibraryWindow::showAddLibrary()
void LibraryWindow::openLibrary(QString path, QString name)
{
_lastAdded = name;
libraries.insert(name,path);
selectedLibrary->addItem(name,path);
_sourceLastAdded = path;
openLastCreated();
saveLibraries();
}
void LibraryWindow::loadLibraries()
@ -1052,12 +1073,14 @@ void LibraryWindow::setFoldersFilter(QString filter)
}
}
}
#include "tableitem.h"
void LibraryWindow::showProperties()
{
QModelIndexList indexList = comicView->selectionModel()->selectedRows();
QList<Comic> comics = dmCV->getComics(indexList);
Comic c = comics[0];
_comicIdEdited = c.id;//static_cast<TableItem*>(indexList[0].internalPointer())->data(4).toULongLong();
//QModelIndex mi = comicView->currentIndex();
//QString path = QDir::cleanPath(currentPath()+dmCV->getComicPath(mi));

View File

@ -131,10 +131,13 @@ private:
QString comicsPath;
QString _lastAdded;
QString _sourceLastAdded;
QModelIndex _rootIndex;
QModelIndex _rootIndexCV;
quint64 _comicIdEdited;
void setupUI();
void createActions();
void createToolBars();

View File

@ -20,6 +20,7 @@
#include <QLineEdit>
#include <QAction>
#include <QPlainTextEdit>
#include <QTableView>
#include "pictureflow.h"
@ -165,5 +166,22 @@ private:
QAction * restore;
};
//class YACReaderTableView : public QTableView
//{
// Q_OBJECT
//public:
// YACReaderTableView(QWidget *parent = 0)
// : QTableView(parent) {}
//
//protected:
// bool viewportEvent ( QEvent * event )
// {
// resizeColumnsToContents();
// return QTableView::viewportEvent(event);
// }
//};
#endif