commit 10f4f2113aa7ed45af7b6aca50e76d4bf9772732
Author: Juergen Spitzmueller <[email protected]>
Date: Fri Mar 12 10:32:03 2021 +0100
Fix deprecation warning (from|toTime_t)
---
src/frontends/qt/GuiApplication.cpp | 2 +-
src/frontends/qt/GuiChanges.cpp | 6 ++++++
src/insets/InsetInfo.cpp | 16 ++++++++++++++++
src/support/ConsoleApplicationPrivate.h | 2 +-
src/support/FileName.cpp | 5 +++++
src/support/lyxtime.cpp | 13 +++++++++++++
6 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/frontends/qt/GuiApplication.cpp
b/src/frontends/qt/GuiApplication.cpp
index 0ed875f..e500fa0 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -1089,7 +1089,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
- QRandomGenerator(QDateTime::currentDateTime().toTime_t());
+ QRandomGenerator(QDateTime::currentDateTime().toSecsSinceEpoch());
#else
qsrand(QDateTime::currentDateTime().toTime_t());
#endif
diff --git a/src/frontends/qt/GuiChanges.cpp b/src/frontends/qt/GuiChanges.cpp
index eda161d..b2f809b 100644
--- a/src/frontends/qt/GuiChanges.cpp
+++ b/src/frontends/qt/GuiChanges.cpp
@@ -70,9 +70,15 @@ void GuiChanges::updateContents()
text += inserted ? qt_("Inserted by %1").arg(author)
: qt_("Deleted by %1").arg(author);
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ QString const date =
+
QLocale().toString(QDateTime::fromSecsSinceEpoch(c.changetime),
+ QLocale::LongFormat);
+#else
QString const date =
QLocale().toString(QDateTime::fromTime_t(c.changetime),
QLocale::LongFormat);
+#endif
if (!date.isEmpty()) {
if (!author.isEmpty())
text += qt_(" on[[date]] %1").arg(date);
diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp
index 819d8ff..61b39ad 100644
--- a/src/insets/InsetInfo.cpp
+++ b/src/insets/InsetInfo.cpp
@@ -297,7 +297,11 @@ vector<pair<string,docstring>>
InsetInfoParams::getArguments(Buffer const * buf,
string const dt = split(name, '@');
QDate date;
if (itype == "moddate")
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ date =
QDateTime::fromSecsSinceEpoch(buf->fileName().lastModified()).date();
+#else
date =
QDateTime::fromTime_t(buf->fileName().lastModified()).date();
+#endif
else if (itype == "fixdate" && !dt.empty()) {
QDate const gdate = QDate::fromString(toqstr(dt),
Qt::ISODate);
date = (gdate.isValid()) ? gdate : QDate::currentDate();
@@ -323,7 +327,11 @@ vector<pair<string,docstring>>
InsetInfoParams::getArguments(Buffer const * buf,
string const tt = split(name, '@');
QTime time;
if (itype == "modtime")
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ time =
QDateTime::fromSecsSinceEpoch(buf->fileName().lastModified()).time();
+#else
time =
QDateTime::fromTime_t(buf->fileName().lastModified()).time();
+#endif
else if (itype == "fixtime" && !tt.empty()) {
QTime const gtime = QTime::fromString(toqstr(tt),
Qt::ISODate);
time = (gtime.isValid()) ? gtime : QTime::currentTime();
@@ -1149,7 +1157,11 @@ void InsetInfo::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
? split(params_.name, date_format, '@') :
string();
QDate date;
if (params_.type == InsetInfoParams::MODDATE_INFO)
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ date =
QDateTime::fromSecsSinceEpoch(buffer().fileName().lastModified()).date();
+#else
date =
QDateTime::fromTime_t(buffer().fileName().lastModified()).date();
+#endif
else if (params_.type == InsetInfoParams::FIXDATE_INFO &&
!date_specifier.empty())
date = QDate::fromString(toqstr(date_specifier),
Qt::ISODate);
else
@@ -1166,7 +1178,11 @@ void InsetInfo::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
? split(params_.name, time_format, '@') :
string();
QTime time;
if (params_.type == InsetInfoParams::MODTIME_INFO)
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ time =
QDateTime::fromSecsSinceEpoch(buffer().fileName().lastModified()).time();
+#else
time =
QDateTime::fromTime_t(buffer().fileName().lastModified()).time();
+#endif
else if (params_.type == InsetInfoParams::FIXTIME_INFO &&
!time_specifier.empty())
time = QTime::fromString(toqstr(time_specifier),
Qt::ISODate);
else
diff --git a/src/support/ConsoleApplicationPrivate.h
b/src/support/ConsoleApplicationPrivate.h
index 097a02d..347f9ad 100644
--- a/src/support/ConsoleApplicationPrivate.h
+++ b/src/support/ConsoleApplicationPrivate.h
@@ -42,7 +42,7 @@ public:
setApplicationName(toqstr(app));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
- QRandomGenerator(QDateTime::currentDateTime().toTime_t());
+
QRandomGenerator(QDateTime::currentDateTime().toSecsSinceEpoch());
#else
qsrand(QDateTime::currentDateTime().toTime_t());
#endif
diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp
index 5295741..69e0211 100644
--- a/src/support/FileName.cpp
+++ b/src/support/FileName.cpp
@@ -519,7 +519,12 @@ time_t FileName::lastModified() const
// been touched between the object creation and now, we refresh the file
// information.
d->refresh();
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ return d->fi.lastModified().toSecsSinceEpoch();
+#else
return d->fi.lastModified().toTime_t();
+#endif
+
}
diff --git a/src/support/lyxtime.cpp b/src/support/lyxtime.cpp
index c155ed4..87e05d5 100644
--- a/src/support/lyxtime.cpp
+++ b/src/support/lyxtime.cpp
@@ -34,11 +34,20 @@ time_t current_time()
docstring formatted_datetime(time_t t, string const & fmt)
{
QString qres;
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ if (fmt.empty())
+ qres = QLocale().toString(QDateTime::fromSecsSinceEpoch(t),
+ QLocale::ShortFormat);
+ else
+ qres = QLocale().toString(QDateTime::fromSecsSinceEpoch(t),
+ toqstr(fmt));
+#else
if (fmt.empty())
qres = QLocale().toString(QDateTime::fromTime_t(t),
QLocale::ShortFormat);
else
qres = QLocale().toString(QDateTime::fromTime_t(t),
toqstr(fmt));
+#endif
return qstring_to_ucs4(qres);
}
@@ -61,7 +70,11 @@ time_t from_asctime_utc(string t)
return static_cast<time_t>(-1);
}
loc_dt.setTimeSpec(Qt::UTC);
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+ return loc_dt.toSecsSinceEpoch();
+#else
return loc_dt.toTime_t();
+#endif
}
} // namespace support
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs