mirror of https://github.com/laurent22/joplin.git
58 lines
1.3 KiB
C++
Executable File
58 lines
1.3 KiB
C++
Executable File
#include "foldermodel.h"
|
|
|
|
using namespace jop;
|
|
|
|
FolderModel::FolderModel() : QAbstractListModel() {}
|
|
|
|
void FolderModel::setService(FolderService &folderService) {
|
|
folderService_ = folderService;
|
|
}
|
|
|
|
void FolderModel::addFolder(Folder* folder) {
|
|
//folders_.push_back(folder);
|
|
}
|
|
|
|
int FolderModel::rowCount(const QModelIndex & parent) const {
|
|
Q_UNUSED(parent);
|
|
return folderService_.count();
|
|
//return 10;
|
|
//return folders_.size();
|
|
}
|
|
|
|
// NOTE: to lazy load - send back "Loading..." if item not currently loaded
|
|
// queue the item for loading.
|
|
// Then batch load them a bit later.
|
|
QVariant FolderModel::data(const QModelIndex & index, int role) const {
|
|
QList<Folder> list = folderService_.overviewList();
|
|
|
|
if (index.row() < 0 || index.row() >= list.size()) return QVariant();
|
|
|
|
Folder folder = list[index.row()];
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
return QVariant(folder.title());
|
|
}
|
|
|
|
if (role == IdRole) {
|
|
return QVariant(folder.id());
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
QHash<int, QByteArray> FolderModel::roleNames() const {
|
|
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
|
roles[TitleRole] = "title";
|
|
roles[IdRole] = "uuid";
|
|
roles[RawRole] = "raw";
|
|
return roles;
|
|
}
|
|
|
|
bool FolderModel::canFetchMore(const QModelIndex &parent) const {
|
|
return folders_.size() < folderService_.count();
|
|
}
|
|
|
|
void FolderModel::fetchMore(const QModelIndex &parent) {
|
|
|
|
}
|