mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Refactorizaci?n para mover c?digo de LibraryWindow a TableModel
This commit is contained in:
parent
7319993b6d
commit
81c59ee1f5
@ -33,6 +33,10 @@ QVariant TableItem::data(int column) const
|
|||||||
}
|
}
|
||||||
//! [6]
|
//! [6]
|
||||||
|
|
||||||
|
void TableItem::setData(int column,const QVariant & value)
|
||||||
|
{
|
||||||
|
itemData[column] = value;
|
||||||
|
}
|
||||||
|
|
||||||
//! [8]
|
//! [8]
|
||||||
int TableItem::row() const
|
int TableItem::row() const
|
||||||
|
@ -12,6 +12,7 @@ public:
|
|||||||
~TableItem();
|
~TableItem();
|
||||||
int columnCount() const;
|
int columnCount() const;
|
||||||
QVariant data(int column) const;
|
QVariant data(int column) const;
|
||||||
|
void setData(int column,const QVariant & value);
|
||||||
int row() const;
|
int row() const;
|
||||||
unsigned long long int id; //TODO sustituir por una clase adecuada
|
unsigned long long int id; //TODO sustituir por una clase adecuada
|
||||||
//Comic comic;
|
//Comic comic;
|
||||||
|
@ -347,7 +347,7 @@ QVector<bool> TableModel::setAllComicsRead(bool read)
|
|||||||
for(int i=0;i<numComics;i++)
|
for(int i=0;i<numComics;i++)
|
||||||
{
|
{
|
||||||
readList[i] = read;
|
readList[i] = read;
|
||||||
_data.value(i)->data(READ) = QVariant(true);
|
_data.value(i)->setData(READ,QVariant(read));
|
||||||
ComicDB c;
|
ComicDB c;
|
||||||
c.load(_data.value(i)->data(ID).toULongLong(),db);
|
c.load(_data.value(i)->data(ID).toULongLong(),db);
|
||||||
c.info.read = read;
|
c.info.read = read;
|
||||||
@ -377,6 +377,45 @@ QList<ComicDB> TableModel::getComics(QList<QModelIndex> list)
|
|||||||
return comics;
|
return comics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<bool> TableModel::setComicsRead(QList<QModelIndex> list,bool read)
|
||||||
|
{
|
||||||
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
|
db.transaction();
|
||||||
|
foreach (QModelIndex mi, list)
|
||||||
|
{
|
||||||
|
_data.value(mi.row())->setData(READ, QVariant(read));
|
||||||
|
ComicDB c;
|
||||||
|
c.load(_data.value(mi.row())->data(ID).toULongLong(),db);
|
||||||
|
c.info.read = read;
|
||||||
|
c.info.update(db);
|
||||||
|
}
|
||||||
|
db.commit();
|
||||||
|
db.close();
|
||||||
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
|
||||||
|
return getReadList();
|
||||||
|
}
|
||||||
|
qint64 TableModel::asignNumbers(QList<QModelIndex> list,int startingNumber)
|
||||||
|
{
|
||||||
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
|
db.transaction();
|
||||||
|
qint64 idFirst = _data.value(list[0].row())->data(ID).toULongLong();
|
||||||
|
int i = 0;
|
||||||
|
foreach (QModelIndex mi, list)
|
||||||
|
{
|
||||||
|
ComicDB c;
|
||||||
|
c.load(_data.value(mi.row())->data(ID).toULongLong(),db);
|
||||||
|
c.info.setNumber(startingNumber+i);
|
||||||
|
c.info.edited = true;
|
||||||
|
c.info.update(db);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
db.commit();
|
||||||
|
db.close();
|
||||||
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
return idFirst;
|
||||||
|
}
|
||||||
QModelIndex TableModel::getIndexFromId(quint64 id)
|
QModelIndex TableModel::getIndexFromId(quint64 id)
|
||||||
{
|
{
|
||||||
QList<TableItem *>::ConstIterator itr;
|
QList<TableItem *>::ConstIterator itr;
|
||||||
|
@ -43,6 +43,8 @@ public:
|
|||||||
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
|
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos
|
||||||
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
|
//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
|
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados
|
||||||
|
QVector<bool> setComicsRead(QList<QModelIndex> list,bool read);
|
||||||
|
qint64 asignNumbers(QList<QModelIndex> list,int startingNumber);
|
||||||
private:
|
private:
|
||||||
void setupModelData( QSqlQuery &sqlquery);
|
void setupModelData( QSqlQuery &sqlquery);
|
||||||
ComicDB _getComic(const QModelIndex & mi);
|
ComicDB _getComic(const QModelIndex & mi);
|
||||||
|
@ -356,10 +356,6 @@ void LibraryWindow::createActions()
|
|||||||
renameLibraryAction->setShortcut(Qt::Key_R);
|
renameLibraryAction->setShortcut(Qt::Key_R);
|
||||||
renameLibraryAction->setIcon(QIcon(":/images/edit.png"));
|
renameLibraryAction->setIcon(QIcon(":/images/edit.png"));
|
||||||
|
|
||||||
/*deleteLibraryAction = new QAction(this);
|
|
||||||
deleteLibraryAction->setToolTip(tr("Delete current library from disk"));
|
|
||||||
deleteLibraryAction->setIcon(QIcon(":/images/deleteLibrary.png"));*/
|
|
||||||
|
|
||||||
removeLibraryAction = new QAction(this);
|
removeLibraryAction = new QAction(this);
|
||||||
removeLibraryAction->setToolTip(tr("Remove current library from your collection"));
|
removeLibraryAction->setToolTip(tr("Remove current library from your collection"));
|
||||||
removeLibraryAction->setIcon(QIcon(":/images/removeLibrary.png"));
|
removeLibraryAction->setIcon(QIcon(":/images/removeLibrary.png"));
|
||||||
@ -986,31 +982,8 @@ void LibraryWindow::openComic()
|
|||||||
|
|
||||||
void LibraryWindow::setCurrentComicsStatusReaded(bool readed)
|
void LibraryWindow::setCurrentComicsStatusReaded(bool readed)
|
||||||
{
|
{
|
||||||
QModelIndexList indexList = comicView->selectionModel()->selectedRows();
|
comicFlow->setMarks(dmCV->setComicsRead(comicView->selectionModel()->selectedRows(),readed));
|
||||||
|
|
||||||
QList<ComicDB> comics = dmCV->getComics(indexList);
|
|
||||||
|
|
||||||
foreach (QModelIndex mi, indexList)
|
|
||||||
{
|
|
||||||
if(readed)
|
|
||||||
comicFlow->markSlide(mi.row());
|
|
||||||
else
|
|
||||||
comicFlow->unmarkSlide(mi.row());
|
|
||||||
|
|
||||||
}
|
|
||||||
comicFlow->updateMarks();
|
comicFlow->updateMarks();
|
||||||
|
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(dm->getDatabase());
|
|
||||||
db.open();
|
|
||||||
db.transaction();
|
|
||||||
foreach (ComicDB c, comics)
|
|
||||||
{
|
|
||||||
c.info.read = readed;
|
|
||||||
c.info.updateRead(db);
|
|
||||||
}
|
|
||||||
db.commit();
|
|
||||||
db.close();
|
|
||||||
QSqlDatabase::removeDatabase(dm->getDatabase());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryWindow::setCurrentComicReaded()
|
void LibraryWindow::setCurrentComicReaded()
|
||||||
@ -1335,39 +1308,18 @@ void LibraryWindow::asignNumbers()
|
|||||||
{
|
{
|
||||||
QModelIndexList indexList = comicView->selectionModel()->selectedRows();
|
QModelIndexList indexList = comicView->selectionModel()->selectedRows();
|
||||||
|
|
||||||
QList<ComicDB> comics = dmCV->getComics(indexList);
|
int startingNumber = indexList[0].row()+1;
|
||||||
ComicDB c = comics[0];
|
if(indexList.count()>1)
|
||||||
_comicIdEdited = c.id;
|
|
||||||
|
|
||||||
int startingNumber = dmCV->getIndexFromId(comics[0].id).row()+1;
|
|
||||||
if(comics.count()>1)
|
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
int n = QInputDialog::getInt(this, tr("Asign comics numbers"),
|
int n = QInputDialog::getInt(this, tr("Asign comics numbers"),
|
||||||
tr("Asign numbers starting in:"), dmCV->getIndexFromId(comics[0].id).row()+1,0,2147483647,1,&ok);
|
tr("Asign numbers starting in:"), startingNumber,0,2147483647,1,&ok);
|
||||||
if (ok)
|
if (ok)
|
||||||
startingNumber = n;
|
startingNumber = n;
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_comicIdEdited = dmCV->asignNumbers(indexList,startingNumber);
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(dm->getDatabase());
|
|
||||||
db.transaction();
|
|
||||||
|
|
||||||
for(int i = 0;i<comics.length();i++)
|
|
||||||
{
|
|
||||||
ComicDB c = comics[i];
|
|
||||||
c.info.setNumber(startingNumber+i);
|
|
||||||
c.info.edited = true;
|
|
||||||
c.info.update(db);
|
|
||||||
/*QString hash = comics[i].info.hash;
|
|
||||||
comics[i].info.setNumber(i+1);
|
|
||||||
comics[i].info.update(db);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
db.commit();
|
|
||||||
db.close();
|
|
||||||
QSqlDatabase::removeDatabase(dm->getDatabase());
|
|
||||||
|
|
||||||
reloadCovers();
|
reloadCovers();
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,6 @@ private:
|
|||||||
QAction * importLibraryAction;
|
QAction * importLibraryAction;
|
||||||
|
|
||||||
QAction * updateLibraryAction;
|
QAction * updateLibraryAction;
|
||||||
//QAction * deleteLibraryAction;
|
|
||||||
QAction * removeLibraryAction;
|
QAction * removeLibraryAction;
|
||||||
QAction * helpAboutAction;
|
QAction * helpAboutAction;
|
||||||
QAction * renameLibraryAction;
|
QAction * renameLibraryAction;
|
||||||
|
Loading…
Reference in New Issue
Block a user