Commit bbed8148 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Don't create full timezone model until needed

Creating the model is rather expensive, only do so when needed

Fixes #58
parent ce73be7e
Pipeline #76139 passed with stage
in 18 seconds
......@@ -67,9 +67,6 @@ int main(int argc, char *argv[])
// KDBusService service(KDBusService::Unique);
// initialize models
auto *timeZoneModel = new TimeZoneSelectorModel();
auto *timeZoneFilterModel = new TimeZoneFilterModel(timeZoneModel);
auto *stopwatchTimer = new StopwatchTimer();
auto *weekModel = new WeekModel();
......@@ -77,6 +74,7 @@ int main(int argc, char *argv[])
qmlRegisterType<Alarm>("kclock", 1, 0, "Alarm");
qmlRegisterType<Timer>("kclock", 1, 0, "Timer");
qmlRegisterType<SavedTimeZonesModel>("kclock", 1, 0, "SavedTimeZonesModel");
qmlRegisterType<TimeZoneFilterModel>("kclock", 1, 0, "TimeZoneFilterModel");
qmlRegisterSingletonType<TimerPresetModel>("kclock", 1, 0, "TimerPresetModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
return TimerPresetModel::instance();
});
......@@ -85,7 +83,6 @@ int main(int argc, char *argv[])
engine->rootContext()->setContextObject(new KLocalizedContext(engine));
// models
engine->rootContext()->setContextProperty("timeZoneFilterModel", timeZoneFilterModel);
engine->rootContext()->setContextProperty("alarmModel", AlarmModel::instance());
engine->rootContext()->setContextProperty("timerModel", TimerModel::instance());
engine->rootContext()->setContextProperty("utilModel", UtilModel::instance());
......
......@@ -11,15 +11,22 @@ import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.12 as Kirigami
import kclock 1.0
ColumnLayout {
id: root
property string filterText: ""
TimeZoneFilterModel {
id: timeZoneModel
}
Kirigami.SearchField {
id: searchField
Layout.fillWidth: true
onTextChanged: {
timeZoneFilterModel.setFilterFixedString(text)
timeZoneModel.setFilterFixedString(text)
root.filterText = text
forceActiveFocus();
focus = true
......@@ -42,7 +49,7 @@ ColumnLayout {
icon.name: "globe"
}
model: root.filterText == "" ? [] : timeZoneFilterModel // only display cities if there is a query (for performance)
model: root.filterText == "" ? [] : timeZoneModel // only display cities if there is a query (for performance)
delegate: Kirigami.AbstractListItem {
activeBackgroundColor: "transparent"
CheckBox {
......
......@@ -89,11 +89,10 @@ bool TimeZoneSelectorModel::setData(const QModelIndex &index, const QVariant &va
return false;
}
TimeZoneFilterModel::TimeZoneFilterModel(TimeZoneSelectorModel *model, QObject *parent)
TimeZoneFilterModel::TimeZoneFilterModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSourceModel(model);
setSourceModel(new TimeZoneSelectorModel(this));
setFilterRole(TimeZoneSelectorModel::IDRole);
}
......@@ -44,7 +44,7 @@ class TimeZoneFilterModel : public QSortFilterProxyModel
Q_OBJECT
public:
explicit TimeZoneFilterModel(TimeZoneSelectorModel *model, QObject *parent = nullptr);
explicit TimeZoneFilterModel(QObject *parent = nullptr);
};
#endif // KCLOCK_TIMEZONESELECTORMODEL_H
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