2017-02-06 20:20:30 +00:00
|
|
|
#include "folderlistcontroller.h"
|
|
|
|
#include "qmlutils.h"
|
|
|
|
|
|
|
|
#include "models/folder.h"
|
|
|
|
|
|
|
|
namespace jop {
|
|
|
|
|
|
|
|
FolderListController::FolderListController() : BaseItemListController() {}
|
|
|
|
|
|
|
|
void FolderListController::updateItemCount() {
|
|
|
|
int itemCount = Folder::count(parentId());
|
|
|
|
qmlUtils::callQml(itemList(), "setItemCount", QVariantList() << itemCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
const BaseModel *FolderListController::cacheGet(int index) const {
|
|
|
|
return cache_[index].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderListController::cacheSet(int index, BaseModel *baseModel) const {
|
|
|
|
Folder* folder = static_cast<Folder*>(baseModel);
|
|
|
|
cache_[index] = std::unique_ptr<Folder>(folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FolderListController::cacheIsset(int index) const {
|
2017-02-07 19:42:35 +00:00
|
|
|
return index > 0 && cache_.size() > (size_t)index;
|
2017-02-06 20:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FolderListController::cacheClear() const {
|
|
|
|
cache_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderListController::itemList_rowsRequested(int fromIndex, int toIndex) {
|
|
|
|
if (!cache_.size()) {
|
2017-02-07 19:42:35 +00:00
|
|
|
qFatal("TODO: replace with root::children()");
|
|
|
|
//cache_ = Folder::all(parentId(), orderBy());
|
2017-02-06 20:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//qDebug() << cache_.size();
|
|
|
|
|
2017-02-07 19:42:35 +00:00
|
|
|
if (fromIndex < 0 || (size_t)toIndex >= cache_.size() || !cache_.size()) {
|
2017-02-06 20:20:30 +00:00
|
|
|
qWarning() << "Invalid folder indexes" << fromIndex << toIndex;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantList output;
|
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
|
|
|
const BaseModel* model = cacheGet(i);
|
|
|
|
//qDebug() << model;
|
|
|
|
//QVariant v(cacheGet(i));
|
|
|
|
QVariant v = QVariant::fromValue((QObject*)model);
|
|
|
|
//qDebug() << v;
|
|
|
|
output.push_back(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantList args;
|
|
|
|
args.push_back(fromIndex);
|
|
|
|
args.push_back(output);
|
|
|
|
|
|
|
|
qmlUtils::callQml(itemList(), "setItems", args);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|