Commit f64632bc authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Improve model

parent 4789a86e
......@@ -33,7 +33,30 @@ AddressBookListViewModel::~AddressBookListViewModel()
QHash<int, QByteArray> AddressBookListViewModel::roleNames() const
{
//TODO
QHash<int, QByteArray> roles;
roles[AddressEmail] = "addressemail";
roles[AddressName] = "addressname";
roles[AddressSection] = "addresssection";
roles[AddressIcon] = "addressicon";
return roles;
}
QVariant AddressBookListViewModel::data(const QModelIndex &index, int role) const
{
//TODO
#if 0
if (index.row() < 0 || index.row() >= mListAddressBook.count())
return QVariant();
const AddressBook &add = mListAddressBook[index.row()];
if (role == AddressEmail) {
return add.email();
} else if (role == AddressName) {
return add.name();
} else if (role == AddressSection) {
return add.section();
} else if (role == AddressIcon) {
return add.iconUrl();
}
#endif
return QVariant();
}
......@@ -29,9 +29,16 @@ class AddressBookListViewModel : public QIdentityProxyModel
public:
explicit AddressBookListViewModel(QObject *parent = Q_NULLPTR);
~AddressBookListViewModel();
enum AddressBookRoles {
AddressEmail = Qt::UserRole + 1,
AddressName = Qt::UserRole + 2,
AddressSection = Qt::UserRole + 3,
AddressIcon = Qt::UserRole + 4
};
protected:
QHash<int, QByteArray> roleNames() const;
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
};
#endif // ADDRESSBOOKLISTVIEWMODEL_H
......@@ -19,6 +19,8 @@
#include "addressbookquickwidget.h"
#include "addressbooklistviewmodel.h"
#include <QQmlContext>
#include <QUrl>
AddressBookQuickWidget::AddressBookQuickWidget(QWidget *parent)
......@@ -26,6 +28,9 @@ AddressBookQuickWidget::AddressBookQuickWidget(QWidget *parent)
{
resize(400, 500);
setResizeMode(QQuickWidget::SizeRootObjectToView);
QQmlContext *ctxt = rootContext();
//TODOctxt->setContextProperty("addressModel", sortProxy/*mModel*/);
}
AddressBookQuickWidget::~AddressBookQuickWidget()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment