BibleTime
Public Types | Public Slots | Public Member Functions | Private Member Functions | Private Attributes | List of all members
BtBookmarksModel Class Reference

#include <btbookmarksmodel.h>

Inheritance diagram for BtBookmarksModel:

Public Types

enum  BookmarksRoles { TypeRole = Qt::UserRole + 1 }
 

Public Slots

bool load (QString fileName=QString(), const QModelIndex &rootItem=QModelIndex())
 Import bookmarks from file. More...
 
bool save (QString fileName=QString(), const QModelIndex &rootItem=QModelIndex())
 Save bookmarks or specified branch to file. More...
 

Public Member Functions

QModelIndex addBookmark (int const row, QModelIndex const &parent, CSwordModuleInfo const &module, QString const &key, QString const &description=QString(), QString const &title=QString())
 add new item with given parameters More...
 
QModelIndex addFolder (int row, const QModelIndex &parent, const QString &name=QString())
 add new folder. More...
 
 BtBookmarksModel (QObject *parent=nullptr)
 
 BtBookmarksModel (QString const &fileName=QString(), QObject *parent=nullptr)
 Constructor/destructor for new bookmarks model, data is loaded on first constructor call and unloaded on last destructor call. More...
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
void copyItems (int row, const QModelIndex &parent, const QModelIndexList &toCopy)
 Copies item to target position. More...
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
QString description (const QModelIndex &index) const
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const override
 
bool hasDescendant (const QModelIndex &baseIndex, const QModelIndex &testIndex) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 
bool isBookmark (const QModelIndex &index) const
 
bool isFolder (const QModelIndex &index) const
 
QString key (const QModelIndex &index) const
 
CSwordModuleInfomodule (const QModelIndex &index) const
 
QModelIndex parent (const QModelIndex &index) const override
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 
QHash< int, QByteArray > roleNames () const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
void setDescription (const QModelIndex &index, const QString &description)
 set descritpion for index. More...
 
void sortItems (QModelIndex const &parent=QModelIndex(), Qt::SortOrder const order=Qt::AscendingOrder)
 
 ~BtBookmarksModel () override
 

Private Member Functions

bool slotSave ()
 

Private Attributes

BtBookmarksModelPrivate *const d_ptr
 

Detailed Description

Model to load and display bookmarks. It is saved periodically if it was loaded from default bookmarks file. No more one such model allowed at time.

Definition at line 25 of file btbookmarksmodel.h.

Member Enumeration Documentation

◆ BookmarksRoles

Enumerator
TypeRole 

Definition at line 32 of file btbookmarksmodel.h.

Constructor & Destructor Documentation

◆ BtBookmarksModel() [1/2]

BtBookmarksModel::BtBookmarksModel ( QObject parent = nullptr)

Definition at line 553 of file btbookmarksmodel.cpp.

References load().

◆ BtBookmarksModel() [2/2]

BtBookmarksModel::BtBookmarksModel ( QString const &  fileName = QString(),
QObject parent = nullptr 
)

Constructor/destructor for new bookmarks model, data is loaded on first constructor call and unloaded on last destructor call.

Parameters
[in]fileNameloads a list of items (with subitem trees) from a named file or from the default bookmarks file if empty.

Definition at line 560 of file btbookmarksmodel.cpp.

References load().

◆ ~BtBookmarksModel()

BtBookmarksModel::~BtBookmarksModel ( )
override

Definition at line 565 of file btbookmarksmodel.cpp.

References d_ptr, and save().

Member Function Documentation

◆ addBookmark()

QModelIndex BtBookmarksModel::addBookmark ( int const  row,
QModelIndex const &  parent,
CSwordModuleInfo const &  module,
QString const &  key,
QString const &  description = QString(),
QString const &  title = QString() 
)

add new item with given parameters

Definition at line 829 of file btbookmarksmodel.cpp.

References description(), key(), module(), parent(), r(), and rowCount().

Referenced by CBookmarkIndex::dropEvent().

◆ addFolder()

QModelIndex BtBookmarksModel::addFolder ( int  row,
const QModelIndex &  parent,
const QString &  name = QString() 
)

add new folder.

Definition at line 855 of file btbookmarksmodel.cpp.

References parent().

Referenced by CBookmarkIndex::CBookmarkIndex().

◆ columnCount()

int BtBookmarksModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 582 of file btbookmarksmodel.cpp.

References parent().

◆ copyItems()

void BtBookmarksModel::copyItems ( int  row,
const QModelIndex &  parent,
const QModelIndexList &  toCopy 
)

Copies item to target position.

Parameters
[in]rownew item will occupy given row.
[in]parentif invalid new item will be placed on top level.
[in]toCopyitem to copy.

Definition at line 740 of file btbookmarksmodel.cpp.

References BT_ASSERT, index(), and parent().

Referenced by CBookmarkIndex::dropEvent().

◆ data()

QVariant BtBookmarksModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 607 of file btbookmarksmodel.cpp.

References index(), isBookmark(), and TypeRole.

◆ description()

QString BtBookmarksModel::description ( const QModelIndex &  index) const
Returns
description for specified index if have.

Definition at line 810 of file btbookmarksmodel.cpp.

References index().

Referenced by addBookmark(), CBookmarkIndex::CBookmarkIndex(), CBookmarkIndex::dragObject(), and setDescription().

