diff --git a/src/event/EventsUpdater.cpp b/src/event/EventsUpdater.cpp index fb5ebacc..885feeca 100644 --- a/src/event/EventsUpdater.cpp +++ b/src/event/EventsUpdater.cpp @@ -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()) diff --git a/src/event/EventsUpdater.h b/src/event/EventsUpdater.h index 816b98e5..66be2d7d 100644 --- a/src/event/EventsUpdater.h +++ b/src/event/EventsUpdater.h @@ -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(); diff --git a/src/ui/EventsView.cpp b/src/ui/EventsView.cpp index 40ca58a7..0de7cea0 100644 --- a/src/ui/EventsView.cpp +++ b/src/ui/EventsView.cpp @@ -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 > &sources) { m_eventsProxyModel->setSources(sources); diff --git a/src/ui/EventsView.h b/src/ui/EventsView.h index 4ecb49d9..05651243 100644 --- a/src/ui/EventsView.h +++ b/src/ui/EventsView.h @@ -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 > &sources); void sortEvents(int logicalIndex, Qt::SortOrder sortOrder); diff --git a/src/ui/EventsWindow.cpp b/src/ui/EventsWindow.cpp index 27ddc3f8..b89c2eb0 100644 --- a/src/ui/EventsWindow.cpp +++ b/src/ui/EventsWindow.cpp @@ -37,7 +37,7 @@ #include "event/MediaEventFilter.h" #include #include -#include +#include #include #include #include @@ -84,7 +84,7 @@ EventsWindow::EventsWindow(DVRServerRepository *serverRepository, QWidget *paren connect(sourcesModel, SIGNAL(checkedSourcesChanged(QMap>)), this, SLOT(setFilterSources(QMap>))); - createDateFilter(filtersLayout); + createDateTimeFilter(filtersLayout); createLoadButton(filtersLayout); #if 1 /* This is not useful currently. */ @@ -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() @@ -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")); @@ -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() diff --git a/src/ui/EventsWindow.h b/src/ui/EventsWindow.h index 7b85c4d0..a3bbc7bd 100644 --- a/src/ui/EventsWindow.h +++ b/src/ui/EventsWindow.h @@ -35,6 +35,7 @@ class QComboBox; class QSlider; class QModelIndex; class QDateTime; +class QDateTimeEdit; class QTabWidget; class EventViewWindow; class QSplitter; @@ -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 > &sources); void loadEvents(); @@ -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(); diff --git a/src/ui/model/EventsProxyModel.cpp b/src/ui/model/EventsProxyModel.cpp index afe8b7ed..d5d04513 100644 --- a/src/ui/model/EventsProxyModel.cpp +++ b/src/ui/model/EventsProxyModel.cpp @@ -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; @@ -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(); } diff --git a/src/ui/model/EventsProxyModel.h b/src/ui/model/EventsProxyModel.h index 84a9321d..07e5f9d6 100644 --- a/src/ui/model/EventsProxyModel.h +++ b/src/ui/model/EventsProxyModel.h @@ -46,6 +46,7 @@ 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 > &sources); private: @@ -53,7 +54,9 @@ class EventsProxyModel : public QSortFilterProxyModel IncompletePlace m_incompletePlace; EventLevel m_minimumLevel; QBitArray m_types; - QDate m_day; + //QDate m_day; + QDateTime m_dtStart; + QDateTime m_dtEnd; QMap > m_sources; bool filterAcceptsRow(EventData *eventData) const;