Skip to content

Commit

Permalink
replaced date selector in event browser with two datetime selectors "…
Browse files Browse the repository at this point in the history
…From" and To\ as part of #233 implementation
  • Loading branch information
antonsviridenko committed Jul 14, 2015
1 parent 69f6145 commit 4b1c099
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 30 deletions.
6 changes: 6 additions & 0 deletions src/event/EventsUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ void EventsUpdater::setDay(const QDate &date)
//updateServers();
}

void EventsUpdater::setTimeRange(const QDateTime &from, const QDateTime &to)
{
m_startTime = from;
m_endTime = to;
}

void EventsUpdater::updateServers()
{
foreach (DVRServer *s, m_serverRepository->servers())
Expand Down
1 change: 1 addition & 0 deletions src/event/EventsUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public slots:
void setUpdateInterval(int miliseconds);
void setLimit(int limit);
void setDay(const QDate &date);
void setTimeRange(const QDateTime &from, const QDateTime &to);

void updateServer(DVRServer *server);
void updateServers();
Expand Down
5 changes: 5 additions & 0 deletions src/ui/EventsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ void EventsView::setDay(const QDate &day)
m_eventsProxyModel->setDay(day);
}

void EventsView::setTimeRange(const QDateTime &from, const QDateTime &to)
{
m_eventsProxyModel->setTimeRange(from, to);
}

void EventsView::setSources(const QMap<DVRServer*, QSet<int> > &sources)
{
m_eventsProxyModel->setSources(sources);
Expand Down
1 change: 1 addition & 0 deletions src/ui/EventsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public slots:
void setMinimumLevel(EventLevel minimumLevel);
void setTypes(QBitArray types);
void setDay(const QDate &day);
void setTimeRange(const QDateTime &from, const QDateTime &to);
void setSources(const QMap<DVRServer*, QSet<int> > &sources);

void sortEvents(int logicalIndex, Qt::SortOrder sortOrder);
Expand Down
72 changes: 49 additions & 23 deletions src/ui/EventsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "event/MediaEventFilter.h"
#include <QBoxLayout>
#include <QGridLayout>
#include <QDateEdit>
#include <QDateTimeEdit>
#include <QComboBox>
#include <QLabel>
#include <QCheckBox>
Expand Down Expand Up @@ -84,7 +84,7 @@ EventsWindow::EventsWindow(DVRServerRepository *serverRepository, QWidget *paren
connect(sourcesModel, SIGNAL(checkedSourcesChanged(QMap<DVRServer*,QSet<int>>)),
this, SLOT(setFilterSources(QMap<DVRServer*,QSet<int>>)));

createDateFilter(filtersLayout);
createDateTimeFilter(filtersLayout);
createLoadButton(filtersLayout);

#if 1 /* This is not useful currently. */
Expand Down Expand Up @@ -161,24 +161,44 @@ void EventsWindow::createLoadButton(QBoxLayout *layout)
connect(m_loadEvents, SIGNAL(clicked()), this, SLOT(loadEvents()));
}

void EventsWindow::createDateFilter(QBoxLayout *layout)
void EventsWindow::createDateTimeFilter(QBoxLayout *layout)
{
m_dateLabel = new QLabel;
m_dateLabel->setStyleSheet(QLatin1String("font-weight:bold;"));
layout->addWidget(m_dateLabel);

QDateEdit *dateEdit = new QDateEdit(QDate::currentDate());
dateEdit->setCalendarPopup(true);
dateEdit->setMaximumDate(QDate::currentDate());
dateEdit->setDisplayFormat(QLatin1String("ddd, MMM dd, yyyy"));
dateEdit->setTime(QTime(23, 59, 59, 999));
dateEdit->setFixedWidth(m_sourcesView->width());
layout->addWidget(dateEdit);

setFilterDay(dateEdit->dateTime());

connect(dateEdit, SIGNAL(dateTimeChanged(QDateTime)), this,
SLOT(setFilterDay(QDateTime)));
m_fromDateTimeLabel = new QLabel;
m_toDateTimeLabel = new QLabel;
m_fromDateTimeLabel->setStyleSheet(QLatin1String("font-weight:bold;"));
m_toDateTimeLabel->setStyleSheet(QLatin1String("font-weight:bold;"));

layout->addWidget(m_fromDateTimeLabel);


QDateTimeEdit *fromDateEdit = new QDateTimeEdit(QDateTime::currentDateTime().addSecs(-60*60*5));
fromDateEdit->setCalendarPopup(true);
fromDateEdit->setMaximumDate(QDate::currentDate());
fromDateEdit->setDisplayFormat(QLatin1String("ddd, MMM dd, yyyy hh:mm"));
//fromDateEdit->setTime(QTime(23, 59, 59, 999));
fromDateEdit->setFixedWidth(m_sourcesView->width());
layout->addWidget(fromDateEdit);
m_fromDateTime = fromDateEdit;

layout->addWidget(m_toDateTimeLabel);

QDateTimeEdit *toDateEdit = new QDateTimeEdit(QDateTime::currentDateTime());
toDateEdit->setCalendarPopup(true);
toDateEdit->setMaximumDate(QDate::currentDate());
toDateEdit->setDisplayFormat(QLatin1String("ddd, MMM dd, yyyy hh:mm"));
//toDateEdit->setTime(QTime(23, 59, 59, 999));
toDateEdit->setFixedWidth(m_sourcesView->width());
layout->addWidget(toDateEdit);
m_toDateTime = toDateEdit;

//setFilterDay(dateEdit->dateTime());
setFilterDateTimeRange();

connect(fromDateEdit, SIGNAL(dateTimeChanged(QDateTime)), this,
SLOT(setFilterDateTimeRange()));
connect(toDateEdit, SIGNAL(dateTimeChanged(QDateTime)), this,
SLOT(setFilterDateTimeRange()));

}

QWidget *EventsWindow::createLevelFilter()
Expand Down Expand Up @@ -290,7 +310,8 @@ void EventsWindow::retranslateUI()
m_zoomLabel->setText(tr("Zoom:"));
if (m_tagInput)
m_tagInput->lineEdit()->setPlaceholderText(tr("Type or select a tag to filter"));
m_dateLabel->setText(tr("Date"));
m_fromDateTimeLabel->setText(tr("From:"));
m_toDateTimeLabel->setText(tr("To:"));

m_levelFilter->blockSignals(true);
m_levelFilter->setItemText(0, tr("Any"));
Expand Down Expand Up @@ -446,10 +467,15 @@ void EventsWindow::setFilterTypes(QBitArray types)
m_resultsView->setTypes(types);
}

