mirror of
https://github.com/YACReader/yacreader
synced 2025-07-23 15:35:03 -04:00
completed drag comics from comics view to reading lists
This commit is contained in:
@ -47,16 +47,17 @@ QMimeData *ComicModel::mimeData(const QModelIndexList &indexes) const
|
||||
QList<qulonglong> ids;
|
||||
foreach(QModelIndex index, indexes)
|
||||
{
|
||||
QLOG_DEBUG() << "dragging : " << index.data(IdRole).toULongLong();
|
||||
ids << index.data(IdRole).toULongLong();
|
||||
|
||||
}
|
||||
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
QDataStream out(&buffer);
|
||||
QDataStream out(&data,QIODevice::WriteOnly);
|
||||
out << ids; //serialize the list of identifiers
|
||||
|
||||
QMimeData * mimeData = new QMimeData();
|
||||
mimeData->setData("application/yacreaderlibrary-comics-ids", data);
|
||||
mimeData->setData(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat, data);
|
||||
|
||||
return mimeData;
|
||||
}
|
||||
@ -137,6 +138,8 @@ QVariant ComicModel::data(const QModelIndex &index, int role) const
|
||||
return item->data(ReadColumn).toBool();
|
||||
else if (role == HasBeenOpenedRole)
|
||||
return item->data(ComicModel::HasBeenOpened);
|
||||
else if (role == IdRole)
|
||||
return item->data(Id);
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
@ -705,7 +708,18 @@ QModelIndex ComicModel::getIndexFromId(quint64 id)
|
||||
i++;
|
||||
}
|
||||
|
||||
return index(i,0);
|
||||
return index(i,0);
|
||||
}
|
||||
|
||||
//TODO completely inefficiently
|
||||
QList<QModelIndex> ComicModel::getIndexesFromIds(const QList<qulonglong> &comicIds)
|
||||
{
|
||||
QList<QModelIndex> comicsIndexes;
|
||||
|
||||
foreach(qulonglong id,comicIds)
|
||||
comicsIndexes << getIndexFromId(id);
|
||||
|
||||
return comicsIndexes;
|
||||
}
|
||||
|
||||
void ComicModel::startTransaction()
|
||||
@ -720,8 +734,6 @@ void ComicModel::finishTransaction()
|
||||
dbTransaction.commit();
|
||||
dbTransaction.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ComicModel::removeInTransaction(int row)
|
||||
@ -800,6 +812,11 @@ void ComicModel::resetComicRating(const QModelIndex &mi)
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
void ComicModel::addComicsToFavorites(const QList<qulonglong> &comicIds)
|
||||
{
|
||||
addComicsToFavorites(getIndexesFromIds(comicIds));
|
||||
}
|
||||
|
||||
void ComicModel::addComicsToFavorites(const QList<QModelIndex> & comicsList)
|
||||
{
|
||||
QList<ComicDB> comics = getComics(comicsList);
|
||||
@ -812,6 +829,11 @@ void ComicModel::addComicsToFavorites(const QList<QModelIndex> & comicsList)
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
void ComicModel::addComicsToLabel(const QList<qulonglong> &comicIds, qulonglong labelId)
|
||||
{
|
||||
addComicsToLabel(getIndexesFromIds(comicIds),labelId);
|
||||
}
|
||||
|
||||
void ComicModel::addComicsToLabel(const QList<QModelIndex> &comicsList, qulonglong labelId)
|
||||
{
|
||||
QList<ComicDB> comics = getComics(comicsList);
|
||||
@ -824,6 +846,23 @@ void ComicModel::addComicsToLabel(const QList<QModelIndex> &comicsList, qulonglo
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
void ComicModel::addComicsToReadingList(const QList<qulonglong> &comicIds, qulonglong readingListId)
|
||||
{
|
||||
addComicsToReadingList(getIndexesFromIds(comicIds),readingListId);
|
||||
}
|
||||
|
||||
void ComicModel::addComicsToReadingList(const QList<QModelIndex> &comicsList, qulonglong readingListId)
|
||||
{
|
||||
QList<ComicDB> comics = getComics(comicsList);
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
|
||||
DBHelper::insertComicsInReadingList(comics,readingListId,db);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
void ComicModel::deleteComicsFromFavorites(const QList<QModelIndex> &comicsList)
|
||||
{
|
||||
QList<ComicDB> comics = getComics(comicsList);
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
QList<ComicDB> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
|
||||
QList<ComicDB> getAllComics();
|
||||
QModelIndex getIndexFromId(quint64 id);
|
||||
QList<QModelIndex> getIndexesFromIds(const QList<qulonglong> &comicIds);
|
||||
//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
|
||||
@ -64,8 +65,11 @@ public:
|
||||
void removeInTransaction(int row);
|
||||
void reload(const ComicDB & comic);
|
||||
void resetComicRating(const QModelIndex & mi);
|
||||
|
||||
|
||||
void addComicsToFavorites(const QList<QModelIndex> &comicsList);
|
||||
void addComicsToLabel(const QList<QModelIndex> &comicsList, qulonglong labelId);
|
||||
void addComicsToReadingList(const QList<QModelIndex> &comicsList, qulonglong readingListId);
|
||||
|
||||
void deleteComicsFromFavorites(const QList<QModelIndex> &comicsList);
|
||||
void deleteComicsFromLabel(const QList<QModelIndex> &comicsList, qulonglong labelId);
|
||||
@ -115,6 +119,10 @@ public slots:
|
||||
void finishTransaction();
|
||||
void updateRating(int rating, QModelIndex mi);
|
||||
|
||||
void addComicsToFavorites(const QList<qulonglong> &comicIds);
|
||||
void addComicsToLabel(const QList<qulonglong> &comicIds, qulonglong labelId);
|
||||
void addComicsToReadingList(const QList<qulonglong> &comicIds, qulonglong readingListId);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
@ -170,7 +170,7 @@ qulonglong ReadingListItem::getId() const
|
||||
{
|
||||
if(itemData.count()>1)
|
||||
{
|
||||
return YACReader::LabelColors(itemData.at(1).toULongLong());
|
||||
return itemData.at(1).toULongLong();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,10 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
if (role == ReadingListModel::IDRole)
|
||||
{
|
||||
QLOG_DEBUG() << "getting role";
|
||||
return item->getId();
|
||||
}
|
||||
|
||||
if (role == ReadingListModel::SpecialListTypeRole && typeid(*item) == typeid(SpecialListItem))
|
||||
{
|
||||
@ -131,20 +134,20 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
||||
{
|
||||
int separatorsCount = labels.isEmpty()?1:2;
|
||||
|
||||
if(row >= 0 && row < specialLists.count())
|
||||
if(rowIsSpecialList(row,parent))
|
||||
return createIndex(row, column, specialLists.at(row));
|
||||
|
||||
if(row == specialLists.count())
|
||||
return createIndex(row,column,separator1);
|
||||
|
||||
if(row > specialLists.count() && row <= specialLists.count() + labels.count())
|
||||
if(rowIsLabel(row,parent))
|
||||
return createIndex(row,column,labels.at(row-specialLists.count()-1));
|
||||
|
||||
if(separatorsCount == 2)
|
||||
if(row == specialLists.count() + labels.count() + 1)
|
||||
return createIndex(row,column,separator2);
|
||||
|
||||
if(row >= specialLists.count() + labels.count() + separatorsCount)
|
||||
if(rowIsReadingList(row,parent))
|
||||
return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count() + separatorsCount)));
|
||||
|
||||
} else //sublist
|
||||
@ -188,13 +191,71 @@ QModelIndex ReadingListModel::parent(const QModelIndex &index) const
|
||||
|
||||
bool ReadingListModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
return data->formats().contains("application/yacreaderlibrary-comics-ids");
|
||||
QLOG_DEBUG() << "trying to drop into row = " << row << "column column = " << column << "parent" << parent;
|
||||
|
||||
if(row == -1)
|
||||
return false;
|
||||
|
||||
if(!parent.isValid()) //top level items
|
||||
{
|
||||
if(row == -1) //no list
|
||||
return false;
|
||||
|
||||
if(row == 1) //reading is just an smart list
|
||||
return false;
|
||||
|
||||
if(rowIsSeparator(row,parent))
|
||||
return false;
|
||||
}
|
||||
|
||||
return data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat);
|
||||
}
|
||||
|
||||
bool ReadingListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||
{
|
||||
QLOG_DEBUG() << "drop mimedata into row = " << row << "column column = " << column << "parent" << parent;
|
||||
return true;
|
||||
QLOG_DEBUG() << "drop mimedata into row = " << row << " column = " << column << "parent" << parent;
|
||||
|
||||
QList<qulonglong> comicIds;
|
||||
QByteArray rawData = data->data(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat);
|
||||
QDataStream in(&rawData,QIODevice::ReadOnly);
|
||||
in >> comicIds; //deserialize the list of indentifiers
|
||||
|
||||
QLOG_DEBUG() << "dropped : " << comicIds;
|
||||
|
||||
QModelIndex dest;
|
||||
QModelIndex parentDest;
|
||||
|
||||
if(row == -1)
|
||||
{
|
||||
dest = parent;
|
||||
}
|
||||
else
|
||||
dest = index(row,column,parent);
|
||||
|
||||
parentDest = dest.parent();
|
||||
|
||||
if(rowIsSpecialList(dest.row(),parentDest)) {
|
||||
if(dest.row() == 0) //add to favorites
|
||||
{
|
||||
QLOG_DEBUG() << "-------addComicsToFavorites : " << comicIds << " to " << dest.data(IDRole).toULongLong();
|
||||
emit addComicsToFavorites(comicIds);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(rowIsLabel(dest.row(),parentDest)) {
|
||||
QLOG_DEBUG() << "+++++++++++addComicsToLabel : " << comicIds << " to " << dest.data(IDRole).toULongLong();
|
||||
emit addComicsToLabel(comicIds, dest.data(IDRole).toULongLong());
|
||||
return true;
|
||||
}
|
||||
|
||||
if(rowIsReadingList(dest.row(),parentDest)) {
|
||||
QLOG_DEBUG() << "///////////addComicsToReadingList : " << comicIds << " to " << dest.data(IDRole).toULongLong();
|
||||
emit addComicsToReadingList(comicIds, dest.data(IDRole).toULongLong());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReadingListModel::setupReadingListsData(QString path)
|
||||
@ -498,8 +559,55 @@ int ReadingListModel::addLabelIntoList(LabelItem *item)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ReadingListModel::rowIsSpecialList(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
return false; //by now no sublists in special list
|
||||
|
||||
if(row >=0 && row < specialLists.count())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ReadingListModel::rowIsLabel(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
return false; //by now no sublists in labels
|
||||
|
||||
if(row > specialLists.count() && row <= specialLists.count() + labels.count())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ReadingListModel::rowIsReadingList(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
return true; //only lists with sublists
|
||||
|
||||
int separatorsCount = labels.isEmpty()?1:2;
|
||||
|
||||
if(row >= specialLists.count() + labels.count() + separatorsCount)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ReadingListModel::rowIsSeparator(int row, const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
return false; //only separators at top level
|
||||
|
||||
if(row == specialLists.count())
|
||||
return true;
|
||||
|
||||
int separatorsCount = labels.isEmpty()?1:2;
|
||||
if(separatorsCount == 2 && row == specialLists.count() + labels.count() + 1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ReadingListModelProxy::ReadingListModelProxy(QObject *parent)
|
||||
:QSortFilterProxyModel(parent)
|
||||
|
@ -74,6 +74,10 @@ public:
|
||||
|
||||
signals:
|
||||
|
||||
void addComicsToFavorites(const QList<qulonglong> & comicIds);
|
||||
void addComicsToLabel(const QList<qulonglong> & comicIds, qulonglong labelId);
|
||||
void addComicsToReadingList(const QList<qulonglong> & comicIds, qulonglong readingListId);
|
||||
|
||||
private:
|
||||
void cleanAll();
|
||||
void setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
||||
@ -82,6 +86,11 @@ private:
|
||||
void setupReadingLists(QSqlDatabase &db);
|
||||
int addLabelIntoList(LabelItem *item);
|
||||
|
||||
bool rowIsSpecialList(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
bool rowIsLabel(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
bool rowIsReadingList(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
bool rowIsSeparator(int row, const QModelIndex & parent = QModelIndex()) const;
|
||||
|
||||
//Special lists
|
||||
QList<SpecialListItem *> specialLists;
|
||||
|
||||
|
Reference in New Issue
Block a user