◆ flags()

Qt::ItemFlags BtBookmarksModel::flags ( const QModelIndex &  index) const
override

Definition at line 632 of file btbookmarksmodel.cpp.

References index().

◆ hasChildren()

bool BtBookmarksModel::hasChildren ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 587 of file btbookmarksmodel.cpp.

References parent(), and rowCount().

◆ hasDescendant()

bool BtBookmarksModel::hasDescendant ( const QModelIndex &  baseIndex,
const QModelIndex &  testIndex 
) const
Returns
true if the testIndex is baseIndex or a direct or indirect subitem of baseIndex.

Definition at line 874 of file btbookmarksmodel.cpp.

Referenced by CBookmarkIndex::dropEvent().

◆ headerData()

QVariant BtBookmarksModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

Definition at line 638 of file btbookmarksmodel.cpp.

◆ index()

QModelIndex BtBookmarksModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
override

◆ insertRows()

bool BtBookmarksModel::insertRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
override

Definition at line 674 of file btbookmarksmodel.cpp.

References BT_ASSERT, and parent().

Referenced by CBookmarkIndex::CBookmarkIndex().

◆ isBookmark()

bool BtBookmarksModel::isBookmark ( const QModelIndex &  index) const

◆ isFolder()

bool BtBookmarksModel::isFolder ( const QModelIndex &  index) const

◆ key()

QString BtBookmarksModel::key ( const QModelIndex &  index) const
Returns
key for specified index if have.

Definition at line 801 of file btbookmarksmodel.cpp.

References index().

Referenced by addBookmark(), CBookmarkIndex::CBookmarkIndex(), and CBookmarkIndex::dragObject().

◆ load

bool BtBookmarksModel::load ( QString  fileName = QString(),
const QModelIndex &  rootItem = QModelIndex() 
)
slot

Import bookmarks from file.

Parameters
[in]fileNamefile to load bookmarks.
[in]rootItembookmarks will be loaded under specified item, if empty, items will be loaded on top level. Items will be placed in append mode.
Returns
true if success.

Definition at line 705 of file btbookmarksmodel.cpp.

References BT_ASSERT, BT_CONNECT, and slotSave().

Referenced by BtBookmarksModel(), and CBookmarkIndex::CBookmarkIndex().

◆ module()

CSwordModuleInfo * BtBookmarksModel::module ( const QModelIndex &  index) const
Returns
sword module for specified index if have.

Definition at line 792 of file btbookmarksmodel.cpp.

References index().

Referenced by addBookmark(), CBookmarkIndex::CBookmarkIndex(), and CBookmarkIndex::dragObject().

◆ parent()

QModelIndex BtBookmarksModel::parent ( const QModelIndex &  index) const
override

◆ removeRows()

bool BtBookmarksModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
override

Definition at line 659 of file btbookmarksmodel.cpp.

References BT_ASSERT, and parent().

◆ roleNames()

QHash< int, QByteArray > BtBookmarksModel::roleNames ( ) const
override
Returns
roleNames needed for QML use

Definition at line 940 of file btbookmarksmodel.cpp.

References TypeRole.

◆ rowCount()

int BtBookmarksModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

◆ save

bool BtBookmarksModel::save ( QString  fileName = QString(),
const QModelIndex &  rootItem = QModelIndex() 
)
slot

Save bookmarks or specified branch to file.

Parameters
[in]fileNameuse file or save to the default bookmarks file if it is empty, file will be overwriten if it exists.
[in]rootItemis used to save specified branch of bookmark items or save all bookmarks if it is empty.
Returns
true if success.

Definition at line 688 of file btbookmarksmodel.cpp.

References BT_ASSERT, BtBookmarksModelPrivate::defaultBookmarksFile(), and util::tool::savePlainFile().

Referenced by CBookmarkIndex::CBookmarkIndex(), slotSave(), and ~BtBookmarksModel().

◆ setData()

bool BtBookmarksModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
override

Definition at line 646 of file btbookmarksmodel.cpp.

References index().

Referenced by CBookmarkIndex::CBookmarkIndex().

◆ setDescription()

void BtBookmarksModel::setDescription ( const QModelIndex &  index,
const QString &  description 
)

set descritpion for index.

Definition at line 819 of file btbookmarksmodel.cpp.

References description(), and index().

Referenced by CBookmarkIndex::CBookmarkIndex().

◆ slotSave()

bool BtBookmarksModel::slotSave ( )
inlineprivate

Definition at line 158 of file btbookmarksmodel.h.

References save().

Referenced by load().

◆ sortItems()

void BtBookmarksModel::sortItems ( QModelIndex const &  parent = QModelIndex(),
Qt::SortOrder const  order = Qt::AscendingOrder 
)
Parameters
[in]parentsort items under specified index, if invalid sort all items.

Definition at line 894 of file btbookmarksmodel.cpp.

References BtBookmarksModelSortAscending(), BtBookmarksModelSortDescending(), and parent().

Referenced by CBookmarkIndex::CBookmarkIndex().

Member Data Documentation

◆ d_ptr

BtBookmarksModelPrivate* const BtBookmarksModel::d_ptr
private

Definition at line 162 of file btbookmarksmodel.h.

Referenced by ~BtBookmarksModel().


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