Commit 1369e2e1 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Add base classes for C++ country codes list model

parent 2b94402e
......@@ -57,7 +57,8 @@ SOURCES += \
$$PWD/src/QtTdLibMessage.cpp \
$$PWD/src/QtTdLibUser.cpp \
$$PWD/src/TextFormatter.cpp \
$$PWD/src/QtTdLibChatAction.cpp
$$PWD/src/QtTdLibChatAction.cpp \
src/CountryCodes.cpp
HEADERS += \
$$PWD/src/QtTdLibJsonWrapper.h \
......@@ -72,7 +73,8 @@ HEADERS += \
$$PWD/src/QtTdLibMessage.h \
$$PWD/src/QtTdLibUser.h \
$$PWD/src/TextFormatter.h \
$$PWD/src/QtTdLibChatAction.h
$$PWD/src/QtTdLibChatAction.h \
src/CountryCodes.h
RESOURCES += \
$$PWD/qml.qrc \
......
......@@ -62,7 +62,7 @@ Dialog {
ExtraAnchors.topDock: parent;
Repeater {
model: countriesModel;
model: countriesModel; // use now TD_Global.countryCodes.list
delegate: ListItem {
visible: (modelData ["name"].toLowerCase ().indexOf (inputFilter.value) >= 0 || modelData ["code"].indexOf (inputFilter.value) >= 0);
highlighted: (dlgCountries.code === modelData ["code"]);
......
#include "CountryCodes.h"
CountryCodesModelItem::CountryCodesModelItem (const QString & country, const QString & abbr, const QString & code, QObject * parent)
: QObject { parent }
, m_country { country }
, m_abbr { abbr }
, m_code { code }
{ }
CountryCodes::CountryCodes (QObject * parent)
: QObject { parent }
, m_list { new QQmlObjectListModel<CountryCodesModelItem> { this } }
{
m_list->append ({
new CountryCodesModelItem { "Xxxxx", "xxx", "+xx" },
new CountryCodesModelItem { "Xxxxx", "xxx", "+xx" },
new CountryCodesModelItem { "Xxxxx", "xxx", "+xx" },
new CountryCodesModelItem { "Xxxxx", "xxx", "+xx" },
new CountryCodesModelItem { "Xxxxx", "xxx", "+xx" },
new CountryCodesModelItem { "Xxxxx", "xxx", "+xx" },
});
}
#ifndef COUNTRYCODES_H
#define COUNTRYCODES_H
#include <QObject>
#include "QmlPropertyHelpers.h"
#include "QQmlObjectListModel.h"
class CountryCodesModelItem : public QObject {
Q_OBJECT
QML_CONSTANT_CSTREF_PROPERTY (country, QString)
QML_CONSTANT_CSTREF_PROPERTY (abbr, QString)
QML_CONSTANT_CSTREF_PROPERTY (code, QString)
public:
explicit CountryCodesModelItem (const QString & country = { },
const QString & abbr = { },
const QString & code = { },
QObject * parent = nullptr);
};
class CountryCodes : public QObject {
Q_OBJECT
QML_OBJMODEL_PROPERTY (list, CountryCodesModelItem)
public:
explicit CountryCodes (QObject * parent = nullptr);
};
#endif // COUNTRYCODES_H
......@@ -18,6 +18,7 @@ QtTdLibGlobal::QtTdLibGlobal (QObject * parent)
, m_currentMessageContent { Q_NULLPTR }
, m_sortedChatsList { new QSortFilterProxyModel { this } }
, m_sortedContactsList { new QSortFilterProxyModel { this } }
, m_countryCodest { new CountryCodes { this } }
, m_sendTextOnEnterKey { false }
, SVG_ICON_FOR_MIMETYPE {
{ "image/png", "image" },
......
......@@ -22,6 +22,7 @@
#include "QtTdLibFile.h"
#include "QtTdLibChat.h"
#include "QtTdLibMessage.h"
#include "CountryCodes.h"
#include "QmlPropertyHelpers.h"
#include "QQmlObjectListModel.h"
......@@ -43,6 +44,7 @@ class QtTdLibGlobal : public QObject {
QML_WRITABLE_PTR_PROPERTY (currentMessageContent, QtTdLibMessageContent)
QML_CONSTANT_PTR_PROPERTY (sortedChatsList, QSortFilterProxyModel)
QML_CONSTANT_PTR_PROPERTY (sortedContactsList, QSortFilterProxyModel)
QML_CONSTANT_PTR_PROPERTY (countryCodes, CountryCodes)
QML_WRITABLE_VAR_PROPERTY (sendTextOnEnterKey, bool)
QML_WRITABLE_CSTREF_PROPERTY (replyingToMessageId, QString)
QML_WRITABLE_CSTREF_PROPERTY (editingMessageId, QString)
......
......@@ -28,6 +28,8 @@ int main (int argc, char * argv []) {
QGuiApplication::setApplicationName (QStringLiteral ("harbour-telegrame"));
QtQmlTricks::registerComponents ();
qmlRegisterType<TextFormatter> ("harbour.Telegrame", 1, 0, "TextFormatter");
qmlRegisterType<CountryCodes> ("harbour.Telegrame", 1, 0, "CountryCodes");
qmlRegisterType<CountryCodesModelItem> ("harbour.Telegrame", 1, 0, "CountryCodesModelItem");
qmlRegisterType<QSortFilterProxyModel> ("harbour.Telegrame", 1, 0, "SortFilterProxyModel");
qmlRegisterType<QtTdLibMessageRefWatcher> ("harbour.Telegrame", 1, 0, "TD_MessageRefWatcher");
qmlRegisterType<QtTdLibAbstractObject> ("harbour.Telegrame", 1, 0, "TD_AbstractObject");
......
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