From 431c257dd29e2e3d8878db200f0de4d452bffe92 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 30 Dec 2016 12:02:12 +0100 Subject: Encapsulate completer and selector. --- framework/domain/composercontroller.h | 67 ++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) (limited to 'framework/domain/composercontroller.h') diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index 11da517e..3e701ed1 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -43,15 +44,62 @@ class ComposerContext : public Kube::Context { KUBE_CONTEXT_PROPERTY(QString, Body, body) }; +class Completer : public QObject { + Q_OBJECT + Q_PROPERTY (QAbstractItemModel* model READ model CONSTANT) + Q_PROPERTY (QString searchString WRITE setSearchString READ searchString) + +public: + Completer(QAbstractItemModel *model) : mModel{model} + { + QQmlEngine::setObjectOwnership(mModel, QQmlEngine::CppOwnership); + } + QAbstractItemModel *model() { return mModel; } + virtual void setSearchString(const QString &s) { mSearchString = s; } + QString searchString() const { return mSearchString; } + +private: + QAbstractItemModel *mModel = nullptr; + QString mSearchString; +}; + +/** + * Exposes a model and maintains a current index selection. + */ +class Selector : public QObject { + Q_OBJECT + Q_PROPERTY (int currentIndex READ currentIndex WRITE setCurrentIndex) + Q_PROPERTY (QAbstractItemModel* model READ model CONSTANT) + +public: + Selector(QAbstractItemModel *model) : mModel{model} + { + QQmlEngine::setObjectOwnership(mModel, QQmlEngine::CppOwnership); + } + + virtual QAbstractItemModel *model() { return mModel; } + + void setCurrentIndex(int i) { + mCurrentIndex = i; + Q_ASSERT(mModel); + setCurrent(mModel->index(mCurrentIndex, 0)); + } + + int currentIndex() { return mCurrentIndex; } + + virtual void setCurrent(const QModelIndex &) = 0; +private: + QAbstractItemModel *mModel = nullptr; + int mCurrentIndex = 0; +}; + class ComposerController : public QObject { Q_OBJECT Q_PROPERTY (Kube::Context* mailContext READ mailContext CONSTANT) - Q_PROPERTY (int currentIdentityIndex READ currentIdentityIndex WRITE setCurrentIdentityIndex) - Q_PROPERTY (QString recepientSearchString READ recepientSearchString WRITE setRecepientSearchString) - Q_PROPERTY (QAbstractItemModel* recepientAutocompletionModel READ recepientAutocompletionModel CONSTANT) - Q_PROPERTY (QAbstractItemModel* identityModel READ identityModel CONSTANT) + Q_PROPERTY (Completer* recipientCompleter READ recipientCompleter CONSTANT) + Q_PROPERTY (Selector* identitySelector READ identitySelector CONSTANT) Q_PROPERTY (Kube::Action* sendAction READ sendAction) Q_PROPERTY (Kube::Action* saveAsDraftAction READ saveAsDraftAction) @@ -61,20 +109,14 @@ public: Kube::Context* mailContext(); - QString recepientSearchString() const; - void setRecepientSearchString(const QString &body); - - QAbstractItemModel *identityModel() const; - QAbstractItemModel *recepientAutocompletionModel() const; + Completer *recipientCompleter() const; + Selector *identitySelector() const; Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); Kube::Action* sendAction(); Kube::Action* saveAsDraftAction(); - void setCurrentIdentityIndex(int index); - int currentIdentityIndex() const; - public slots: void clear(); @@ -86,6 +128,5 @@ private: void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); void setMessage(const QSharedPointer &msg); - int m_currentAccountIndex = -1; ComposerContext mContext; }; -- cgit v1.2.3