]> Some of my projects - localmylist.git/commitdiff
Add option to delete a file location to localmylist-management.
authorAPTX <marek321@gmail.com>
Sun, 21 Apr 2013 15:11:51 +0000 (17:11 +0200)
committerAPTX <marek321@gmail.com>
Sun, 21 Apr 2013 15:11:51 +0000 (17:11 +0200)
File locations are internal to LML so they can actually be removed very easily.

localmylist-management/mainwindow.cpp
localmylist-management/mainwindow.h
localmylist-management/mylistview.cpp
localmylist-management/mylistview.h
localmylist/mylistmodel.cpp
localmylist/mylistmodel.h
localmylist/mylistnode.cpp
localmylist/mylistnode.h

index ed7c82feb482878dd4f74fe58393dab090ceb241..7c0a84a0fb24c6757b1b8aea96e25ce30f037e2a 100644 (file)
@@ -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())
index d9f2f12a895e00109d30f7461b682f7ba8d1e951..989cd7cae77ed2d387a846f02213daccb3cda4c1 100644 (file)
@@ -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);
index 1e6bcb39713e9ac1c751211e5aca0558f1d4220b..69270e8b6a38973747bef04fce8dab3f868b7c2e 100644 (file)
@@ -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);
+}
index 9a34585d15c14de3fa0c4efbb72e927a3c003899..1b168dd152b979fe2ab0eafe2f9dc42890edf595 100644 (file)
@@ -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
index 931954e37b1f8e8ed85bbfb367a3a7cabe1c1e36..a9c3c25a4ba9484a169b944faf920682f04ad712 100644 (file)
@@ -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<MyListNode *>(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)
index caa4edcaef286dfa46e8bc3e23ddb61e1ff56a06..efd2ad4fb5754820a682ca353d06fb568ee85db4 100644 (file)
@@ -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;
index 339778b45f7cc4de0cc80251ab4316a420ee2ffc..354b4709ae2897d41ac87879ad6d26d98f789745 100644 (file)
@@ -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)
index ff4319d7e80c4001139abb9471ff282ec695b243..af0c215dd9adcbbb618713c14defbe8fc5d9c60e 100644 (file)
@@ -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);