Commit af0686d0 authored by Dimitris Kardarakos's avatar Dimitris Kardarakos

Event model created, to be used in VEVENT ical implementation

parent dcd201fa
......@@ -3,6 +3,7 @@ set(qmlplugin_SRCS
calindoriconfig.cpp
todosmodel.cpp
localcalendar.cpp
eventmodel.cpp
)
add_library (calindoriqmlplugin SHARED ${qmlplugin_SRCS})
......
/*
* Copyright (C) 2019 Dimitris Kardarakos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "eventmodel.h"
using namespace KCalCore;
EventModel::EventModel(QObject* parent) :
QAbstractListModel(parent),
m_events(Event::List()),
m_filterdt(QDate()),
m_calendar(nullptr)
{
connect(this, &EventModel::filterdtChanged, this, &EventModel::loadEvents);
connect(this, &EventModel::memorycalendarChanged, this, &EventModel::loadEvents);
}
EventModel::~EventModel() = default;
QDate EventModel::filterdt() const
{
return m_filterdt;
}
void EventModel::setFilterdt(const QDate& filterDate)
{
m_filterdt = filterDate;
emit filterdtChanged();
}
MemoryCalendar::Ptr EventModel::memorycalendar() const
{
return m_calendar;
}
void EventModel::setMemorycalendar(const MemoryCalendar::Ptr calendarPtr)
{
m_calendar = calendarPtr;
emit memorycalendarChanged();
}
QHash<int, QByteArray> EventModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
roles.insert(Uid, "uid");
roles.insert(DtStart, "dtstart");
roles.insert(AllDay, "allday");
roles.insert(Description, "description");
roles.insert(Summary, "summary");
roles.insert(LastModified, "lastmodified");
roles.insert(Location, "location");
roles.insert(Categories, "categories");
roles.insert(Priority, "priority");
roles.insert(Created, "created");
roles.insert(Secrecy, "secrecy");
roles.insert(EndDate, "dtend");
roles.insert(Transparency, "transparency");
return roles;
}
QVariant EventModel::data(const QModelIndex& index, int role) const
{
if(!index.isValid())
return QVariant();
switch(role)
{
case Uid :
return m_events.at(index.row())->uid();
case Summary:
return m_events.at(index.row())->summary();
default:
return QVariant();
}
}
int EventModel::rowCount(const QModelIndex& parent) const
{
if(parent.isValid())
return 0;
return m_events.count();
}
void EventModel::loadEvents()
{
beginResetModel();
m_events.clear();
if(m_calendar != nullptr && m_filterdt.isValid())
m_events = m_calendar->rawEventsForDate(m_filterdt);
if(m_calendar != nullptr && m_filterdt.isNull())
m_events = m_calendar->rawEvents();
endResetModel();
emit rowCountChanged();
}
/*
* Copyright (C) 2019 Dimitris Kardarakos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef EVENTMODEL_H
#define EVENTMODEL_H
#include <QAbstractListModel>
#include <KCalCore/Event>
#include <KCalCore/MemoryCalendar>
using namespace KCalCore;
class EventModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QDate filterdt READ filterdt WRITE setFilterdt NOTIFY filterdtChanged)
Q_PROPERTY(QSharedPointer<MemoryCalendar> memorycalendar READ memorycalendar WRITE setMemorycalendar NOTIFY memorycalendarChanged)
Q_PROPERTY(int count READ rowCount NOTIFY rowCountChanged)
public:
explicit EventModel(QObject* parent = nullptr);
~EventModel() override;
enum Roles
{
Uid = Qt::UserRole+1,
LastModified,
DtStart,
AllDay,
Description,
Summary,
Location,
Categories,
Priority,
Created,
Secrecy,
EndDate,
Transparency
};
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QDate filterdt() const;
void setFilterdt(const QDate & filterDate);
MemoryCalendar::Ptr memorycalendar() const;
void setMemorycalendar(const MemoryCalendar::Ptr calendarPtr);
public Q_SLOTS:
void loadEvents();
Q_SIGNALS:
void filterdtChanged();
void memorycalendarChanged();
void rowCountChanged();
private:
Event::List m_events;
QDate m_filterdt;
MemoryCalendar::Ptr m_calendar;
};
#endif //EVENTMODEL_H
......@@ -21,6 +21,7 @@
#include "calindoriconfig.h"
#include "localcalendar.h"
#include "todosmodel.h"
#include "eventmodel.h"
#include <QQmlEngine>
#include <QtQml/qqml.h>
......@@ -30,4 +31,5 @@ void QmlPlugins::registerTypes(const char *uri)
qmlRegisterType<CalindoriConfig>(uri, 0, 1, "Config");
qmlRegisterType<TodosModel>(uri, 0, 1, "TodosModel");
qmlRegisterType<LocalCalendar>(uri, 0, 1, "LocalCalendar");
qmlRegisterType<EventModel>(uri, 0, 1, "EventModel");
}
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