#2082 Support custom date time format (#4594)

* #2082 Support custom date time format

* Clang-format
This commit is contained in:
Gaute Lindkvist
2019-08-19 09:37:42 +02:00
committed by GitHub
parent 824ec5cef6
commit e58da136e3
21 changed files with 855 additions and 134 deletions
@@ -22,6 +22,7 @@
#include "RiaPreferences.h"
#include "RiaColorTables.h"
#include "RiaQDateTimeTools.h"
#include "RifReaderSettings.h"
#include "cafPdmFieldCvfColor.h"
@@ -30,6 +31,9 @@
#include "cafPdmUiFieldHandle.h"
#include "cafPdmUiFilePathEditor.h"
#include <QDate>
#include <QLocale>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QStandardPaths>
#endif
@@ -167,6 +171,13 @@ RiaPreferences::RiaPreferences(void)
CAF_PDM_InitFieldNoDefault(&m_readerSettings, "readerSettings", "Reader Settings", "", "", "");
m_readerSettings = new RifReaderSettings;
CAF_PDM_InitFieldNoDefault(&m_dateFormat, "dateFormat", "Date Format", "", "", "");
m_dateFormat.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName());
m_dateFormat = RiaQDateTimeTools::supportedDateFormats().front();
CAF_PDM_InitFieldNoDefault(&m_timeFormat, "timeFormat", "Time Format", "", "", "");
m_timeFormat.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName());
m_timeFormat = RiaQDateTimeTools::supportedTimeFormats().front();
}
//--------------------------------------------------------------------------------------------------
@@ -257,6 +268,8 @@ void RiaPreferences::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
viewsGroup->add(&showHud);
caf::PdmUiGroup* otherGroup = uiOrdering.addNewGroup("Other");
otherGroup->add(&m_dateFormat);
otherGroup->add(&m_timeFormat);
otherGroup->add(&ssihubAddress);
otherGroup->add(&showLasCurveWithoutTvdWarning);
otherGroup->add(&holoLensDisableCertificateVerification);
@@ -353,6 +366,30 @@ QList<caf::PdmOptionItemInfo> RiaPreferences::calculateValueOptions(const caf::P
options.push_back(caf::PdmOptionItemInfo(skip.uiText(), RiaPreferences::NOT_IMPORT));
options.push_back(caf::PdmOptionItemInfo(allowImport.uiText(), RiaPreferences::IMPORT));
}
else if (fieldNeedingOptions == &m_dateFormat)
{
for (auto dateFormat : RiaQDateTimeTools::supportedDateFormats())
{
QDate exampleDate = QDate(2019, 8, 16);
QString fullDateFormat =
RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY);
QString uiText = QString("%1 (%2)").arg(fullDateFormat).arg(exampleDate.toString(fullDateFormat));
uiText.replace("AP", "AM/PM");
options.push_back(caf::PdmOptionItemInfo(uiText, QVariant::fromValue(dateFormat)));
}
}
else if (fieldNeedingOptions == &m_timeFormat)
{
for (auto timeFormat : RiaQDateTimeTools::supportedTimeFormats())
{
QTime exampleTime = QTime(15, 48, 22);
QString timeFormatString =
RiaQDateTimeTools::timeFormatString(timeFormat, RiaQDateTimeTools::TIME_FORMAT_HOUR_MINUTE_SECOND);
QString uiText = QString("%1 (%2)").arg(timeFormatString).arg(exampleTime.toString(timeFormatString));
uiText.replace("AP", "AM/PM");
options.push_back(caf::PdmOptionItemInfo(uiText, QVariant::fromValue(timeFormat)));
}
}
return options;
}
@@ -500,6 +537,22 @@ QString RiaPreferences::holoLensExportFolder() const
return m_holoLensExportFolder();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const QString& RiaPreferences::dateFormat() const
{
return m_dateFormat();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const QString& RiaPreferences::timeFormat() const
{
return m_timeFormat();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
+7 -2
View File
@@ -25,7 +25,7 @@
#include "RiaGuiApplication.h"
#include "RiaDefines.h"
#include "RiaFontCache.h"
#include "RiaQDateTimeTools.h"
#include "cafAppEnum.h"
#include "cafPdmChildField.h"
@@ -71,6 +71,9 @@ public:
bool showProjectChangedDialog() const;
QString holoLensExportFolder() const;
const QString& dateFormat() const;
const QString& timeFormat() const;
std::map<RiaDefines::FontSettingType, RiaFontCache::FontSize> defaultFontSizes() const;
public: // Pdm Fields
@@ -129,7 +132,6 @@ protected:
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override;
void initAfterRead() override;
private:
static QString tabNameGeneral();
static QString tabNameEclipse();
@@ -148,4 +150,7 @@ private:
caf::PdmField<bool> m_showTestToolbar;
caf::PdmField<bool> m_includeFractureDebugInfoFile;
caf::PdmField<QString> m_holoLensExportFolder;
caf::PdmField<QString> m_dateFormat;
caf::PdmField<QString> m_timeFormat;
QStringList m_tabNames;
};
@@ -392,4 +392,80 @@ QString RiaQDateTimeTools::createTimeFormatStringFromDates(const std::vector<QDa
QString RiaQDateTimeTools::dateFormatString()
{
return "dd.MMM yyyy";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QString> RiaQDateTimeTools::supportedDateFormats()
{
std::vector<QString> dateFormats;
// See enum DateFormatComponents in header
// The semi-colon separated components are:
// DATE_FORMAT_YEAR, ..YEAR_MONTH, ..YEAR_MONTH_DAY
dateFormats.push_back("yyyy;yyyy-MM;yyyy-MM-dd");
dateFormats.push_back("yyyy;MMM yyyy;dd. MMM yyyy");
dateFormats.push_back("yyyy;MMM yyyy;MMM dd. yyyy");
dateFormats.push_back("yyyy;MM/yyyy;dd/MM/yyyy");
dateFormats.push_back("yyyy;M/yyyy;d/M/yyyy");
dateFormats.push_back("yyyy;M/yyyy;M/d/yyyy");
dateFormats.push_back("yy;M/yy;d/M/yy");
dateFormats.push_back("yy;M/yy;M/d/yy");
dateFormats.push_back("yyyy;MM-yyyy;dd-MM-yyyy");
dateFormats.push_back("yyyy;MM-yyyy;MM-dd-yyyy");
dateFormats.push_back("yy;MM-yy;dd-MM-yy");
dateFormats.push_back("yy;MM-yy;MM-dd-yy");
return dateFormats;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QString> RiaQDateTimeTools::supportedTimeFormats()
{
std::vector<QString> timeFormats;
// See enum TimeFormatComponents in header
// The semi-colon separated components are:
// TIME_FORMAT_HOUR, ..HOUR_MINUTE, ..HOUR_MINUTE_SECOND and ..HOUR_MINUTE_MILLISECOND
timeFormats.push_back("HH;HH:mm;HH:mm:ss;HH:mm:ss.zzz");
timeFormats.push_back("H;H:mm;H:mm:ss;H:mm:ss.zzz");
timeFormats.push_back("hh AP;hh:mm AP;hh:mm:ss AP;hh:mm:ss.zzz AP");
timeFormats.push_back("h AP;h:mm AP;h:mm:ss AP;h:mm:ss.zzz AP");
return timeFormats;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaQDateTimeTools::dateFormatString(const QString& fullDateFormat, DateFormatComponents dateComponents)
{
if (dateComponents == DATE_FORMAT_NONE) return "";
QStringList allVariants = fullDateFormat.split(";");
if (static_cast<int>(dateComponents) < allVariants.size())
{
return allVariants[dateComponents];
}
CVF_ASSERT(false && "Date format string is malformed");
return "";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaQDateTimeTools::timeFormatString(const QString& fullTimeFormat, TimeFormatComponents timeComponents)
{
if (timeComponents == TIME_FORMAT_NONE) return "";
QStringList allVariants = fullTimeFormat.split(";");
if (static_cast<int>(timeComponents) < allVariants.size())
{
return allVariants[timeComponents];
}
CVF_ASSERT(false && "Time format string is malformed");
return "";
}
@@ -22,7 +22,11 @@
#include <qnamespace.h>
#include <QString>
#include <QStringList>
#include <QTextStream>
#include <QVariant>
#include <map>
#include <string>
#include <vector>
@@ -60,6 +64,25 @@ class RiaQDateTimeTools
static const DateTimeSpan TIMESPAN_DECADE;
public:
enum DateFormatComponents
{
DATE_FORMAT_NONE = -1,
DATE_FORMAT_YEAR = 0,
DATE_FORMAT_YEAR_MONTH,
DATE_FORMAT_YEAR_MONTH_DAY,
DATE_FORMAT_SIZE
};
enum TimeFormatComponents
{
TIME_FORMAT_NONE = -1,
TIME_FORMAT_HOUR,
TIME_FORMAT_HOUR_MINUTE,
TIME_FORMAT_HOUR_MINUTE_SECOND,
TIME_FORMAT_HOUR_MINUTE_SECOND_MILLISECOND,
TIME_FORMAT_SIZE
};
static const QString TIMESPAN_DAY_NAME;
static const QString TIMESPAN_WEEK_NAME;
static const QString TIMESPAN_MONTH_NAME;
@@ -104,9 +127,16 @@ public:
static QString createTimeFormatStringFromDates(const std::vector<QDateTime>& dates);
static QString dateFormatString();
static std::vector<QString> supportedDateFormats();
static std::vector<QString> supportedTimeFormats();
static QString dateFormatString(const QString& fullDateFormat, DateFormatComponents dateComponents);
static QString timeFormatString(const QString& fullTimeFormat, TimeFormatComponents timeComponents);
private:
static quint64 secondsInDay();
static quint64 secondsInYear();
};
//==================================================================================================