mirror of
https://github.com/YACReader/yacreader
synced 2025-07-23 15:35:03 -04:00
added support for deleting labels/lists
This commit is contained in:
@ -114,6 +114,7 @@ ReadingListItem *ReadingListItem::child(int row)
|
||||
void ReadingListItem::appendChild(ReadingListItem *item)
|
||||
{
|
||||
childItems.append(item);
|
||||
item->parent = this;
|
||||
return; //TODO
|
||||
|
||||
item->parent = this;
|
||||
@ -151,6 +152,11 @@ void ReadingListItem::appendChild(ReadingListItem *item)
|
||||
|
||||
}
|
||||
|
||||
void ReadingListItem::removeChild(ReadingListItem *item)
|
||||
{
|
||||
childItems.removeOne(item);
|
||||
}
|
||||
|
||||
qulonglong ReadingListItem::getId() const
|
||||
{
|
||||
if(itemData.count()>1)
|
||||
|
@ -53,9 +53,11 @@ public:
|
||||
int row() const;
|
||||
ReadingListItem * child(int row);
|
||||
void appendChild(ReadingListItem *item);
|
||||
void removeChild(ReadingListItem *item);
|
||||
qulonglong getId() const;
|
||||
QString name() const;
|
||||
void setName(const QString & name);
|
||||
|
||||
QList<ReadingListItem*> children();
|
||||
|
||||
private:
|
||||
|
@ -276,7 +276,31 @@ void ReadingListModel::rename(const QModelIndex &mi, const QString &name)
|
||||
|
||||
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()
|
||||
|
@ -40,12 +40,10 @@ public:
|
||||
bool isReadingList(const QModelIndex & mi);
|
||||
QString name(const QModelIndex & mi);
|
||||
void rename(const QModelIndex & mi, const QString & name);
|
||||
void deleteItem(const QModelIndex & mi);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void deleteItem(const QModelIndex & mi);
|
||||
|
||||
private:
|
||||
void cleanAll();
|
||||
void setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent);
|
||||
|
Reference in New Issue
Block a user