From: APTX Date: Sun, 21 Apr 2013 15:11:51 +0000 (+0200) Subject: Add option to delete a file location to localmylist-management. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=6679e8633227050bf18d7e2e1f99054240860e94;p=localmylist.git Add option to delete a file location to localmylist-management. File locations are internal to LML so they can actually be removed very easily. --- diff --git a/localmylist-management/mainwindow.cpp b/localmylist-management/mainwindow.cpp index ed7c82f..7c0a84a 100644 --- a/localmylist-management/mainwindow.cpp +++ b/localmylist-management/mainwindow.cpp @@ -415,6 +415,11 @@ void MainWindow::on_myListView_dataRequested(const QModelIndex &index) MyList::instance()->database()->addRequest(r); } +void MainWindow::on_myListView_removeFileLocationRequested(int id) +{ + myListModel->removeFileLocation(id); +} + void MainWindow::on_filterInput_textChanged(const QString &filter) { switch (ui->filterType->currentIndex()) diff --git a/localmylist-management/mainwindow.h b/localmylist-management/mainwindow.h index d9f2f12..989cd7c 100644 --- a/localmylist-management/mainwindow.h +++ b/localmylist-management/mainwindow.h @@ -74,6 +74,7 @@ private slots: void on_myListView_openFileRequested(const QModelIndex &index); void on_myListView_renameFilesRequested(const QModelIndex &index); void on_myListView_dataRequested(const QModelIndex &index); + void on_myListView_removeFileLocationRequested(int id); void on_filterInput_textChanged(const QString &filter); void on_filterType_currentIndexChanged(int); diff --git a/localmylist-management/mylistview.cpp b/localmylist-management/mylistview.cpp index 1e6bcb3..69270e8 100644 --- a/localmylist-management/mylistview.cpp +++ b/localmylist-management/mylistview.cpp @@ -38,6 +38,8 @@ MyListView::MyListView(QWidget *parent) : connect(renameTestAction, SIGNAL(triggered()), this, SLOT(renameTest())); requestDataAction = new QAction(tr("Request Data"), this); connect(requestDataAction, SIGNAL(triggered()), this, SLOT(requestData())); + removeFileLocationAction = new QAction(tr("Remove this File Location"), this); + connect(removeFileLocationAction, SIGNAL(triggered()), this, SLOT(removeFileLocation())); if (!LocalMyList::MyList::isUdpClientAvailable()) { @@ -94,7 +96,8 @@ void MyListView::showCustomContextMenu(const QPoint &pos) aniDBLinkAction->setText(tr("Open AniDB Page (%1%2)").arg('f').arg(node->id())); actions << aniDBLinkAction << renameTestAction - << renameFilesAction; + << renameFilesAction + << removeFileLocationAction; break; default: break; @@ -203,3 +206,10 @@ void MyListView::requestData() { emit dataRequested(customContextMenuIndex); } + +void MyListView::removeFileLocation() +{ + int id = myListFilterModel()->node(customContextMenuIndex)->id(); + if (id) + emit removeFileLocationRequested(id); +} diff --git a/localmylist-management/mylistview.h b/localmylist-management/mylistview.h index 9a34585..1b168dd 100644 --- a/localmylist-management/mylistview.h +++ b/localmylist-management/mylistview.h @@ -17,6 +17,7 @@ signals: void renameFilesRequested(const QModelIndex &index); void dataRequested(const QModelIndex &index); void renameTest(int fid); + void removeFileLocationRequested(int locationId); private slots: MyListFilterModel *myListFilterModel() const; @@ -29,6 +30,7 @@ private slots: void requestFileRename(); void renameTest(); void requestData(); + void removeFileLocation(); private: QModelIndex customContextMenuIndex; @@ -43,6 +45,7 @@ private: QAction *renameTestAction; QAction *renameFilesAction; QAction *requestDataAction; + QAction *removeFileLocationAction; }; #endif // MYLISTVIEW_H diff --git a/localmylist/mylistmodel.cpp b/localmylist/mylistmodel.cpp index 931954e..a9c3c25 100644 --- a/localmylist/mylistmodel.cpp +++ b/localmylist/mylistmodel.cpp @@ -166,6 +166,31 @@ QModelIndex MyListModel::fileLocationIndex(int id) const return index(node); } +void MyListModel::removeFileLocation(int id) +{ + auto it = fileLocationSet.find(id); + + if (it != fileLocationSet.end()) + { + MyListFileLocationNode *node = it->node; + MyListNode *parent = node->parent(); + + parent->childRemoved(node); + } + + MyList::instance()->database()->removeFileLocation(id); +} + +void MyListModel::removeFileLocation(const QModelIndex &index) +{ + MyListNode *node = static_cast(index.internalPointer()); + + if (node->type() != MyListNode::FileLocationNode) + return; + + removeFileLocation(node->id()); +} + QVariant MyListModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal) diff --git a/localmylist/mylistmodel.h b/localmylist/mylistmodel.h index caa4edc..efd2ad4 100644 --- a/localmylist/mylistmodel.h +++ b/localmylist/mylistmodel.h @@ -50,6 +50,8 @@ public: FileLocation fileLocation(int id) const; FileLocation fileLocation(const QModelIndex &index) const; QModelIndex fileLocationIndex(int id) const; + void removeFileLocation(int id); + void removeFileLocation(const QModelIndex &index); QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; Qt::ItemFlags flags(const QModelIndex &index) const; diff --git a/localmylist/mylistnode.cpp b/localmylist/mylistnode.cpp index 339778b..354b470 100644 --- a/localmylist/mylistnode.cpp +++ b/localmylist/mylistnode.cpp @@ -306,6 +306,19 @@ void MyListNode::childAdded(int id) ++m_totalRowCount; } +void MyListNode::childRemoved(MyListNode *child) +{ + const int row = child->row(); + + Q_ASSERT(childItems.contains(child)); + + model->beginRemoveRows(model->index(this), row, row + 1); + childItems.removeAt(row); + --m_totalRowCount; + model->endRemoveRows(); + delete child; +} + bool MyListNode::updated(Operation type) { Q_UNUSED(type) diff --git a/localmylist/mylistnode.h b/localmylist/mylistnode.h index ff4319d..af0c215 100644 --- a/localmylist/mylistnode.h +++ b/localmylist/mylistnode.h @@ -62,6 +62,7 @@ public: virtual int id() const; virtual void childAdded(int id); + virtual void childRemoved(MyListNode *child); virtual bool updated(Operation type); virtual void childUpdate(const EpisodeData &oldData, const EpisodeData &newData, Operation type); virtual void childUpdate(const FileData &oldData, const FileData &newData, Operation type);