2016-12-10 22:39:53 +00:00
|
|
|
#ifndef FOLDERMODEL_H
|
|
|
|
#define FOLDERMODEL_H
|
|
|
|
|
|
|
|
#include <stable.h>
|
|
|
|
|
2017-01-01 11:33:14 +01:00
|
|
|
#include "models/folder.h"
|
2017-01-12 21:33:56 +01:00
|
|
|
#include "models/abstractlistmodel.h"
|
2016-12-29 20:19:00 +01:00
|
|
|
#include "database.h"
|
2016-12-10 22:39:53 +00:00
|
|
|
|
|
|
|
namespace jop {
|
|
|
|
|
2017-01-12 21:33:56 +01:00
|
|
|
class FolderModel : public AbstractListModel {
|
2016-12-10 22:39:53 +00:00
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-12 17:59:19 +01:00
|
|
|
FolderModel();
|
2016-12-11 16:09:39 +00:00
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
void addFolder(Folder* folder);
|
2017-01-13 10:36:27 +01:00
|
|
|
BaseModel* atIndex(int index) const;
|
2016-12-29 20:19:00 +01:00
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
protected:
|
|
|
|
|
2017-01-12 21:33:56 +01:00
|
|
|
int baseModelCount() const;
|
2017-01-13 10:24:34 +01:00
|
|
|
BaseModel* cacheGet(int index) const;
|
|
|
|
void cacheSet(int index, BaseModel *baseModel) const;
|
|
|
|
bool cacheIsset(int index) const;
|
|
|
|
void cacheClear() const;
|
|
|
|
int cacheSize() const;
|
2016-12-10 22:39:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QList<Folder> folders_;
|
2016-12-31 10:48:18 +01:00
|
|
|
QString orderBy_;
|
2017-01-12 23:30:26 +01:00
|
|
|
mutable std::vector<std::unique_ptr<Folder>> cache_;
|
2017-01-12 23:09:24 +01:00
|
|
|
|
2017-01-01 11:33:14 +01:00
|
|
|
QString lastInsertId_;
|
2016-12-29 20:19:00 +01:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
2016-12-31 10:48:18 +01:00
|
|
|
void addData(const QString& title);
|
|
|
|
void deleteData(const int index);
|
2017-01-13 10:36:27 +01:00
|
|
|
bool setTitle(int index, const QVariant &value, int role = Qt::EditRole);
|
2017-01-02 13:17:15 +01:00
|
|
|
QString indexToId(int index) const;
|
2016-12-31 10:48:18 +01:00
|
|
|
int idToIndex(const QString& id) const;
|
2017-01-01 11:33:14 +01:00
|
|
|
QString lastInsertId() const;
|
2016-12-31 10:48:18 +01:00
|
|
|
|
2017-01-07 10:40:13 +01:00
|
|
|
void dispatcher_folderCreated(const QString& folderId);
|
|
|
|
void dispatcher_folderUpdated(const QString& folderId);
|
|
|
|
void dispatcher_folderDeleted(const QString& folderId);
|
2017-01-11 15:18:56 +01:00
|
|
|
void dispatcher_allFoldersDeleted();
|
2017-01-07 10:40:13 +01:00
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // FOLDERMODEL_H
|