diff --git a/tests/linphone.pro b/tests/linphone.pro index fbfde45ad..32e6b7104 100644 --- a/tests/linphone.pro +++ b/tests/linphone.pro @@ -8,22 +8,24 @@ RESOURCES = resources.qrc SOURCES = \ src/app.cpp \ + src/components/contacts/ContactModel.cpp \ + src/components/contacts/ContactsListModel.cpp \ + src/components/contacts/ContactsListProxyModel.cpp \ + src/components/notification/Notification.cpp \ + src/components/settings/AccountSettingsListModel.cpp \ + src/components/settings/AccountSettingsModel.cpp \ + src/components/settings/SettingsModel.cpp \ src/main.cpp \ - src/models/contacts/ContactModel.cpp \ - src/models/contacts/ContactsListModel.cpp \ - src/models/notification/NotificationModel.cpp \ - src/models/settings/AccountSettingsListModel.cpp \ - src/models/settings/AccountSettingsModel.cpp \ - src/models/settings/SettingsModel.cpp \ HEADERS = \ src/app.hpp \ - src/models/contacts/ContactModel.hpp \ - src/models/contacts/ContactsListModel.hpp \ - src/models/notification/NotificationModel.hpp \ - src/models/settings/AccountSettingsListModel.hpp \ - src/models/settings/AccountSettingsModel.hpp \ - src/models/settings/SettingsModel.hpp \ + src/components/contacts/ContactModel.hpp \ + src/components/contacts/ContactsListModel.hpp \ + src/components/contacts/ContactsListProxyModel.hpp \ + src/components/notification/Notification.hpp \ + src/components/settings/AccountSettingsListModel.hpp \ + src/components/settings/AccountSettingsModel.hpp \ + src/components/settings/SettingsModel.hpp \ TRANSLATIONS = \ languages/en.ts \ diff --git a/tests/src/models/contacts/ContactModel.cpp b/tests/src/components/contacts/ContactModel.cpp similarity index 100% rename from tests/src/models/contacts/ContactModel.cpp rename to tests/src/components/contacts/ContactModel.cpp diff --git a/tests/src/models/contacts/ContactModel.hpp b/tests/src/components/contacts/ContactModel.hpp similarity index 100% rename from tests/src/models/contacts/ContactModel.hpp rename to tests/src/components/contacts/ContactModel.hpp index 6ddb65508..5419fa889 100644 --- a/tests/src/models/contacts/ContactModel.hpp +++ b/tests/src/components/contacts/ContactModel.hpp @@ -76,14 +76,14 @@ public: m_sip_addresses = sip_addresses; } -signals: - void contactUpdated (); - -private: QString getUsername () const { return m_username; } +signals: + void contactUpdated (); + +private: void setUsername (const QString &username) { m_username = username; } diff --git a/tests/src/components/contacts/ContactsListModel.cpp b/tests/src/components/contacts/ContactsListModel.cpp new file mode 100644 index 000000000..52bb410fe --- /dev/null +++ b/tests/src/components/contacts/ContactsListModel.cpp @@ -0,0 +1,38 @@ +#include "ContactsListModel.hpp" + +// =================================================================== + +ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(parent) { + m_list << new ContactModel("Toto Roi", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Cecelia Cyler", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Daniel Elliott", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Effie Forton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Agnes Hurner", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Luke Lemin", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Olga Manning", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Isabella Ahornton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); + m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); +} + +int ContactsListModel::rowCount (const QModelIndex &) const { + return m_list.count(); +} + +QHash ContactsListModel::roleNames () const { + QHash roles; + roles[ContactRole] = "$contact"; + return roles; +} + +QVariant ContactsListModel::data (const QModelIndex &index, int role) const { + int row = index.row(); + + if (row < 0 || row >= m_list.count()) + return QVariant(); + + if (role == ContactRole) + return QVariant::fromValue(m_list[row]); + + return QVariant(); +} diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp new file mode 100644 index 000000000..55d756d34 --- /dev/null +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -0,0 +1,28 @@ +#ifndef CONTACTS_LIST_MODEL_H +#define CONTACTS_LIST_MODEL_H + +#include + +#include "ContactModel.hpp" + +// =================================================================== + +class ContactsListModel : public QAbstractListModel { + Q_OBJECT; + +public: + enum Roles { + ContactRole = Qt::UserRole + 1 + }; + + ContactsListModel (QObject *parent = Q_NULLPTR); + + int rowCount (const QModelIndex &) const; + QHash roleNames () const; + QVariant data (const QModelIndex &index, int role) const; + +private: + QList m_list; +}; + +#endif // CONTACTS_LIST_MODEL_H diff --git a/tests/src/components/contacts/ContactsListProxyModel.cpp b/tests/src/components/contacts/ContactsListProxyModel.cpp new file mode 100644 index 000000000..444b7c561 --- /dev/null +++ b/tests/src/components/contacts/ContactsListProxyModel.cpp @@ -0,0 +1,17 @@ +#include "ContactsListProxyModel.hpp" + +#include + +// =================================================================== + +bool ContactsListProxyModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const { + QModelIndex index = sourceModel()->index(source_row, 0, source_parent); + const ContactModel *contact = qvariant_cast( + index.data(ContactsListModel::ContactRole) + ); + + return contact->getUsername().contains( + filterRegExp().pattern(), + Qt::CaseInsensitive + ); +} diff --git a/tests/src/components/contacts/ContactsListProxyModel.hpp b/tests/src/components/contacts/ContactsListProxyModel.hpp new file mode 100644 index 000000000..bcb2c50e5 --- /dev/null +++ b/tests/src/components/contacts/ContactsListProxyModel.hpp @@ -0,0 +1,27 @@ +#ifndef CONTACTS_LIST_PROXY_MODEL_H +#define CONTACTS_LIST_PROXY_MODEL_H + +#include + +#include "ContactsListModel.hpp" + +// =================================================================== + +class ContactsListProxyModel : public QSortFilterProxyModel { + Q_OBJECT; + +public: + ContactsListProxyModel (QObject *parent = Q_NULLPTR) : QSortFilterProxyModel(parent) { + setSourceModel(&m_list); + setDynamicSortFilter(true); + sort(0); + } + +protected: + bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const; + +private: + ContactsListModel m_list; +}; + +#endif // CONTACTS_LIST_PROXY_MODEL_H diff --git a/tests/src/models/notification/NotificationModel.cpp b/tests/src/components/notification/Notification.cpp similarity index 71% rename from tests/src/models/notification/NotificationModel.cpp rename to tests/src/components/notification/Notification.cpp index c226f22f9..72afdae56 100644 --- a/tests/src/models/notification/NotificationModel.cpp +++ b/tests/src/components/notification/Notification.cpp @@ -1,14 +1,14 @@ #include -#include "NotificationModel.hpp" +#include "Notification.hpp" // =================================================================== -NotificationModel::NotificationModel (QObject *parent) : +Notification::Notification (QObject *parent) : QObject(parent) { } -void NotificationModel::showMessage ( +void Notification::showMessage ( const QString &summary, const QString &body, const QString &icon, diff --git a/tests/src/models/notification/NotificationModel.hpp b/tests/src/components/notification/Notification.hpp similarity index 58% rename from tests/src/models/notification/NotificationModel.hpp rename to tests/src/components/notification/Notification.hpp index 6b2a6048d..8ce571154 100644 --- a/tests/src/models/notification/NotificationModel.hpp +++ b/tests/src/components/notification/Notification.hpp @@ -1,15 +1,15 @@ -#ifndef NOTIFICATION_MODEL_H_ -#define NOTIFICATION_MODEL_H_ +#ifndef NOTIFICATION_H_ +#define NOTIFICATION_H_ #include // =================================================================== -class NotificationModel : public QObject { +class Notification : public QObject { Q_OBJECT public: - NotificationModel (QObject *parent = Q_NULLPTR); + Notification (QObject *parent = Q_NULLPTR); public slots: void showMessage ( @@ -20,4 +20,4 @@ public slots: ); }; -#endif // NOTIFICATION_MODEL_H_ +#endif // NOTIFICATION_H_ diff --git a/tests/src/models/settings/AccountSettingsListModel.cpp b/tests/src/components/settings/AccountSettingsListModel.cpp similarity index 100% rename from tests/src/models/settings/AccountSettingsListModel.cpp rename to tests/src/components/settings/AccountSettingsListModel.cpp diff --git a/tests/src/models/settings/AccountSettingsListModel.hpp b/tests/src/components/settings/AccountSettingsListModel.hpp similarity index 100% rename from tests/src/models/settings/AccountSettingsListModel.hpp rename to tests/src/components/settings/AccountSettingsListModel.hpp diff --git a/tests/src/models/settings/AccountSettingsModel.cpp b/tests/src/components/settings/AccountSettingsModel.cpp similarity index 100% rename from tests/src/models/settings/AccountSettingsModel.cpp rename to tests/src/components/settings/AccountSettingsModel.cpp diff --git a/tests/src/models/settings/AccountSettingsModel.hpp b/tests/src/components/settings/AccountSettingsModel.hpp similarity index 100% rename from tests/src/models/settings/AccountSettingsModel.hpp rename to tests/src/components/settings/AccountSettingsModel.hpp diff --git a/tests/src/models/settings/SettingsModel.cpp b/tests/src/components/settings/SettingsModel.cpp similarity index 100% rename from tests/src/models/settings/SettingsModel.cpp rename to tests/src/components/settings/SettingsModel.cpp diff --git a/tests/src/models/settings/SettingsModel.hpp b/tests/src/components/settings/SettingsModel.hpp similarity index 100% rename from tests/src/models/settings/SettingsModel.hpp rename to tests/src/components/settings/SettingsModel.hpp diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 3b8cff2d6..a25318cb9 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -9,8 +9,8 @@ #include #include "app.hpp" -#include "models/contacts/ContactsListModel.hpp" -#include "models/notification/NotificationModel.hpp" +#include "components/contacts/ContactsListProxyModel.hpp" +#include "components/notification/Notification.hpp" // =================================================================== @@ -56,8 +56,8 @@ void registerTypes () { void addContextProperties (QQmlApplicationEngine &engine) { QQmlContext *context = engine.rootContext(); - context->setContextProperty("Notification", new NotificationModel()); - context->setContextProperty("ContactsList", new ContactsListModel()); + context->setContextProperty("Notification", new Notification()); + context->setContextProperty("ContactsListModel", new ContactsListProxyModel()); } int main (int argc, char *argv[]) { diff --git a/tests/src/models/contacts/ContactsListModel.cpp b/tests/src/models/contacts/ContactsListModel.cpp deleted file mode 100644 index 0b7e1af1a..000000000 --- a/tests/src/models/contacts/ContactsListModel.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "ContactsListModel.hpp" - -// =================================================================== diff --git a/tests/src/models/contacts/ContactsListModel.hpp b/tests/src/models/contacts/ContactsListModel.hpp deleted file mode 100644 index bab653f18..000000000 --- a/tests/src/models/contacts/ContactsListModel.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef CONTACTS_LIST_MODEL_H -#define CONTACTS_LIST_MODEL_H - -#include - -#include "ContactModel.hpp" - -// =================================================================== - -class ContactsListModel : public QAbstractListModel { - Q_OBJECT - -public: - enum Roles { - ContactRole = Qt::UserRole + 1 - }; - - ContactsListModel (QObject *parent = Q_NULLPTR): QAbstractListModel(parent) { - m_list << new ContactModel("Toto Roi", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Cecelia Cyler", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Daniel Elliott", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Effie Forton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Agnes Hurner", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Luke Lemin", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Olga Manning", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Isabella Ahornton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org")); - } - - int rowCount (const QModelIndex &) const { - return m_list.count(); - } - - QHash roleNames () const { - QHash roles; - roles[ContactRole] = "$contact"; - return roles; - } - - QVariant data (const QModelIndex &index, int role) const { - if (index.row() < 0 || index.row() >= m_list.count()) - return QVariant(); - - if (role == ContactRole) - return QVariant::fromValue(m_list[index.row()]); - - return QVariant(); - } - -private: - QList m_list; -}; - -#endif // CONTACTS_LIST_MODEL_H diff --git a/tests/ui/views/MainWindow/Contacts.qml b/tests/ui/views/MainWindow/Contacts.qml index 03b8caac9..5a3004a2d 100644 --- a/tests/ui/views/MainWindow/Contacts.qml +++ b/tests/ui/views/MainWindow/Contacts.qml @@ -31,6 +31,10 @@ ColumnLayout { implicitHeight: 30 } placeholderText: qsTr('searchContactPlaceholder') + + Component.onCompleted: ContactsListModel.setFilterRegExp('') + + onTextChanged: ContactsListModel.setFilterRegExp(text) } ExclusiveButtons { @@ -58,17 +62,19 @@ ColumnLayout { anchors.fill: parent spacing: 2 - model: ContactsList + model: ContactsListModel delegate: Rectangle { + id: contact + color: '#FFFFFF' height: 50 - id: contact width: parent.width MouseArea { anchors.fill: parent hoverEnabled: true + onEntered: contact.state = 'hover' onExited: contact.state = '' } @@ -104,24 +110,21 @@ ColumnLayout { } // Username. - Item { + Text { Layout.fillHeight: parent.height Layout.fillWidth: true - - Text { - anchors.fill: parent - clip: true - color: '#5A585B' - font.bold: true - text: $contact.username - verticalAlignment: Text.AlignVCenter - } + clip: true + color: '#5A585B' + font.bold: true + text: $contact.username + verticalAlignment: Text.AlignVCenter } // Actions. Row { - Layout.fillHeight: true id: actions + + Layout.fillHeight: true spacing: 50 visible: false