Commit d1d3fe97 authored by Volker Krause's avatar Volker Krause

Add country model for the home country configuration

parent 0c1332e6
...@@ -21,6 +21,7 @@ target_link_libraries(itinerary PUBLIC ...@@ -21,6 +21,7 @@ target_link_libraries(itinerary PUBLIC
add_executable(itinerary-app add_executable(itinerary-app
main.cpp main.cpp
applicationcontroller.cpp applicationcontroller.cpp
countrymodel.cpp
localizer.cpp localizer.cpp
pkpassimageprovider.cpp pkpassimageprovider.cpp
settings.cpp settings.cpp
......
...@@ -26,6 +26,10 @@ Kirigami.ScrollablePage { ...@@ -26,6 +26,10 @@ Kirigami.ScrollablePage {
id: root id: root
title: qsTr("Settings") title: qsTr("Settings")
CountryModel {
id: countryModel
}
GridLayout { GridLayout {
columns: 2 columns: 2
width: root.width width: root.width
...@@ -34,7 +38,8 @@ Kirigami.ScrollablePage { ...@@ -34,7 +38,8 @@ Kirigami.ScrollablePage {
text: qsTr("Home Country") text: qsTr("Home Country")
} }
QQC2.ComboBox { QQC2.ComboBox {
model: [ "TODO", "TODO" ] model: countryModel
textRole: "display"
} }
QQC2.Label { QQC2.Label {
......
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "countrymodel.h"
#include <KItinerary/CountryDb>
#include <KContacts/Address>
using namespace KItinerary;
CountryModel::CountryModel(QObject *parent)
: QAbstractListModel(parent)
{
}
CountryModel::~CountryModel() = default;
int CountryModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid()) {
return 0;
}
return std::distance(KnowledgeDb::countriesBegin(), KnowledgeDb::countriesEnd());
}
QVariant CountryModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid()) {
return {};
}
const auto it = KnowledgeDb::countriesBegin() + index.row();
switch (role) {
case Qt::DisplayRole:
return KContacts::Address::ISOtoCountry((*it).id.toString());
case Qt::EditRole:
return (*it).id.toString();
}
return {};
}
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COUNTRYMODEL_H
#define COUNTRYMODEL_H
#include <QAbstractListModel>
/** Country model for selecting the home country. */
class CountryModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit CountryModel(QObject *parent = nullptr);
~CountryModel();
int rowCount(const QModelIndex& parent) const override;
QVariant data(const QModelIndex& index, int role) const override;
};
#endif // COUNTRYMODEL_H
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "applicationcontroller.h" #include "applicationcontroller.h"
#include "countryinformation.h" #include "countryinformation.h"
#include "countrymodel.h"
#include "localizer.h" #include "localizer.h"
#include "pkpassmanager.h" #include "pkpassmanager.h"
#include "timelinemodel.h" #include "timelinemodel.h"
...@@ -132,6 +133,7 @@ int main(int argc, char **argv) ...@@ -132,6 +133,7 @@ int main(int argc, char **argv)
qmlRegisterSingletonType<Localizer>("org.kde.itinerary", 1, 0, "Localizer", [](QQmlEngine*, QJSEngine*) -> QObject*{ qmlRegisterSingletonType<Localizer>("org.kde.itinerary", 1, 0, "Localizer", [](QQmlEngine*, QJSEngine*) -> QObject*{
return new Localizer; return new Localizer;
}); });
qmlRegisterType<CountryModel>("org.kde.itinerary", 1, 0, "CountryModel");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.addImageProvider(QStringLiteral("org.kde.pkpass"), new PkPassImageProvider(&passMgr)); engine.addImageProvider(QStringLiteral("org.kde.pkpass"), new PkPassImageProvider(&passMgr));
......
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