[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kholidays] /: Add declarative plugin
From: Martin Klapetek <mklapetek () kde ! org>
Date: 2016-03-16 21:24:55
Message-ID: E1agIw3-0003ym-V7 () scm ! kde ! org
[Download RAW message or body]
Git commit e311a7a845a35a4e82e786cdd4d07592624f6741 by Martin Klapetek.
Committed on 16/03/2016 at 21:24.
Pushed by mklapetek into branch 'master'.
Add declarative plugin
For now it contains just the model of holiday regions
which will be used in the Plasma calendar events
configuration.
REVIEW: 125965
M +1 -1 CMakeLists.txt
M +2 -0 src/CMakeLists.txt
A +12 -0 src/declarative/CMakeLists.txt
A +84 -0 src/declarative/holidayregionsmodel.cpp [License: LGPL (v2+)]
A +49 -0 src/declarative/holidayregionsmodel.h [License: LGPL (v2+)]
A +0 -0 src/declarative/holidaysmodel.h [License: Trivial file]
A +30 -0 src/declarative/kholidaysdeclarativeplugin.cpp [License: LGPL \
(v2+)] A +35 -0 src/declarative/kholidaysdeclarativeplugin.h [License: LGPL \
(v2+)] A +3 -0 src/declarative/qmldir
http://commits.kde.org/kholidays/e311a7a845a35a4e82e786cdd4d07592624f6741
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0095419..7cc5b05 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,7 +29,7 @@ ecm_setup_version(${KHOLIDAYS_LIB_VERSION} VARIABLE_PREFIX \
KHOLIDAYS
########### Find packages ###########
set(REQUIRED_QT_VERSION 5.4.0)
-find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core)
+find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Qml)
remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e7ea4be..ded8bc9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -74,3 +74,5 @@ install(FILES
ecm_generate_pri_file(BASE_NAME KHolidays LIB_NAME KF5KHolidays DEPS "widgets" \
FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR \
${KDE_INSTALL_INCLUDEDIR_KF5}/KHolidays)
install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
+
+add_subdirectory(declarative)
diff --git a/src/declarative/CMakeLists.txt b/src/declarative/CMakeLists.txt
new file mode 100644
index 0000000..bd1eff7
--- /dev/null
+++ b/src/declarative/CMakeLists.txt
@@ -0,0 +1,12 @@
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_library(kholidaysdeclarativeplugin SHARED kholidaysdeclarativeplugin.cpp
+ holidayregionsmodel.cpp)
+
+target_link_libraries(kholidaysdeclarativeplugin Qt5::Qml
+ Qt5::Core
+ KF5Holidays
+)
+
+install(TARGETS kholidaysdeclarativeplugin DESTINATION \
${KDE_INSTALL_QMLDIR}/org/kde/kholidays) +install(FILES qmldir DESTINATION \
${KDE_INSTALL_QMLDIR}/org/kde/kholidays)
diff --git a/src/declarative/holidayregionsmodel.cpp \
b/src/declarative/holidayregionsmodel.cpp new file mode 100644
index 0000000..74a75e7
--- /dev/null
+++ b/src/declarative/holidayregionsmodel.cpp
@@ -0,0 +1,84 @@
+/*
+ This file is part of the kholidays library.
+
+ Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
+
+ This library 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 library 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 Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "holidayregionsmodel.h"
+
+#include "../holidayregion.h"
+
+class HolidayRegionsDeclarativeModel::Private
+{
+public:
+ QStringList regionCodes;
+};
+
+
+HolidayRegionsDeclarativeModel::HolidayRegionsDeclarativeModel(QObject *parent)
+ : QAbstractListModel(parent),
+ d(new Private())
+{
+ d->regionCodes = KHolidays::HolidayRegion::regionCodes();
+ // Make sure we don't add the same regions twice
+ // This can happen if two copies of the data exists
+ // in the system and both are read by KHolidays
+ d->regionCodes.removeDuplicates();
+}
+
+HolidayRegionsDeclarativeModel::~HolidayRegionsDeclarativeModel()
+{
+ delete d;
+}
+
+int HolidayRegionsDeclarativeModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent)
+
+ return d->regionCodes.size();
+}
+
+QVariant HolidayRegionsDeclarativeModel::data(const QModelIndex &index, int role) \
const +{
+ if (!index.isValid()) {
+ return QVariant();
+ }
+
+ const QString regionCode = d->regionCodes.at(index.row());
+
+ switch (role) {
+ case HolidayRegionsDeclarativeModel::RegionRole:
+ return regionCode;
+ case HolidayRegionsDeclarativeModel::NameRole:
+ return KHolidays::HolidayRegion::name(regionCode);
+ case HolidayRegionsDeclarativeModel::DescriptionRole:
+ return KHolidays::HolidayRegion::description(regionCode);
+ }
+
+ return QVariant();
+}
+
+QHash<int, QByteArray> HolidayRegionsDeclarativeModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles.insert(HolidayRegionsDeclarativeModel::RegionRole, "region");
+ roles.insert(HolidayRegionsDeclarativeModel::NameRole, "name");
+ roles.insert(HolidayRegionsDeclarativeModel::DescriptionRole, "description");
+
+ return roles;
+}
diff --git a/src/declarative/holidayregionsmodel.h \
b/src/declarative/holidayregionsmodel.h new file mode 100644
index 0000000..74209c7
--- /dev/null
+++ b/src/declarative/holidayregionsmodel.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of the kholidays library.
+
+ Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
+
+ This library 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 library 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 Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef HOLIDAYREGIONSDECLARATIVEMODEL_H
+#define HOLIDAYREGIONSDECLARATIVEMODEL_H
+
+#include <QObject>
+#include <QAbstractListModel>
+
+class HolidayRegionsDeclarativeModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum Roles {
+ RegionRole = Qt::UserRole + 1,
+ NameRole,
+ DescriptionRole
+ };
+ HolidayRegionsDeclarativeModel(QObject *parent = 0);
+ virtual ~HolidayRegionsDeclarativeModel();
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
+ QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
+
+private:
+ class Private;
+ Private * const d;
+};
+
+#endif
diff --git a/src/declarative/holidaysmodel.h b/src/declarative/holidaysmodel.h
new file mode 100644
index 0000000..e69de29
diff --git a/src/declarative/kholidaysdeclarativeplugin.cpp \
b/src/declarative/kholidaysdeclarativeplugin.cpp new file mode 100644
index 0000000..e30c924
--- /dev/null
+++ b/src/declarative/kholidaysdeclarativeplugin.cpp
@@ -0,0 +1,30 @@
+/*
+ This file is part of the kholidays library.
+
+ Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
+
+ This library 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 library 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 Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kholidaysdeclarativeplugin.h"
+#include "holidayregionsmodel.h"
+
+#include <qqml.h>
+
+void KHolidaysDeclarativePlugin::registerTypes(const char* uri)
+{
+ qmlRegisterType<HolidayRegionsDeclarativeModel>(uri, 1, 0, \
"HolidayRegionsModel"); +}
diff --git a/src/declarative/kholidaysdeclarativeplugin.h \
b/src/declarative/kholidaysdeclarativeplugin.h new file mode 100644
index 0000000..9c38ec8
--- /dev/null
+++ b/src/declarative/kholidaysdeclarativeplugin.h
@@ -0,0 +1,35 @@
+/*
+ This file is part of the kholidays library.
+
+ Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
+
+ This library 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 library 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 Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KHOLIDAYSDECLARATIVEPLUGIN_H
+#define KHOLIDAYSDECLARATIVEPLUGIN_H
+
+#include <QQmlExtensionPlugin>
+
+class KHolidaysDeclarativePlugin : public QQmlExtensionPlugin
+{
+Q_OBJECT
+Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+public:
+ virtual void registerTypes(const char* uri);
+};
+
+#endif // KHOLIDAYSDECLARATIVEPLUGIN_H
diff --git a/src/declarative/qmldir b/src/declarative/qmldir
new file mode 100644
index 0000000..77e3103
--- /dev/null
+++ b/src/declarative/qmldir
@@ -0,0 +1,3 @@
+module org.kde.kholidays
+
+plugin kholidaysdeclarativeplugin
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic