mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
* #2082 Support custom date time format * Clang-format
This commit is contained in:
parent
824ec5cef6
commit
e58da136e3
@ -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();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -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();
|
||||
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
|
@ -926,7 +926,10 @@ void RimSummaryPlot::updateTimeAxis()
|
||||
|
||||
if (m_timeAxisProperties->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
||||
{
|
||||
m_qwtPlot->useDateBasedTimeAxis();
|
||||
QString dateFormat = m_timeAxisProperties->dateFormat();
|
||||
QString timeFormat = m_timeAxisProperties->timeFormat();
|
||||
|
||||
m_qwtPlot->useDateBasedTimeAxis(dateFormat, timeFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,17 +1,17 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016 Statoil ASA
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@ -24,16 +24,17 @@
|
||||
|
||||
#include "RimSummaryPlot.h"
|
||||
|
||||
#include "cafPdmUiComboBoxEditor.h"
|
||||
#include "cafPdmUiDateEditor.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
|
||||
#include "qwt_date.h"
|
||||
#include "cafPdmUiTimeEditor.h"
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include "qwt_date.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template<>
|
||||
void caf::AppEnum< RimSummaryTimeAxisProperties::TimeModeType >::setUp()
|
||||
void caf::AppEnum<RimSummaryTimeAxisProperties::TimeModeType>::setUp()
|
||||
{
|
||||
addItem(RimSummaryTimeAxisProperties::DATE, "DATE", "Date");
|
||||
addItem(RimSummaryTimeAxisProperties::TIME_FROM_SIMULATION_START, "TIME_FROM_SIMULATION_START", "Time From Simulation Start");
|
||||
@ -42,26 +43,23 @@ void caf::AppEnum< RimSummaryTimeAxisProperties::TimeModeType >::setUp()
|
||||
}
|
||||
|
||||
template<>
|
||||
void caf::AppEnum< RimSummaryTimeAxisProperties::TimeUnitType >::setUp()
|
||||
void caf::AppEnum<RimSummaryTimeAxisProperties::TimeUnitType>::setUp()
|
||||
{
|
||||
addItem(RimSummaryTimeAxisProperties::SECONDS, "SECONDS", "Seconds");
|
||||
addItem(RimSummaryTimeAxisProperties::MINUTES, "MINUTES", "Minutes");
|
||||
addItem(RimSummaryTimeAxisProperties::HOURS, "HOURS", "Hours");
|
||||
addItem(RimSummaryTimeAxisProperties::DAYS, "DAYS ", "Days");
|
||||
addItem(RimSummaryTimeAxisProperties::DAYS, "DAYS ", "Days");
|
||||
addItem(RimSummaryTimeAxisProperties::YEARS, "YEARS", "Years");
|
||||
|
||||
setDefault(RimSummaryTimeAxisProperties::YEARS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace caf
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimSummaryTimeAxisProperties, "SummaryTimeAxisProperties");
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties()
|
||||
{
|
||||
@ -77,17 +75,24 @@ RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties()
|
||||
CAF_PDM_InitFieldNoDefault(&m_timeMode, "TimeMode", "Time Mode", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault(&m_timeUnit, "TimeUnit", "Time Unit", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateRangeMax, "VisibleRangeMax", "Max", "", "", "");
|
||||
m_visibleDateRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateRangeMax, "VisibleDateRangeMax", "Max Date", "", "", "");
|
||||
m_visibleDateRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiDateEditor::uiEditorTypeName());
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateRangeMin, "VisibleDateRangeMin", "Min Date", "", "", "");
|
||||
m_visibleDateRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiDateEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateRangeMin, "VisibleRangeMin", "Min", "", "", "");
|
||||
m_visibleDateRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeRangeMax, "VisibleTimeRangeMax", "MaxTime", "", "", "");
|
||||
m_visibleTimeRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiTimeEditor::uiEditorTypeName());
|
||||
m_visibleTimeRangeMax.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeRangeMax, "VisibleTimeModeRangeMax", "Max", "", "", "");
|
||||
m_visibleDateRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeRangeMin, "VisibleTimeRangeMin", "Min Time", "", "", "");
|
||||
m_visibleTimeRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiTimeEditor::uiEditorTypeName());
|
||||
m_visibleTimeRangeMin.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeRangeMin, "VisibleTimeModeRangeMin", "Min", "", "", "");
|
||||
m_visibleDateRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeSinceStartRangeMax, "VisibleTimeModeRangeMax", "Max", "", "", "");
|
||||
m_visibleTimeSinceStartRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeSinceStartRangeMin, "VisibleTimeModeRangeMin", "Min", "", "", "");
|
||||
m_visibleTimeSinceStartRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_titlePositionEnum, "TitlePosition", "Title Position", "", "", "");
|
||||
CAF_PDM_InitField(&m_titleFontSize, "FontSize", 10, "Font Size", "", "", "");
|
||||
@ -95,6 +100,19 @@ RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties()
|
||||
CAF_PDM_InitField(&m_valuesFontSize, "ValuesFontSize", 10, "Font Size", "", "", "");
|
||||
m_valuesFontSize = RiaFontCache::pointSizeFromFontSizeEnum(RiaApplication::instance()->preferences()->defaultPlotFontSize());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_dateFormat, "DateFormat", "Date Format", "", "", "");
|
||||
m_dateFormat.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName());
|
||||
m_dateFormat = RiaApplication::instance()->preferences()->dateFormat();
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_timeFormat, "TimeFormat", "Time Format", "", "", "");
|
||||
m_timeFormat.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName());
|
||||
m_timeFormat = RiaApplication::instance()->preferences()->timeFormat();
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateTimeRangeMax_OBSOLETE, "VisibleRangeMax", "Max", "", "", "");
|
||||
m_visibleDateTimeRangeMax_OBSOLETE.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateTimeRangeMin_OBSOLETE, "VisibleRangeMin", "Min", "", "", "");
|
||||
m_visibleDateTimeRangeMin_OBSOLETE.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -138,66 +156,71 @@ void RimSummaryTimeAxisProperties::setValuesFontSize(int fontSize)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::visibleRangeMin() const
|
||||
{
|
||||
if ( m_timeMode() == DATE )
|
||||
return QwtDate::toDouble(m_visibleDateRangeMin());
|
||||
if (m_timeMode() == DATE)
|
||||
{
|
||||
return QwtDate::toDouble(visibleDateTimeMin());
|
||||
}
|
||||
else
|
||||
return m_visibleTimeRangeMin();
|
||||
return m_visibleTimeSinceStartRangeMin();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::visibleRangeMax() const
|
||||
{
|
||||
if ( m_timeMode() == DATE )
|
||||
return QwtDate::toDouble(m_visibleDateRangeMax());
|
||||
if (m_timeMode() == DATE)
|
||||
{
|
||||
return QwtDate::toDouble(visibleDateTimeMax());
|
||||
}
|
||||
else
|
||||
return m_visibleTimeRangeMax();
|
||||
return m_visibleTimeSinceStartRangeMax();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::setVisibleRangeMin(double value)
|
||||
{
|
||||
if ( m_timeMode() == DATE )
|
||||
if (m_timeMode() == DATE)
|
||||
{
|
||||
m_visibleDateRangeMin = QwtDate::toDateTime(value);
|
||||
m_visibleTimeRangeMin = fromDateToDisplayTime(m_visibleDateRangeMin());
|
||||
QDateTime dateTime = QwtDate::toDateTime(value);
|
||||
m_visibleTimeSinceStartRangeMin = fromDateToDisplayTime(dateTime);
|
||||
setVisibleDateTimeMin(dateTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_visibleTimeRangeMin = value;
|
||||
m_visibleDateRangeMin = fromDisplayTimeToDate(value);
|
||||
m_visibleTimeSinceStartRangeMin = value;
|
||||
QDateTime dateTime = fromDisplayTimeToDate(value);
|
||||
setVisibleDateTimeMin(dateTime);
|
||||
}
|
||||
auto s = m_visibleDateRangeMin().toString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::setVisibleRangeMax(double value)
|
||||
{
|
||||
if ( m_timeMode() == DATE )
|
||||
if (m_timeMode() == DATE)
|
||||
{
|
||||
m_visibleDateRangeMax = QwtDate::toDateTime(value);
|
||||
m_visibleTimeRangeMax = fromDateToDisplayTime(m_visibleDateRangeMax());
|
||||
|
||||
QDateTime dateTime = QwtDate::toDateTime(value);
|
||||
m_visibleTimeSinceStartRangeMax = fromDateToDisplayTime(dateTime);
|
||||
setVisibleDateTimeMax(dateTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_visibleTimeRangeMax = value;
|
||||
m_visibleDateRangeMax = fromDisplayTimeToDate(value);
|
||||
m_visibleTimeSinceStartRangeMax = value;
|
||||
QDateTime dateTime = fromDisplayTimeToDate(value);
|
||||
setVisibleDateTimeMax(dateTime);
|
||||
}
|
||||
auto s = m_visibleDateRangeMax().toString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimSummaryTimeAxisProperties::isAutoZoom() const
|
||||
{
|
||||
@ -205,7 +228,7 @@ bool RimSummaryTimeAxisProperties::isAutoZoom() const
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::setAutoZoom(bool enableAutoZoom)
|
||||
{
|
||||
@ -213,25 +236,25 @@ void RimSummaryTimeAxisProperties::setAutoZoom(bool enableAutoZoom)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::updateTimeVisibleRange()
|
||||
{
|
||||
m_visibleTimeRangeMax = fromDateToDisplayTime(m_visibleDateRangeMax());
|
||||
m_visibleTimeRangeMin = fromDateToDisplayTime(m_visibleDateRangeMin());
|
||||
m_visibleTimeSinceStartRangeMax = fromDateToDisplayTime(visibleDateTimeMax());
|
||||
m_visibleTimeSinceStartRangeMin = fromDateToDisplayTime(visibleDateTimeMin());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::updateDateVisibleRange()
|
||||
{
|
||||
m_visibleDateRangeMin = fromDisplayTimeToDate(m_visibleTimeRangeMin());
|
||||
m_visibleDateRangeMax = fromDisplayTimeToDate(m_visibleTimeRangeMax());
|
||||
setVisibleDateTimeMin(fromDisplayTimeToDate(m_visibleTimeSinceStartRangeMin()));
|
||||
setVisibleDateTimeMax(fromDisplayTimeToDate(m_visibleTimeSinceStartRangeMax()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RimSummaryTimeAxisProperties::fromDisplayTimeToDate(double displayTime)
|
||||
{
|
||||
@ -239,7 +262,7 @@ QDateTime RimSummaryTimeAxisProperties::fromDisplayTimeToDate(double displayTime
|
||||
this->firstAncestorOrThisOfType(rimSummaryPlot);
|
||||
time_t startOfSimulation = rimSummaryPlot->firstTimeStepOfFirstCurve();
|
||||
|
||||
time_t secsSinceSimulationStart = displayTime/fromTimeTToDisplayUnitScale();
|
||||
time_t secsSinceSimulationStart = displayTime / fromTimeTToDisplayUnitScale();
|
||||
QDateTime date;
|
||||
date.setTime_t(startOfSimulation + secsSinceSimulationStart);
|
||||
|
||||
@ -247,7 +270,7 @@ QDateTime RimSummaryTimeAxisProperties::fromDisplayTimeToDate(double displayTime
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::fromDateToDisplayTime(const QDateTime& displayTime)
|
||||
{
|
||||
@ -257,12 +280,11 @@ double RimSummaryTimeAxisProperties::fromDateToDisplayTime(const QDateTime& disp
|
||||
this->firstAncestorOrThisOfType(rimSummaryPlot);
|
||||
time_t startOfSimulation = rimSummaryPlot->firstTimeStepOfFirstCurve();
|
||||
|
||||
return fromTimeTToDisplayUnitScale()*(secsSinceEpoc - startOfSimulation);
|
||||
return fromTimeTToDisplayUnitScale() * (secsSinceEpoc - startOfSimulation);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimSummaryTimeAxisProperties::isActive() const
|
||||
{
|
||||
@ -270,15 +292,51 @@ bool RimSummaryTimeAxisProperties::isActive() const
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo> RimSummaryTimeAxisProperties::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly)
|
||||
QDateTime RimSummaryTimeAxisProperties::visibleDateTimeMin() const
|
||||
{
|
||||
QDateTime fullMin(m_visibleDateRangeMin(), m_visibleTimeRangeMin());
|
||||
return fullMin;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RimSummaryTimeAxisProperties::visibleDateTimeMax() const
|
||||
{
|
||||
QDateTime fullMax(m_visibleDateRangeMax(), m_visibleTimeRangeMax());
|
||||
return fullMax;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::setVisibleDateTimeMin(const QDateTime& dateTime)
|
||||
{
|
||||
m_visibleDateRangeMin = dateTime.date();
|
||||
m_visibleTimeRangeMin = dateTime.time();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::setVisibleDateTimeMax(const QDateTime& dateTime)
|
||||
{
|
||||
m_visibleDateRangeMax = dateTime.date();
|
||||
m_visibleTimeRangeMax = dateTime.time();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo> RimSummaryTimeAxisProperties::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly)
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
*useOptionsOnly = true;
|
||||
|
||||
if (&m_titleFontSize == fieldNeedingOptions ||
|
||||
&m_valuesFontSize == fieldNeedingOptions)
|
||||
if (&m_titleFontSize == fieldNeedingOptions || &m_valuesFontSize == fieldNeedingOptions)
|
||||
{
|
||||
std::vector<int> fontSizes;
|
||||
fontSizes.push_back(8);
|
||||
@ -297,12 +355,35 @@ QList<caf::PdmOptionItemInfo> RimSummaryTimeAxisProperties::calculateValueOption
|
||||
options.push_back(caf::PdmOptionItemInfo(text, value));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimSummaryTimeAxisProperties::objectToggleField()
|
||||
{
|
||||
@ -326,7 +407,7 @@ void RimSummaryTimeAxisProperties::setTimeMode(TimeModeType val)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::fromTimeTToDisplayUnitScale()
|
||||
{
|
||||
@ -334,59 +415,75 @@ double RimSummaryTimeAxisProperties::fromTimeTToDisplayUnitScale()
|
||||
switch (m_timeUnit())
|
||||
{
|
||||
case SECONDS:
|
||||
break;
|
||||
break;
|
||||
case MINUTES:
|
||||
scale = 1.0/60.0;
|
||||
break;
|
||||
scale = 1.0 / 60.0;
|
||||
break;
|
||||
case HOURS:
|
||||
scale = 1.0/(60.0*60.0);
|
||||
break;
|
||||
scale = 1.0 / (60.0 * 60.0);
|
||||
break;
|
||||
case DAYS:
|
||||
scale = 1.0/(60.0*60.0*24.0);
|
||||
break;
|
||||
scale = 1.0 / (60.0 * 60.0 * 24.0);
|
||||
break;
|
||||
case YEARS:
|
||||
scale = 1.0/31556952.0;
|
||||
break;
|
||||
scale = 1.0 / 31556952.0;
|
||||
break;
|
||||
default:
|
||||
CVF_ASSERT(false);
|
||||
break;
|
||||
CVF_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::fromDaysToDisplayUnitScale()
|
||||
{
|
||||
double scale = 1.0;
|
||||
switch (m_timeUnit())
|
||||
{
|
||||
case SECONDS:
|
||||
scale = 60.0 * 60.0 * 24.0;
|
||||
break;
|
||||
case MINUTES:
|
||||
scale = 60.0 * 24.0;
|
||||
break;
|
||||
case HOURS:
|
||||
scale = 24.0;
|
||||
break;
|
||||
case DAYS:
|
||||
break;
|
||||
case YEARS:
|
||||
scale = 1.0/365.2425;
|
||||
break;
|
||||
default:
|
||||
CVF_ASSERT(false);
|
||||
break;
|
||||
case SECONDS:
|
||||
scale = 60.0 * 60.0 * 24.0;
|
||||
break;
|
||||
case MINUTES:
|
||||
scale = 60.0 * 24.0;
|
||||
break;
|
||||
case HOURS:
|
||||
scale = 24.0;
|
||||
break;
|
||||
case DAYS:
|
||||
break;
|
||||
case YEARS:
|
||||
scale = 1.0 / 365.2425;
|
||||
break;
|
||||
default:
|
||||
CVF_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString& RimSummaryTimeAxisProperties::dateFormat() const
|
||||
{
|
||||
return m_dateFormat();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString& RimSummaryTimeAxisProperties::timeFormat() const
|
||||
{
|
||||
return m_timeFormat();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
@ -396,18 +493,22 @@ void RimSummaryTimeAxisProperties::defineUiOrdering(QString uiConfigName, caf::P
|
||||
titleGroup.add(&m_titlePositionEnum);
|
||||
titleGroup.add(&m_titleFontSize);
|
||||
|
||||
caf::PdmUiGroup* timeGroup = uiOrdering.addNewGroup("Time Values");
|
||||
caf::PdmUiGroup* timeGroup = uiOrdering.addNewGroup("Time Values");
|
||||
timeGroup->add(&m_timeMode);
|
||||
if (m_timeMode() == DATE)
|
||||
{
|
||||
timeGroup->add( &m_visibleDateRangeMax);
|
||||
timeGroup->add(&m_visibleDateRangeMin);
|
||||
timeGroup->add(&m_visibleDateRangeMax, true);
|
||||
timeGroup->add(&m_visibleTimeRangeMax, false);
|
||||
timeGroup->add(&m_visibleDateRangeMin, true);
|
||||
timeGroup->add(&m_visibleTimeRangeMin, false);
|
||||
timeGroup->add(&m_dateFormat);
|
||||
timeGroup->add(&m_timeFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
timeGroup->add(&m_timeUnit);
|
||||
timeGroup->add(&m_visibleTimeRangeMax);
|
||||
timeGroup->add(&m_visibleTimeRangeMin);
|
||||
timeGroup->add(&m_timeUnit);
|
||||
timeGroup->add(&m_visibleTimeSinceStartRangeMax);
|
||||
timeGroup->add(&m_visibleTimeSinceStartRangeMin);
|
||||
}
|
||||
timeGroup->add(&m_valuesFontSize);
|
||||
|
||||
@ -415,9 +516,11 @@ void RimSummaryTimeAxisProperties::defineUiOrdering(QString uiConfigName, caf::P
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
|
||||
void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
|
||||
const QVariant& oldValue,
|
||||
const QVariant& newValue)
|
||||
{
|
||||
RimSummaryPlot* rimSummaryPlot = nullptr;
|
||||
this->firstAncestorOrThisOfType(rimSummaryPlot);
|
||||
@ -425,10 +528,21 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c
|
||||
|
||||
if (changedField == &m_visibleDateRangeMax)
|
||||
{
|
||||
QDateTime test = newValue.toDateTime();
|
||||
QDate test = newValue.toDate();
|
||||
if (!test.isValid())
|
||||
{
|
||||
m_visibleDateRangeMax = oldValue.toDateTime();
|
||||
m_visibleDateRangeMax = oldValue.toDate();
|
||||
}
|
||||
|
||||
updateTimeVisibleRange();
|
||||
m_isAutoZoom = false;
|
||||
}
|
||||
else if (changedField == &m_visibleTimeRangeMax)
|
||||
{
|
||||
QTime test = newValue.toTime();
|
||||
if (!test.isValid())
|
||||
{
|
||||
m_visibleTimeRangeMax = oldValue.toTime();
|
||||
}
|
||||
|
||||
updateTimeVisibleRange();
|
||||
@ -436,16 +550,27 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c
|
||||
}
|
||||
else if (changedField == &m_visibleDateRangeMin)
|
||||
{
|
||||
QDateTime test = newValue.toDateTime();
|
||||
QDate test = newValue.toDate();
|
||||
if (!test.isValid())
|
||||
{
|
||||
m_visibleDateRangeMin = oldValue.toDateTime();
|
||||
m_visibleDateRangeMin = oldValue.toDate();
|
||||
}
|
||||
|
||||
updateTimeVisibleRange();
|
||||
m_isAutoZoom = false;
|
||||
}
|
||||
else if (changedField == &m_visibleTimeRangeMin || changedField == &m_visibleTimeRangeMax)
|
||||
else if (changedField == &m_visibleTimeRangeMin)
|
||||
{
|
||||
QTime test = newValue.toTime();
|
||||
if (!test.isValid())
|
||||
{
|
||||
m_visibleTimeRangeMin = oldValue.toTime();
|
||||
}
|
||||
|
||||
updateTimeVisibleRange();
|
||||
m_isAutoZoom = false;
|
||||
}
|
||||
else if (changedField == &m_visibleTimeSinceStartRangeMin || changedField == &m_visibleTimeSinceStartRangeMax)
|
||||
{
|
||||
updateDateVisibleRange();
|
||||
m_isAutoZoom = false;
|
||||
@ -460,7 +585,58 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c
|
||||
rimSummaryPlot->loadDataAndUpdate();
|
||||
updateDateVisibleRange();
|
||||
}
|
||||
else if (changedField == &m_dateFormat || changedField == &m_timeFormat)
|
||||
{
|
||||
updateTimeVisibleRange(); // Use the stored max min dates to update the visible time range to new unit
|
||||
rimSummaryPlot->loadDataAndUpdate();
|
||||
updateDateVisibleRange();
|
||||
}
|
||||
|
||||
rimSummaryPlot->updateAxes();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::initAfterRead()
|
||||
{
|
||||
QDateTime maxDateTime = m_visibleDateTimeRangeMax_OBSOLETE();
|
||||
QDateTime minDateTime = m_visibleDateTimeRangeMin_OBSOLETE();
|
||||
if (maxDateTime.isValid())
|
||||
{
|
||||
m_visibleDateRangeMax = maxDateTime.date();
|
||||
m_visibleTimeRangeMax = maxDateTime.time();
|
||||
}
|
||||
if (minDateTime.isValid())
|
||||
{
|
||||
m_visibleDateRangeMin = minDateTime.date();
|
||||
m_visibleTimeRangeMin = minDateTime.time();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::defineEditorAttribute(const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute)
|
||||
{
|
||||
if (field == &m_visibleDateRangeMin || field == &m_visibleDateRangeMax)
|
||||
{
|
||||
auto dateAttrib = dynamic_cast<caf::PdmUiDateEditorAttribute*>(attribute);
|
||||
if (dateAttrib)
|
||||
{
|
||||
dateAttrib->dateFormat =
|
||||
RiaQDateTimeTools::dateFormatString(m_dateFormat(), RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY);
|
||||
}
|
||||
}
|
||||
else if (field == &m_visibleTimeRangeMin || field == &m_visibleTimeRangeMax)
|
||||
{
|
||||
auto timeAttrib = dynamic_cast<caf::PdmUiTimeEditorAttribute*>(attribute);
|
||||
if (timeAttrib)
|
||||
{
|
||||
timeAttrib->timeFormat =
|
||||
RiaQDateTimeTools::timeFormatString(m_timeFormat(), RiaQDateTimeTools::TIME_FORMAT_HOUR_MINUTE_SECOND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaQDateTimeTools.h"
|
||||
#include "RimPlotAxisPropertiesInterface.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
@ -70,6 +71,9 @@ public:
|
||||
double fromTimeTToDisplayUnitScale();
|
||||
double fromDaysToDisplayUnitScale();
|
||||
|
||||
const QString& dateFormat() const;
|
||||
const QString& timeFormat() const;
|
||||
|
||||
double visibleRangeMin() const;
|
||||
double visibleRangeMax() const;
|
||||
|
||||
@ -81,30 +85,49 @@ public:
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
QDateTime visibleDateTimeMin() const;
|
||||
QDateTime visibleDateTimeMax() const;
|
||||
|
||||
void setVisibleDateTimeMin(const QDateTime& dateTime);
|
||||
void setVisibleDateTimeMax(const QDateTime& dateTime);
|
||||
|
||||
protected:
|
||||
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override;
|
||||
caf::PdmFieldHandle* objectToggleField() override;
|
||||
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
|
||||
void initAfterRead() override;
|
||||
void defineEditorAttribute(const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute) override;
|
||||
|
||||
double fromDateToDisplayTime(const QDateTime& displayTime);
|
||||
QDateTime fromDisplayTimeToDate(double displayTime);
|
||||
void updateTimeVisibleRange();
|
||||
void updateDateVisibleRange();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
caf::PdmField< caf::AppEnum< TimeModeType > > m_timeMode;
|
||||
caf::PdmField< caf::AppEnum< TimeUnitType > > m_timeUnit;
|
||||
|
||||
caf::PdmField<bool> m_isActive;
|
||||
caf::PdmField<QDateTime> m_visibleDateRangeMin;
|
||||
caf::PdmField<QDateTime> m_visibleDateRangeMax;
|
||||
caf::PdmField<double> m_visibleTimeRangeMin;
|
||||
caf::PdmField<double> m_visibleTimeRangeMax;
|
||||
caf::PdmField<QDate> m_visibleDateRangeMin;
|
||||
caf::PdmField<QDate> m_visibleDateRangeMax;
|
||||
caf::PdmField<QTime> m_visibleTimeRangeMin;
|
||||
caf::PdmField<QTime> m_visibleTimeRangeMax;
|
||||
|
||||
caf::PdmField<double> m_visibleTimeSinceStartRangeMin;
|
||||
caf::PdmField<double> m_visibleTimeSinceStartRangeMax;
|
||||
caf::PdmField<bool> m_isAutoZoom;
|
||||
|
||||
caf::PdmField<int> m_titleFontSize;
|
||||
caf::PdmField<caf::AppEnum<AxisTitlePositionType>> m_titlePositionEnum;
|
||||
caf::PdmField<int> m_valuesFontSize;
|
||||
caf::PdmField<QString> m_dateFormat;
|
||||
caf::PdmField<QString> m_timeFormat;
|
||||
|
||||
caf::PdmField<QDateTime> m_visibleDateTimeRangeMin_OBSOLETE;
|
||||
caf::PdmField<QDateTime> m_visibleDateTimeRangeMax_OBSOLETE;
|
||||
};
|
||||
|
@ -82,7 +82,11 @@ RiuFlowCharacteristicsPlot::RiuFlowCharacteristicsPlot(RimFlowCharacteristicsPlo
|
||||
RiuQwtPlotTools::setCommonPlotBehaviour(m_lorenzPlot);
|
||||
new RiuQwtPlotWheelZoomer(m_lorenzPlot);
|
||||
addWindowZoom(m_lorenzPlot);
|
||||
RiuQwtPlotTools::enableDateBasedBottomXAxis(m_lorenzPlot);
|
||||
|
||||
QString dateFormat = RiaApplication::instance()->preferences()->dateFormat();
|
||||
QString timeFormat = RiaApplication::instance()->preferences()->timeFormat();
|
||||
|
||||
RiuQwtPlotTools::enableDateBasedBottomXAxis(m_lorenzPlot, dateFormat, timeFormat);
|
||||
m_lorenzPlot->setTitle("Lorenz Coefficient");
|
||||
|
||||
RiuQwtPlotTools::setCommonPlotBehaviour(m_sweepEffPlot);
|
||||
|
@ -17,12 +17,16 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RiuQwtPlotTools.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "qwt_date_scale_draw.h"
|
||||
#include "qwt_date_scale_engine.h"
|
||||
#include "qwt_plot.h"
|
||||
#include "qwt_plot_grid.h"
|
||||
#include "qwt_plot_layout.h"
|
||||
|
||||
#include <QRegExp>
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -63,8 +67,8 @@ void RiuQwtPlotTools::setCommonPlotBehaviour(QwtPlot* plot)
|
||||
plot->setAxisFont(QwtPlot::yRight, axisFont);
|
||||
|
||||
// Axis title font
|
||||
std::vector<QwtPlot::Axis> axes = { QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, QwtPlot::yRight };
|
||||
|
||||
std::vector<QwtPlot::Axis> axes = {QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, QwtPlot::yRight};
|
||||
|
||||
for (QwtPlot::Axis axis : axes)
|
||||
{
|
||||
QwtText axisTitle = plot->axisTitle(axis);
|
||||
@ -108,12 +112,69 @@ void RiuQwtPlotTools::setDefaultAxes(QwtPlot* plot)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotTools::enableDateBasedBottomXAxis(QwtPlot* plot)
|
||||
void RiuQwtPlotTools::enableDateBasedBottomXAxis(QwtPlot* plot,
|
||||
const QString& dateFormat,
|
||||
const QString& timeFormat)
|
||||
{
|
||||
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
|
||||
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
|
||||
|
||||
std::set<QwtDate::IntervalType> intervals = {QwtDate::Year,
|
||||
QwtDate::Month,
|
||||
QwtDate::Week,
|
||||
QwtDate::Day,
|
||||
QwtDate::Hour,
|
||||
QwtDate::Minute,
|
||||
QwtDate::Second,
|
||||
QwtDate::Millisecond};
|
||||
|
||||
for (QwtDate::IntervalType interval : intervals)
|
||||
{
|
||||
scaleDraw->setDateFormat(interval, dateTimeFormatForInterval(interval, dateFormat, timeFormat));
|
||||
}
|
||||
|
||||
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
|
||||
plot->setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
|
||||
plot->setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuQwtPlotTools::dateTimeFormatForInterval(QwtDate::IntervalType interval,
|
||||
const QString& dateFormat,
|
||||
const QString& timeFormat)
|
||||
{
|
||||
switch (interval)
|
||||
{
|
||||
case QwtDate::Millisecond:
|
||||
return RiaQDateTimeTools::timeFormatString(timeFormat, RiaQDateTimeTools::TIME_FORMAT_HOUR_MINUTE_SECOND_MILLISECOND);
|
||||
case QwtDate::Second:
|
||||
return RiaQDateTimeTools::timeFormatString(timeFormat, RiaQDateTimeTools::TIME_FORMAT_HOUR_MINUTE_SECOND);
|
||||
case QwtDate::Minute: {
|
||||
QString fullFormat = RiaQDateTimeTools::timeFormatString(timeFormat, RiaQDateTimeTools::TIME_FORMAT_HOUR_MINUTE);
|
||||
fullFormat += "\n";
|
||||
fullFormat += RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY);
|
||||
return fullFormat;
|
||||
}
|
||||
case QwtDate::Hour: {
|
||||
QString fullFormat = RiaQDateTimeTools::timeFormatString(timeFormat, RiaQDateTimeTools::TIME_FORMAT_HOUR);
|
||||
if (!fullFormat.endsWith("AP"))
|
||||
{
|
||||
fullFormat += ":00";
|
||||
}
|
||||
fullFormat += "\n";
|
||||
fullFormat += RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY);
|
||||
return fullFormat;
|
||||
}
|
||||
case QwtDate::Day:
|
||||
return RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY);
|
||||
case QwtDate::Week:
|
||||
return RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH);
|
||||
case QwtDate::Month:
|
||||
return RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH);
|
||||
case QwtDate::Year:
|
||||
return RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR);
|
||||
default:
|
||||
return RiaQDateTimeTools::dateFormatString(dateFormat, RiaQDateTimeTools::DATE_FORMAT_YEAR_MONTH_DAY);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,9 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "RiaQDateTimeTools.h"
|
||||
#include <qwt_date.h>
|
||||
|
||||
class QwtPlot;
|
||||
|
||||
class RiuQwtPlotTools
|
||||
@ -24,6 +27,8 @@ class RiuQwtPlotTools
|
||||
public:
|
||||
static void setCommonPlotBehaviour(QwtPlot* plot);
|
||||
static void setDefaultAxes(QwtPlot* plot);
|
||||
static void enableDateBasedBottomXAxis(QwtPlot* plot);
|
||||
};
|
||||
static void enableDateBasedBottomXAxis(QwtPlot* plot, const QString& dateFormat, const QString& timeFormat);
|
||||
|
||||
static QString
|
||||
dateTimeFormatForInterval(QwtDate::IntervalType interval, const QString& dateFormat, const QString& timeFormat);
|
||||
};
|
||||
|
@ -183,7 +183,10 @@ void RiuResultQwtPlot::setDefaults()
|
||||
enableAxis(QwtPlot::xTop, false);
|
||||
enableAxis(QwtPlot::yRight, false);
|
||||
|
||||
RiuQwtPlotTools::enableDateBasedBottomXAxis(this);
|
||||
QString dateFormat = RiaApplication::instance()->preferences()->dateFormat();
|
||||
QString timeFormat = RiaApplication::instance()->preferences()->timeFormat();
|
||||
|
||||
RiuQwtPlotTools::enableDateBasedBottomXAxis(this, dateFormat, timeFormat);
|
||||
|
||||
setAxisMaxMinor(QwtPlot::xBottom, 2);
|
||||
setAxisMaxMinor(QwtPlot::yLeft, 3);
|
||||
|
@ -17,6 +17,9 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RiuSummaryQwtPlot.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimEnsembleCurveSetCollection.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
@ -98,9 +101,10 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimViewWindow* viewWindow, QWidget* parent
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::useDateBasedTimeAxis()
|
||||
void RiuSummaryQwtPlot::useDateBasedTimeAxis(const QString& dateFormat,
|
||||
const QString& timeFormat)
|
||||
{
|
||||
RiuQwtPlotTools::enableDateBasedBottomXAxis(this);
|
||||
RiuQwtPlotTools::enableDateBasedBottomXAxis(this, dateFormat, timeFormat);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -198,7 +202,10 @@ void RiuSummaryQwtPlot::contextMenuEvent(QContextMenuEvent* event)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::setDefaults()
|
||||
{
|
||||
useDateBasedTimeAxis();
|
||||
QString dateFormat = RiaApplication::instance()->preferences()->dateFormat();
|
||||
QString timeFormat = RiaApplication::instance()->preferences()->timeFormat();
|
||||
|
||||
useDateBasedTimeAxis(dateFormat, timeFormat);
|
||||
|
||||
// The legend will be deleted in the destructor of the plot or when
|
||||
// another legend is inserted.
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaQDateTimeTools.h"
|
||||
#include "RiuInterfaceToViewWindow.h"
|
||||
#include "RiuQwtPlot.h"
|
||||
|
||||
@ -40,7 +41,7 @@ class RiuSummaryQwtPlot : public RiuQwtPlot
|
||||
public:
|
||||
RiuSummaryQwtPlot(RimViewWindow* ownerViewWindow, QWidget* parent = nullptr);
|
||||
|
||||
void useDateBasedTimeAxis();
|
||||
void useDateBasedTimeAxis(const QString& dateFormat, const QString& timeFormat);
|
||||
void useTimeBasedTimeAxis();
|
||||
|
||||
void addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet* curveSetToShowLegendFor);
|
||||
|
@ -41,3 +41,41 @@ QTextStream& operator << (QTextStream& str, const QDateTime& value)
|
||||
str << text;
|
||||
return str;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Specialized read operation for QDates
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include <QDate>
|
||||
QTextStream& operator >> (QTextStream& str, QDate& value)
|
||||
{
|
||||
QString text;
|
||||
str >> text;
|
||||
value = QDate::fromString(text, "yyyy_MM_dd");
|
||||
return str;
|
||||
}
|
||||
|
||||
QTextStream& operator << (QTextStream& str, const QDate& value)
|
||||
{
|
||||
QString text = value.toString("yyyy_MM_dd");
|
||||
str << text;
|
||||
return str;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Specialized read operation for QTimes
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include <QTime>
|
||||
QTextStream& operator >> (QTextStream& str, QTime& value)
|
||||
{
|
||||
QString text;
|
||||
str >> text;
|
||||
value = QTime::fromString(text, "HH:mm:ss");
|
||||
return str;
|
||||
}
|
||||
|
||||
QTextStream& operator << (QTextStream& str, const QTime& value)
|
||||
{
|
||||
QString text = value.toString("HH:mm:ss");
|
||||
str << text;
|
||||
return str;
|
||||
}
|
||||
|
@ -19,6 +19,22 @@ QTextStream& operator << (QTextStream& str, const bool& value);
|
||||
QTextStream& operator >> (QTextStream& str, QDateTime& value);
|
||||
QTextStream& operator << (QTextStream& str, const QDateTime& value);
|
||||
|
||||
//==================================================================================================
|
||||
/// QTextStream Stream operator overloading for QDates
|
||||
///
|
||||
//==================================================================================================
|
||||
//class QDate;
|
||||
QTextStream& operator >> (QTextStream& str, QDate& value);
|
||||
QTextStream& operator << (QTextStream& str, const QDate& value);
|
||||
|
||||
//==================================================================================================
|
||||
/// QTextStream Stream operator overloading for QTimes
|
||||
///
|
||||
//==================================================================================================
|
||||
//class QTime;
|
||||
QTextStream& operator >> (QTextStream& str, QTime& value);
|
||||
QTextStream& operator << (QTextStream& str, const QTime& value);
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
/// QTextStream Stream operator overloading for std::vector of things.
|
||||
|
@ -15,6 +15,7 @@ set (MOC_HEADER_FILES
|
||||
cafPdmUiColorEditor.h
|
||||
cafPdmUiComboBoxEditor.h
|
||||
cafPdmUiDateEditor.h
|
||||
cafPdmUiTimeEditor.h
|
||||
cafPdmUiDefaultObjectEditor.h
|
||||
cafPdmUiDoubleSliderEditor.h
|
||||
cafPdmUiFilePathEditor.h
|
||||
@ -71,6 +72,8 @@ set( PROJECT_FILES
|
||||
cafPdmUiComboBoxEditor.h
|
||||
cafPdmUiDateEditor.cpp
|
||||
cafPdmUiDateEditor.h
|
||||
cafPdmUiTimeEditor.cpp
|
||||
cafPdmUiTimeEditor.h
|
||||
cafPdmUiDoubleSliderEditor.cpp
|
||||
cafPdmUiDoubleSliderEditor.h
|
||||
cafPdmUiDragDropInterface.h
|
||||
|
@ -88,6 +88,7 @@ void PdmUiDateEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
|
||||
m_dateEdit->setDate(uiField()->uiValue().toDate());
|
||||
m_dateEdit->setTime(uiField()->uiValue().toTime());
|
||||
}
|
||||
|
||||
|
||||
@ -96,7 +97,7 @@ void PdmUiDateEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiDateEditor::createEditorWidget(QWidget* parent)
|
||||
{
|
||||
m_dateEdit = new QDateEdit(parent);
|
||||
m_dateEdit = new QDateTimeEdit(parent);
|
||||
m_dateEdit->setCalendarPopup(true);
|
||||
connect(m_dateEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
|
||||
return m_dateEdit;
|
||||
@ -116,7 +117,7 @@ QWidget* PdmUiDateEditor::createLabelWidget(QWidget* parent)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiDateEditor::slotEditingFinished()
|
||||
{
|
||||
this->setValueToField(m_dateEdit->date());
|
||||
this->setValueToField(m_dateEdit->dateTime());
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
|
||||
#include <QDateEdit>
|
||||
#include <QDateTimeEdit>
|
||||
#include <QLabel>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
@ -83,7 +83,7 @@ protected slots:
|
||||
void slotEditingFinished();
|
||||
|
||||
private:
|
||||
QPointer<QDateEdit> m_dateEdit;
|
||||
QPointer<QDateTimeEdit> m_dateEdit;
|
||||
QPointer<QShortenedLabel> m_label;
|
||||
|
||||
PdmUiDateEditorAttribute m_attributes;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "cafPdmProxyValueField.h"
|
||||
#include "cafPdmUiCheckBoxEditor.h"
|
||||
#include "cafPdmUiDateEditor.h"
|
||||
#include "cafPdmUiTimeEditor.h"
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafPdmUiFilePathEditor.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
@ -57,6 +58,7 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiCheckBoxEditor, bool);
|
||||
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, QString);
|
||||
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiDateEditor, QDate);
|
||||
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiDateEditor, QDateTime);
|
||||
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiTimeEditor, QTime);
|
||||
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, int);
|
||||
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, double);
|
||||
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, float);
|
||||
|
121
Fwk/AppFwk/cafUserInterface/cafPdmUiTimeEditor.cpp
Normal file
121
Fwk/AppFwk/cafUserInterface/cafPdmUiTimeEditor.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cafPdmUiTimeEditor.h"
|
||||
|
||||
#include "cafFactory.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiDefaultObjectEditor.h"
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
#include "cafSelectionManager.h"
|
||||
#include "cafQShortenedLabel.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDate>
|
||||
#include <QGridLayout>
|
||||
#include <QIntValidator>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QPalette>
|
||||
#include <QStatusBar>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiTimeEditor);
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTimeEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
{
|
||||
CAF_ASSERT(!m_timeEdit.isNull());
|
||||
|
||||
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
|
||||
|
||||
m_timeEdit->setEnabled(!uiField()->isUiReadOnly(uiConfigName));
|
||||
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
|
||||
if (uiObject)
|
||||
{
|
||||
uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &m_attributes);
|
||||
}
|
||||
|
||||
if (!m_attributes.timeFormat.isEmpty())
|
||||
{
|
||||
m_timeEdit->setDisplayFormat(m_attributes.timeFormat);
|
||||
}
|
||||
|
||||
m_timeEdit->setDate(uiField()->uiValue().toDate());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiTimeEditor::createEditorWidget(QWidget* parent)
|
||||
{
|
||||
m_timeEdit = new QTimeEdit(parent);
|
||||
connect(m_timeEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
|
||||
return m_timeEdit;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiTimeEditor::createLabelWidget(QWidget* parent)
|
||||
{
|
||||
m_label = new QShortenedLabel(parent);
|
||||
return m_label;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTimeEditor::slotEditingFinished()
|
||||
{
|
||||
this->setValueToField(m_timeEdit->date());
|
||||
}
|
||||
|
||||
} // end namespace caf
|
93
Fwk/AppFwk/cafUserInterface/cafPdmUiTimeEditor.h
Normal file
93
Fwk/AppFwk/cafUserInterface/cafPdmUiTimeEditor.h
Normal file
@ -0,0 +1,93 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2019- Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
|
||||
#include <QTimeEdit>
|
||||
#include <QLabel>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class PdmUiTimeEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
QString timeFormat;
|
||||
|
||||
public:
|
||||
PdmUiTimeEditorAttribute()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class PdmUiTimeEditor : public PdmUiFieldEditorHandle
|
||||
{
|
||||
Q_OBJECT
|
||||
CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT;
|
||||
|
||||
public:
|
||||
PdmUiTimeEditor() {}
|
||||
~PdmUiTimeEditor() override {}
|
||||
|
||||
protected:
|
||||
QWidget* createEditorWidget(QWidget * parent) override;
|
||||
QWidget* createLabelWidget(QWidget * parent) override;
|
||||
void configureAndUpdateUi(const QString& uiConfigName) override;
|
||||
|
||||
protected slots:
|
||||
void slotEditingFinished();
|
||||
|
||||
private:
|
||||
QPointer<QTimeEdit> m_timeEdit;
|
||||
QPointer<QShortenedLabel> m_label;
|
||||
|
||||
PdmUiTimeEditorAttribute m_attributes;
|
||||
};
|
||||
|
||||
|
||||
} // end namespace caf
|
Loading…
Reference in New Issue
Block a user