mirror of
https://github.com/YACReader/yacreader
synced 2025-07-27 01:15:07 -04:00
added separators to the reading lists model/view
This commit is contained in:
@ -115,3 +115,15 @@ int ReadingListItem::row() const
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ReadingListSeparatorItem::ReadingListSeparatorItem()
|
||||
:ListItem(QList<QVariant>())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QIcon ReadingListSeparatorItem::getIcon() const
|
||||
{
|
||||
return QIcon();
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public:
|
||||
int columnCount();
|
||||
virtual QIcon getIcon() const = 0;
|
||||
QVariant data(int column) const;
|
||||
protected:
|
||||
|
||||
QList<QVariant> itemData;
|
||||
};
|
||||
|
||||
@ -51,4 +51,13 @@ private:
|
||||
|
||||
};
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
class ReadingListSeparatorItem : public ListItem
|
||||
{
|
||||
public:
|
||||
ReadingListSeparatorItem();
|
||||
QIcon getIcon() const;
|
||||
};
|
||||
|
||||
#endif // READING_LIST_ITEM_H
|
||||
|
@ -2,19 +2,28 @@
|
||||
|
||||
#include "reading_list_item.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
ReadingListModel::ReadingListModel(QObject *parent) :
|
||||
QAbstractItemModel(parent),rootItem(0)
|
||||
{
|
||||
separator1 = new ReadingListSeparatorItem;
|
||||
separator2 = new ReadingListSeparatorItem;
|
||||
}
|
||||
|
||||
int ReadingListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if(!parent.isValid()) //TOP
|
||||
return specialLists.count() + labels.count() + rootItem->childCount();
|
||||
{
|
||||
int separatorsCount = labels.isEmpty()?1:2;
|
||||
return specialLists.count() + labels.count() + rootItem->childCount() + separatorsCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
||||
|
||||
QLOG_DEBUG() << item->itemData;
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * item = static_cast<ReadingListItem*>(parent.internalPointer());
|
||||
@ -27,6 +36,12 @@ int ReadingListModel::rowCount(const QModelIndex &parent) const
|
||||
|
||||
int ReadingListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
{
|
||||
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
||||
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
/*if (parent.isValid())
|
||||
return static_cast<ListItem*>(parent.internalPointer())->columnCount();
|
||||
@ -41,6 +56,9 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
return QVariant(item->getIcon());
|
||||
@ -57,6 +75,10 @@ Qt::ItemFlags ReadingListModel::flags(const QModelIndex &index) const
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||
if(typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
return 0;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
|
||||
@ -75,14 +97,23 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
||||
|
||||
if(!parent.isValid())
|
||||
{
|
||||
int separatorsCount = labels.isEmpty()?1:2;
|
||||
|
||||
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())
|
||||
return createIndex(row,column,separator1);
|
||||
|
||||
if(row >= specialLists.count() + labels.count())
|
||||
return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count())));
|
||||
if(row > specialLists.count() && row <= specialLists.count() + labels.count())
|
||||
return createIndex(row,column,labels.at(row-specialLists.count()-1));
|
||||
|
||||
if(separatorsCount == 2)
|
||||
if(row == specialLists.count() + labels.count() + 1)
|
||||
return createIndex(row,column,separator2);
|
||||
|
||||
if(row >= specialLists.count() + labels.count() + separatorsCount)
|
||||
return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count() + separatorsCount)));
|
||||
|
||||
} else //sublist
|
||||
{
|
||||
@ -146,6 +177,8 @@ void ReadingListModel::setupModelData(QString path)
|
||||
specialLists << new SpecialListItem(QList<QVariant>() /*<< 0*/ << "Favorites");
|
||||
specialLists << new SpecialListItem(QList<QVariant>() /*<< 1*/ << "Reading");
|
||||
|
||||
//separator
|
||||
|
||||
//setup labels
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 0*/ << "Oh Oh" << "red");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 1*/ << "lalala" << "orange");
|
||||
@ -160,6 +193,8 @@ void ReadingListModel::setupModelData(QString path)
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 10*/ << "ainsss" << "light");
|
||||
labels << new LabelItem(QList<QVariant>() /*<< 11*/ << "put a smile on my face" << "dark");
|
||||
|
||||
//separator
|
||||
|
||||
//setup root item
|
||||
rootItem = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "ROOT" << "atr");
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
class LabelItem;
|
||||
class SpecialListItem;
|
||||
class ReadingListItem;
|
||||
class ReadingListSeparatorItem;
|
||||
|
||||
class ReadingListModel : public QAbstractItemModel
|
||||
{
|
||||
@ -49,6 +50,10 @@ private:
|
||||
ReadingListItem * rootItem; //
|
||||
QMap<unsigned long long int, ReadingListItem *> items; //lists relationship
|
||||
|
||||
//separators
|
||||
ReadingListSeparatorItem * separator1;
|
||||
ReadingListSeparatorItem * separator2;
|
||||
|
||||
QString _databasePath;
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user