feat(ui/views/App/MainWindow/MainWindow): it uses a SmartSearchBarProxyModel component (unstable)

This commit is contained in:
Ronan Abhamon 2016-12-22 11:07:24 +01:00
parent e6276c6212
commit c27e33a163
9 changed files with 46 additions and 17 deletions

View file

@ -70,6 +70,7 @@ set(SOURCES
src/components/sip-addresses/UnregisteredSipAddressesModel.cpp
src/components/sip-addresses/UnregisteredSipAddressesProxyModel.cpp
src/components/smart-search-bar/SmartSearchBarModel.cpp
src/components/smart-search-bar/SmartSearchBarProxyModel.cpp
src/components/timeline/TimelineModel.cpp
src/main.cpp
)
@ -96,6 +97,7 @@ set(HEADERS
src/components/sip-addresses/UnregisteredSipAddressesModel.hpp
src/components/sip-addresses/UnregisteredSipAddressesProxyModel.hpp
src/components/smart-search-bar/SmartSearchBarModel.hpp
src/components/smart-search-bar/SmartSearchBarProxyModel.hpp
src/components/timeline/TimelineModel.hpp
src/utils.hpp
)

View file

@ -12,7 +12,7 @@
#include "../components/settings/AccountSettingsModel.hpp"
#include "../components/sip-addresses/UnregisteredSipAddressesProxyModel.hpp"
#include "../components/timeline/TimelineModel.hpp"
#include "../components/smart-search-bar/SmartSearchBarModel.hpp"
#include "../components/smart-search-bar/SmartSearchBarProxyModel.hpp"
#include "App.hpp"
@ -139,17 +139,12 @@ void App::registerTypes () {
}
);
qmlRegisterSingletonType<SmartSearchBarModel>(
"Linphone", 1, 0, "SmartSearchBarModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new SmartSearchBarModel();
}
);
qmlRegisterType<Camera>("Linphone", 1, 0, "Camera");
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
qmlRegisterType<ChatModel>("Linphone", 1, 0, "ChatModel");
qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel");
qmlRegisterType<UnregisteredSipAddressesProxyModel>("Linphone", 1, 0, "UnregisteredSipAddressesProxyModel");
qmlRegisterType<SmartSearchBarProxyModel>("Linphone", 1, 0, "SmartSearchBarProxyModel");
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
}

View file

@ -9,11 +9,11 @@
// =============================================================================
class ContactsListModel : public QAbstractListModel {
Q_OBJECT;
friend class ContactsListProxyModel;
friend class SipAddressesModel;
Q_OBJECT;
public:
ContactsListModel (QObject *parent = Q_NULLPTR);
~ContactsListModel () = default;

View file

@ -27,10 +27,14 @@ bool UnregisteredSipAddressesProxyModel::filterAcceptsRow (int source_row, const
}
bool UnregisteredSipAddressesProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
return computeStringWeight(
sourceModel()->data(left).toMap()["sipAddress"].toString()
) > computeStringWeight(
sourceModel()->data(right).toMap()["sipAddress"].toString()
QString sip_address_a = sourceModel()->data(left).toMap()["sipAddress"].toString();
QString sip_address_b = sourceModel()->data(right).toMap()["sipAddress"].toString();
int weight_a = computeStringWeight(sip_address_a);
int weight_b = computeStringWeight(sip_address_b);
return weight_a > weight_b || (
weight_a == weight_b && sip_address_a >= sip_address_b
);
}

View file

@ -14,14 +14,14 @@ class SmartSearchBarModel : public QAbstractListModel {
public:
SmartSearchBarModel (QObject *parent = Q_NULLPTR) : QAbstractListModel(parent) {}
~SmartSearchBarModel () = default;
virtual ~SmartSearchBarModel () = default;
int rowCount (const QModelIndex &index = QModelIndex()) const override;
QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex &index, int role) const override;
private:
protected:
ContactsListProxyModel m_contacts;
UnregisteredSipAddressesProxyModel m_sip_addresses;
};

View file

@ -0,0 +1,8 @@
#include "SmartSearchBarProxyModel.hpp"
// =============================================================================
void SmartSearchBarProxyModel::setFilter (const QString &pattern) {
m_contacts.setFilter(pattern);
m_sip_addresses.setFilter(pattern);
}

View file

@ -0,0 +1,20 @@
#ifndef SMART_SEARCH_BAR_PROXY_MODEL_H_
#define SMART_SEARCH_BAR_PROXY_MODEL_H_
#include "SmartSearchBarModel.hpp"
// =============================================================================
class SmartSearchBarProxyModel : public SmartSearchBarModel {
Q_OBJECT;
public:
SmartSearchBarProxyModel (QObject *parent = Q_NULLPTR) : SmartSearchBarModel(parent) {}
~SmartSearchBarProxyModel () = default;
public slots:
void setFilter (const QString &pattern);
};
#endif // SMART_SEARCH_BAR_PROXY_MODEL_H_

View file

@ -70,7 +70,7 @@ Item {
Keys.onEscapePressed: searchBox.hideMenu()
onActiveFocusChanged: activeFocus && searchBox.showMenu()
onTextChanged: _filter()
onTextChanged: _filter(text)
}
// Wrap the search box menu in a window.

View file

@ -145,7 +145,7 @@ ApplicationWindow {
maxMenuHeight: MainWindowStyle.searchBox.maxHeight
placeholderText: qsTr('mainSearchBarPlaceholder')
model: SmartSearchBarModel
model: SmartSearchBarProxyModel {}
}
}
}