[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
KLFLibModelCache Class Reference

#include <klflibview_p.h>

Collaboration diagram for KLFLibModelCache:
Collaboration graph
[legend]

Classes

struct  CategoryLabelNode
 
struct  EntryNode
 
class  KLFLibModelSorter
 
struct  Node
 
class  NodeCache
 
struct  NodeId
 

Public Types

enum  ItemKind { EntryKind = KLFLibModel::EntryKind, CategoryLabelKind = KLFLibModel::CategoryLabelKind }
 
typedef qint32 IndexType
 
typedef quint32 UIDType
 
typedef NodeCache< EntryNodeEntryCache
 
typedef NodeCache
< CategoryLabelNode
CategoryLabelCache
 

Public Member Functions

 KLFLibModelCache (KLFLibModel *model)
 
virtual ~KLFLibModelCache ()
 
void rebuildCache ()
 
QModelIndex createIndexFromId (NodeId nodeid, int row, int column)
 
NodeId getNodeForIndex (const QModelIndex &index)
 
Node getNode (NodeId nodeid)
 
NodegetNodeRef (NodeId nodeid)
 
EntryNodegetEntryNodeRef (NodeId nodeid, bool requireNotMinimalist=false)
 
CategoryLabelNodegetCategoryLabelNodeRef (NodeId nodeid)
 
int getNodeRow (NodeId nodeid)
 
void ensureNotMinimalist (NodeId nodeId, int count=-1)
 
bool canFetchMore (NodeId parentId)
 
void fetchMore (NodeId parentId, int batchCount=-1)
 
void updateData (const QList< KLFLib::entryId > &entryIdList, int modifyType)
 
void treeInsertEntry (const EntryNode &e, bool isRebuildingCache=false)
 
EntryNode treeTakeEntry (const NodeId &e, bool notifyQtApi=true)
 
IndexType cacheFindCategoryLabel (QStringList catelements, bool createIfNotExists=false, bool notifyQtApi=false, bool newlyCreatedAreChildrenFetched=true)
 
QString nodeValue (NodeId node, int propId=KLFLibEntry::Latex)
 
bool searchNodeMatches (const NodeId &nodeId, const QString &searchString, Qt::CaseSensitivity cs)
 
void setSortingBy (int propId, Qt::SortOrder order)
 
void sortCategory (NodeId category, KLFLibModelSorter *sorter, bool rootCall=true)
 
NodeId nextNode (NodeId n)
 
NodeId prevNode (NodeId n)
 
NodeId lastNode (NodeId n)
 
QList< KLFLib::entryIdentryIdList (const QModelIndexList &indexlist)
 
QList< KLFLib::entryIdentryIdForIndexList (const QModelIndexList &indexlist)
 
QModelIndexList findEntryIdList (const QList< KLFLib::entryId > &eidlist)
 
NodeId findEntryId (KLFLib::entryId eId)
 
QStringList categoryListCache ()
 
void fullDump ()
 
void dumpNodeTree (NodeId node, int indent=0)
 

Static Public Member Functions

static QList< int > minimalistEntryPropIds ()
 

Public Attributes

EntryNode pInvalidEntryNode
 
KLFLibModelpModel
 

Static Public Attributes

static const quint8 UIDKindShift = 30
 
static const UIDType UIDKindMask = 0xC0000000
 
static const UIDType UIDIndexMask = 0x3FFFFFFF
 
static const UIDType UIDInvalid = 0xFFFFFFFF
 

Detailed Description

Definition at line 72 of file klflibview_p.h.

Member Typedef Documentation

Definition at line 206 of file klflibview_p.h.

Definition at line 205 of file klflibview_p.h.

Definition at line 75 of file klflibview_p.h.

typedef quint32 KLFLibModelCache::UIDType

UIDType standing for UniversalIdType: on 32 bits:

  mask shift for Node Kind:  30 bits
  mask for Node Kind:  0x c0000000
  mask for Node Index: 0x 3FFFFFFF

Definition at line 83 of file klflibview_p.h.

Member Enumeration Documentation

Enumerator
EntryKind 
CategoryLabelKind 

Definition at line 89 of file klflibview_p.h.

Constructor & Destructor Documentation

KLFLibModelCache::KLFLibModelCache ( KLFLibModel model)
inline

Definition at line 212 of file klflibview_p.h.

References KLFLibEntry::DateTime.

virtual KLFLibModelCache::~KLFLibModelCache ( )
inlinevirtual

Definition at line 221 of file klflibview_p.h.

Member Function Documentation

KLFLibModelCache::IndexType KLFLibModelCache::cacheFindCategoryLabel ( QStringList  catelements,
bool  createIfNotExists = false,
bool  notifyQtApi = false,
bool  newlyCreatedAreChildrenFetched = true 
)

emits QAbstractItemModel-appropriate signals and updates indexes if notifyQtApi is true.

If newlyCreatedAreChildrenFetched is TRUE, then any newly created CategoryLabelNode will have its allChildrenFetched flag set to TRUE (eg. when updating data, a new entry was changed category to a yet-inexistant category). If the parameter is FALSE, then any newly created CategoryLabelNode will have its allChildrenFetched flag set to FALSE (eg. when rebuilding the cache).

Definition at line 1116 of file klflibview.cpp.

References KLFLibModelCache::Node::allChildrenFetched, QList::begin(), QAbstractItemModel::beginInsertRows(), KLFLibModelCache::CategoryLabelNode::categoryLabel, CategoryLabelKind, KLFLibModel::CategoryTree, KLFLibModelCache::Node::children, createIndexFromId(), KLFLibModel::displayType(), QList::end(), QAbstractItemModel::endInsertRows(), KLFLibModelCache::CategoryLabelNode::fullCategoryPath, KLFLibModel::GroupSubCategories, QList::insert(), KLFLibModelCache::NodeCache< N >::insertNewNode(), KLFLibModelCache::NodeCache< N >::isAllocated(), QStringList::join(), KLF_FUNC_NAME, klfDbg, pModel, and QList::size().

Referenced by rebuildCache(), and treeInsertEntry().

bool KLFLibModelCache::canFetchMore ( NodeId  parentId)
QStringList KLFLibModelCache::categoryListCache ( )
inline

Definition at line 359 of file klflibview_p.h.

Referenced by KLFLibModel::categoryList().

QModelIndex KLFLibModelCache::createIndexFromId ( NodeId  nodeid,
int  row,
int  column 
)
void KLFLibModelCache::dumpNodeTree ( NodeId  node,
int  indent = 0 
)
void KLFLibModelCache::ensureNotMinimalist ( NodeId  nodeId,
int  count = -1 
)
QList< KLFLib::entryId > KLFLibModelCache::entryIdForIndexList ( const QModelIndexList &  indexlist)

Returns a list of same size as indexlist in which each entry is exactly the entryId of the corresponding index in indexlist, setting -1 if it isn't an entry index.

Definition at line 1388 of file klflibview.cpp.

References KLFLibModelCache::EntryNode::entryid, EntryKind, getEntryNodeRef(), getNodeForIndex(), KLFLibModelCache::NodeId::kind, and KLFLibModelCache::NodeId::valid().

Referenced by KLFLibModel::entryIdForIndexList().

QList< KLFLib::entryId > KLFLibModelCache::entryIdList ( const QModelIndexList &  indexlist)

Returns a list of all valid entryIds in the index list. ORDER of result is not garanteed and invalid indexes are ignored, as opposed to entryIdForIndexList().

Definition at line 1366 of file klflibview.cpp.

References QList::contains(), KLFLibModelCache::EntryNode::entryid, EntryKind, getEntryNodeRef(), getNodeForIndex(), KLFLibModelCache::NodeId::kind, and KLFLibModelCache::NodeId::valid().

void KLFLibModelCache::fetchMore ( NodeId  parentId,
int  batchCount = -1 
)
Todo:
....... the items are appended. this supposes that the items that may have already been listed as children nodes are the beginning, and that what we fetched is what follows. This order must be enforced when updating data, for eg. an entry category change. (in updateData()).

Definition at line 735 of file klflibview.cpp.

References KLFLibModelCache::Node::allChildrenFetched, QList::append(), QAbstractItemModel::beginInsertRows(), KLFLibEntry::Category, CategoryLabelKind, KLFLibModel::CategoryTree, KLFLibModelCache::Node::children, createIndexFromId(), KLFLibResourceEngine::defaultSubResource(), QAbstractItemModel::endInsertRows(), KLFLibModelCache::EntryNode::entry, KLFLibResourceEngine::KLFLibEntryWithId::entry, KLFLibModelCache::EntryNode::entryid, EntryKind, KLFLibResourceEngine::QueryResult::entryWithIdList, KLFLibResourceEngine::QueryResult::FillEntryWithIdList, KLFLibModelCache::CategoryLabelNode::fullCategoryPath, fullDump(), getCategoryLabelNodeRef(), KLFLibResourceEngine::KLFLibEntryWithId::id, KLFLibModelCache::NodeId::index, KLFLibModelCache::NodeId::kind, KLFLibModelCache::Node::kind, KLF_DEBUG_TIME_BLOCK, KLF_FUNC_NAME, klfDbg, KLFLibResourceEngine::Query::limit, KLFLibResourceEngine::Query::matchCondition, KLFLibModelCache::EntryNode::minimalist, minimalistEntryPropIds(), KLFLib::EntryMatchCondition::mkPropertyMatch(), KLFLibEntry::normalizeCategoryPath(), KLFLibResourceEngine::Query::orderDirection, KLFLibResourceEngine::Query::orderPropId, KLFLibModelCache::Node::parent, pModel, KLFLibResourceEngine::query(), KLFLibModelCache::NodeId::rootNode(), QList::size(), KLFLibResourceEngine::Query::skip, KLFLibModel::url(), KLFLibModelCache::NodeId::valid(), and KLFLibResourceEngine::Query::wantedEntryProperties.

Referenced by createIndexFromId(), KLFLibModel::fetchMore(), lastNode(), nextNode(), and treeInsertEntry().

KLFLibModelCache::NodeId KLFLibModelCache::findEntryId ( KLFLib::entryId  eId)

Definition at line 1428 of file klflibview.cpp.

References EntryKind, klfDbg, and QList::size().

Referenced by updateData().

QModelIndexList KLFLibModelCache::findEntryIdList ( const QList< KLFLib::entryId > &  eidlist)
void KLFLibModelCache::fullDump ( )
KLFLibModelCache::CategoryLabelNode & KLFLibModelCache::getCategoryLabelNodeRef ( NodeId  nodeid)
KLFLibModelCache::EntryNode & KLFLibModelCache::getEntryNodeRef ( NodeId  nodeid,
bool  requireNotMinimalist = false 
)
KLFLibModelCache::Node KLFLibModelCache::getNode ( NodeId  nodeid)
KLFLibModelCache::NodeId KLFLibModelCache::getNodeForIndex ( const QModelIndex index)
KLFLibModelCache::Node & KLFLibModelCache::getNodeRef ( NodeId  nodeid)
int KLFLibModelCache::getNodeRow ( NodeId  nodeid)
KLFLibModelCache::NodeId KLFLibModelCache::lastNode ( NodeId  n)

Returns the last node in tree defined by node n.

If n has children, returns last child of the last child of the last child etc. If n does not have children, it is itself returned.

If NULL is given, the root node is assumed.

Definition at line 1339 of file klflibview.cpp.

References KLFLibModelCache::Node::allChildrenFetched, canFetchMore(), KLFLibModelCache::Node::children, fetchMore(), getNode(), KLF_FUNC_NAME, KLFLibModelCache::NodeId::rootNode(), and KLFLibModelCache::NodeId::valid().

Referenced by prevNode().

static QList<int> KLFLibModelCache::minimalistEntryPropIds ( )
inlinestatic

define here what prop ids are stored in minimalist entries. Warning: some functions may make some assumptions on what minimalist entries have, and these properties must make sense here (eg. PreviewSize for delegate's sizeHint(), Category for creating the tree, etc.)

Definition at line 246 of file klflibview_p.h.

References KLFLibEntry::Category, KLFLibEntry::DateTime, KLFLibEntry::Latex, KLFLibEntry::PreviewSize, and KLFLibEntry::Tags.

Referenced by KLFLibModel::data(), fetchMore(), and rebuildCache().

KLFLibModelCache::NodeId KLFLibModelCache::nextNode ( NodeId  n)

Walks the whole tree returning all the nodes one after the other, in the following order: if n has children, first child is returned; otherwise next sibling is returned.

This function returns all nodes in the order they would be displayed in a tree view.

Returns NULL after last node. Returns first node in tree if NULL is given as paremeter.

Definition at line 1274 of file klflibview.cpp.

References KLFLibModelCache::Node::allChildrenFetched, canFetchMore(), KLFLibModelCache::Node::children, fetchMore(), getNode(), getNodeRow(), KLFLibModelCache::Node::parent, KLFLibModelCache::NodeId::rootNode(), and KLFLibModelCache::NodeId::valid().

Referenced by ensureNotMinimalist(), KLFLibModel::searchFindNext(), and KLFLibModel::walkNextIndex().

QString KLFLibModelCache::nodeValue ( NodeId  node,
int  propId = KLFLibEntry::Latex 
)
KLFLibModelCache::NodeId KLFLibModelCache::prevNode ( NodeId  n)

Same as nextNode() but the walk is performed in the opposite direction.

This function returns all nodes in the inverse order they would be displayed in a tree view. In particular, it returns a parent node after having explored its children.

Definition at line 1317 of file klflibview.cpp.

References KLFLibModelCache::Node::children, getNode(), getNodeRow(), KLFLibModelCache::NodeId::isRoot(), lastNode(), KLFLibModelCache::Node::parent, KLFLibModelCache::NodeId::rootNode(), and KLFLibModelCache::NodeId::valid().

Referenced by KLFLibModel::searchFindNext(), and KLFLibModel::walkPrevIndex().

void KLFLibModelCache::rebuildCache ( )
bool KLFLibModelCache::searchNodeMatches ( const NodeId nodeId,
const QString searchString,
Qt::CaseSensitivity  cs 
)

returns TRUE if the node nodeId matches the search query defined by searchString and case-sensitivity cs.

Definition at line 2272 of file klflibview.cpp.

References KLFLibEntry::Category, CategoryLabelKind, KLFLibModel::CategoryTree, KLFLibModelCache::NodeId::kind, KLF_DEBUG_TIME_BLOCK, KLF_FUNC_NAME, KLFLibEntry::Latex, nodeValue(), pModel, and KLFLibEntry::Tags.

Referenced by KLFLibModel::searchFindNext().

void KLFLibModelCache::setSortingBy ( int  propId,
Qt::SortOrder  order 
)
inline

Remembers the given sort parameters, but does NOT update anything.

Definition at line 318 of file klflibview_p.h.

Referenced by KLFLibModel::sort().

void KLFLibModelCache::sortCategory ( NodeId  category,
KLFLibModelSorter sorter,
bool  rootCall = true 
)
void KLFLibModelCache::treeInsertEntry ( const EntryNode e,
bool  isRebuildingCache = false 
)

if isRebuildingCache is set, then items are just appended to the category childs (as they are inserted in the right order), and calls to cacheFindCategoryLabel will set newlyCreatedAllChildrenFetched parameter to FALSE.

emits QAbstractItemModel-appropriate beginInsertRows()/endInsertRows() if isRebuildingCache is FALSE. Those signals are also emitted (if isRebuildingCache is false) when category labels are created to fit the node.

The entry-node e must not be yet in the entry cache.

Definition at line 963 of file klflibview.cpp.

References QList::begin(), QAbstractItemModel::beginInsertRows(), cacheFindCategoryLabel(), canFetchMore(), KLFLibEntry::category(), CategoryLabelKind, KLFLibModel::CategoryTree, KLFLibModelCache::Node::children, createIndexFromId(), KLFLibModel::displayType(), QList::end(), QAbstractItemModel::endInsertRows(), KLFLibModelCache::EntryNode::entry, EntryKind, fetchMore(), KLFLibModelCache::CategoryLabelNode::fullCategoryPath, getCategoryLabelNodeRef(), getNodeRef(), KLFLibModel::GroupSubCategories, KLFLibModelCache::NodeId::index, QList::insert(), KLFLibModelCache::NodeCache< N >::insertNewNode(), KLFLibModelCache::NodeId::kind, KLF_DEBUG_TIME_BLOCK, KLF_FUNC_NAME, klfDbg, KLFLibModel::LinearList, pModel, QList::size(), and QString::split().

Referenced by rebuildCache(), and updateData().

KLFLibModelCache::EntryNode KLFLibModelCache::treeTakeEntry ( const NodeId e,
bool  notifyQtApi = true 
)
void KLFLibModelCache::updateData ( const QList< KLFLib::entryId > &  entryIdList,
int  modifyType 
)

Member Data Documentation

EntryNode KLFLibModelCache::pInvalidEntryNode

Definition at line 208 of file klflibview_p.h.

Referenced by getNodeRef().

KLFLibModel* KLFLibModelCache::pModel
const UIDType KLFLibModelCache::UIDIndexMask = 0x3FFFFFFF
static

Definition at line 86 of file klflibview_p.h.

Referenced by KLFLibModelCache::NodeId::fromUID().

const UIDType KLFLibModelCache::UIDInvalid = 0xFFFFFFFF
static

Definition at line 87 of file klflibview_p.h.

const UIDType KLFLibModelCache::UIDKindMask = 0xC0000000
static

Definition at line 85 of file klflibview_p.h.

Referenced by KLFLibModelCache::NodeId::fromUID().

const quint8 KLFLibModelCache::UIDKindShift = 30
static

The documentation for this class was generated from the following files:

Generated by doxygen 1.8.6