Commit 13f5afaa authored by Robert Krawitz's avatar Robert Krawitz

Fast DateTime class.

The FastDateTime class implements a datetime that is much faster than
QDateTime for comparing dates.  It caches the linear time since the
epoch for use in comparisons.  See
https://bugreports.qt.io/browse/QTBUG-41714 and
https://bugreports.qt.io/browse/QTBUG-75585 for an explanation of why
the standard QDateTime is extremely slow (on the order of 1 usec per
comparison).
parent 9bc2650c
......@@ -202,7 +202,7 @@ void AnnotationDialog::DateEdit::dateSelected(QDate newDate)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
emit dateChanged(DB::ImageDate(newDate.startOfDay(), newDate.startOfDay()));
#else
emit dateChanged(DB::ImageDate(QDateTime(newDate), QDateTime(newDate)));
emit dateChanged(DB::ImageDate(Utilities::FastDateTime(newDate), Utilities::FastDateTime(newDate)));
#endif
m_DateFrame->hide();
}
......@@ -216,7 +216,7 @@ void AnnotationDialog::DateEdit::dateEntered(QDate newDate)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
emit dateChanged(DB::ImageDate(newDate.startOfDay(), newDate.startOfDay()));
#else
emit dateChanged(DB::ImageDate(QDateTime(newDate), QDateTime(newDate)));
emit dateChanged(DB::ImageDate(Utilities::FastDateTime(newDate), Utilities::FastDateTime(newDate)));
#endif
}
}
......@@ -236,7 +236,7 @@ void AnnotationDialog::DateEdit::lineEnterPressed()
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
emit dateChanged(DB::ImageDate(date.startOfDay(), end.startOfDay()));
#else
emit dateChanged(DB::ImageDate(QDateTime(date), QDateTime(end)));
emit dateChanged(DB::ImageDate(Utilities::FastDateTime(date), Utilities::FastDateTime(end)));
#endif
} else {
// Invalid or unacceptable date - revert to previous value
......
......@@ -631,13 +631,13 @@ void AnnotationDialog::Dialog::writeToInfo()
if (m_time->isHidden()) {
if (m_endDate->date().isValid())
info.setDate(DB::ImageDate(QDateTime(m_startDate->date(), QTime(0, 0, 0)),
QDateTime(m_endDate->date(), QTime(23, 59, 59))));
info.setDate(DB::ImageDate(Utilities::FastDateTime(m_startDate->date(), QTime(0, 0, 0)),
Utilities::FastDateTime(m_endDate->date(), QTime(23, 59, 59))));
else
info.setDate(DB::ImageDate(QDateTime(m_startDate->date(), QTime(0, 0, 0)),
QDateTime(m_startDate->date(), QTime(23, 59, 59))));
info.setDate(DB::ImageDate(Utilities::FastDateTime(m_startDate->date(), QTime(0, 0, 0)),
Utilities::FastDateTime(m_startDate->date(), QTime(23, 59, 59))));
} else
info.setDate(DB::ImageDate(QDateTime(m_startDate->date(), m_time->time())));
info.setDate(DB::ImageDate(Utilities::FastDateTime(m_startDate->date(), m_time->time())));
// Generate a list of all tagged areas
......
......@@ -226,6 +226,7 @@ set(libUtilities_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/Utilities/FileNameUtil.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Utilities/VideoUtil.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Utilities/ImageUtil.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Utilities/FastDateTime.cpp"
)
set(libMainWindow_SRCS
......
......@@ -2042,7 +2042,7 @@ Previous changes
2005-08-03 Jesper K. Pedersen <blackie@kde.org>
* Internal: Simplify ImageDate so it now is only a from and a to
QDateTime - this makes it possible for backends to do better date
Utilities::FastDateTime - this makes it possible for backends to do better date
searches (needed by the SQL backend)
* Delay loading plugins - this will save us half a second at start
......
......@@ -21,7 +21,7 @@
#include <Settings/SettingsData.h>
#include <Utilities/VideoUtil.h>
#include <QDateTime>
#include <Utilities/FastDateTime.h>
#include <QFileInfo>
#include <QRegularExpression>
......@@ -105,17 +105,17 @@ void DB::FileInfo::parseEXIV2(const DB::FileName &fileName)
}
}
QDateTime FileInfo::fetchEXIV2Date(Exiv2::ExifData &map, const char *key)
Utilities::FastDateTime FileInfo::fetchEXIV2Date(Exiv2::ExifData &map, const char *key)
{
try {
if (map.findKey(Exiv2::ExifKey(key)) != map.end()) {
const Exiv2::Exifdatum &datum = map[key];
return QDateTime::fromString(QString::fromLatin1(datum.toString().c_str()), Qt::ISODate);
return Utilities::FastDateTime::fromString(QString::fromLatin1(datum.toString().c_str()), Qt::ISODate);
}
} catch (...) {
}
return QDateTime();
return Utilities::FastDateTime();
}
int DB::FileInfo::orientationToAngle(int orientation)
......
......@@ -23,7 +23,7 @@
#include <Exif/Info.h>
#include <qdatetime.h>
#include <Utilities/FastDateTime.h>
#include <qstring.h>
namespace DB
......@@ -34,7 +34,7 @@ class FileInfo
{
public:
static FileInfo read(const DB::FileName &fileName, DB::ExifMode mode);
QDateTime dateTime() { return m_date; }
Utilities::FastDateTime dateTime() { return m_date; }
int angle() { return m_angle; }
QString description() { return m_description; }
Exiv2::ExifData &getExifData();
......@@ -42,14 +42,14 @@ public:
protected:
void parseEXIV2(const DB::FileName &fileName);
QDateTime fetchEXIV2Date(Exiv2::ExifData &map, const char *key);
Utilities::FastDateTime fetchEXIV2Date(Exiv2::ExifData &map, const char *key);
int orientationToAngle(int orientation);
private:
FileInfo(const DB::FileName &fileName, DB::ExifMode mode);
bool updateDataFromFileTimeStamp(const DB::FileName &fileName, DB::ExifMode mode);
QDateTime m_date;
Utilities::FastDateTime m_date;
int m_angle;
QString m_description;
Exiv2::ExifData m_exifMap;
......
......@@ -176,7 +176,7 @@ DB::FileName ImageDB::findFirstItemInRange(const DB::FileNameList &images,
bool includeRanges) const
{
DB::FileName candidate;
QDateTime candidateDateStart;
Utilities::FastDateTime candidateDateStart;
for (const DB::FileName &fileName : images) {
ImageInfoPtr iInfo = info(fileName);
......
......@@ -26,11 +26,11 @@ using namespace DB;
ImageDate::ImageDate(const QDate &date)
{
m_start = QDateTime(date, QTime(0, 0, 0));
m_end = QDateTime(date, QTime(0, 0, 0));
m_start = Utilities::FastDateTime(date, QTime(0, 0, 0));
m_end = Utilities::FastDateTime(date, QTime(0, 0, 0));
}
ImageDate::ImageDate(const QDateTime &date)
ImageDate::ImageDate(const Utilities::FastDateTime &date)
{
m_start = date;
m_end = date;
......@@ -56,22 +56,22 @@ bool ImageDate::isFuzzy() const
return m_start != m_end;
}
static bool isFirstSecOfMonth(const QDateTime &date)
static bool isFirstSecOfMonth(const Utilities::FastDateTime &date)
{
return date.date().day() == 1 && date.time().hour() == 0 && date.time().minute() == 0;
}
static bool isLastSecOfMonth(QDateTime date)
static bool isLastSecOfMonth(Utilities::FastDateTime date)
{
return isFirstSecOfMonth(date.addSecs(1));
}
static bool isFirstSecOfDay(const QDateTime &time)
static bool isFirstSecOfDay(const Utilities::FastDateTime &time)
{
return time.time().hour() == 0 && time.time().minute() == 0 && time.time().second() == 0;
}
static bool isLastSecOfDay(const QDateTime &time)
static bool isLastSecOfDay(const Utilities::FastDateTime &time)
{
return time.time().hour() == 23 && time.time().minute() == 59 && time.time().second() == 59;
}
......@@ -163,12 +163,12 @@ QString ImageDate::formatRegexp()
return str;
}
QDateTime ImageDate::start() const
Utilities::FastDateTime ImageDate::start() const
{
return m_start;
}
QDateTime ImageDate::end() const
Utilities::FastDateTime ImageDate::end() const
{
return m_end;
}
......@@ -178,7 +178,7 @@ bool ImageDate::operator<(const ImageDate &other) const
return start() < other.start() || (start() == other.start() && end() < other.end());
}
ImageDate::ImageDate(const QDateTime &start, const QDateTime &end)
ImageDate::ImageDate(const Utilities::FastDateTime &start, const Utilities::FastDateTime &end)
{
if (!start.isValid() || !end.isValid() || start <= end) {
m_start = start;
......@@ -192,11 +192,11 @@ ImageDate::ImageDate(const QDateTime &start, const QDateTime &end)
ImageDate::ImageDate(const QDate &start, const QDate &end)
{
if (!start.isValid() || !end.isValid() || start <= end) {
m_start = QDateTime(start, QTime(0, 0, 0));
m_end = QDateTime(end, QTime(23, 59, 59));
m_start = Utilities::FastDateTime(start, QTime(0, 0, 0));
m_end = Utilities::FastDateTime(end, QTime(23, 59, 59));
} else {
m_start = QDateTime(end, QTime(0, 0, 0));
m_end = QDateTime(start, QTime(23, 59, 59));
m_start = Utilities::FastDateTime(end, QTime(0, 0, 0));
m_end = Utilities::FastDateTime(start, QTime(23, 59, 59));
}
}
......@@ -213,8 +213,8 @@ static QDate addMonth(int year, int month)
ImageDate::ImageDate(int yearFrom, int monthFrom, int dayFrom, int yearTo, int monthTo, int dayTo, int hourFrom, int minuteFrom, int secondFrom)
{
if (yearFrom <= 0) {
m_start = QDateTime();
m_end = QDateTime();
m_start = Utilities::FastDateTime();
m_end = Utilities::FastDateTime();
return;
}
......@@ -223,33 +223,33 @@ ImageDate::ImageDate(int yearFrom, int monthFrom, int dayFrom, int yearTo, int m
m_start = QDate(yearFrom, 1, 1).startOfDay();
m_end = QDate(yearFrom + 1, 1, 1).startOfDay().addSecs(-1);
#else
m_start = QDateTime(QDate(yearFrom, 1, 1));
m_end = QDateTime(QDate(yearFrom + 1, 1, 1)).addSecs(-1);
m_start = Utilities::FastDateTime(QDate(yearFrom, 1, 1));
m_end = Utilities::FastDateTime(QDate(yearFrom + 1, 1, 1)).addSecs(-1);
#endif
} else if (dayFrom <= 0) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
m_start = QDate(yearFrom, monthFrom, 1).startOfDay();
m_end = addMonth(yearFrom, monthFrom).startOfDay().addSecs(-1);
#else
m_start = QDateTime(QDate(yearFrom, monthFrom, 1));
m_end = QDateTime(addMonth(yearFrom, monthFrom)).addSecs(-1);
m_start = Utilities::FastDateTime(QDate(yearFrom, monthFrom, 1));
m_end = Utilities::FastDateTime(addMonth(yearFrom, monthFrom)).addSecs(-1);
#endif
} else if (hourFrom < 0) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
m_start = QDate(yearFrom, monthFrom, dayFrom).startOfDay();
m_end = QDate(yearFrom, monthFrom, dayFrom).addDays(1).startOfDay().addSecs(-1);
#else
m_start = QDateTime(QDate(yearFrom, monthFrom, dayFrom));
m_end = QDateTime(QDate(yearFrom, monthFrom, dayFrom).addDays(1)).addSecs(-1);
m_start = Utilities::FastDateTime(QDate(yearFrom, monthFrom, dayFrom));
m_end = Utilities::FastDateTime(QDate(yearFrom, monthFrom, dayFrom).addDays(1)).addSecs(-1);
#endif
} else if (minuteFrom < 0) {
m_start = QDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, 0, 0));
m_end = QDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, 23, 59));
m_start = Utilities::FastDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, 0, 0));
m_end = Utilities::FastDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, 23, 59));
} else if (secondFrom < 0) {
m_start = QDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, minuteFrom, 0));
m_end = QDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, minuteFrom, 59));
m_start = Utilities::FastDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, minuteFrom, 0));
m_end = Utilities::FastDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, minuteFrom, 59));
} else {
m_start = QDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, minuteFrom, secondFrom));
m_start = Utilities::FastDateTime(QDate(yearFrom, monthFrom, dayFrom), QTime(hourFrom, minuteFrom, secondFrom));
m_end = m_start;
}
......@@ -257,14 +257,14 @@ ImageDate::ImageDate(int yearFrom, int monthFrom, int dayFrom, int yearTo, int m
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
m_end = QDate(yearTo + 1, 1, 1).startOfDay().addSecs(-1);
#else
m_end = QDateTime(QDate(yearTo + 1, 1, 1)).addSecs(-1);
m_end = Utilities::FastDateTime(QDate(yearTo + 1, 1, 1)).addSecs(-1);
#endif
if (monthTo > 0) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
m_end = addMonth(yearTo, monthTo).startOfDay().addSecs(-1);
#else
m_end = QDateTime(addMonth(yearTo, monthTo)).addSecs(-1);
m_end = Utilities::FastDateTime(addMonth(yearTo, monthTo)).addSecs(-1);
#endif
if (dayTo > 0) {
......@@ -274,7 +274,7 @@ ImageDate::ImageDate(int yearFrom, int monthFrom, int dayFrom, int yearTo, int m
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
m_end = QDate(yearTo, monthTo, dayTo).addDays(1).startOfDay().addSecs(-1);
#else
m_end = QDateTime(QDate(yearTo, monthTo, dayTo).addDays(1)).addSecs(-1);
m_end = Utilities::FastDateTime(QDate(yearTo, monthTo, dayTo).addDays(1)).addSecs(-1);
#endif
}
}
......@@ -345,15 +345,15 @@ ImageDate::ImageDate(const QDate &start, QDate end, const QTime &time)
end = start;
if (start == end && time.isValid()) {
m_start = QDateTime(start, time);
m_start = Utilities::FastDateTime(start, time);
m_end = m_start;
} else {
if (start > end) {
m_end = QDateTime(start, QTime(0, 0, 0));
m_start = QDateTime(end, QTime(23, 59, 59));
m_end = Utilities::FastDateTime(start, QTime(0, 0, 0));
m_start = Utilities::FastDateTime(end, QTime(23, 59, 59));
} else {
m_start = QDateTime(start, QTime(0, 0, 0));
m_end = QDateTime(end, QTime(23, 59, 59));
m_start = Utilities::FastDateTime(start, QTime(0, 0, 0));
m_end = Utilities::FastDateTime(end, QTime(23, 59, 59));
}
}
}
......@@ -369,7 +369,7 @@ ImageDate::MatchType ImageDate::isIncludedIn(const ImageDate &searchRange) const
return DontMatch;
}
bool ImageDate::includes(const QDateTime &date) const
bool ImageDate::includes(const Utilities::FastDateTime &date) const
{
return ImageDate(date).isIncludedIn(*this) == ExactMatch;
}
......
......@@ -18,7 +18,7 @@
#ifndef IMAGEDATE_H
#define IMAGEDATE_H
#include <qdatetime.h>
#include <Utilities/FastDateTime.h>
#include <qstring.h>
#include <qstringlist.h>
......@@ -30,14 +30,14 @@ class ImageDate
public:
ImageDate();
ImageDate(const QDate &start, const QDate &end);
ImageDate(const QDateTime &start, const QDateTime &end);
ImageDate(const Utilities::FastDateTime &start, const Utilities::FastDateTime &end);
ImageDate(int yearFrom, int monthFrom, int dayFrom, int yearTo, int monthTo, int dayTo, int hourFrom, int minuteFrom, int secondFrom);
explicit ImageDate(const QDate &);
explicit ImageDate(const QDateTime &);
explicit ImageDate(const Utilities::FastDateTime &);
ImageDate(const QDate &start, QDate end, const QTime &time);
QDateTime start() const;
QDateTime end() const;
Utilities::FastDateTime start() const;
Utilities::FastDateTime end() const;
static QDate parseDate(const QString &date, bool startDate);
bool operator<(const ImageDate &other) const;
......@@ -55,7 +55,7 @@ public:
ExactMatch,
RangeMatch };
MatchType isIncludedIn(const ImageDate &searchRange) const;
bool includes(const QDateTime &date) const;
bool includes(const Utilities::FastDateTime &date) const;
void extendTo(const ImageDate &other);
......@@ -64,7 +64,7 @@ protected:
static QString formatRegexp();
private:
QDateTime m_start, m_end;
Utilities::FastDateTime m_start, m_end;
};
}
......
......@@ -44,8 +44,8 @@ class ImageDateCollection : public QSharedData
public:
virtual ~ImageDateCollection() {}
virtual ImageCount count(const ImageDate &range) = 0;
virtual QDateTime lowerLimit() const = 0;
virtual QDateTime upperLimit() const = 0;
virtual Utilities::FastDateTime lowerLimit() const = 0;
virtual Utilities::FastDateTime upperLimit() const = 0;
};
}
......
......@@ -22,7 +22,7 @@
#include "Logging.h"
#include <KLocalizedString>
#include <QDateTime>
#include <Utilities/FastDateTime.h>
#include <QVector>
#include <QtAlgorithms>
using namespace DB;
......@@ -30,14 +30,14 @@ using namespace DB;
class SortableImageInfo
{
public:
SortableImageInfo(const QDateTime &datetime, const QString &string, const ImageInfoPtr &info)
SortableImageInfo(const Utilities::FastDateTime &datetime, const QString &string, const ImageInfoPtr &info)
: m_dt(datetime)
, m_st(string)
, m_in(info)
{
}
SortableImageInfo() = default;
const QDateTime &DateTime(void) const { return m_dt; }
const Utilities::FastDateTime &DateTime(void) const { return m_dt; }
const QString &String(void) const { return m_st; }
const ImageInfoPtr &ImageInfo(void) const { return m_in; }
bool operator==(const SortableImageInfo &other) const { return m_dt == other.m_dt && m_st == other.m_st; }
......@@ -62,7 +62,7 @@ public:
bool operator<=(const SortableImageInfo &other) const { return *this == other || *this < other; }
private:
QDateTime m_dt;
Utilities::FastDateTime m_dt;
QString m_st;
ImageInfoPtr m_in;
};
......@@ -122,10 +122,10 @@ bool ImageInfoList::isSorted()
if (count() == 0)
return true;
QDateTime prev = first()->date().start();
Utilities::FastDateTime prev = first()->date().start();
QString prevFile = first()->fileName().absolute();
for (ImageInfoListConstIterator it = constBegin(); it != constEnd(); ++it) {
QDateTime cur = (*it)->date().start();
Utilities::FastDateTime cur = (*it)->date().start();
QString curFile = (*it)->fileName().absolute();
if (prev > cur || (prev == cur && prevFile > curFile))
return false;
......@@ -140,10 +140,10 @@ void ImageInfoList::mergeIn(ImageInfoList other)
ImageInfoList tmp;
for (ImageInfoListConstIterator it = constBegin(); it != constEnd(); ++it) {
QDateTime thisDate = (*it)->date().start();
Utilities::FastDateTime thisDate = (*it)->date().start();
QString thisFileName = (*it)->fileName().absolute();
while (other.count() != 0) {
QDateTime otherDate = other.first()->date().start();
Utilities::FastDateTime otherDate = other.first()->date().start();
QString otherFileName = other.first()->fileName().absolute();
if (otherDate < thisDate || (otherDate == thisDate && otherFileName < thisFileName)) {
tmp.append(other[0]);
......
......@@ -175,8 +175,8 @@ bool ImageSearchInfo::doMatch(ImageInfoPtr info) const
return false;
// -------------------------------------------------- Date
QDateTime actualStart = info->date().start();
QDateTime actualEnd = info->date().end();
Utilities::FastDateTime actualStart = info->date().start();
Utilities::FastDateTime actualEnd = info->date().end();
if (m_date.start().isValid()) {
if (actualEnd < m_date.start() || (m_date.end().isValid() && actualStart > m_date.end()))
......
......@@ -26,7 +26,7 @@
#include <KLocalizedString>
#include <QAction>
#include <QContextMenuEvent>
#include <QDateTime>
#include <Utilities/FastDateTime.h>
#include <QFontMetrics>
#include <QGuiApplication>
#include <QIcon>
......@@ -61,7 +61,7 @@ DateBar::DateBarWidget::DateBarWidget(QWidget *parent)
, m_tp(YearView)
, m_currentMouseHandler(nullptr)
, m_currentUnit(0)
, m_currentDate(QDateTime::currentDateTime())
, m_currentDate(Utilities::FastDateTime::currentDateTime())
, m_includeFuzzyCounts(true)
, m_contextMenu(nullptr)
, m_showResolutionIndicator(true)
......@@ -218,7 +218,7 @@ void DateBar::DateBarWidget::drawTickMarks(QPainter &p, const QRect &textRect)
p.save();
p.setPen(Qt::NoPen);
p.setBrush(palette().brush(QPalette::Highlight));
QDateTime date = dateForUnit(unit);
Utilities::FastDateTime date = dateForUnit(unit);
if (isUnitSelected(unit))
p.drawRect(QRect(x, rect.top(), m_barWidth, rect.height()));
p.restore();
......@@ -280,7 +280,7 @@ void DateBar::DateBarWidget::setViewHandlerForType(ViewType tp)
}
}
void DateBar::DateBarWidget::setDate(const QDateTime &date)
void DateBar::DateBarWidget::setDate(const Utilities::FastDateTime &date)
{
m_currentDate = date;
if (hasSelection()) {
......@@ -300,10 +300,10 @@ void DateBar::DateBarWidget::setImageDateCollection(const QExplicitlySharedDataP
{
m_dates = dates;
if (m_doAutomaticRangeAdjustment && m_dates && !m_dates->lowerLimit().isNull()) {
QDateTime start = m_dates->lowerLimit();
QDateTime end = m_dates->upperLimit();
Utilities::FastDateTime start = m_dates->lowerLimit();
Utilities::FastDateTime end = m_dates->upperLimit();
if (end.isNull())
end = QDateTime::currentDateTime();
end = Utilities::FastDateTime::currentDateTime();
m_currentDate = start;
m_currentUnit = 0;
......@@ -596,9 +596,9 @@ DB::ImageDate DateBar::DateBarWidget::rangeAt(const QPoint &p)
DB::ImageDate DateBar::DateBarWidget::rangeForUnit(int unit)
{
// Note on the use of setTimeSpec.
// It came to my attention that addSec would create a QDateTime with internal type LocalStandard, while all the others would have type LocalUnknown,
// this resulted in that QDateTime::operator<() would call getUTC(), which took 90% of the time for populating the datebar.
QDateTime toUnit = dateForUnit(unit + 1).addSecs(-1);
// It came to my attention that addSec would create a Utilities::FastDateTime with internal type LocalStandard, while all the others would have type LocalUnknown,
// this resulted in that Utilities::FastDateTime::operator<() would call getUTC(), which took 90% of the time for populating the datebar.
Utilities::FastDateTime toUnit = dateForUnit(unit + 1).addSecs(-1);
toUnit.setTimeSpec(Qt::LocalTime);
return DB::ImageDate(dateForUnit(unit), toUnit);
}
......@@ -803,7 +803,7 @@ void DateBar::DateBarWidget::keyPressEvent(QKeyEvent *event)
else
return;
QDateTime newDate = dateForUnit(offset, m_currentDate);
Utilities::FastDateTime newDate = dateForUnit(offset, m_currentDate);
if ((offset < 0 && newDate >= m_dates->lowerLimit()) || (offset > 0 && newDate <= m_dates->upperLimit())) {
m_currentDate = newDate;
m_currentUnit += offset;
......@@ -836,16 +836,16 @@ int DateBar::DateBarWidget::unitAtPos(int x) const
return (x - barAreaGeometry().left()) / m_barWidth;
}
QDateTime DateBar::DateBarWidget::dateForUnit(int unit, const QDateTime &offset) const
Utilities::FastDateTime DateBar::DateBarWidget::dateForUnit(int unit, const Utilities::FastDateTime &offset) const
{
return m_currentHandler->date(unit, offset);
}
bool DateBar::DateBarWidget::isUnitSelected(int unit) const
{
QDateTime minDate = m_selectionHandler->min();
QDateTime maxDate = m_selectionHandler->max();
QDateTime date = dateForUnit(unit);
Utilities::FastDateTime minDate = m_selectionHandler->min();
Utilities::FastDateTime maxDate = m_selectionHandler->max();
Utilities::FastDateTime date = dateForUnit(unit);
return (minDate <= date && date < maxDate && !minDate.isNull());
}
......@@ -874,7 +874,7 @@ void DateBar::DateBarWidget::emitRangeSelection(const DB::ImageDate &range)
emit dateRangeChange(range);
}
int DateBar::DateBarWidget::unitForDate(const QDateTime &date) const
int DateBar::DateBarWidget::unitForDate(const Utilities::FastDateTime &date) const
{
for (int unit = 0; unit < numberOfUnits(); ++unit) {
if (m_currentHandler->date(unit) <= date && date < m_currentHandler->date(unit + 1))
......
......@@ -20,7 +20,7 @@
#define DATEBAR_H
#include "ViewHandler.h"
#include <QDateTime>
#include <Utilities/FastDateTime.h>
#include <QExplicitlySharedDataPointer>
#include <QPixmap>
#include <QWidget>
......@@ -88,7 +88,7 @@ public:
public slots:
void clearSelection();
void setViewType(ViewType tp, bool redrawNow = true);
void setDate(const QDateTime &date);
void setDate(const Utilities::FastDateTime &date);
void setImageDateCollection(const QExplicitlySharedDataPointer<DB::ImageDateCollection> &);
void scrollLeft();
void scrollRight();
......@@ -173,13 +173,13 @@ protected:
* @return a unit index between 0 and numberOfUnits
*/
int unitAtPos(int x) const;
QDateTime dateForUnit(int unit, const QDateTime &offset = QDateTime()) const;
Utilities::FastDateTime dateForUnit(int unit, const Utilities::FastDateTime &offset = Utilities::FastDateTime()) const;
/**
* @brief unitForDate return the unit index corresponding to the date/time.
* @param date a valid QDateTime.
* @param date a valid Utilities::FastDateTime.
* @return An integer greater or equal to 0 if \p date is in view, -1 otherwise.
*/
int unitForDate(const QDateTime &date) const;
int unitForDate(const Utilities::FastDateTime &date) const;
bool isUnitSelected(int unit) const;
bool hasSelection() const;
DB::ImageDate currentSelection() const;
......@@ -220,7 +220,7 @@ private:
QToolButton *m_cancelSelection;
int m_currentUnit;
QDateTime m_currentDate;
Utilities::FastDateTime m_currentDate;
int m_barWidth; ///< width of a single unit in pixel
int m_barHeight;
bool m_includeFuzzyCounts;
......
......@@ -89,7 +89,7 @@ void DateBar::SelectionHandler::mousePressEvent(int x)
void DateBar::SelectionHandler::mouseMoveEvent(int x)
{
int unit = m_dateBar->unitAtPos(x);
QDateTime date = m_dateBar->dateForUnit(unit);
Utilities::FastDateTime date = m_dateBar->dateForUnit(unit);
if (m_start < date)
m_end = m_dateBar->dateForUnit(unit + 1);
else
......@@ -175,7 +175,7 @@ void DateBar::BarDragHandler::mouseMoveEvent(int x)
m_dateBar->emitDateSelected();
}
QDateTime DateBar::SelectionHandler::min() const
Utilities::FastDateTime DateBar::SelectionHandler::min() const
{
if (m_start < m_end)
return m_start;
......@@ -183,7 +183,7 @@ QDateTime DateBar::SelectionHandler::min() const