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"
|
2016-12-29 20:19:00 +01:00
|
|
|
#include "database.h"
|
2016-12-10 22:39:53 +00:00
|
|
|
|
|
|
|
namespace jop {
|
|
|
|
|
|
|
|
class FolderModel : public QAbstractListModel {
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum FolderRoles {
|
2016-12-11 16:09:39 +00:00
|
|
|
IdRole = Qt::UserRole + 1,
|
|
|
|
TitleRole,
|
|
|
|
RawRole
|
2016-12-10 22:39:53 +00:00
|
|
|
};
|
|
|
|
|
2016-12-29 20:19:00 +01:00
|
|
|
FolderModel(Database& database);
|
2016-12-11 16:09:39 +00:00
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
void addFolder(Folder* folder);
|
|
|
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
2016-12-29 20:19:00 +01:00
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
2017-01-01 11:33:14 +01:00
|
|
|
Folder atIndex(int index) const;
|
|
|
|
Folder atIndex(const QModelIndex &index) const;
|
2016-12-29 20:19:00 +01:00
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QList<Folder> folders_;
|
2016-12-31 10:48:18 +01:00
|
|
|
bool virtualItemShown_;
|
|
|
|
QString orderBy_;
|
|
|
|
Database& db_;
|
2017-01-01 11:33:14 +01:00
|
|
|
mutable QVector<Folder> cache_;
|
|
|
|
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);
|
2016-12-29 20:19:00 +01:00
|
|
|
bool setData(int index, const QVariant &value, int role = Qt::EditRole);
|
2016-12-31 10:48:18 +01:00
|
|
|
void showVirtualItem();
|
|
|
|
bool virtualItemShown() const;
|
|
|
|
void hideVirtualItem();
|
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);
|
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // FOLDERMODEL_H
|