mirror of https://github.com/laurent22/joplin.git
refactoring to use vector of smart pointers
parent
42bc141d3a
commit
e42971b2d6
|
@ -56,7 +56,7 @@ int AbstractListModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(par
|
|||
// return atIndex(index.row());
|
||||
//}
|
||||
|
||||
BaseModel AbstractListModel::baseModel() const {
|
||||
BaseModel AbstractListModel::newBaseModel() const {
|
||||
qFatal("AbstractListModel::baseModel() not implemented");
|
||||
return BaseModel();
|
||||
}
|
||||
|
@ -66,6 +66,24 @@ int AbstractListModel::baseModelCount() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
BaseModel AbstractListModel::cacheGet(int index) const {
|
||||
qFatal("AbstractListModel::cacheGet() not implemented");
|
||||
return BaseModel();
|
||||
}
|
||||
|
||||
void AbstractListModel::cacheSet(int index, const BaseModel &baseModel) {
|
||||
qFatal("AbstractListModel::cacheSet() not implemented");
|
||||
}
|
||||
|
||||
bool AbstractListModel::cacheIsset(int index) const {
|
||||
qFatal("AbstractListModel::cacheIsset() not implemented");
|
||||
return false;
|
||||
}
|
||||
|
||||
void AbstractListModel::cacheClear() {
|
||||
qFatal("AbstractListModel::cacheClear() not implemented");
|
||||
}
|
||||
|
||||
void AbstractListModel::showVirtualItem() {
|
||||
virtualItemShown_ = true;
|
||||
beginInsertRows(QModelIndex(), this->rowCount() - 1, this->rowCount() - 1);
|
||||
|
|
|
@ -26,9 +26,14 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual BaseModel baseModel() const;
|
||||
virtual BaseModel newBaseModel() const;
|
||||
virtual int baseModelCount() const;
|
||||
|
||||
virtual BaseModel cacheGet(int index) const;
|
||||
virtual void cacheSet(int index, const BaseModel& baseModel);
|
||||
virtual bool cacheIsset(int index) const;
|
||||
virtual void cacheClear();
|
||||
|
||||
private:
|
||||
|
||||
bool virtualItemShown_;
|
||||
|
|
|
@ -14,6 +14,10 @@ BaseModel::BaseModel() {
|
|||
isNew_ = -1;
|
||||
}
|
||||
|
||||
//BaseModel::BaseModel(const BaseModel &baseModel) : BaseModel() {
|
||||
|
||||
//}
|
||||
|
||||
QStringList BaseModel::changedFields() const {
|
||||
QStringList output;
|
||||
for (QHash<QString, bool>::const_iterator it = changedFields_.begin(); it != changedFields_.end(); ++it) {
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
};
|
||||
|
||||
BaseModel();
|
||||
//BaseModel(const BaseModel& baseModel);
|
||||
QStringList changedFields() const;
|
||||
static int count(jop::Table table);
|
||||
bool load(const QString& id);
|
||||
|
|
|
@ -12,6 +12,26 @@ FolderModel::FolderModel() : AbstractListModel(), orderBy_("title") {
|
|||
}
|
||||
|
||||
QVariant FolderModel::data(const QModelIndex & index, int role) const {
|
||||
|
||||
//QVector<std::unique_ptr<Folder>> folders;
|
||||
// std::unique_ptr<Folder> f(new Folder());
|
||||
// f->setValue("title", QString("ancd"));
|
||||
// BaseModel* b = static_cast<BaseModel*>(f.get());
|
||||
// qDebug() << b->value("title").toString();
|
||||
// Folder* f2 = static_cast<Folder*>(b);
|
||||
// qDebug() << "*" << f2->value("title").toString();
|
||||
|
||||
|
||||
// std::unique_ptr<BaseModel> baseModel(f.release());
|
||||
// qDebug() << "££££££££££££££££££££££££££££££££" << baseModel->value("title").toString();
|
||||
// std::unique_ptr<Folder> f2(baseModel.release());
|
||||
// qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << f2->value("title").toString();
|
||||
|
||||
|
||||
//f->setValue("title", "abcd");
|
||||
|
||||
|
||||
|
||||
Folder folder;
|
||||
|
||||
if (virtualItemShown() && index.row() == rowCount() - 1) {
|
||||
|
@ -71,7 +91,7 @@ Folder FolderModel::atIndex(const QModelIndex &index) const {
|
|||
return atIndex(index.row());
|
||||
}
|
||||
|
||||
BaseModel FolderModel::baseModel() const {
|
||||
BaseModel FolderModel::newBaseModel() const {
|
||||
return Folder();
|
||||
}
|
||||
|
||||
|
@ -79,6 +99,23 @@ int FolderModel::baseModelCount() const {
|
|||
return Folder::count();
|
||||
}
|
||||
|
||||
BaseModel FolderModel::cacheGet(int index) const {
|
||||
return cache_[index];
|
||||
}
|
||||
|
||||
void FolderModel::cacheSet(int index, const BaseModel &baseModel) {
|
||||
// Folder f(baseModel);
|
||||
// cache_[index] = f;
|
||||
}
|
||||
|
||||
bool FolderModel::cacheIsset(int index) const {
|
||||
return index > 0 && cache_.size() > index;
|
||||
}
|
||||
|
||||
void FolderModel::cacheClear() {
|
||||
cache_.clear();
|
||||
}
|
||||
|
||||
QString FolderModel::indexToId(int index) const {
|
||||
return data(this->index(index), IdRole).toString();
|
||||
}
|
||||
|
|
|
@ -25,14 +25,20 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
BaseModel baseModel() const;
|
||||
BaseModel newBaseModel() const;
|
||||
int baseModelCount() const;
|
||||
virtual BaseModel cacheGet(int index) const;
|
||||
virtual void cacheSet(int index, const BaseModel& baseModel);
|
||||
virtual bool cacheIsset(int index) const;
|
||||
virtual void cacheClear();
|
||||
|
||||
private:
|
||||
|
||||
QList<Folder> folders_;
|
||||
QString orderBy_;
|
||||
mutable QVector<Folder> cache_;
|
||||
//mutable QVector<std::unique_ptr<Folder>> cache_;
|
||||
|
||||
QString lastInsertId_;
|
||||
|
||||
public slots:
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#if defined __cplusplus
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QGuiApplication>
|
||||
#include <QDebug>
|
||||
|
|
Loading…
Reference in New Issue