Skip to content

Commit

Permalink
Added missing track field to UI
Browse files Browse the repository at this point in the history
Added sorting by different values
  • Loading branch information
k0rmarun committed Dec 28, 2018
1 parent e4b1566 commit ddf7245
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 31 deletions.
7 changes: 5 additions & 2 deletions harbour-companion.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
31 changes: 21 additions & 10 deletions qml/pages/ConferenceDayView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions qml/pages/ConferenceEventView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rpm/harbour-companion.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rpm/harbour-companion.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <sailfishapp.h>
#include "loader.h"
#include "event.h"
#include "conferenceeventsortingorder.h"
#include <unistd.h>
#include <grp.h>
#include <pwd.h>
Expand Down Expand Up @@ -68,6 +69,7 @@ int main(int argc, char *argv[])
qmlRegisterType<Conference>("harbour.companion", 1, 0, "Conference");
qmlRegisterType<ConferenceDay>("harbour.companion", 1, 0, "ConferenceDay");
qmlRegisterType<ConferenceEvent>("harbour.companion", 1, 0, "ConferenceEvent");
qmlRegisterType<ConferenceEventSortingOrder>("harbour.companion", 1, 0, "SortingOrder");

QList<QObject*> eventList = generateEventList();
QQmlContext* ctxt = v->rootContext();
Expand Down
23 changes: 22 additions & 1 deletion src/conferenceday.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "conferenceday.h"
#include "conferenceeventcompare.h"

ConferenceDay::ConferenceDay(QObject *parent) : QObject(parent)
{
Expand All @@ -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;
Expand All @@ -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);
}
9 changes: 9 additions & 0 deletions src/conferenceday.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
#include <QObject>
#include <QDate>
#include "conferenceevent.h"
#include "conferenceeventsortingorder.h"

class ConferenceDay : public QObject
{
Q_OBJECT
Q_PROPERTY(QDate date MEMBER date NOTIFY dateChanged)
Q_PROPERTY(QList<QObject*> 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<QObject*> events;
Expand All @@ -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<QObject*>& events);
void roomsChanged(const QStringList& rooms);
void sortingOrderChanged(const ConferenceEventSortingOrder::SortingOrder& sortingOrder);
};

#endif // CONFERENCEDAY_H
60 changes: 49 additions & 11 deletions src/conferenceevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<const ConferenceEvent*>(a);
const ConferenceEvent* bb = dynamic_cast<const ConferenceEvent*>(b);

if(aa == nullptr || bb == nullptr)
return false;
return *aa < *bb;
}
13 changes: 8 additions & 5 deletions src/conferenceevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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
23 changes: 23 additions & 0 deletions src/conferenceeventcompare.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "conferenceeventcompare.h"
#include "conferenceevent.h"

bool ConferenceEventPointerCompare::operator()(const QObject *a, const QObject *b) {
const ConferenceEvent* aa = dynamic_cast<const ConferenceEvent*>(a);
const ConferenceEvent* bb = dynamic_cast<const ConferenceEvent*>(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;
}
}
11 changes: 11 additions & 0 deletions src/conferenceeventcompare.h
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions src/conferenceeventsortingorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef CONFERENCEEVENTSORTINGORDER_H
#define CONFERENCEEVENTSORTINGORDER_H

#include <QObject>

class ConferenceEventSortingOrder: public QObject {
Q_OBJECT
public:
enum SortingOrder {
BY_TIME,
BY_TITLE,
BY_TRACK,
BY_ROOM
};

Q_ENUM(SortingOrder)
};

#endif // CONFERENCEEVENTSORTINGORDER_H
15 changes: 15 additions & 0 deletions translations/harbour-companion-de.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>ConferenceDayView</name>
<message>
<source>Sort by time</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sort by room</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sort by track</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ConferenceEventView</name>
<message>
Expand Down
Loading

0 comments on commit ddf7245

Please sign in to comment.