mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added sublists support to ReadingListsModel
This commit is contained in:
parent
73060fe064
commit
9250f02474
@ -28,8 +28,8 @@ LIBS += -lpoppler-qt4
|
||||
INCLUDEPATH += ../dependencies/poppler/include/qt4
|
||||
}
|
||||
|
||||
QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL
|
||||
QMAKE_LFLAGS_RELEASE += /LTCG
|
||||
#QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL
|
||||
#QMAKE_LFLAGS_RELEASE += /LTCG
|
||||
CONFIG -= embed_manifest_exe
|
||||
}
|
||||
|
||||
|
@ -70,11 +70,7 @@ public:
|
||||
QList<FolderItem*> children();
|
||||
private:
|
||||
QList<FolderItem*> childItems;
|
||||
QList<QVariant> itemData;
|
||||
|
||||
|
||||
|
||||
|
||||
QList<QVariant> itemData;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
|
@ -230,7 +230,7 @@ QModelIndex FolderModel::parent(const QModelIndex &index) const
|
||||
if (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
//! [7]
|
||||
|
||||
|
@ -107,3 +107,11 @@ void ReadingListItem::appendChild(ReadingListItem *item)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int ReadingListItem::row() const
|
||||
{
|
||||
if (parent)
|
||||
return parent->childItems.indexOf(const_cast<ReadingListItem*>(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -40,13 +40,15 @@ class ReadingListItem : public ListItem
|
||||
public:
|
||||
ReadingListItem(const QList<QVariant> &data, ReadingListItem * parent = 0);
|
||||
QIcon getIcon() const;
|
||||
ReadingListItem * parent;
|
||||
int childCount() const;
|
||||
int row() const;
|
||||
ReadingListItem * child(int row);
|
||||
void appendChild(ReadingListItem *item);
|
||||
|
||||
private:
|
||||
QList<ReadingListItem*> childItems;
|
||||
ReadingListItem * parent;
|
||||
|
||||
};
|
||||
|
||||
#endif // READING_LIST_ITEM_H
|
||||
|
@ -12,7 +12,17 @@ int ReadingListModel::rowCount(const QModelIndex &parent) const
|
||||
if(!parent.isValid()) //TOP
|
||||
return specialLists.count() + labels.count() + rootItem->childCount();
|
||||
else
|
||||
return 0;
|
||||
{
|
||||
ListItem * item = static_cast<ListItem*>(parent.internalPointer());
|
||||
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * item = static_cast<ReadingListItem*>(parent.internalPointer());
|
||||
return item->childCount();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ReadingListModel::columnCount(const QModelIndex &parent) const
|
||||
@ -63,14 +73,6 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
||||
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())
|
||||
@ -82,6 +84,17 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
||||
if(row >= specialLists.count() + labels.count())
|
||||
return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count())));
|
||||
|
||||
} else //sublist
|
||||
{
|
||||
ReadingListItem *parentItem;
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem; //this should be impossible
|
||||
else
|
||||
parentItem = static_cast<ReadingListItem*>(parent.internalPointer());
|
||||
|
||||
ReadingListItem *childItem = parentItem->child(row);
|
||||
return createIndex(row,column,childItem);
|
||||
}
|
||||
/*FolderItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
@ -93,16 +106,21 @@ QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &pare
|
||||
|
||||
QModelIndex ReadingListModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
//if (!index.isValid())
|
||||
|
||||
if(!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
/*FolderItem *childItem = static_cast<FolderItem*>(index.internalPointer());
|
||||
FolderItem *parentItem = childItem->parent();
|
||||
ListItem * item = static_cast<ListItem*>(index.internalPointer());
|
||||
|
||||
if (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
if(typeid(*item) == typeid(ReadingListItem))
|
||||
{
|
||||
ReadingListItem * childItem = static_cast<ReadingListItem*>(index.internalPointer());
|
||||
ReadingListItem * parent = childItem->parent;
|
||||
if(parent != 0)
|
||||
return createIndex(parent->row(), 0, parent);
|
||||
}
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem); */
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void ReadingListModel::setupModelData(QString path)
|
||||
@ -146,9 +164,12 @@ void ReadingListModel::setupModelData(QString path)
|
||||
rootItem = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "ROOT" << "atr");
|
||||
|
||||
//setup reading lists
|
||||
rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "My reading list" << "atr"));
|
||||
ReadingListItem * node1;
|
||||
rootItem->appendChild(node1 = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "My reading list" << "atr"));
|
||||
rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "X timeline" << "atr"));
|
||||
|
||||
node1->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "sublist" << "atr",node1));
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user