diff --git a/YACReaderLibrary/comic_vine/model/local_comic_list_model.cpp b/YACReaderLibrary/comic_vine/model/local_comic_list_model.cpp index 2e05222f..861e61f1 100644 --- a/YACReaderLibrary/comic_vine/model/local_comic_list_model.cpp +++ b/YACReaderLibrary/comic_vine/model/local_comic_list_model.cpp @@ -88,7 +88,52 @@ QModelIndex LocalComicListModel::index(int row, int column, const QModelIndex &p QList LocalComicListModel::getData() { - return _data; + return _data; +} + +void LocalComicListModel::removeComics(const QList &selectedIndexes) +{ + QModelIndex mi = selectedIndexes.first(); + QModelIndex lastMi = selectedIndexes.last(); + int sourceRow = mi.row(); + int sourceLastRow = lastMi.row(); + + beginRemoveRows(QModelIndex(),selectedIndexes.first().row(),selectedIndexes.last().row()); + + for(int i = sourceLastRow;i>=sourceRow;i--) + { + _removed.push_front(_data.at(i)); + _data.removeAt(i); + } + + endRemoveRows(); + + beginInsertRows(QModelIndex(),_data.count()-_removed.count(),_data.count()-1); + for(int i = 0; i<_removed.count(); i++) + _data.append(ComicDB()); + endInsertRows(); +} + +void LocalComicListModel::restoreAll() +{ + int numItemsToRemove = 0; + for(int i = 0;numItemsToRemove<_removed.count();i++) + { + if(_data.at(i).getFileName().isEmpty()) + { + beginRemoveRows(QModelIndex(),i,i); + _data.removeAt(i); + endRemoveRows(); + + beginInsertRows(QModelIndex(),i,i); + _data.insert(i,_removed.at(numItemsToRemove)); + endInsertRows(); + + numItemsToRemove++; + } + } + + _removed.clear(); } void LocalComicListModel::moveSelectionUp(const QList &selectedIndexes) diff --git a/YACReaderLibrary/comic_vine/model/local_comic_list_model.h b/YACReaderLibrary/comic_vine/model/local_comic_list_model.h index 5b793ec1..98edd62e 100644 --- a/YACReaderLibrary/comic_vine/model/local_comic_list_model.h +++ b/YACReaderLibrary/comic_vine/model/local_comic_list_model.h @@ -23,6 +23,9 @@ public: int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QList getData(); + + void removeComics(const QList & selectedIndexes); + void restoreAll(); signals: public slots: @@ -33,6 +36,7 @@ public slots: private: int numExtraRows; QList _data; + QList _removed; }; #endif // LOCAL_COMIC_LIST_MODEL_H diff --git a/YACReaderLibrary/comic_vine/select_volume.cpp b/YACReaderLibrary/comic_vine/select_volume.cpp index 3faa3309..9650a7f7 100644 --- a/YACReaderLibrary/comic_vine/select_volume.cpp +++ b/YACReaderLibrary/comic_vine/select_volume.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "scraper_tableview.h" @@ -49,7 +50,11 @@ SelectVolume::SelectVolume(QWidget *parent) tableVolumes = new ScraperTableView(this); tableVolumes->setSortingEnabled(true); +#if QT_VERSION >= 0x050000 tableVolumes->horizontalHeader()->setSectionsClickable(true); +#else + tableVolumes->horizontalHeader()->setClickable(true); +#endif //tableVolumes->horizontalHeader()->setSortIndicatorShown(false); connect(tableVolumes->horizontalHeader(),SIGNAL(sectionClicked(int)), tableVolumes, SLOT(sortByColumn(int))); //connections diff --git a/YACReaderLibrary/comic_vine/sort_volume_comics.cpp b/YACReaderLibrary/comic_vine/sort_volume_comics.cpp index 041e6b22..6d7441f2 100644 --- a/YACReaderLibrary/comic_vine/sort_volume_comics.cpp +++ b/YACReaderLibrary/comic_vine/sort_volume_comics.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "scraper_tableview.h" #include "local_comic_list_model.h" @@ -85,6 +86,20 @@ SortVolumeComics::SortVolumeComics(QWidget *parent) : l->setContentsMargins(0,0,0,0); setLayout(l); setContentsMargins(0,0,0,0); + + //rows actions + QAction * removeItemFromList = new QAction(tr("remove selected comics"),this); + QAction * restoreAllItems = new QAction(tr("restore all removed comics"),this); + QAction * restoreItems = new QAction(tr("restore removed comics"),this); + + tableFiles->setContextMenuPolicy(Qt::ActionsContextMenu); + tableFiles->addAction(removeItemFromList); + tableFiles->addAction(restoreAllItems); + //tableFiles->addAction(restoreItems); + + connect(removeItemFromList,SIGNAL(triggered()),this,SLOT(removeSelectedComics())); + connect(restoreAllItems,SIGNAL(triggered()),this,SLOT(restoreAllComics())); + connect(restoreItems,SIGNAL(triggered()),this,SLOT(showRemovedComicsSelector())); } void SortVolumeComics::setData(QList & comics, const QString &json, const QString &vID) @@ -170,6 +185,23 @@ void SortVolumeComics::moveDownIL() } +void SortVolumeComics::removeSelectedComics() +{ + QList selection = tableFiles->selectionModel()->selectedIndexes(); + + localComicsModel->removeComics(selection); +} + +void SortVolumeComics::restoreAllComics() +{ + localComicsModel->restoreAll(); +} + +void SortVolumeComics::showRemovedComicsSelector() +{ + +} + QList > SortVolumeComics::getMatchingInfo() { QList comicList = localComicsModel->getData(); diff --git a/YACReaderLibrary/comic_vine/sort_volume_comics.h b/YACReaderLibrary/comic_vine/sort_volume_comics.h index e87ff40e..92955f90 100644 --- a/YACReaderLibrary/comic_vine/sort_volume_comics.h +++ b/YACReaderLibrary/comic_vine/sort_volume_comics.h @@ -77,6 +77,10 @@ protected slots: void moveUpIL(); void moveDownIL(); + void removeSelectedComics(); + void restoreAllComics(); + void showRemovedComicsSelector(); + private: ScraperTableView * tableFiles;