From 37c15e9f8bc51324988ee99ae92f678ead73dcda Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 22 Nov 2016 17:28:31 +0100 Subject: [PATCH] fix(app): many changes, expose locale and use it with dates, use qmlRegisterSingletonType instead of context properties --- tests/src/app/App.cpp | 41 +++++++++++++------ tests/src/app/App.hpp | 8 ++++ .../src/components/timeline/TimelineModel.cpp | 6 ++- .../ui/modules/Common/Tooltip/TooltipArea.qml | 4 +- tests/ui/modules/Linphone/Timeline.qml | 14 ++++--- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp index 5bbf9e9b2..8518c048e 100644 --- a/tests/src/app/App.cpp +++ b/tests/src/app/App.cpp @@ -70,19 +70,43 @@ void App::registerTypes () { "Linphone", 1, 0, "Presence", "Presence is uncreatable" ); + qmlRegisterSingletonType( + "Linphone", 1, 0, "App", + [](QQmlEngine *, QJSEngine *) -> QObject *{ + return App::getInstance(); + } + ); + + qmlRegisterSingletonType( + "Linphone", 1, 0, "CoreManager", + [](QQmlEngine *, QJSEngine *) -> QObject *{ + return CoreManager::getInstance(); + } + ); + ContactsListProxyModel::initContactsListModel(new ContactsListModel()); qmlRegisterType("Linphone", 1, 0, "ContactsListProxyModel"); - // Expose the static functions of ContactsListModel. qmlRegisterSingletonType( "Linphone", 1, 0, "ContactsListModel", - [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject *{ - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - + [](QQmlEngine *, QJSEngine *) -> QObject *{ return ContactsListProxyModel::getContactsListModel(); } ); + + qmlRegisterSingletonType( + "Linphone", 1, 0, "AccountSettingsModel", + [](QQmlEngine *, QJSEngine *) -> QObject *{ + return new AccountSettingsModel(); + } + ); + + qmlRegisterSingletonType( + "Linphone", 1, 0, "TimelineModel", + [](QQmlEngine *, QJSEngine *) -> QObject *{ + return new TimelineModel(); + } + ); } void App::addContextProperties () { @@ -96,13 +120,6 @@ void App::addContextProperties () { //context->setContextProperty("CallsWindow", component.create()); } - // Models. - context->setContextProperty("AccountSettingsModel", new AccountSettingsModel()); - context->setContextProperty("TimelineModel", new TimelineModel()); - - // Other. - context->setContextProperty("CoreManager", CoreManager::getInstance()); - m_notifier = new Notifier(); context->setContextProperty("Notifier", m_notifier); } diff --git a/tests/src/app/App.hpp b/tests/src/app/App.hpp index 1ff86295a..58c836ea7 100644 --- a/tests/src/app/App.hpp +++ b/tests/src/app/App.hpp @@ -12,6 +12,8 @@ // =================================================================== class App : public QApplication { + Q_OBJECT; + public: static void init (int &argc, char **argv) { if (!m_instance) { @@ -28,6 +30,11 @@ public: return &m_engine; } +public slots: + QString locale () const { + return m_locale; + } + private: App (int &argc, char **argv); @@ -43,6 +50,7 @@ private: QTranslator m_translator; Notifier *m_notifier = nullptr; + QString m_locale; static App *m_instance; }; diff --git a/tests/src/components/timeline/TimelineModel.cpp b/tests/src/components/timeline/TimelineModel.cpp index 0ed71b029..8826c22a9 100644 --- a/tests/src/components/timeline/TimelineModel.cpp +++ b/tests/src/components/timeline/TimelineModel.cpp @@ -80,7 +80,11 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { m_entries.insert(search_entry(map), map); else if (map["timestamp"] > (*it)["timestamp"]) { // Remove old entry and insert. - it = m_entries.erase(it) - 1; + it = m_entries.erase(it); + + if (it != m_entries.cbegin()) + it--; + m_entries.insert(search_entry(map, &it), map); } } diff --git a/tests/ui/modules/Common/Tooltip/TooltipArea.qml b/tests/ui/modules/Common/Tooltip/TooltipArea.qml index 33765fb9e..3df5c9a7e 100644 --- a/tests/ui/modules/Common/Tooltip/TooltipArea.qml +++ b/tests/ui/modules/Common/Tooltip/TooltipArea.qml @@ -4,7 +4,7 @@ import QtQuick 2.7 MouseArea { property alias text: tooltip.text - property var toolTipParent: this + property var tooltipParent: this anchors.fill: parent hoverEnabled: true @@ -14,7 +14,7 @@ MouseArea { Tooltip { id: tooltip - parent: toolTipParent + parent: tooltipParent visible: containsMouse } } diff --git a/tests/ui/modules/Linphone/Timeline.qml b/tests/ui/modules/Linphone/Timeline.qml index afb4ee777..05df26eb5 100644 --- a/tests/ui/modules/Linphone/Timeline.qml +++ b/tests/ui/modules/Linphone/Timeline.qml @@ -97,13 +97,17 @@ ColumnLayout { : TimelineStyle.contact.username.color.normal } + Loader { + anchors.fill: parent + sourceComponent: TooltipArea { + text: $timelineEntry.timestamp.toLocaleString( + Qt.locale(App.locale()), Locale.ShortFormat + ) + } + } + MouseArea { anchors.fill: parent - cursorShape: containsMouse - ? Qt.PointingHandCursor - : Qt.ArrowCursor - hoverEnabled: true - onClicked: { view.currentIndex = index timeline.entrySelected(parent.contact)