mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added support for deleting labels/lists
This commit is contained in:
parent
2c547e30f8
commit
331b5988a1
@ -114,6 +114,7 @@ ReadingListItem *ReadingListItem::child(int row)
|
|||||||
void ReadingListItem::appendChild(ReadingListItem *item)
|
void ReadingListItem::appendChild(ReadingListItem *item)
|
||||||
{
|
{
|
||||||
childItems.append(item);
|
childItems.append(item);
|
||||||
|
item->parent = this;
|
||||||
return; //TODO
|
return; //TODO
|
||||||
|
|
||||||
item->parent = this;
|
item->parent = this;
|
||||||
@ -151,6 +152,11 @@ void ReadingListItem::appendChild(ReadingListItem *item)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadingListItem::removeChild(ReadingListItem *item)
|
||||||
|
{
|
||||||
|
childItems.removeOne(item);
|
||||||
|
}
|
||||||
|
|
||||||
qulonglong ReadingListItem::getId() const
|
qulonglong ReadingListItem::getId() const
|
||||||
{
|
{
|
||||||
if(itemData.count()>1)
|
if(itemData.count()>1)
|
||||||
|
@ -53,9 +53,11 @@ public:
|
|||||||
int row() const;
|
int row() const;
|
||||||
ReadingListItem * child(int row);
|
ReadingListItem * child(int row);
|
||||||
void appendChild(ReadingListItem *item);
|
void appendChild(ReadingListItem *item);
|
||||||
|
void removeChild(ReadingListItem *item);
|
||||||
qulonglong getId() const;
|
qulonglong getId() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString & name);
|
void setName(const QString & name);
|
||||||
|
|
||||||
QList<ReadingListItem*> children();
|
QList<ReadingListItem*> children();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -276,7 +276,31 @@ void ReadingListModel::rename(const QModelIndex &mi, const QString &name)
|
|||||||
|
|
||||||
void ReadingListModel::deleteItem(const QModelIndex &mi)
|
void ReadingListModel::deleteItem(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
|
if(isEditable(mi))
|
||||||
|
{
|
||||||
|
beginRemoveRows(mi.parent(),mi.row(),mi.row());
|
||||||
|
|
||||||
|
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||||
|
|
||||||
|
ListItem * item = static_cast<ListItem*>(mi.internalPointer());
|
||||||
|
|
||||||
|
if(typeid(*item) == typeid(ReadingListItem))
|
||||||
|
{
|
||||||
|
ReadingListItem * rli = static_cast<ReadingListItem*>(item);
|
||||||
|
rli->parent->removeChild(rli);
|
||||||
|
DBHelper::removeListFromDB(item->getId(), db);
|
||||||
|
}
|
||||||
|
else if(typeid(*item) == typeid(LabelItem))
|
||||||
|
{
|
||||||
|
LabelItem * li = static_cast<LabelItem*>(item);
|
||||||
|
labels.removeOne(li);
|
||||||
|
DBHelper::removeLabelFromDB(item->getId(), db);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlDatabase::removeDatabase(_databasePath);
|
||||||
|
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadingListModel::cleanAll()
|
void ReadingListModel::cleanAll()
|
||||||
|
@ -40,12 +40,10 @@ public:
|
|||||||
bool isReadingList(const QModelIndex & mi);
|
bool isReadingList(const QModelIndex & mi);
|
||||||
QString name(const QModelIndex & mi);
|
QString name(const QModelIndex & mi);
|
||||||
void rename(const QModelIndex & mi, const QString & name);
|
void rename(const QModelIndex & mi, const QString & name);
|
||||||
|
void deleteItem(const QModelIndex & mi);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
|
||||||
void deleteItem(const QModelIndex & mi);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void cleanAll();
|
void cleanAll();
|
||||||
void setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
void setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
||||||
|
@ -142,7 +142,23 @@ void DBHelper::removeFromDB(ComicDB * comic, QSqlDatabase & db)
|
|||||||
QSqlQuery query(db);
|
QSqlQuery query(db);
|
||||||
query.prepare("DELETE FROM comic WHERE id = :id");
|
query.prepare("DELETE FROM comic WHERE id = :id");
|
||||||
query.bindValue(":id", comic->id);
|
query.bindValue(":id", comic->id);
|
||||||
query.exec();
|
query.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBHelper::removeLabelFromDB(qulonglong id, QSqlDatabase &db)
|
||||||
|
{
|
||||||
|
QSqlQuery query(db);
|
||||||
|
query.prepare("DELETE FROM label WHERE id = :id");
|
||||||
|
query.bindValue(":id", id);
|
||||||
|
query.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBHelper::removeListFromDB(qulonglong id, QSqlDatabase &db)
|
||||||
|
{
|
||||||
|
QSqlQuery query(db);
|
||||||
|
query.prepare("DELETE FROM reading_list WHERE id = :id");
|
||||||
|
query.bindValue(":id", id);
|
||||||
|
query.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
//updates
|
//updates
|
||||||
|
@ -34,6 +34,8 @@ public:
|
|||||||
static void removeFromDB(LibraryItem * item, QSqlDatabase & db);
|
static void removeFromDB(LibraryItem * item, QSqlDatabase & db);
|
||||||
static void removeFromDB(Folder * folder, QSqlDatabase & db);
|
static void removeFromDB(Folder * folder, QSqlDatabase & db);
|
||||||
static void removeFromDB(ComicDB * comic, QSqlDatabase & db);
|
static void removeFromDB(ComicDB * comic, QSqlDatabase & db);
|
||||||
|
static void removeLabelFromDB(qulonglong id, QSqlDatabase & db);
|
||||||
|
static void removeListFromDB(qulonglong id, QSqlDatabase & db);
|
||||||
//inserts
|
//inserts
|
||||||
static qulonglong insert(Folder * folder, QSqlDatabase & db);
|
static qulonglong insert(Folder * folder, QSqlDatabase & db);
|
||||||
static qulonglong insert(ComicDB * comic, QSqlDatabase & db);
|
static qulonglong insert(ComicDB * comic, QSqlDatabase & db);
|
||||||
|
@ -1646,7 +1646,19 @@ void LibraryWindow::addNewReadingList()
|
|||||||
|
|
||||||
void LibraryWindow::deleteSelectedReadingList()
|
void LibraryWindow::deleteSelectedReadingList()
|
||||||
{
|
{
|
||||||
|
QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes();
|
||||||
|
if(!selectedLists.isEmpty())
|
||||||
|
{
|
||||||
|
QModelIndex mi = selectedLists.at(0);
|
||||||
|
if(listsModel->isEditable(mi))
|
||||||
|
{
|
||||||
|
int ret = QMessageBox::question(this,tr("Delete list/label"),tr("The selected item will be deleted, your comics or folders will NOT be deleted from your disk. Are you sure?"),QMessageBox::Yes,QMessageBox::No);
|
||||||
|
if(ret == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
listsModel->deleteItem(mi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryWindow::showAddNewLabelDialog()
|
void LibraryWindow::showAddNewLabelDialog()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user