-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "stickerpackmodel.h" | ||
#include "../cache/sticker/stickercache.h" | ||
|
||
StickerPackModel::StickerPackModel(QObject *parent) : TelegramModel(parent), _stickerset(NULL) | ||
{ | ||
connect(this, &StickerPackModel::stickerSetChanged, this, &StickerPackModel::titleChanged); | ||
} | ||
|
||
StickerSet *StickerPackModel::stickerSet() const | ||
{ | ||
return this->_stickerset; | ||
} | ||
|
||
void StickerPackModel::setStickerSet(StickerSet *stickerset) | ||
{ | ||
if(this->_stickerset == stickerset) | ||
return; | ||
|
||
this->_stickerset = stickerset; | ||
this->telegramReady(); | ||
emit stickerSetChanged(); | ||
} | ||
|
||
QString StickerPackModel::title() const | ||
{ | ||
if(!this->_stickerset) | ||
return QString(); | ||
|
||
return this->_stickerset->title().toString(); | ||
} | ||
|
||
QVariant StickerPackModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if(!index.isValid() || (index.row() >= this->_stickers.count())) | ||
return QVariant(); | ||
|
||
Document* sticker = this->_stickers[index.row()]; | ||
|
||
if(role == StickerPackModel::ItemRole) | ||
return QVariant::fromValue(sticker); | ||
|
||
return QVariant(); | ||
} | ||
|
||
int StickerPackModel::rowCount(const QModelIndex &) const | ||
{ | ||
return this->_stickers.length(); | ||
} | ||
|
||
QHash<int, QByteArray> StickerPackModel::roleNames() const | ||
{ | ||
return this->initRoles(); | ||
} | ||
|
||
void StickerPackModel::telegramReady() | ||
{ | ||
if(!this->_telegram || !this->_stickerset) | ||
return; | ||
|
||
this->beginResetModel(); | ||
StickerCache_populatePack(this->_stickerset, this->_stickers); | ||
this->endResetModel(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef STICKERPACKMODEL_H | ||
#define STICKERPACKMODEL_H | ||
|
||
#include "abstract/telegrammodel.h" | ||
|
||
class StickerPackModel : public TelegramModel | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(StickerSet* stickerSet READ stickerSet WRITE setStickerSet NOTIFY stickerSetChanged) | ||
Q_PROPERTY(QString title READ title NOTIFY titleChanged) | ||
|
||
public: | ||
explicit StickerPackModel(QObject *parent = 0); | ||
StickerSet* stickerSet() const; | ||
void setStickerSet(StickerSet* stickerset); | ||
QString title() const; | ||
|
||
public: | ||
virtual QVariant data(const QModelIndex &index, int role) const; | ||
virtual int rowCount(const QModelIndex& = QModelIndex()) const; | ||
virtual QHash<int, QByteArray> roleNames() const; | ||
|
||
protected: | ||
virtual void telegramReady(); | ||
|
||
signals: | ||
void stickerSetChanged(); | ||
void titleChanged(); | ||
|
||
private: | ||
StickerSet* _stickerset; | ||
QList<Document*> _stickers; | ||
}; | ||
|
||
#endif // STICKERPACKMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters