mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added some dummy lists for visual testing, list model is partially implemented
This commit is contained in:
parent
c14c3b2031
commit
73060fe064
@ -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;};
|
||||
|
@ -1,5 +1,109 @@
|
||||
#include "reading_list_item.h"
|
||||
|
||||
ReadingListItem::ReadingListItem()
|
||||
ListItem::ListItem(const QList<QVariant> &data)
|
||||
:itemData(data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ListItem::columnCount()
|
||||
{
|
||||
return itemData.count();
|
||||
}
|
||||
|
||||
QVariant ListItem::data(int column) const
|
||||
{
|
||||
return itemData.at(column);
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
SpecialListItem::SpecialListItem(const QList<QVariant> &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<QVariant> &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<QVariant> &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<73> disponible, sino el nombre del fichero.....
|
||||
QString nameCurrent = item->data(1).toString();
|
||||
QList<FolderItem *>::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<70>s
|
||||
childItems.insert(++i,item);
|
||||
else
|
||||
childItems.insert(i,item);*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,52 @@
|
||||
#ifndef READING_LIST_ITEM_H
|
||||
#define READING_LIST_ITEM_H
|
||||
|
||||
class ReadingListItem
|
||||
#include <QIcon>
|
||||
#include <QVariant>
|
||||
|
||||
class ListItem
|
||||
{
|
||||
public:
|
||||
ReadingListItem();
|
||||
ListItem(const QList<QVariant> &data);
|
||||
int columnCount();
|
||||
virtual QIcon getIcon() const = 0;
|
||||
QVariant data(int column) const;
|
||||
protected:
|
||||
QList<QVariant> itemData;
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
class SpecialListItem : public ListItem
|
||||
{
|
||||
public:
|
||||
SpecialListItem(const QList<QVariant> &data);
|
||||
QIcon getIcon() const;
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
class LabelItem : public ListItem
|
||||
{
|
||||
public:
|
||||
LabelItem(const QList<QVariant> &data);
|
||||
QIcon getIcon() const;
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
class ReadingListItem : public ListItem
|
||||
{
|
||||
public:
|
||||
ReadingListItem(const QList<QVariant> &data, ReadingListItem * parent = 0);
|
||||
QIcon getIcon() const;
|
||||
int childCount() const;
|
||||
ReadingListItem * child(int row);
|
||||
void appendChild(ReadingListItem *item);
|
||||
|
||||
private:
|
||||
QList<ReadingListItem*> childItems;
|
||||
ReadingListItem * parent;
|
||||
};
|
||||
|
||||
#endif // READING_LIST_ITEM_H
|
||||
|
@ -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<ListItem*>(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<ListItem*>(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<ListItem*>(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<FolderItem*>(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<QVariant>() /*<< 0*/ << "Favorites");
|
||||
specialLists << new SpecialListItem(QList<QVariant>() /*<< 1*/ << "Reading");
|
||||
|
||||
//setup labels
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 0*/ << "Oh Oh" << "red");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 1*/ << "lalala" << "orange");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 2*/ << "we are not sorry" << "yellow");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 3*/ << "there we go" << "green");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 4*/ << "oklabunga" << "cyan");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 5*/ << "hailer mailer" << "blue");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 6*/ << "lol" << "violet");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 7*/ << "problems" << "purple");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 8*/ << "me gussssta" << "pink");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 9*/ << ":D" << "white");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 10*/ << "ainsss" << "light");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 11*/ << "put a smile on my face" << "dark");
|
||||
|
||||
//setup root item
|
||||
rootItem = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "ROOT" << "atr");
|
||||
|
||||
//setup reading lists
|
||||
rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "My reading list" << "atr"));
|
||||
rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "X timeline" << "atr"));
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ReadingListModel::deleteItem(const QModelIndex &mi)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ReadingListModel::setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,14 @@
|
||||
#define READING_LIST_MODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QModelIndex>
|
||||
#include <QVariant>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
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<SpecialListItem *> specialLists;
|
||||
|
||||
//Label
|
||||
QList<LabelItem *> labels;
|
||||
|
||||
//Reading lists
|
||||
ReadingListItem * rootItem; //
|
||||
QMap<unsigned long long int, ReadingListItem *> items; //lists relationship
|
||||
|
||||
QString _databasePath;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 165 B After Width: | Height: | Size: 184 B |
Binary file not shown.
Before Width: | Height: | Size: 201 B After Width: | Height: | Size: 233 B |
Loading…
x
Reference in New Issue
Block a user