From ddf72452b45c6f33e4aec20e5f3cb99b9c8daa4d Mon Sep 17 00:00:00 2001 From: Kormarun Date: Fri, 28 Dec 2018 16:56:25 +0100 Subject: [PATCH] Added missing track field to UI Added sorting by different values --- harbour-companion.pro | 7 +++- qml/pages/ConferenceDayView.qml | 31 +++++++++----- qml/pages/ConferenceEventView.qml | 12 ++++++ rpm/harbour-companion.spec | 2 +- rpm/harbour-companion.yaml | 2 +- src/companion.cpp | 2 + src/conferenceday.cpp | 23 ++++++++++- src/conferenceday.h | 9 +++++ src/conferenceevent.cpp | 60 +++++++++++++++++++++++----- src/conferenceevent.h | 13 +++--- src/conferenceeventcompare.cpp | 23 +++++++++++ src/conferenceeventcompare.h | 11 +++++ src/conferenceeventsortingorder.h | 19 +++++++++ translations/harbour-companion-de.ts | 15 +++++++ translations/harbour-companion.ts | 15 +++++++ 15 files changed, 213 insertions(+), 31 deletions(-) create mode 100644 src/conferenceeventcompare.cpp create mode 100644 src/conferenceeventcompare.h create mode 100644 src/conferenceeventsortingorder.h diff --git a/harbour-companion.pro b/harbour-companion.pro index 05c2470..b6d4027 100644 --- a/harbour-companion.pro +++ b/harbour-companion.pro @@ -25,7 +25,8 @@ SOURCES += src/companion.cpp \ src/event.cpp \ src/conference.cpp \ src/conferenceday.cpp \ - src/conferenceevent.cpp + src/conferenceevent.cpp \ + src/conferenceeventcompare.cpp OTHER_FILES += qml/companion.qml \ qml/cover/CoverPage.qml \ @@ -48,7 +49,9 @@ HEADERS += \ src/event.h \ src/conference.h \ src/conferenceday.h \ - src/conferenceevent.h + src/conferenceevent.h \ + src/conferenceeventsortingorder.h \ + src/conferenceeventcompare.h DISTFILES += \ rpm/harbour-companion.changes \ diff --git a/qml/pages/ConferenceDayView.qml b/qml/pages/ConferenceDayView.qml index 8c62798..aac2fa1 100644 --- a/qml/pages/ConferenceDayView.qml +++ b/qml/pages/ConferenceDayView.qml @@ -42,16 +42,27 @@ Page { SilicaListView { -// PullDownMenu { - -// MenuItem { -// text: page.order ? qsTr("Sort by time") : qsTr("Sort by place") -// onClicked: { -// page.order = !page.order -// page.model = Global.orderBy(page.model, page.order); -// } -// } -// } + PullDownMenu { + + MenuItem { + text: qsTr("Sort by time") + onClicked: { + page.day.sortingOrder = SortingOrder.BY_TIME; + } + } + MenuItem { + text: qsTr("Sort by room") + onClicked: { + page.day.sortingOrder = SortingOrder.BY_ROOM; + } + } + MenuItem { + text: qsTr("Sort by track") + onClicked: { + page.day.sortingOrder = SortingOrder.BY_TRACK; + } + } + } id: listView diff --git a/qml/pages/ConferenceEventView.qml b/qml/pages/ConferenceEventView.qml index c183834..3509ff4 100644 --- a/qml/pages/ConferenceEventView.qml +++ b/qml/pages/ConferenceEventView.qml @@ -187,6 +187,18 @@ Page { // width: parent.width // } + Label { + text:"Track:" + color: Theme.primaryColor + } + + Label { + text: page.event.track + font.capitalization: Font.Capitalize + wrapMode: Text.Wrap + color: Theme.highlightColor + width: parent.width + } Label { text:"Type:" color: Theme.primaryColor diff --git a/rpm/harbour-companion.spec b/rpm/harbour-companion.spec index 843bed4..56d8e78 100644 --- a/rpm/harbour-companion.spec +++ b/rpm/harbour-companion.spec @@ -13,7 +13,7 @@ Name: harbour-companion %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: Chaos Companion -Version: 0.3 +Version: 0.5 Release: 1 Group: Qt/Qt License: LICENSE diff --git a/rpm/harbour-companion.yaml b/rpm/harbour-companion.yaml index 2f520ec..0890f76 100644 --- a/rpm/harbour-companion.yaml +++ b/rpm/harbour-companion.yaml @@ -1,6 +1,6 @@ Name: harbour-companion Summary: Chaos Companion -Version: 0.4 +Version: 0.5 Release: 1 # The contents of the Group field should be one of the groups listed here: # http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS diff --git a/src/companion.cpp b/src/companion.cpp index 85ab240..5cdd848 100644 --- a/src/companion.cpp +++ b/src/companion.cpp @@ -36,6 +36,7 @@ #include #include "loader.h" #include "event.h" +#include "conferenceeventsortingorder.h" #include #include #include @@ -68,6 +69,7 @@ int main(int argc, char *argv[]) qmlRegisterType("harbour.companion", 1, 0, "Conference"); qmlRegisterType("harbour.companion", 1, 0, "ConferenceDay"); qmlRegisterType("harbour.companion", 1, 0, "ConferenceEvent"); + qmlRegisterType("harbour.companion", 1, 0, "SortingOrder"); QList eventList = generateEventList(); QQmlContext* ctxt = v->rootContext(); diff --git a/src/conferenceday.cpp b/src/conferenceday.cpp index 1a709e5..f44ff3f 100644 --- a/src/conferenceday.cpp +++ b/src/conferenceday.cpp @@ -1,4 +1,5 @@ #include "conferenceday.h" +#include "conferenceeventcompare.h" ConferenceDay::ConferenceDay(QObject *parent) : QObject(parent) { @@ -23,6 +24,17 @@ void ConferenceDay::addRoom(const QString &room) emit roomsChanged(this->rooms); } +ConferenceEventSortingOrder::SortingOrder ConferenceDay::getSortingOrder() const +{ + return sortingOrder; +} + +void ConferenceDay::setSortingOrder(const ConferenceEventSortingOrder::SortingOrder &sortingOrder) +{ + this->sortingOrder = sortingOrder; + sort(); +} + ConferenceDay *ConferenceDay::fromJson(const QJsonObject &json) { ConferenceDay* day = new ConferenceDay; @@ -35,6 +47,15 @@ ConferenceDay *ConferenceDay::fromJson(const QJsonObject &json) day->addEvent(ConferenceEvent::fromJson(event.toObject())); } } - std::sort(day->events.begin(), day->events.end(), ConferenceEventPointerCompare()); + day->setSortingOrder(ConferenceEventSortingOrder::BY_TIME); + day->sort(); return day; } + +void ConferenceDay::sort() +{ + ConferenceEventPointerCompare comparator; + comparator.sortingOrder = sortingOrder; + std::sort(events.begin(), events.end(), comparator); + emit eventsChanged(events); +} diff --git a/src/conferenceday.h b/src/conferenceday.h index 5007008..ea036b0 100644 --- a/src/conferenceday.h +++ b/src/conferenceday.h @@ -4,6 +4,7 @@ #include #include #include "conferenceevent.h" +#include "conferenceeventsortingorder.h" class ConferenceDay : public QObject { @@ -11,6 +12,9 @@ class ConferenceDay : public QObject Q_PROPERTY(QDate date MEMBER date NOTIFY dateChanged) Q_PROPERTY(QList events MEMBER events NOTIFY eventsChanged) Q_PROPERTY(QStringList rooms MEMBER rooms NOTIFY roomsChanged) + Q_PROPERTY(ConferenceEventSortingOrder::SortingOrder sortingOrder READ getSortingOrder WRITE setSortingOrder NOTIFY sortingOrderChanged) + + ConferenceEventSortingOrder::SortingOrder sortingOrder; QDate date; QList events; @@ -20,13 +24,18 @@ class ConferenceDay : public QObject void setDate(const QDate& date); void addEvent(ConferenceEvent* event); void addRoom(const QString& room); + ConferenceEventSortingOrder::SortingOrder getSortingOrder() const; + void setSortingOrder(const ConferenceEventSortingOrder::SortingOrder &sortingOrder); static ConferenceDay* fromJson(const QJsonObject& json); + Q_INVOKABLE void sort(); + signals: void dateChanged(const QDate& date); void eventsChanged(const QList& events); void roomsChanged(const QStringList& rooms); + void sortingOrderChanged(const ConferenceEventSortingOrder::SortingOrder& sortingOrder); }; #endif // CONFERENCEDAY_H diff --git a/src/conferenceevent.cpp b/src/conferenceevent.cpp index fd04497..9e2f8ad 100644 --- a/src/conferenceevent.cpp +++ b/src/conferenceevent.cpp @@ -17,6 +17,29 @@ struct CalendarInfo : name(name), notebookUID(notebookUID) {} }; +bool ConferenceEvent::_compareByTime(const ConferenceEvent &b) const +{ + if(start == b.start){ + return end < b.end; + } + return start < b.start; +} + +bool ConferenceEvent::_compareByTitle(const ConferenceEvent &b) const +{ + return title < b.title; +} + +bool ConferenceEvent::_compareByTrack(const ConferenceEvent &b) const +{ + return track < b.track; +} + +bool ConferenceEvent::_compareByRoom(const ConferenceEvent &b) const +{ + return room < b.room; +} + ConferenceEvent::ConferenceEvent(QObject *parent) : QObject(parent) { @@ -100,17 +123,41 @@ void ConferenceEvent::addLink(const QString &link) emit linksChanged(this->links); } -bool ConferenceEvent::operator <(const ConferenceEvent& b) const +bool ConferenceEvent::compareByTime(const ConferenceEvent& b) const { if(start == b.start){ if(end == b.end){ - return room < b.room; + return _compareByRoom(b); } return end < b.end; } return start < b.start; } +bool ConferenceEvent::compareByTitle(const ConferenceEvent& b) const +{ + if(title == b.title){ + return _compareByTime(b); + } + return title < b.title; +} + +bool ConferenceEvent::compareByTrack(const ConferenceEvent& b) const +{ + if(track == b.track){ + return _compareByTime(b); + } + return track < b.track; +} +bool ConferenceEvent::compareByRoom(const ConferenceEvent& b) const +{ + if(room == b.room){ + return _compareByTime(b); + } + return room < b.room; +} + + ConferenceEvent* ConferenceEvent::fromJson(const QJsonObject &json) { ConferenceEvent* event = new ConferenceEvent; @@ -170,12 +217,3 @@ void ConferenceEvent::addToCalendar() const qDebug() << "FAILED TO ACCESS CALENDER" << calendar << storage; } } - -bool ConferenceEventPointerCompare::operator()(const QObject *a, const QObject *b) { - const ConferenceEvent* aa = dynamic_cast(a); - const ConferenceEvent* bb = dynamic_cast(b); - - if(aa == nullptr || bb == nullptr) - return false; - return *aa < *bb; -} diff --git a/src/conferenceevent.h b/src/conferenceevent.h index 33c421b..c289828 100644 --- a/src/conferenceevent.h +++ b/src/conferenceevent.h @@ -28,6 +28,10 @@ class ConferenceEvent : public QObject QString room, title, subtitle, track, type, language, abstract, description; bool record; QStringList persons, links; + bool _compareByTime(const ConferenceEvent& b) const; + bool _compareByTitle(const ConferenceEvent& b) const; + bool _compareByTrack(const ConferenceEvent& b) const; + bool _compareByRoom(const ConferenceEvent& b) const; public: explicit ConferenceEvent(QObject *parent = nullptr); @@ -43,7 +47,10 @@ class ConferenceEvent : public QObject void setRecord(bool record); void addPerson(const QString& person); void addLink(const QString& link); - bool operator <(const ConferenceEvent& b) const; + bool compareByTime(const ConferenceEvent& b) const; + bool compareByTitle(const ConferenceEvent& b) const; + bool compareByTrack(const ConferenceEvent& b) const; + bool compareByRoom(const ConferenceEvent& b) const; static ConferenceEvent* fromJson(const QJsonObject& json); @@ -64,10 +71,6 @@ class ConferenceEvent : public QObject void linksChanged(const QStringList& links); }; -struct ConferenceEventPointerCompare { - bool operator()(const QObject* a, const QObject* b); -}; - #endif // CONFERENCEEVENT_H diff --git a/src/conferenceeventcompare.cpp b/src/conferenceeventcompare.cpp new file mode 100644 index 0000000..8a7bc77 --- /dev/null +++ b/src/conferenceeventcompare.cpp @@ -0,0 +1,23 @@ +#include "conferenceeventcompare.h" +#include "conferenceevent.h" + +bool ConferenceEventPointerCompare::operator()(const QObject *a, const QObject *b) { + const ConferenceEvent* aa = dynamic_cast(a); + const ConferenceEvent* bb = dynamic_cast(b); + + if(aa == nullptr || bb == nullptr) + return false; + + switch (sortingOrder) { + case ConferenceEventSortingOrder::SortingOrder::BY_TIME: + return aa->compareByTime(*bb); + case ConferenceEventSortingOrder::SortingOrder::BY_TITLE: + return aa->compareByTitle(*bb); + case ConferenceEventSortingOrder::SortingOrder::BY_TRACK: + return aa->compareByTrack(*bb); + case ConferenceEventSortingOrder::SortingOrder::BY_ROOM: + return aa->compareByRoom(*bb); + default: + return false; + } +} diff --git a/src/conferenceeventcompare.h b/src/conferenceeventcompare.h new file mode 100644 index 0000000..4fc3226 --- /dev/null +++ b/src/conferenceeventcompare.h @@ -0,0 +1,11 @@ +#ifndef CONFERENCEEVENTCOMPARE_H +#define CONFERENCEEVENTCOMPARE_H + +#include "conferenceeventsortingorder.h" + +struct ConferenceEventPointerCompare { + ConferenceEventSortingOrder::SortingOrder sortingOrder; + bool operator()(const QObject* a, const QObject* b); +}; + +#endif // CONFERENCEEVENTCOMPARE_H diff --git a/src/conferenceeventsortingorder.h b/src/conferenceeventsortingorder.h new file mode 100644 index 0000000..851074e --- /dev/null +++ b/src/conferenceeventsortingorder.h @@ -0,0 +1,19 @@ +#ifndef CONFERENCEEVENTSORTINGORDER_H +#define CONFERENCEEVENTSORTINGORDER_H + +#include + +class ConferenceEventSortingOrder: public QObject { + Q_OBJECT +public: + enum SortingOrder { + BY_TIME, + BY_TITLE, + BY_TRACK, + BY_ROOM + }; + + Q_ENUM(SortingOrder) +}; + +#endif // CONFERENCEEVENTSORTINGORDER_H diff --git a/translations/harbour-companion-de.ts b/translations/harbour-companion-de.ts index 0a36dc4..8fa091f 100644 --- a/translations/harbour-companion-de.ts +++ b/translations/harbour-companion-de.ts @@ -1,6 +1,21 @@ + + ConferenceDayView + + Sort by time + + + + Sort by room + + + + Sort by track + + + ConferenceEventView diff --git a/translations/harbour-companion.ts b/translations/harbour-companion.ts index 0a36dc4..8fa091f 100644 --- a/translations/harbour-companion.ts +++ b/translations/harbour-companion.ts @@ -1,6 +1,21 @@ + + ConferenceDayView + + Sort by time + + + + Sort by room + + + + Sort by track + + + ConferenceEventView