1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-03 23:50:33 +02:00
Files
joplin/QtClient/JoplinQtClient/models/abstractlistmodel.h

60 lines
1.4 KiB
C
Raw Normal View History

2017-01-12 21:33:56 +01:00
#ifndef ABSTRACTLISTMODEL_H
#define ABSTRACTLISTMODEL_H
#include <stable.h>
#include "models/basemodel.h"
namespace jop {
class AbstractListModel : public QAbstractListModel {
Q_OBJECT
public:
enum ModelRoles {
IdRole = Qt::UserRole + 1,
TitleRole
2017-01-12 21:33:56 +01:00
};
AbstractListModel();
int rowCount(const QModelIndex & parent = QModelIndex()) const;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
virtual BaseModel* atIndex(int index) const;
BaseModel* atIndex(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
2017-01-12 21:33:56 +01:00
protected:
2017-01-13 21:19:47 +01:00
QString lastInsertId_;
2017-01-12 21:33:56 +01:00
virtual int baseModelCount() const;
// All these methods are const because we want to be able to clear the
// cache or set values from any method including const ones.
// http://stackoverflow.com/a/4248661/561309
virtual BaseModel* cacheGet(int index) const;
virtual void cacheSet(int index, BaseModel* baseModel) const;
virtual bool cacheIsset(int index) const;
virtual void cacheClear() const;
2017-01-12 21:33:56 +01:00
private:
bool virtualItemShown_;
public slots:
void showVirtualItem();
bool virtualItemShown() const;
void hideVirtualItem();
QHash<int, QByteArray> roleNames() const;
QString indexToId(int index) const;
2017-01-13 21:19:47 +01:00
virtual int idToIndex(const QString& id) const;
QString lastInsertId() const;
2017-01-12 21:33:56 +01:00
};
}
#endif // ABSTRACTLISTMODEL_H