mirror of
https://github.com/YACReader/yacreader
synced 2025-07-22 06:54:39 -04:00
'Add to...' submenu completed
This commit is contained in:
@ -815,6 +815,24 @@ void ComicModel::addComicsToFavorites(const QList<QModelIndex> & comicsList)
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
void ComicModel::addComicsToLabel(const QList<QModelIndex> &comicsList, qulonglong labelId)
|
||||
{
|
||||
QList<ComicDB> comics = getComics(comicsList);
|
||||
|
||||
DBHelper::insertComicsInFavorites(comics, QSqlDatabase());
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
|
||||
db.transaction();
|
||||
|
||||
DBHelper::insertComicsInLabel(comics,labelId,db);
|
||||
|
||||
db.commit();
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
|
||||
void ComicModel::updateRating(int rating, QModelIndex mi)
|
||||
{
|
||||
|
@ -63,6 +63,7 @@ public:
|
||||
void reload(const ComicDB & comic);
|
||||
void resetComicRating(const QModelIndex & mi);
|
||||
void addComicsToFavorites(const QList<QModelIndex> &comicsList);
|
||||
void addComicsToLabel(const QList<QModelIndex> &comicsList, qulonglong labelId);
|
||||
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
|
@ -339,6 +339,11 @@ void ReadingListModel::deleteItem(const QModelIndex &mi)
|
||||
}
|
||||
}
|
||||
|
||||
const QList<LabelItem *> ReadingListModel::getLabels()
|
||||
{
|
||||
return labels;
|
||||
}
|
||||
|
||||
void ReadingListModel::cleanAll()
|
||||
{
|
||||
if(rootItem != 0)
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
QString name(const QModelIndex & mi);
|
||||
void rename(const QModelIndex & mi, const QString & name);
|
||||
void deleteItem(const QModelIndex & mi);
|
||||
const QList<LabelItem *> getLabels();
|
||||
|
||||
enum Roles {
|
||||
TypeListsRole = Qt::UserRole + 1,
|
||||
|
@ -434,6 +434,20 @@ void DBHelper::insertComicsInFavorites(const QList<ComicDB> &comicsList, QSqlDat
|
||||
query.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void DBHelper::insertComicsInLabel(const QList<ComicDB> &comicsList, qulonglong labelId, QSqlDatabase &db)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
query.prepare("INSERT INTO comic_label (label_id, comic_id) "
|
||||
"VALUES (:label_id, :comic_id)");
|
||||
|
||||
foreach(ComicDB comic, comicsList)
|
||||
{
|
||||
query.bindValue(":label_id", labelId);
|
||||
query.bindValue(":comic_id", comic.id);
|
||||
query.exec();
|
||||
}
|
||||
}
|
||||
//queries
|
||||
QList<LibraryItem *> DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort)
|
||||
{
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
static qulonglong insertLabel(const QString & name, YACReader::LabelColors color , QSqlDatabase & db);
|
||||
static qulonglong insertReadingList(const QString & name, QSqlDatabase & db);
|
||||
static void insertComicsInFavorites(const QList<ComicDB> & comicsList, QSqlDatabase & db);
|
||||
static void insertComicsInLabel(const QList<ComicDB> & comicsList, qulonglong labelId, QSqlDatabase & db);
|
||||
//updates
|
||||
static void update(qulonglong libraryId, ComicInfo & comicInfo);
|
||||
static void update(ComicDB * comics, QSqlDatabase & db);
|
||||
|
@ -83,6 +83,8 @@
|
||||
#include "yacreader_history_controller.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
#include "reading_list_item.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@ -1698,6 +1700,33 @@ void LibraryWindow::setupAddToSubmenu(QMenu &menu)
|
||||
{
|
||||
menu.addAction(addToFavoritesAction);
|
||||
addToMenuAction->setMenu(&menu);
|
||||
|
||||
const QList<LabelItem*> labels = listsModel->getLabels();
|
||||
if(labels.count() > 0)
|
||||
menu.addSeparator();
|
||||
foreach(LabelItem * label, labels)
|
||||
{
|
||||
QAction * action = new QAction(this);
|
||||
action->setIcon(label->getIcon());
|
||||
action->setText(label->name());
|
||||
|
||||
action->setData(label->getId());
|
||||
|
||||
menu.addAction(action);
|
||||
|
||||
connect(action,SIGNAL(triggered()),this,SLOT(onAddComicsToLabel()));
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryWindow::onAddComicsToLabel()
|
||||
{
|
||||
QAction * action = static_cast<QAction *>(sender());
|
||||
|
||||
qulonglong labelId = action->data().toULongLong();
|
||||
|
||||
QModelIndexList comics = getSelectedComics();
|
||||
|
||||
comicsModel->addComicsToLabel(comics,labelId);
|
||||
}
|
||||
|
||||
void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child)
|
||||
|
@ -391,6 +391,7 @@ public slots:
|
||||
void showComicsViewContextMenu(const QPoint & point);
|
||||
void showComicsItemContextMenu(const QPoint & point);
|
||||
void setupAddToSubmenu(QMenu & menu);
|
||||
void onAddComicsToLabel();
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user