diff --git a/YACReaderLibrary/db/folder_model.h b/YACReaderLibrary/db/folder_model.h index f545f83a..eb00634a 100644 --- a/YACReaderLibrary/db/folder_model.h +++ b/YACReaderLibrary/db/folder_model.h @@ -61,6 +61,7 @@ public: FolderModel( QSqlQuery &sqlquery, QObject *parent = 0); ~FolderModel(); + //QAbstractItemModel methods QVariant data(const QModelIndex &index, int role) const; Qt::ItemFlags flags(const QModelIndex &index) const; QVariant headerData(int section, Qt::Orientation orientation, @@ -68,18 +69,14 @@ public: QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &index) const; - QModelIndex indexFromItem(FolderItem * item, int column); - /*QModelIndex _indexFromItem(TreeItem * item, int column); - int column;*/ - int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; - void setupModelData(QString path); - QString getDatabase(); - //Métodos de conveniencia + //Convenience methods + void setupModelData(QString path); + QString getDatabase(); QString getFolderPath(const QModelIndex &folder); - + QModelIndex indexFromItem(FolderItem * item, int column); void setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics); void resetFilter(); bool isFilterEnabled(){return filterEnabled;}; diff --git a/YACReaderLibrary/db/reading_list_item.cpp b/YACReaderLibrary/db/reading_list_item.cpp index 12899437..3dea3f67 100644 --- a/YACReaderLibrary/db/reading_list_item.cpp +++ b/YACReaderLibrary/db/reading_list_item.cpp @@ -1,5 +1,109 @@ #include "reading_list_item.h" -ReadingListItem::ReadingListItem() +ListItem::ListItem(const QList &data) + :itemData(data) { + +} + +int ListItem::columnCount() +{ + return itemData.count(); +} + +QVariant ListItem::data(int column) const +{ + return itemData.at(column); +} + +//------------------------------------------------------ + +SpecialListItem::SpecialListItem(const QList &data) + :ListItem(data) +{ + +} + +QIcon SpecialListItem::getIcon() const +{ + if(itemData.count()>0) + { + QString name = itemData.at(0).toString(); + return QIcon(QString(":/images/lists/%1.png").arg(name).toLower()); + } +} + +//------------------------------------------------------ + +LabelItem::LabelItem(const QList &data) + :ListItem(data) +{ + +} + +QIcon LabelItem::getIcon() const +{ + if(itemData.count()>1) + { + QString color = itemData.at(1).toString(); + return QIcon(QString(":/images/lists/label_%1.png").arg(color).toLower()); + } +} + +//------------------------------------------------------ + +ReadingListItem::ReadingListItem(const QList &data, ReadingListItem *p) + :ListItem(data), parent(p) +{ + +} + +QIcon ReadingListItem::getIcon() const +{ + if(parent == 0) + return QIcon(":/images/lists/list.png"); + else + return QIcon(":/images/folder.png"); +} + +int ReadingListItem::childCount() const +{ + return childItems.count(); +} + +ReadingListItem *ReadingListItem::child(int row) +{ + return childItems.at(row); +} + +//items are sorted by order +void ReadingListItem::appendChild(ReadingListItem *item) +{ + childItems.append(item); + return; //TODO + + item->parent = this; + + if(childItems.isEmpty()) + childItems.append(item); + else + { + /*ReadingListItem * last = childItems.back(); + QString nameLast = last->data(1).toString(); //TODO usar info name si est� disponible, sino el nombre del fichero..... + QString nameCurrent = item->data(1).toString(); + QList::iterator i; + i = childItems.end(); + i--; + while (naturalSortLessThanCI(nameCurrent,nameLast) && i != childItems.begin()) + { + i--; + nameLast = (*i)->data(1).toString(); + } + if(!naturalSortLessThanCI(nameCurrent,nameLast)) //si se ha encontrado un elemento menor que current, se inserta justo despu�s + childItems.insert(++i,item); + else + childItems.insert(i,item);*/ + + } + } diff --git a/YACReaderLibrary/db/reading_list_item.h b/YACReaderLibrary/db/reading_list_item.h index 250d64b5..cdb0daab 100644 --- a/YACReaderLibrary/db/reading_list_item.h +++ b/YACReaderLibrary/db/reading_list_item.h @@ -1,10 +1,52 @@ #ifndef READING_LIST_ITEM_H #define READING_LIST_ITEM_H -class ReadingListItem +#include +#include + +class ListItem { public: - ReadingListItem(); + ListItem(const QList &data); + int columnCount(); + virtual QIcon getIcon() const = 0; + QVariant data(int column) const; +protected: + QList itemData; +}; + +//------------------------------------------------------ + +class SpecialListItem : public ListItem +{ +public: + SpecialListItem(const QList &data); + QIcon getIcon() const; +}; + +//------------------------------------------------------ + +class LabelItem : public ListItem +{ +public: + LabelItem(const QList &data); + QIcon getIcon() const; +}; + +//------------------------------------------------------ + +class ReadingListItem : public ListItem +{ +public: + ReadingListItem(const QList &data, ReadingListItem * parent = 0); + QIcon getIcon() const; + int childCount() const; + ReadingListItem * child(int row); + void appendChild(ReadingListItem *item); + +private: + QList childItems; + ReadingListItem * parent; }; #endif // READING_LIST_ITEM_H diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index d52be38f..a006e7e1 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -1,6 +1,165 @@ #include "reading_list_model.h" +#include "reading_list_item.h" + ReadingListModel::ReadingListModel(QObject *parent) : - QAbstractItemModel(parent) + QAbstractItemModel(parent),rootItem(0) { } + +int ReadingListModel::rowCount(const QModelIndex &parent) const +{ + if(!parent.isValid()) //TOP + return specialLists.count() + labels.count() + rootItem->childCount(); + else + return 0; +} + +int ReadingListModel::columnCount(const QModelIndex &parent) const +{ + return 1; + /*if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return rootItem->columnCount();*/ +} + +QVariant ReadingListModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + ListItem * item = static_cast(index.internalPointer()); + + if (role == Qt::DecorationRole) + { + return QVariant(item->getIcon()); + } + + if (role != Qt::DisplayRole) + return QVariant(); + + return item->data(index.column()); +} + +Qt::ItemFlags ReadingListModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled; +} + +QVariant ReadingListModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return rootItem->data(section); + + return QVariant(); +} + +QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + ListItem *parentItem; + + /*if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer());*/ + + + if(!parent.isValid()) + { + if(row >= 0 && row < specialLists.count()) + return createIndex(row, column, specialLists.at(row)); + + if(row >= specialLists.count() && row < specialLists.count() + labels.count()) + return createIndex(row,column,labels.at(row-specialLists.count())); + + if(row >= specialLists.count() + labels.count()) + return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count()))); + + } + /*FolderItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else*/ + return QModelIndex(); + +} + +QModelIndex ReadingListModel::parent(const QModelIndex &index) const +{ + //if (!index.isValid()) + return QModelIndex(); + + /*FolderItem *childItem = static_cast(index.internalPointer()); + FolderItem *parentItem = childItem->parent(); + + if (parentItem == rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); */ +} + +void ReadingListModel::setupModelData(QString path) +{ + beginResetModel(); + + if(rootItem != 0) + { + delete rootItem; + + qDeleteAll(specialLists); + qDeleteAll(labels); + + specialLists.clear(); + labels.clear(); + + items.clear(); + } + + rootItem = 0; + + //setup special lists + specialLists << new SpecialListItem(QList() /*<< 0*/ << "Favorites"); + specialLists << new SpecialListItem(QList() /*<< 1*/ << "Reading"); + + //setup labels + labels << new LabelItem(QList() /*<< 0*/ << "Oh Oh" << "red"); + labels << new LabelItem(QList() /*<< 1*/ << "lalala" << "orange"); + labels << new LabelItem(QList() /*<< 2*/ << "we are not sorry" << "yellow"); + labels << new LabelItem(QList() /*<< 3*/ << "there we go" << "green"); + labels << new LabelItem(QList() /*<< 4*/ << "oklabunga" << "cyan"); + labels << new LabelItem(QList() /*<< 5*/ << "hailer mailer" << "blue"); + labels << new LabelItem(QList() /*<< 6*/ << "lol" << "violet"); + labels << new LabelItem(QList() /*<< 7*/ << "problems" << "purple"); + labels << new LabelItem(QList() /*<< 8*/ << "me gussssta" << "pink"); + labels << new LabelItem(QList() /*<< 9*/ << ":D" << "white"); + labels << new LabelItem(QList() /*<< 10*/ << "ainsss" << "light"); + labels << new LabelItem(QList() /*<< 11*/ << "put a smile on my face" << "dark"); + + //setup root item + rootItem = new ReadingListItem(QList() /*<< 0*/ << "ROOT" << "atr"); + + //setup reading lists + rootItem->appendChild(new ReadingListItem(QList() /*<< 0*/ << "My reading list" << "atr")); + rootItem->appendChild(new ReadingListItem(QList() /*<< 0*/ << "X timeline" << "atr")); + + endResetModel(); +} + +void ReadingListModel::deleteItem(const QModelIndex &mi) +{ + +} + +void ReadingListModel::setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent) +{ + +} + + diff --git a/YACReaderLibrary/db/reading_list_model.h b/YACReaderLibrary/db/reading_list_model.h index 4535b4f3..7b473ca0 100644 --- a/YACReaderLibrary/db/reading_list_model.h +++ b/YACReaderLibrary/db/reading_list_model.h @@ -2,6 +2,14 @@ #define READING_LIST_MODEL_H #include +#include +#include +#include +#include + +class LabelItem; +class SpecialListItem; +class ReadingListItem; class ReadingListModel : public QAbstractItemModel { @@ -9,9 +17,39 @@ class ReadingListModel : public QAbstractItemModel public: explicit ReadingListModel(QObject *parent = 0); + //QAbstractItemModel methods + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + + //Convenience methods + void setupModelData(QString path); + signals: public slots: + void deleteItem(const QModelIndex & mi); + +private: + void setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent); + + //Special lists + QList specialLists; + + //Label + QList labels; + + //Reading lists + ReadingListItem * rootItem; // + QMap items; //lists relationship + + QString _databasePath; }; diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index e64c4893..c1e75fb0 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -73,6 +73,9 @@ #include "comic_files_manager.h" +#include "reading_list_model.h" +#include "yacreader_reading_lists_view.h" + #include "QsLog.h" #ifdef Q_OS_WIN @@ -179,6 +182,7 @@ void LibraryWindow::doLayout() sideBar = new YACReaderSideBar; foldersView = sideBar->foldersView; + listsView = sideBar->readingListsView; selectedLibrary = sideBar->selectedLibrary; YACReaderTitledToolBar * librariesTitle = sideBar->librariesTitle; @@ -391,6 +395,8 @@ void LibraryWindow::doModels() foldersModel = new FolderModel(); //comics comicsModel = new ComicModel(); + //lists + listsModel = new ReadingListModel(); setSearchFilter(YACReader::NoModifiers, ""); //clear search filter } @@ -1156,6 +1162,7 @@ void LibraryWindow::loadLibrary(const QString & name) { comicsView->setModel(NULL); foldersView->setModel(NULL); + listsView->setModel(NULL); disableAllActions();//TODO comprobar que se deben deshabilitar //será possible renombrar y borrar estas bibliotecas renameLibraryAction->setEnabled(true); @@ -1170,6 +1177,9 @@ void LibraryWindow::loadLibrary(const QString & name) foldersModel->setupModelData(path); foldersView->setModel(foldersModel); + listsModel->setupModelData(path); + listsView->setModel(listsModel); + if(foldersModel->rowCount(QModelIndex())>0) disableFoldersActions(false); else @@ -1208,6 +1218,7 @@ void LibraryWindow::loadLibrary(const QString & name) comicsView->setModel(NULL); foldersView->setModel(NULL); + listsView->setModel(NULL); disableAllActions();//TODO comprobar que se deben deshabilitar //será possible renombrar y borrar estas bibliotecas renameLibraryAction->setEnabled(true); @@ -1218,6 +1229,7 @@ void LibraryWindow::loadLibrary(const QString & name) { comicsView->setModel(NULL); foldersView->setModel(NULL); + listsView->setModel(NULL); disableAllActions();//TODO comprobar que se deben deshabilitar //si la librería no existe en disco, se ofrece al usuario la posibiliad de eliminarla @@ -1788,6 +1800,7 @@ void LibraryWindow::deleteCurrentLibrary() { comicsView->setModel(NULL); foldersView->setModel(NULL); + listsView->setModel(NULL); disableAllActions(); showNoLibrariesWidget(); @@ -1812,6 +1825,7 @@ void LibraryWindow::removeLibrary() { comicsView->setModel(NULL); foldersView->setModel(NULL); + listsView->setModel(NULL); disableAllActions(); showNoLibrariesWidget(); diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 1611d784..34dfe0a3 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -58,6 +58,8 @@ class NoSearchResultsWidget; class EditShortcutsDialog; class ComicFilesManager; class QProgressDialog; +class ReadingListModel; +class YACReaderReadingListsView; #include "comic_db.h" @@ -109,9 +111,11 @@ private: NoSearchResultsWidget * noSearchResultsWidget; YACReaderFoldersView * foldersView; + YACReaderReadingListsView * listsView; YACReaderLibraryListWidget * selectedLibrary; FolderModel * foldersModel; ComicModel * comicsModel; + ReadingListModel * listsModel; //QStringList paths; YACReaderLibraries libraries; diff --git a/images/lists/list.png b/images/lists/list.png index ee18e955..9d890d42 100644 Binary files a/images/lists/list.png and b/images/lists/list.png differ diff --git a/images/lists/reading.png b/images/lists/reading.png index 6548c42e..b00a0b6f 100644 Binary files a/images/lists/reading.png and b/images/lists/reading.png differ