diff --git a/QtClient/JoplinQtClient/models/abstractlistmodel.cpp b/QtClient/JoplinQtClient/models/abstractlistmodel.cpp index 5a4b3b4db..150f6e7d3 100755 --- a/QtClient/JoplinQtClient/models/abstractlistmodel.cpp +++ b/QtClient/JoplinQtClient/models/abstractlistmodel.cpp @@ -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); diff --git a/QtClient/JoplinQtClient/models/abstractlistmodel.h b/QtClient/JoplinQtClient/models/abstractlistmodel.h index cc25c045f..31c8f38ae 100755 --- a/QtClient/JoplinQtClient/models/abstractlistmodel.h +++ b/QtClient/JoplinQtClient/models/abstractlistmodel.h @@ -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_; diff --git a/QtClient/JoplinQtClient/models/basemodel.cpp b/QtClient/JoplinQtClient/models/basemodel.cpp index 904a2d14a..befc1315d 100755 --- a/QtClient/JoplinQtClient/models/basemodel.cpp +++ b/QtClient/JoplinQtClient/models/basemodel.cpp @@ -14,6 +14,10 @@ BaseModel::BaseModel() { isNew_ = -1; } +//BaseModel::BaseModel(const BaseModel &baseModel) : BaseModel() { + +//} + QStringList BaseModel::changedFields() const { QStringList output; for (QHash::const_iterator it = changedFields_.begin(); it != changedFields_.end(); ++it) { diff --git a/QtClient/JoplinQtClient/models/basemodel.h b/QtClient/JoplinQtClient/models/basemodel.h index d91a65f39..b976a2265 100755 --- a/QtClient/JoplinQtClient/models/basemodel.h +++ b/QtClient/JoplinQtClient/models/basemodel.h @@ -40,6 +40,7 @@ public: }; BaseModel(); + //BaseModel(const BaseModel& baseModel); QStringList changedFields() const; static int count(jop::Table table); bool load(const QString& id); diff --git a/QtClient/JoplinQtClient/models/foldermodel.cpp b/QtClient/JoplinQtClient/models/foldermodel.cpp index 6b31d0698..b639f8254 100755 --- a/QtClient/JoplinQtClient/models/foldermodel.cpp +++ b/QtClient/JoplinQtClient/models/foldermodel.cpp @@ -12,6 +12,26 @@ FolderModel::FolderModel() : AbstractListModel(), orderBy_("title") { } QVariant FolderModel::data(const QModelIndex & index, int role) const { + + //QVector> folders; +// std::unique_ptr f(new Folder()); +// f->setValue("title", QString("ancd")); +// BaseModel* b = static_cast(f.get()); +// qDebug() << b->value("title").toString(); +// Folder* f2 = static_cast(b); +// qDebug() << "*" << f2->value("title").toString(); + + +// std::unique_ptr baseModel(f.release()); +// qDebug() << "££££££££££££££££££££££££££££££££" << baseModel->value("title").toString(); +// std::unique_ptr 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(); } diff --git a/QtClient/JoplinQtClient/models/foldermodel.h b/QtClient/JoplinQtClient/models/foldermodel.h index c57f41568..766ce3e60 100755 --- a/QtClient/JoplinQtClient/models/foldermodel.h +++ b/QtClient/JoplinQtClient/models/foldermodel.h @@ -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 folders_; QString orderBy_; mutable QVector cache_; + //mutable QVector> cache_; + QString lastInsertId_; public slots: diff --git a/QtClient/JoplinQtClient/stable.h b/QtClient/JoplinQtClient/stable.h index 465289e7d..0bb43aa44 100755 --- a/QtClient/JoplinQtClient/stable.h +++ b/QtClient/JoplinQtClient/stable.h @@ -3,6 +3,8 @@ #if defined __cplusplus +#include + #include #include #include