void EventsWindow::setFilterDay(const QDateTime &day)
void EventsWindow::setFilterDateTimeRange()
{
m_eventsUpdater->setDay(day.date());
m_resultsView->setDay(day.date());
QDateTime from, to;

from = m_fromDateTime->dateTime();
to = m_toDateTime->dateTime();

m_eventsUpdater->setTimeRange(from, to);
m_resultsView->setTimeRange(from, to);
}

void EventsWindow::loadEvents()
Expand Down
10 changes: 7 additions & 3 deletions src/ui/EventsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class QComboBox;
class QSlider;
class QModelIndex;
class QDateTime;
class QDateTimeEdit;
class QTabWidget;
class EventViewWindow;
class QSplitter;
Expand Down Expand Up @@ -65,7 +66,7 @@ private slots:
void showServerEvent(const EventData &eventData);

void setFilterTypes(QBitArray types);
void setFilterDay(const QDateTime &day);
void setFilterDateTimeRange();
void setFilterSources(const QMap<DVRServer *, QSet<int> > &sources);
void loadEvents();

Expand Down Expand Up @@ -104,11 +105,14 @@ private slots:
QLabel *m_minimumLevelLabel;
QLabel *m_typeLabel;
QLabel *m_tagsLabel;
QLabel *m_dateLabel;
QLabel *m_fromDateTimeLabel;
QDateTimeEdit *m_fromDateTime;
QLabel *m_toDateTimeLabel;
QDateTimeEdit *m_toDateTime;
QComboBox *m_tagInput;
QLabel *m_zoomLabel;

void createDateFilter(QBoxLayout *layout);
void createDateTimeFilter(QBoxLayout *layout);
void createLoadButton(QBoxLayout *layout);
QWidget *createLevelFilter();
QWidget *createTypeFilter();
Expand Down
27 changes: 24 additions & 3 deletions src/ui/model/EventsProxyModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ bool EventsProxyModel::filterAcceptsRow(EventData *eventData) const
if (!m_types.isNull() && (int)eventData->type() >= 0 && !m_types.testBit((int)eventData->type()))
return false;

if (!m_day.isNull() && eventData->localStartDate().date() != m_day)
//if (!m_day.isNull() && eventData->localStartDate().date() != m_day)
// return false;
if (!m_dtStart.isNull() && !m_dtEnd.isNull() && (eventData->localStartDate() < m_dtStart || eventData->localStartDate() > m_dtEnd))
return false;



if (m_sources.isEmpty())
return true;

Expand Down Expand Up @@ -156,10 +160,27 @@ void EventsProxyModel::setTypes(QBitArray types)

void EventsProxyModel::setDay(const QDate &day)
{
if (m_day == day)
/*if (m_day == day)
return;
m_day = day;*/
if (m_dtStart.date() == day && m_dtEnd.date() == day)
return;

m_dtStart.setDate(day);
m_dtEnd.setDate(day);
m_dtEnd.setTime(QTime(23, 59, 59, 999));

invalidateFilter();
}

void EventsProxyModel::setTimeRange(const QDateTime &from, const QDateTime &to)
{
if (m_dtStart == from && m_dtEnd == to)
return;

m_day = day;
m_dtStart = from;
m_dtEnd = to;
invalidateFilter();
}

Expand Down
5 changes: 4 additions & 1 deletion src/ui/model/EventsProxyModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ class EventsProxyModel : public QSortFilterProxyModel
void setMinimumLevel(EventLevel minimumLevel);
void setTypes(QBitArray types);
void setDay(const QDate &day);
void setTimeRange(const QDateTime &from, const QDateTime &to);
void setSources(const QMap<DVRServer*, QSet<int> > &sources);

private:
int m_column;
IncompletePlace m_incompletePlace;
EventLevel m_minimumLevel;
QBitArray m_types;
QDate m_day;
//QDate m_day;
QDateTime m_dtStart;
QDateTime m_dtEnd;
QMap<DVRServer*, QSet<int> > m_sources;

bool filterAcceptsRow(EventData *eventData) const;
Expand Down

0 comments on commit 4b1c099

Please sign in to comment.